Example usage for org.apache.commons.lang StringUtils contains

List of usage examples for org.apache.commons.lang StringUtils contains

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils contains.

Prototype

public static boolean contains(String str, String searchStr) 

Source Link

Document

Checks if String contains a search String, handling null.

Usage

From source file:edu.ku.brc.specify.conversion.CollectionInfo.java

/**
 * @param oldDBConn/*ww w. ja v  a 2 s .  c  o  m*/
 * @return
 */
public static Vector<CollectionInfo> getCollectionInfoList(final Connection oldDBConn,
        final boolean doSkipCheck) {
    //collectionInfoList.clear();
    if (collectionInfoList.isEmpty()) {

        String hostTaxonID = "SELECT Count(tn.TaxonomicUnitTypeID) FROM habitat h "
                + "INNER JOIN taxonname tn ON h.HostTaxonID = tn.TaxonNameID WHERE tn.TaxonomyTypeId = ";

        /*String sql = "SELECT cot.CollectionObjectTypeID, cot.CollectionObjectTypeName, csd.CatalogSeriesDefinitionID, csd.CatalogSeriesID FROM collectionobjecttype cot " +
                 "INNER JOIN catalogseriesdefinition csd on " + 
                 "csd.ObjectTypeId = cot.CollectionObjectTypeId WHERE cot.Category = 'Biological' ORDER BY cot.CollectionObjectTypeID, csd.CatalogSeriesID";
        */

        String catSeriesSQL = "SELECT SeriesName, CatalogSeriesPrefix, Remarks, LastEditedBy FROM catalogseries WHERE CatalogSeriesID = ";

        String cntTaxonName = "SELECT COUNT(TaxonNameID) FROM taxonname WHERE TaxonName IS NOT NULL AND TaxonomyTypeId = ";

        String colObjCountPerCatSeriesSQL = "SELECT COUNT(cc.CatalogSeriesID) " + //, cc.CatalogSeriesID, cs.SeriesName " +
                "FROM collectionobjectcatalog cc INNER JOIN catalogseries cs ON cc.CatalogSeriesID = cs.CatalogSeriesID "
                + "WHERE cs.CatalogSeriesID = %d GROUP BY cs.CatalogSeriesID";

        String colObjDetCountPerCatSeriesSQL = "SELECT COUNT(cc.CatalogSeriesID) "
                + "FROM determination d INNER JOIN collectionobject co ON d.BiologicalObjectID = co.CollectionObjectID "
                + "INNER JOIN collectionobjectcatalog cc ON co.CollectionObjectID = cc.CollectionObjectCatalogID "
                + "WHERE cc.CatalogSeriesID = %d AND d.TaxonNameID IS NOT NULL GROUP BY cc.CatalogSeriesID";

        String colObjCatSeriesSQL = "SELECT cot.CollectionObjectTypeID, cot.CollectionObjectTypeName, csd.CatalogSeriesDefinitionID, csd.CatalogSeriesID FROM collectionobjecttype cot "
                + "INNER JOIN catalogseriesdefinition csd on csd.ObjectTypeId = cot.CollectionObjectTypeId "
                + "WHERE cot.Category = 'Biological' ORDER BY cot.CollectionObjectTypeID, csd.CatalogSeriesID";

        Statement stmt = null;

        try {
            pw = new PrintWriter(String.format("sql_%d.log", pwPassCnt++));

            log.debug(colObjCatSeriesSQL);
            logSQL("ColObj Cat Series", colObjCatSeriesSQL);

            HashSet<Integer> taxonTypeIdHash = new HashSet<Integer>();

            stmt = oldDBConn.createStatement();
            ResultSet rs = stmt.executeQuery(colObjCatSeriesSQL);
            while (rs.next()) {
                CollectionInfo info = new CollectionInfo(oldDBConn);

                Integer colObjTypeID = rs.getInt(1);
                pw.println(String.format(
                        "%d ================================================================================",
                        colObjTypeID));

                System.err.println("ColObjType: " + colObjTypeID);

                info.setColObjTypeId(colObjTypeID);
                info.setColObjTypeName(rs.getString(2));
                info.setCatSeriesDefId(rs.getInt(3));
                info.setCatSeriesId(rs.getInt(4));

                String sql = String.format(colObjCountPerCatSeriesSQL, info.getCatSeriesId());
                log.debug(sql);
                logSQL("ColObj Count Per Cat Series", sql);

                int colObjCnt = BasicSQLUtils.getCountAsInt(oldDBConn, sql);
                info.setColObjCnt(colObjCnt);

                sql = String.format(colObjDetCountPerCatSeriesSQL, info.getCatSeriesId());
                log.debug(sql);
                logSQL("ColObj Count Determinations Per Cat Series", sql);

                info.setColObjDetTaxCnt(BasicSQLUtils.getCountAsInt(oldDBConn, sql));

                sql = catSeriesSQL + info.getCatSeriesId();
                log.debug(sql);
                logSQL("Cat Series", sql);

                Vector<Object[]> rows = BasicSQLUtils.query(oldDBConn, sql);
                if (rows != null && rows.size() == 1) {
                    Object[] row = rows.get(0);

                    info.setCatSeriesName((String) row[0]);
                    info.setCatSeriesPrefix((String) row[1]);
                    info.setCatSeriesRemarks((String) row[2]);
                    info.setCatSeriesLastEditedBy((String) row[3]);

                } else {
                    log.error("Error getting CollectionInfo for CollectionObjectTypeID: " + rs.getInt(1)
                            + " number of CatlogSeries: " + rows.size());
                }

                if (!doSkipCheck) {
                    String detSQLStr = "SELECT ct.TaxonomyTypeID, (select distinct relatedsubtypevalues FROM usysmetacontrol c "
                            + "LEFT JOIN usysmetafieldsetsubtype fst ON fst.fieldsetsubtypeid = c.fieldsetsubtypeid "
                            + "WHERE objectid = 10290 AND ct.taxonomytypeid = c.relatedsubtypevalues) AS DeterminationTaxonType "
                            + "FROM collectiontaxonomytypes ct WHERE ct.biologicalobjecttypeid = "
                            + info.getColObjTypeId();
                    log.debug(detSQLStr);
                    logSQL("Checking USYS data", detSQLStr);

                    Vector<Object[]> detRows = BasicSQLUtils.query(oldDBConn, detSQLStr);
                    for (Object[] row : detRows) {
                        Integer txnTypeId = (Integer) row[0];
                        String detTxnTypes = (String) row[1];
                        if (detTxnTypes == null) {
                            detTxnTypes = Integer.toString(txnTypeId);
                        }

                        if (StringUtils.isNotEmpty(detTxnTypes)) {
                            String txNameSQL = "SELECT TaxonomyTypeName FROM taxonomytype WHERE TaxonomyTypeID = ";
                            logSQL("Getting Taxon Type Name", txNameSQL + txnTypeId);

                            if (StringUtils.contains(detTxnTypes, ',')) {
                                StringBuilder sb = new StringBuilder();
                                String[] toks = StringUtils.split(detTxnTypes, ',');

                                String dtName = BasicSQLUtils.querySingleObj(oldDBConn, txNameSQL + txnTypeId);
                                sb.append(String.format(
                                        "Warning - There are %d DeterminationTaxonTypes for TaxonObjectType %d (%s) they are:\n",
                                        toks.length, txnTypeId, dtName));
                                for (String id : toks) {
                                    logSQL("Getting Taxon Type Name", txNameSQL + id);
                                    String name = BasicSQLUtils.querySingleObj(oldDBConn, txNameSQL + id);
                                    sb.append(id);
                                    sb.append(" - ");
                                    sb.append(name);
                                    sb.append("\n");
                                }
                                sb.append(
                                        "\nThis database will need to be fixed by hand before it can be converted.");
                                UIRegistry.showError(sb.toString());
                                System.exit(0);
                                askForFix = true;
                                return null;

                            } else if (StringUtils.isNumeric(detTxnTypes.trim())) {
                                Integer txnType = Integer.parseInt(detTxnTypes);
                                if (!txnType.equals(txnTypeId)) {
                                    String tName = BasicSQLUtils.querySingleObj(oldDBConn, txNameSQL + txnType);
                                    String dtName = BasicSQLUtils.querySingleObj(oldDBConn,
                                            txNameSQL + txnTypeId);
                                    StringBuilder sb = new StringBuilder();
                                    sb.append(String.format(
                                            "Warning - The TaxonObjectType %d (%s) in the DeterminationTaxonTypes field\ndoesn't match the actual TaxonObjectType %d (%s)",
                                            txnType, tName, txnTypeId, dtName));
                                    UIRegistry.showError(sb.toString());
                                    askForFix = true;
                                    return null;
                                }
                            }
                        }
                    }
                }

                /*info.setDeterminationTaxonType(detTxnTypeStr);
                for (Integer id : info.getDetTaxonTypeIdList())
                {
                log.debug("ID: "+id);
                }*/

                // This represents a mapping from what would be the Discipline (Biological Object Type) to the Taxonomic Root
                sql = String.format(
                        "SELECT tt.TaxonomyTypeID, tt.TaxonomyTypeName, tt.KingdomID, tn.TaxonNameID, tn.TaxonName, tu.TaxonomicUnitTypeID FROM taxonomytype AS tt "
                                + "INNER JOIN taxonomicunittype AS tu ON tt.TaxonomyTypeID = tu.TaxonomyTypeID "
                                + "INNER JOIN taxonname AS tn ON tu.TaxonomyTypeID = tn.TaxonomyTypeID "
                                + "INNER JOIN collectiontaxonomytypes AS ct ON tn.TaxonomyTypeID = ct.TaxonomyTypeID "
                                + "WHERE tu.RankID =  0 AND tn.RankID =  0 AND ct.BiologicalObjectTypeID = %d "
                                + "ORDER BY ct.BiologicalObjectTypeID ASC",
                        info.getColObjTypeId());
                log.debug(sql);
                logSQL("Taxon -> Coll Taxon Types", sql);

                rows = BasicSQLUtils.query(oldDBConn, sql);
                if (rows != null) {
                    Object[] row = rows.get(0);

                    int taxonomyTypeID = (Integer) row[0];

                    info.setTaxonomyTypeId(taxonomyTypeID);
                    info.setTaxonomyTypeName((String) row[1]);
                    info.setKingdomId((Integer) row[2]);
                    info.setTaxonNameId((Integer) row[3]);
                    info.setTaxonName((String) row[4]);
                    info.setTaxonomicUnitTypeID((Integer) row[5]);

                    info.setTaxonNameCnt(BasicSQLUtils.getCountAsInt(oldDBConn, cntTaxonName + taxonomyTypeID));

                    log.debug("TaxonomyTypeName: " + info.getTaxonomyTypeName() + "  TaxonName: "
                            + info.getTaxonName() + "  TaxonomyTypeId: " + info.getTaxonomyTypeId());

                    sql = hostTaxonID + taxonomyTypeID;
                    log.debug(sql);
                    Vector<Object> ttNames = BasicSQLUtils.querySingleCol(oldDBConn, sql);
                    if (ttNames != null && ttNames.size() > 0 && ((Long) ttNames.get(0)) > 0) {
                        info.setSrcHostTaxonCnt((Long) ttNames.get(0));
                    } else {
                        info.setSrcHostTaxonCnt(0);
                    }

                    taxonTypeIdHash.add(taxonomyTypeID);

                } else {
                    log.error("Error getting CollectionInfo for CollectionObjectTypeID: " + rs.getInt(1));
                }

                collectionInfoList.add(info);
                //System.out.println(info.toString());
            }
            rs.close();

            // Here we figure out whether a Taxon Tree that is used by HostTaxonID is associated with a Collection.
            String sql = "SELECT DISTINCT tt.TaxonomyTypeID, tt.TaxonomyTypeName FROM habitat AS h "
                    + "INNER JOIN taxonname AS tn ON h.HostTaxonID = tn.TaxonNameID "
                    + "INNER JOIN taxonomytype AS tt ON tn.TaxonomyTypeID = tt.TaxonomyTypeID";
            logSQL("Check for HostID", sql);

            Vector<Integer> txTypeIds = BasicSQLUtils.queryForInts(oldDBConn, sql);

            HashSet<Integer> txnTypeIdHashSet = new HashSet<Integer>();
            for (Integer txTypId : txTypeIds) {
                Boolean hasColInfo = false;
                for (CollectionInfo colInfo : collectionInfoList) {
                    if (colInfo.getTaxonomyTypeId().equals(txTypId)) {
                        hasColInfo = true;
                    }
                }

                if (!hasColInfo) {
                    txnTypeIdHashSet.add(txTypId);
                }
            }

            // These TaxonTypeIds do not have CollectionInfo
            for (Iterator<Integer> iter = txnTypeIdHashSet.iterator(); iter.hasNext();) {
                Integer taxonomyTypeID = iter.next();
                System.out.println(taxonomyTypeID);

                sql = "SELECT tt.TaxonomyTypeName, tn.TaxonName, tt.KingdomID, tn.TaxonNameID, tn.TaxonomicUnitTypeID FROM taxonomytype AS tt "
                        + "INNER JOIN taxonomicunittype AS tut ON tt.TaxonomyTypeID = tut.TaxonomyTypeID "
                        + "INNER JOIN taxonname AS tn ON tt.TaxonomyTypeID = tn.TaxonomyTypeID AND tut.TaxonomicUnitTypeID = tn.TaxonomicUnitTypeID "
                        + "WHERE tt.TaxonomyTypeID =  " + taxonomyTypeID + " AND tn.RankID =  0";
                log.debug(sql);
                logSQL("Get TaxonTypeName etc from TaxonomyTypeID and RankID = 0", sql);

                Vector<Object[]> rows = BasicSQLUtils.query(oldDBConn, sql);
                if (rows.size() != 1) {
                    String msg = "There should only be '1' TaxonTypeName for  TaxonomyTypeID:" + taxonomyTypeID;
                    log.error(msg);
                    UIRegistry.showError(msg);
                    continue;
                }

                CollectionInfo colInfo = new CollectionInfo(oldDBConn);

                String taxonTypeName = (String) rows.get(0)[0];
                String taxonRootName = (String) rows.get(0)[1];
                if (StringUtils.isEmpty(taxonRootName)) {
                    taxonRootName = taxonTypeName;
                }

                //colInfo.setColObjTypeId();
                colInfo.setColObjTypeName(taxonRootName);
                //colInfo.setCatSeriesDefId(rs.getInt(3));
                //colInfo.setCatSeriesId(rs.getInt(4));

                colInfo.setCatSeriesName(taxonRootName);
                colInfo.setCatSeriesPrefix("");
                colInfo.setCatSeriesRemarks("");
                colInfo.setCatSeriesLastEditedBy("");

                colInfo.setColObjCnt(1);
                colInfo.setColObjDetTaxCnt(1);

                colInfo.setTaxonomyTypeId(taxonomyTypeID);
                colInfo.setTaxonomyTypeName(taxonTypeName);
                colInfo.setKingdomId((Integer) rows.get(0)[2]);
                colInfo.setTaxonNameId((Integer) rows.get(0)[3]);
                colInfo.setTaxonName(taxonRootName);
                colInfo.setTaxonomicUnitTypeID((Integer) rows.get(0)[4]);

                colInfo.setTaxonNameCnt(BasicSQLUtils.getCountAsInt(oldDBConn, cntTaxonName + taxonomyTypeID));

                colInfo.setSrcHostTaxonCnt(0);

                collectionInfoList.add(colInfo);
            }

            // Do All
            /*String sqlAllTx = "SELECT cot.CollectionObjectTypeID, cot.CollectionObjectTypeName, tt.TaxonomyTypeID, tt.TaxonomyTypeName, tt.KingdomID, tn.TaxonNameID, tn.TaxonName, tn.TaxonomicUnitTypeID " + 
                          "FROM collectionobjecttype AS cot " +
                          "INNER JOIN collectiontaxonomytypes as ctt ON cot.CollectionObjectTypeID = ctt.BiologicalObjectTypeID " + 
                          "INNER JOIN taxonomytype as tt ON ctt.TaxonomyTypeID = tt.TaxonomyTypeID " + 
                          "INNER JOIN taxonname as tn ON tt.TaxonomyTypeID = tn.TaxonomyTypeID " + 
                          "WHERE  cot.Category = 'Biological' AND tn.ParentTaxonNameID IS NULL";
                    
            log.debug(sqlAllTx);
            Vector<Object[]> rows = BasicSQLUtils.query(oldDBConn, sqlAllTx);
            for (Object[] row : rows)
            {
            int taxonomyTypeID = (Integer)row[2];
            if (taxonTypeIdHash.get(taxonomyTypeID) == null)
            {
                CollectionInfo info = new CollectionInfo(oldDBConn);
                        
                info.setColObjTypeId((Integer)row[0]);
                info.setColObjTypeName((String)row[1]);
                info.setCatSeriesDefId(null);
                info.setCatSeriesId(null);
                info.setCatSeriesName("");
                info.setCatSeriesPrefix("");
                info.setCatSeriesRemarks("");
                info.setCatSeriesLastEditedBy("");
                        
                info.setTaxonomyTypeId(taxonomyTypeID);
                info.setTaxonomyTypeName((String)row[3]);
                info.setKingdomId((Integer)row[4]);
                info.setTaxonNameId((Integer)row[5]);
                info.setTaxonName((String)row[6]);
                        
                info.setTaxonomicUnitTypeID((Integer)row[7]);
                        
                info.setTaxonNameCnt(BasicSQLUtils.getCountAsInt(oldDBConn, cntTaxonName + taxonomyTypeID));
                        
                Vector<Object> ttNames = BasicSQLUtils.querySingleCol(oldDBConn, hostTaxonID + taxonomyTypeID);
                if (ttNames != null && ttNames.size() > 0 && ((Long)ttNames.get(0)) > 0)
                {
                    info.setSrcHostTaxonCnt((Long)ttNames.get(0));
                } else
                {
                    info.setSrcHostTaxonCnt(0);
                }
                        
                taxonTypeIdHash.put(taxonomyTypeID, true);
                        
                collectionInfoList.add(info);
            }
            }*/

            dump();

        } catch (Exception ex) {
            ex.printStackTrace();
            try {
                if (stmt != null) {
                    stmt.close();
                }
            } catch (Exception e) {
            }

        } finally {
            if (pw != null)
                pw.close();
        }
    }

    Collections.sort(collectionInfoList);

    return collectionInfoList;
}

