List of usage examples for org.apache.commons.lang StringUtils contains
public static boolean contains(String str, String searchStr)
Checks if String contains a search String, handling null
.
From source file:edu.monash.merc.system.scheduling.impl.TpbDataProcessor.java
private void processNextProtData(ChromType chromType, Date importedTime) { FTPFileGetter ftpFileGetter = new FTPFileGetter(); String ftpHost = systemPropSettings.getPropValue(SystemPropConts.FTP_NX_SERVER_NAME); String ftpUserName = systemPropSettings.getPropValue(SystemPropConts.FTP_NX_USER_NAME); String ftpPassword = systemPropSettings.getPropValue(SystemPropConts.FTP_NX_USER_PASSWORD); String workingDir = systemPropSettings.getPropValue(SystemPropConts.FTP_NX_CHROMOSOME_REL_DIR); try {//from w w w. j a v a 2 s.c o m if (ftpFileGetter.connectAndLogin(ftpHost, ftpUserName, ftpPassword)) { ftpFileGetter.changeToWorkingDirectory(workingDir); ftpFileGetter.setPassiveMode(true); //get all chromosome file Vector<String> chromosomeFiles = ftpFileGetter.listFileNames(); //set the binary download mode ftpFileGetter.binary(); InputStream chromInputStream = null; for (String file : chromosomeFiles) { if (StringUtils.contains(file, NEXTPROT_CHROME_NAME + "_" + chromType.chm() + ".xml")) { String fileLastModifiedTime = ftpFileGetter.getLastModifiedTime(file); logger.info( "The nextprot xml file: " + file + ", last modified time: " + fileLastModifiedTime); //check if the file hasn't been updated, then get the file if (!checkUpToDate(DbAcType.NextProt, chromType, file, fileLastModifiedTime)) { chromInputStream = ftpFileGetter.downloadFileStream(file); DMFileGZipper gZipper = new DMFileGZipper(); String outFileName = StringUtils.substringBefore(file, ".gz"); String storeDir = this.downloadLocation + File.separator; gZipper.unzipFile(chromInputStream, storeDir + outFileName); //call completePendingCommand to to finish command if (!ftpFileGetter.completePendingCommand()) { ftpFileGetter.logout(); ftpFileGetter.disconnect(); } FileInputStream fileInputStream = new FileInputStream(new File(storeDir + outFileName)); processNextProtXML(chromType, fileInputStream, importedTime, file, fileLastModifiedTime); } else { logger.info("The nextprot xml file - " + file + " is already imported."); } } } } else { logger.error("Failed to login the ftp server - " + ftpHost); } } catch (Exception ex) { logger.error(ex); } finally { try { ftpFileGetter.logout(); ftpFileGetter.disconnect(); } catch (Exception ftpEx) { //ignore whatever caught here } } }
From source file:com.iyonger.apm.web.model.AgentManager.java
/** * Select agent. This method return agent set which is belong to the given user first and then share agent set. * * @param user user/*from ww w . j a va 2 s. com*/ * @param allFreeAgents agents * @param agentCount number of agent * @return selected agent. */ public Set<AgentIdentity> selectAgent(User user, Set<AgentIdentity> allFreeAgents, int agentCount) { Set<AgentIdentity> userAgent = new HashSet<AgentIdentity>(); for (AgentIdentity each : allFreeAgents) { String region = ((AgentControllerIdentityImplementation) each).getRegion(); if (StringUtils.endsWith(region, "owned_" + user.getUserId())) { userAgent.add(each); if (userAgent.size() == agentCount) { return userAgent; } } } for (AgentIdentity each : allFreeAgents) { String region = ((AgentControllerIdentityImplementation) each).getRegion(); if (!StringUtils.contains(region, "owned_")) { userAgent.add(each); if (userAgent.size() == agentCount) { return userAgent; } } } return userAgent; }
From source file:com.impetus.kundera.loader.PersistenceXMLLoader.java
/** * Returns persistence unit root url/*w w w . j a va 2s . com*/ * * @param url * raw url * @return rootUrl rootUrl */ private static URL getPersistenceRootUrl(URL url) { String f = url.getFile(); f = parseFilePath(f); URL jarUrl = url; try { if (AllowedProtocol.isJarProtocol(url.getProtocol())) { jarUrl = new URL(f); if (jarUrl.getProtocol() != null && AllowedProtocol.FILE.name().equals(jarUrl.getProtocol().toUpperCase()) && StringUtils.contains(f, " ")) { jarUrl = new File(f).toURI().toURL(); } } else if (AllowedProtocol.isValidProtocol(url.getProtocol())) { if (StringUtils.contains(f, " ")) { jarUrl = new File(f).toURI().toURL(); } else { jarUrl = new File(f).toURL(); } } } catch (MalformedURLException mex) { log.error("Error during getPersistenceRootUrl(), Caused by: {}.", mex); throw new IllegalArgumentException("Invalid jar URL[] provided!" + url); } return jarUrl; }
From source file:com.haulmont.cuba.gui.components.filter.edit.CustomConditionFrame.java
protected List<Suggestion> requestHint(SourceCodeEditor sender, String text, int senderCursorPosition) { String joinStr = joinField.getValue(); String whereStr = whereField.getValue(); CollectionDatasource ds = (CollectionDatasource) condition.getDatasource(); // CAUTION: the magic entity name! The length is three character to match "{E}" length in query String entityAlias = "a39"; int queryPosition = -1; String queryStart = "select " + entityAlias + " from " + ds.getMetaClass().getName() + " " + entityAlias + " "; StringBuilder queryBuilder = new StringBuilder(queryStart); if (StringUtils.isNotEmpty(joinStr)) { if (sender == joinField) { queryPosition = queryBuilder.length() + senderCursorPosition - 1; }// ww w . j a v a 2s. c o m if (!StringUtils.containsIgnoreCase(joinStr, "join") && !StringUtils.contains(joinStr, ",")) { queryBuilder.append("join ").append(joinStr); queryPosition += "join ".length(); } else { queryBuilder.append(joinStr); } } if (StringUtils.isNotEmpty(whereStr)) { if (sender == whereField) { queryPosition = queryBuilder.length() + WHERE.length() + senderCursorPosition - 1; } queryBuilder.append(WHERE).append(whereStr); } String query = queryBuilder.toString(); query = query.replace("{E}", entityAlias); return JpqlSuggestionFactory.requestHint(query, queryPosition, sender.getAutoCompleteSupport(), senderCursorPosition); }
From source file:com.sfs.whichdoctor.beans.RotationBean.java
/** * Gets the excess./* ww w .ja va 2 s .c om*/ * * @return the excess */ public final boolean getExcess() { boolean excess = false; if (StringUtils.contains(getTrainingClass(), "ontinuing") || this.getInterruption()) { excess = true; } return excess; }
From source file:edu.ku.brc.specify.datamodel.busrules.PickListBusRules.java
@Override public void okToDelete(final Object dataObj, final DataProviderSessionIFace session, final BusinessRulesOkDeleteIFace deletable) { reasonList.clear();//from w w w . ja v a 2 s. co m PickList pickList = (PickList) dataObj; if (!pickList.getIsSystem()) { // Check all the forms here // This is cheap and a hack because we should probably parse the XML // instead of just doing a text search String searchText = "picklist=\"" + pickList.getName() + "\""; for (SpAppResourceDir appDir : ((SpecifyAppContextMgr) AppContextMgr.getInstance()) .getSpAppResourceList()) { for (SpViewSetObj viewSet : appDir.getSpViewSets()) { String xml = viewSet.getDataAsString(); if (StringUtils.contains(xml, searchText)) { if (deletable != null) { deletable.doDeleteDataObj(dataObj, session, false); } return; } } } super.okToDelete(dataObj, session, deletable); } }
From source file:edu.ku.brc.specify.toycode.mexconabio.MexConvToSQLNew.java
/** * /*from w w w. java 2 s . co m*/ */ public void convertFROMCSV(final ConfigureCSV config, final CsvReader csv) { String str = ""; int strLen = 0; int inx = 0; CsvReader csvObj = null; Connection conn = null; Statement stmt = null; try { conn = DriverManager.getConnection( "jdbc:mysql://localhost/mex?characterEncoding=UTF-8&autoReconnect=true", "root", "root"); stmt = conn.createStatement(); StringBuilder pStmtStr = new StringBuilder(); StringBuilder sb = new StringBuilder(); StringBuilder ques = new StringBuilder(); int[] fieldLengths = null; BasicSQLUtils.deleteAllRecordsFromTable(conn, "mex", SERVERTYPE.MySQL); Vector<Integer> types = new Vector<Integer>(); Vector<String> names = new Vector<String>(); File file = new File("/Users/rods/Documents/Untitled.mer"); Element root = XMLHelper.readFileToDOM4J(new File("/Users/rods/Documents/Acer.xml")); if (root != null) { fieldLengths = new int[csv.getColumnCount()]; for (int i = 0; i < fieldLengths.length; i++) { fieldLengths[i] = 0; } int row = 0; while (csv.readRecord()) { row++; for (int col = 0; col < csv.getColumnCount(); col++) { String dataObj = csv.get(col); int len = dataObj.length() + 1; if (len > fieldLengths[inx]) { fieldLengths[inx] = len; } inx++; } if (row % 10000 == 0) System.out.println(row); } System.out.println("--------------"); HashMap<String, Integer> hashSize = new HashMap<String, Integer>(); for (int i = 0; i < names.size(); i++) { hashSize.put(names.get(i), fieldLengths[i]); System.out.println(names.get(i) + " -> " + fieldLengths[i]); } sb.append("CREATE TABLE mex ("); List<?> items = root.selectNodes("/FIELDS/FIELD"); //$NON-NLS-1$ System.out.println(items.size()); inx = 0; for (Iterator<?> capIter = items.iterator(); capIter.hasNext();) { Element fieldNode = (Element) capIter.next(); String nullOK = fieldNode.attributeValue("EMPTYOK"); //$NON-NLS-1$ String fldName = fixName(fieldNode.attributeValue("NAME").trim()); //$NON-NLS-1$ String type = fieldNode.attributeValue("TYPE"); //$NON-NLS-1$ sb.append("`"); sb.append(fldName); sb.append("` "); System.err.println("[" + fldName + "]"); int len = hashSize.get(fldName); if (pStmtStr.length() > 0) pStmtStr.append(','); pStmtStr.append("`" + fldName + "`"); if (ques.length() > 0) ques.append(','); ques.append("?"); if (type.equals("TEXT")) { if (StringUtils.contains(fldName, "img folder")) { sb.append("longtext "); } else { sb.append("VARCHAR(" + len + ") CHARACTER SET utf8 "); } types.add(DataType.TEXT.ordinal()); } else if (type.equals("NUMBER")) { sb.append("DOUBLE "); types.add(DataType.NUMBER.ordinal()); } else if (type.equals("DATE")) { sb.append("DATE "); types.add(DataType.DATE.ordinal()); } else if (type.equals("TIME")) { sb.append("VARCHAR(16) "); types.add(DataType.TIME.ordinal()); } else { System.err.println("Unhandled Type[" + type + "]"); } sb.append(nullOK.equals("YES") ? "DEFAULT NULL," : ","); sb.append("\n"); inx++; } sb.setLength(sb.length() - 2); sb.append(") ENGINE=MyISAM DEFAULT CHARSET=utf8;"); } SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy"); int rowCnt = 0; try { String stmtStr = "INSERT INTO mex (" + pStmtStr + ") VALUES(" + ques + ")"; System.out.println(stmtStr); try { stmt.executeUpdate("DROP TABLE mex"); } catch (SQLException e) { } System.err.println(sb.toString()); stmt.executeUpdate(sb.toString()); PreparedStatement pStmt = conn.prepareStatement(stmtStr); csv.close(); csvObj = new CsvReader(new FileInputStream(config.getFile()), config.getDelimiter(), config.getCharset()); csvObj.readRecord(); // skip header int row = 0; while (csvObj.readRecord()) { row++; for (int col = 0; col < csvObj.getColumnCount(); col++) { String dataStr = csvObj.get(col); strLen = dataStr.length(); switch (types.get(inx)) { case 3: case 0: { if (strLen > 0) { if (strLen <= fieldLengths[inx]) { pStmt.setString(col, dataStr); } else { System.err.println(String.format("The data for `%s` (%d) is too big %d", names.get(inx), fieldLengths[inx], strLen)); pStmt.setString(col, null); } } else { pStmt.setString(col, null); } } break; case 1: { if (StringUtils.isNotEmpty(dataStr)) { if (StringUtils.isNumeric(dataStr)) { pStmt.setDouble(col, strLen > 0 ? Double.parseDouble(dataStr) : null); } else { System.err.println(col + " Bad Number[" + dataStr + "] "); pStmt.setDate(col, null); } } else { pStmt.setDate(col, null); } } break; case 2: { try { if (StringUtils.isNotEmpty(dataStr)) { if (StringUtils.contains(dataStr, "/")) { dataStr = StringUtils.replace(dataStr, "/", "-"); } else if (StringUtils.contains(dataStr, " ")) { dataStr = StringUtils.replace(dataStr, " ", "-"); } pStmt.setDate(col, strLen > 0 ? new java.sql.Date(sdf.parse(dataStr).getTime()) : null); } else { pStmt.setDate(col, null); } } catch (Exception ex) { System.err.println(col + " Bad Date[" + dataStr + "]\n" + str); pStmt.setDate(col, null); } } break; default: { System.err.println("Error - " + types.get(inx)); } } inx++; col++; } pStmt.execute(); row++; } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (Exception e) { System.err.println("Row: " + rowCnt); System.err.println(str); System.err.println(inx + " " + fieldLengths[inx] + " - Field Len: " + strLen); e.printStackTrace(); } finally { if (csvObj != null) { csvObj.close(); } } } catch (Exception ex) { ex.printStackTrace(); } finally { try { stmt.close(); conn.close(); } catch (Exception ex) { ex.printStackTrace(); } } }
From source file:adalid.util.velocity.BaseBuilder.java
private void createTextFilePropertiesFile(String source, String target) { boolean java = StringUtils.endsWithIgnoreCase(source, ".java"); boolean bundle = StringUtils.endsWithIgnoreCase(source, ".properties"); File sourceFile = new File(source); String sourceFileName = sourceFile.getName(); String sourceFileSimpleName = StringUtils.substringBeforeLast(sourceFileName, "."); String sourceFolderName = sourceFile.getParentFile().getName(); String sourceFolderSimpleName = StringUtils.substringBeforeLast(sourceFolderName, "."); String sourceEntityName = getOptionalEntityName(sourceFileSimpleName, sourceFolderSimpleName); String properties = source.replace(projectFolderPath, velocityPlatformsTargetFolderPath) + ".properties"; String folder = StringUtils.substringBeforeLast(properties, FS); String template = StringUtils.substringAfter(target, velocityFolderPath + FS).replace(FS, "/"); String path = StringUtils.substringBeforeLast(StringUtils.substringAfter(source, projectFolderPath), FS) .replace(FS, "/").replace(project, PROJECT_ALIAS).replace("eclipse.settings", ".settings"); path = replaceAliasWithRootFolderName(path); String pack = null;//w w w . j a v a2s . c o m if (java || bundle) { String s1 = StringUtils.substringAfter(path, SRC); if (StringUtils.contains(s1, PROJECT_ALIAS)) { String s2 = StringUtils.substringBefore(s1, PROJECT_ALIAS); String s3 = SRC + s2; String s4 = StringUtils.substringBefore(path, s3) + s3; String s5 = StringUtils.substringAfter(s1, PROJECT_ALIAS).replace("/", "."); path = StringUtils.removeEnd(s4, "/"); pack = ROOT_PACKAGE_NAME + s5; } } path = finalisePath(path); String file = StringUtils.substringAfterLast(source, FS).replace(project, PROJECT_ALIAS) .replace("eclipse.project", ".project"); List<String> lines = new ArrayList<>(); lines.add("template = " + template); // lines.add("template-type = velocity"); lines.add("path = " + path); if (StringUtils.isNotBlank(pack)) { lines.add("package = " + pack); } lines.add("file = " + file); if (sourceFileSimpleName.equals("eclipse") || sourceFolderSimpleName.equals("eclipse") || sourceFolderSimpleName.equals("nbproject")) { lines.add("disabled = true"); } else if (sourceEntityName != null) { lines.add("disabled-when-missing = " + sourceEntityName); } if (source.endsWith(".css") || source.endsWith(".jrtx")) { lines.add("preserve = true"); } else if (ArrayUtils.contains(preservableFiles, sourceFileName)) { lines.add("preserve = true"); } lines.add("dollar.string = $"); lines.add("pound.string = #"); lines.add("backslash.string = \\\\"); FilUtils.mkdirs(folder); if (write(properties, lines, WINDOWS_CHARSET)) { propertiesFilesCreated++; } }
From source file:com.primovision.lutransport.core.util.TollCompanyTagUploadUtil.java
private static void setCellValueTagNumberFormat(HSSFWorkbook wb, Cell cell, Object oneCellValue, String vendor) {/*from w ww .ja va2 s. co m*/ if (oneCellValue == null) { cell.setCellValue(StringUtils.EMPTY); return; } String tagNum = StringUtils.trimToEmpty(oneCellValue.toString()); tagNum = tagNum.replaceAll("\u00a0", StringUtils.EMPTY); tagNum = StringUtils.stripStart(tagNum, "0"); if (StringUtils.contains(vendor, TOLL_COMPANY_SUN_PASS)) { if (StringUtils.startsWith(tagNum, "155")) { tagNum = StringUtils.stripEnd(tagNum, "0"); } } cell.setCellValue(tagNum); }
From source file:com.sfs.whichdoctor.beans.RotationBean.java
/** * Gets the interruption.// w ww . j a va 2 s.c o m * * @return the interruption value */ public final boolean getInterruption() { boolean interruption = false; if (StringUtils.contains(getTrainingClass(), "nterrupt")) { interruption = true; } return interruption; }