From source file:gda.jython.translator.GeneralTranslator.java

/**
 * Ignoring whitespace, the is next character in the string after currentlocation an operator symbol or a comma?
 * //from www . j av  a2 s  .  c  om
 * @param string
 * @param currentlocation
 * @return boolean
 */
static boolean isNextPartASymbol(String string, int currentlocation) {
    char nextPart = nextPart(string, currentlocation);
    return StringUtils.contains(symbols, nextPart);
}

From source file:hydrograph.ui.common.property.util.Utils.java

/**
* 
* get the file Path according to the Parameter value
* @param extSchemaPath//from   w w w  . j  a va 2 s.  com
* @param paramValue
* @param extSchemaPathText
* @return the file Path according to the Parameter value
*/
public String getParamFilePath(String extSchemaPath, String paramValue, Text extSchemaPathText) {
    String remainingString = "";
    if (checkParameterValue(extSchemaPath)) {
        if (StringUtils.isNotEmpty(paramValue)) {
            extSchemaPathText.setToolTipText(paramValue + remainingString);
        } else {
            extSchemaPathText.setToolTipText(PARAMETER_NOT_FOUND);
        }
    } else if (StringUtils.contains(paramValue, PARAMETER_NOT_FOUND)) {
        extSchemaPathText.setToolTipText(remainingString);
    } else {
        remainingString = extSchemaPath.substring(extSchemaPath.indexOf("}") + 1, extSchemaPath.length());
        extSchemaPathText.setToolTipText(paramValue + remainingString);
    }

    return paramValue + remainingString;
}

From source file:de.awtools.basic.file.AWToolsFileUtils.java

/**
 * Extrahiert aus einem Dateibezeichner den Verzeichnispfad. Beispiel:<br/>
 * Der Parameter <code>temp/ab/db/text.txt</code> fhrt zu der Rckgabe
 * <code>/temp/ab/db</code>. hnliches versucht die Methode
 * <code>File.getParent()</code>, kann aber z.B. die zwei Pfade
 * 'temp/test.txt' und '/temp/test.txt' nicht auf Gleichheit prfen.
 *
 * @param fileName Der Dateibezeichner dessen Verzeichnispfad ermittelt
 *  werden soll./* www .j  a v  a2 s .  c o m*/
 * @return Der Verzeichnispfad.
 */
public static String getParent(final String fileName) {
    String tmp = AWToolsFileUtils.normalizePath(fileName);
    if (StringUtils.contains(tmp, "/")) {
        return StringUtils.substringBeforeLast(tmp, "/");
    } else {
        return "";
    }
}

From source file:com.ultrapower.eoms.common.plugin.ecside.util.ECSideUtils.java

 public static boolean isSearchMatch(String value, String search) {
   if (search.startsWith("*") && search.endsWith("*") && StringUtils.contains(value, search.substring(1,search.length()-1))) {
      return true;
   }else if (search.startsWith("*") && value.endsWith(StringUtils.replace(search, "*", ""))) {
        return true;
    } else if (search.endsWith("*") && value.startsWith(StringUtils.replace(search, "*", ""))) {
        return true;
    }else if (value.equals(search)){
       return true;
    }/*from  ww w  .j  a v a2s  .  co  m*/
   
    return false;
}

From source file:gda.jython.translator.GeneralTranslator.java

/**
 * Ignoring whitespace, the is previous character in the string before currentlocation an operator symbol or a
 * comma?// w ww. j a  v  a 2 s.c  om
 * 
 * @param string
 * @param currentlocation
 * @return boolean
 */
static boolean isPreviousPartASymbol(String string, int currentlocation) {
    char previousPart = previousPart(string, currentlocation);
    return StringUtils.contains(symbols, previousPart);
}

From source file:edu.ku.brc.af.core.db.MySQLBackupService.java

/**
 * Does the backup on a SwingWorker Thread.
 * @param isMonthly whether it is a monthly backup
 * @param doSendAppExit requests sending an application exit command when done
 * @return true if the prefs are set up and there were no errors before the SwingWorker thread was started
 *//*from   w  ww  . j av  a 2s. c  o  m*/
private boolean doBackUp(final boolean isMonthly, final boolean doSendAppExit,
        final PropertyChangeListener propChgListener) {
    AppPreferences remotePrefs = AppPreferences.getLocalPrefs();

    final String mysqldumpLoc = remotePrefs.get(MYSQLDUMP_LOC, getDefaultMySQLDumpLoc());
    final String backupLoc = remotePrefs.get(MYSQLBCK_LOC, getDefaultBackupLoc());

    if (!(new File(mysqldumpLoc)).exists()) {
        UIRegistry.showLocalizedError("MySQLBackupService.MYSQL_NO_DUMP", mysqldumpLoc);
        if (propChgListener != null) {
            propChgListener.propertyChange(new PropertyChangeEvent(MySQLBackupService.this, ERROR, 0, 1));
        }
        return false;
    }

    File backupDir = new File(backupLoc);
    if (!backupDir.exists()) {
        if (!backupDir.mkdir()) {
            UIRegistry.showLocalizedError("MySQLBackupService.MYSQL_NO_BK_DIR", backupDir.getAbsoluteFile());
            if (propChgListener != null) {
                propChgListener.propertyChange(new PropertyChangeEvent(MySQLBackupService.this, ERROR, 0, 1));
            }
            return false;
        }
    }

    errorMsg = null;

    final String databaseName = DBConnection.getInstance().getDatabaseName();

    getNumberofTables();

    SwingWorker<Integer, Integer> backupWorker = new SwingWorker<Integer, Integer>() {
        protected String fullPath = null;

        /* (non-Javadoc)
         * @see javax.swing.SwingWorker#doInBackground()
         */
        @Override
        protected Integer doInBackground() throws Exception {
            FileOutputStream backupOut = null;
            try {
                Thread.sleep(100);

                // Create output file
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy_MM_dd_kk_mm_ss");
                String fileName = sdf.format(Calendar.getInstance().getTime()) + (isMonthly ? "_monthly" : "")
                        + ".sql";

                fullPath = backupLoc + File.separator + fileName;

                File file = new File(fullPath);
                backupOut = new FileOutputStream(file);

                writeStats(getCollectionStats(getTableNames()), getStatsName(fullPath));

                String userName = DBConnection.getInstance().getUserName();
                String password = DBConnection.getInstance().getPassword();

                if (StringUtils.isEmpty(userName) || StringUtils.isEmpty(password)) {
                    Pair<String, String> up = UserAndMasterPasswordMgr.getInstance().getUserNamePasswordForDB();
                    if (up != null && up.first != null && up.second != null) {
                        userName = up.first;
                        password = up.second;
                    }
                }

                String port = DatabaseDriverInfo.getDriver(DBConnection.getInstance().getDriverName())
                        .getPort();
                String server = DBConnection.getInstance().getServerName();

                Vector<String> args = new Vector<String>();
                args.add(mysqldumpLoc);
                args.add("--user=" + userName);
                args.add("--password=" + password);
                args.add("--host=" + server);
                if (port != null) {
                    args.add("--port=" + port);
                }
                args.add(databaseName);
                Process process = Runtime.getRuntime().exec(args.toArray(new String[0]));

                InputStream input = process.getInputStream();
                byte[] bytes = new byte[8192 * 2];

                double oneMeg = (1024.0 * 1024.0);
                long dspMegs = 0;
                long totalBytes = 0;

                do {
                    int numBytes = input.read(bytes, 0, bytes.length);
                    totalBytes += numBytes;
                    if (numBytes > 0) {
                        long megs = (long) (totalBytes / oneMeg);
                        if (megs != dspMegs) {
                            dspMegs = megs;
                            long megsWithTenths = (long) ((totalBytes * 10.0) / oneMeg);
                            firePropertyChange(MEGS, 0, megsWithTenths);
                        }

                        backupOut.write(bytes, 0, numBytes);

                    } else {
                        break;
                    }

                } while (true);

                StringBuilder sb = new StringBuilder();

                String line;
                BufferedReader errIn = new BufferedReader(new InputStreamReader(process.getErrorStream()));
                while ((line = errIn.readLine()) != null) {
                    //System.err.println(line);
                    if (line.startsWith("ERR") || StringUtils.contains(line, "Got error")) {
                        sb.append(line);
                        sb.append("\n");

                        if (StringUtils.contains(line, "1044") && StringUtils.contains(line, "LOCK TABLES")) {
                            sb.append("\n");
                            sb.append(UIRegistry.getResourceString("MySQLBackupService.LCK_TBL_ERR"));
                            sb.append("\n");
                        }
                    }
                }
                errorMsg = sb.toString();

            } catch (Exception ex) {
                ex.printStackTrace();
                errorMsg = ex.toString();
                UIRegistry.showLocalizedError("MySQLBackupService.EXCP_BK");

            } finally {
                if (backupOut != null) {
                    try {
                        backupOut.flush();
                        backupOut.close();

                    } catch (IOException ex) {
                        ex.printStackTrace();
                        errorMsg = ex.toString();
                    }
                }
            }

            return null;
        }

        @Override
        protected void done() {
            super.done();

            UIRegistry.getStatusBar().setProgressDone(STATUSBAR_NAME);

            UIRegistry.clearSimpleGlassPaneMsg();

            if (StringUtils.isNotEmpty(errorMsg)) {
                UIRegistry.showError(errorMsg);
            }

            if (doSendAppExit) {
                CommandDispatcher.dispatch(new CommandAction("App", "AppReqExit"));
            }

            if (propChgListener != null) {
                propChgListener
                        .propertyChange(new PropertyChangeEvent(MySQLBackupService.this, DONE, null, fullPath));
            }
        }
    };

    final JStatusBar statusBar = UIRegistry.getStatusBar();
    statusBar.setIndeterminate(STATUSBAR_NAME, true);

    UIRegistry.writeSimpleGlassPaneMsg(getLocalizedMessage("MySQLBackupService.BACKINGUP", databaseName), 24);

    backupWorker.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(final PropertyChangeEvent evt) {
            if (MEGS.equals(evt.getPropertyName())) {
                long value = (Long) evt.getNewValue();
                double val = value / 10.0;
                statusBar.setText(UIRegistry.getLocalizedMessage("MySQLBackupService.BACKUP_MEGS", val));
            }
        }
    });
    backupWorker.execute();

    return true;
}

From source file:edu.arizona.kra.kim.impl.identity.PersonServiceImpl.java

private boolean isPersonProperty(BusinessObject bo, String propertyName) {
    try {/*from w w  w  .j ava 2s  .c om*/
        if (ObjectUtils.isNestedAttribute(propertyName) // is a nested property
                && !StringUtils.contains(propertyName, "add.")) {// exclude add line properties (due to path parsing problems in PropertyUtils.getPropertyType)
            Class<?> type = PropertyUtils.getPropertyType(bo,
                    ObjectUtils.getNestedAttributePrefix(propertyName));
            // property type indicates a Person object
            if (type != null) {
                return Person.class.isAssignableFrom(type);
            }
            LOG.warn("Unable to determine type of nested property: " + bo.getClass().getName() + " / "
                    + propertyName);
        }
    } catch (Exception ex) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Unable to determine if property on " + bo.getClass().getName() + " to a person object: "
                    + propertyName, ex);
        }
    }
    return false;
}

From source file:de.awtools.basic.file.AWToolsFileUtils.java

/**
 * Entfernt aus einem Dateibezeichner alle Pfadangaben.
 * /*from   www .ja va2 s .  c om*/
 * @param fileName Der zu untersuchende Dateibezeichner. 
 * @return Liefert den Dateibezeichner ohne Pfadangaben.
 */
public static String getFileName(final String fileName) {
    String tmp = AWToolsFileUtils.normalizePath(fileName);
    if (StringUtils.contains(tmp, "/")) {
        return StringUtils.substringAfterLast(tmp, "/");
    } else {
        return tmp;
    }
}

From source file:hydrograph.ui.common.property.util.Utils.java

/**
  * //  w ww. j av  a  2 s  .c o m
  * get the file Path according to the Parameter value
  * @param extSchemaPath
  * @param paramValue
  * @param extSchemaPathText
  * @return the file Path according to the Parameter value
  */
public String getParamFilePath(String extSchemaPath, String paramValue) {
    String remainingString = "";
    if (!checkParameterValue(extSchemaPath) && StringUtils.contains(paramValue, PARAMETER_NOT_FOUND)) {
        remainingString = extSchemaPath.substring(extSchemaPath.indexOf("}") + 1, extSchemaPath.length());
    }
    return paramValue + remainingString;
}