List of usage examples for org.apache.commons.lang StringUtils countMatches
public static int countMatches(String str, String sub)
Counts how many times the substring appears in the larger String.
From source file:com.sic.bb.jenkins.plugins.sicci_for_xcode.XcodeBuilder.java
private Set<String> getToPerformStep(String cmd, boolean force) { Set<String> toPerformStep = new HashSet<String>(); for (String key : this.data.keySet()) { if (StringUtils.countMatches(key, FIELD_DELIMITER) < 2) continue; String[] fields = key.split(PluginUtils.stringToPattern(FIELD_DELIMITER)); if (!cmd.equals(BUILD_ARG) && (!fields[fields.length - 1].equals(cmd) || (!force && !this.data.get(key).equals(TRUE)))) continue; toPerformStep.add(fields[0] + FIELD_DELIMITER + fields[1]); }/*from www. j a v a2s. co m*/ return toPerformStep; }
From source file:com.hangum.tadpole.commons.admin.core.editors.sqlaudit.AdminSQLAuditEditor.java
/** * search//from w w w .j ava2 s .c om */ private void search() { // ? ?? . clearGrid(); mapSQLHistory.clear(); String strEmail = "%" + StringUtils.trim(textEmail.getText()) + "%"; //$NON-NLS-1$ //$NON-NLS-2$ Calendar cal = Calendar.getInstance(); cal.set(dateTimeStart.getYear(), dateTimeStart.getMonth(), dateTimeStart.getDay(), 0, 0, 0); long startTime = cal.getTimeInMillis(); cal.set(dateTimeEnd.getYear(), dateTimeEnd.getMonth(), dateTimeEnd.getDay(), 23, 59, 59); long endTime = cal.getTimeInMillis(); int duringExecute = Integer.parseInt(textMillis.getText()); String strSearchTxt = "%" + StringUtils.trimToEmpty(textSearch.getText()) + "%"; //$NON-NLS-1$ //$NON-NLS-2$ try { List<RequestResultDAO> listSQLHistory = TadpoleSystem_ExecutedSQL.getAllExecuteQueryHistoryDetail( strEmail, comboTypes.getText(), startTime, endTime, duringExecute, strSearchTxt); for (int i = 0; i < listSQLHistory.size(); i++) { RequestResultDAO reqResultDAO = (RequestResultDAO) listSQLHistory.get(i); mapSQLHistory.put("" + i, reqResultDAO); //$NON-NLS-1$ GridItem item = new GridItem(gridHistory, SWT.V_SCROLL | SWT.H_SCROLL); String strSQL = StringUtils.strip(reqResultDAO.getStrSQLText()); int intLine = StringUtils.countMatches(strSQL, "\n"); //$NON-NLS-1$ if (intLine >= 1) { int height = (intLine + 1) * 24; if (height > 100) item.setHeight(100); else item.setHeight(height); } item.setText(0, "" + i); //$NON-NLS-1$ item.setText(1, reqResultDAO.getDbName()); item.setText(2, reqResultDAO.getUserName()); item.setText(3, Utils.dateToStr(reqResultDAO.getStartDateExecute())); item.setText(4, Utils.convLineToHtml(strSQL)); item.setToolTipText(4, strSQL); item.setText(5, "" + ((reqResultDAO.getEndDateExecute().getTime() //$NON-NLS-1$ - reqResultDAO.getStartDateExecute().getTime()) / 1000f)); item.setText(6, "" + reqResultDAO.getRows()); //$NON-NLS-1$ item.setText(7, reqResultDAO.getResult()); item.setText(8, Utils.convLineToHtml(reqResultDAO.getMesssage())); item.setToolTipText(8, reqResultDAO.getMesssage()); item.setText(9, reqResultDAO.getIpAddress()); if ("F".equals(reqResultDAO.getResult())) { //$NON-NLS-1$ item.setBackground(SWTResourceManager.getColor(240, 180, 167)); } } } catch (Exception ee) { logger.error("Executed SQL History call", ee); //$NON-NLS-1$ } }
From source file:com.cubusmail.server.mail.imap.IMAPMailbox.java
/** * @throws MessagingException//from w w w . j a va 2s . c o m */ private void loadMailFolder() throws MessagingException { log.debug("loading folder tree..."); long millis = System.currentTimeMillis(); this.mailFolderMap.clear(); this.mailFolderList.clear(); Folder defaultFolder = this.store.getDefaultFolder(); this.folderSeparator = defaultFolder.getSeparator(); // read all folders to a map List<String> topFolderNames = new ArrayList<String>(); Folder[] allFolders = defaultFolder.list("*"); if (allFolders != null && allFolders.length > 0) { for (Folder folder : allFolders) { this.mailFolderMap.put(folder.getFullName(), createMailFolder(folder)); if (SessionManager.get().getPreferences().getInboxFolderName().equals(folder.getFullName())) { topFolderNames.add(0, SessionManager.get().getPreferences().getInboxFolderName()); } else { String folderName = folder.getFullName(); if (!StringUtils.isEmpty(this.personalNameSpace) && folderName.startsWith(this.personalNameSpace)) { folderName = StringUtils.substringAfter(folderName, this.personalNameSpace); } if (StringUtils.countMatches(folderName, String.valueOf(getFolderSeparator())) == 0) { topFolderNames.add(folder.getFullName()); } } } } // build the tree structure for (String folderName : topFolderNames) { IMailFolder mailFolder = this.mailFolderMap.get(folderName); this.mailFolderList.add(mailFolder); if (mailFolder.hasChildren()) { mailFolder.setSubfolders(getSubfolders(mailFolder)); } } log.debug("...finish: " + (System.currentTimeMillis() - millis) + "ms"); }
From source file:com.hangum.tadpole.mongodb.core.ext.editors.javascript.ServerSideJavaScriptEditor.java
/** * execute javascript eval // w w w . j a v a2 s. c o m * * @param strJavaScript */ private void executeEval(String strJavaScript) { Object[] arryArgs = null;//{25, 34}; logger.debug("[original javascript]" + strJavaScript); // argument String strArgument = StringUtils.substringBetween(strJavaScript, "function", "{"); if (strArgument != null) { int intArgumentCount = StringUtils.countMatches(strArgument, ",") + 1; EvalInputDialog dialog = new EvalInputDialog(getSite().getShell(), intArgumentCount); if (Dialog.OK == dialog.open()) { arryArgs = dialog.getInputObject(); try { Object objResult = MongoDBQuery.executeEval(getUserDB(), strJavaScript, arryArgs); textResultJavaScript.setText(objResult == null ? "" : objResult.toString()); } catch (Exception e) { textResultJavaScript.setText(""); logger.error("execute javascript", e); //$NON-NLS-1$ Status errStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e); //$NON-NLS-1$ ExceptionDetailsErrorDialog.openError(getSite().getShell(), Messages.get().Error, Messages.get().MainEditor_19, errStatus); //$NON-NLS-1$ } } } }
From source file:gov.nih.nci.caarray.magetab.MageTabParserTest.java
@Test public void testValidateMisplacedFactorValues() throws MageTabParsingException { final MageTabFileSet inputFileSet = TestMageTabSets.MAGE_TAB_MISPLACED_FACTOR_VALUES_INPUT_SET; final ValidationResult result = validate(inputFileSet); assertNotNull(result);/*from w ww . j ava 2 s . c om*/ assertFalse(result.isValid()); assertEquals(3, StringUtils.countMatches(result.toString(), "Factor Value columns must come after (to the right of) a Hybridization column")); assertFalse(result.toString().contains("Exception")); }
From source file:com.hangum.tadpole.manager.core.editor.executedsql.SQLAuditEditor.java
/** * search// w ww . j av a2s . c o m */ private void search() { // ? ?? . clearGrid(); mapSQLHistory.clear(); String strEmail = "%" + StringUtils.trim(textEmail.getText()) + "%"; //$NON-NLS-1$ //$NON-NLS-2$ // check all db String db_seq = ""; //$NON-NLS-1$ if (!comboDatabase.getText().equals("All")) { //$NON-NLS-1$ searchUserDBDAO = (UserDBDAO) comboDatabase.getData(comboDatabase.getText()); db_seq = "" + searchUserDBDAO.getSeq(); //$NON-NLS-1$ } else { searchUserDBDAO = null; for (int i = 0; i < listUserDBDAO.size(); i++) { UserDBDAO userDB = listUserDBDAO.get(i); if (i == (listUserDBDAO.size() - 1)) db_seq += ("" + userDB.getSeq()); //$NON-NLS-1$ else db_seq += userDB.getSeq() + ","; //$NON-NLS-1$ } } Calendar cal = Calendar.getInstance(); cal.set(dateTimeStart.getYear(), dateTimeStart.getMonth(), dateTimeStart.getDay(), 0, 0, 0); long startTime = cal.getTimeInMillis(); cal.set(dateTimeEnd.getYear(), dateTimeEnd.getMonth(), dateTimeEnd.getDay(), 23, 59, 59); long endTime = cal.getTimeInMillis(); int duringExecute = 0; try { duringExecute = Integer.parseInt(textMillis.getText()); } catch (Exception e) { // ignore exception } String strSearchTxt = "%" + StringUtils.trimToEmpty(textSearch.getText()) + "%"; //$NON-NLS-1$ //$NON-NLS-2$ try { List<RequestResultDAO> listSQLHistory = TadpoleSystem_ExecutedSQL.getExecuteQueryHistoryDetail(strEmail, comboTypes.getText(), db_seq, startTime, endTime, duringExecute, strSearchTxt); // for (RequestResultDAO reqResultDAO : listSQLHistory) { for (int i = 0; i < listSQLHistory.size(); i++) { RequestResultDAO reqResultDAO = (RequestResultDAO) listSQLHistory.get(i); mapSQLHistory.put("" + i, reqResultDAO); //$NON-NLS-1$ GridItem item = new GridItem(gridHistory, SWT.V_SCROLL | SWT.H_SCROLL); String strSQL = StringUtils.strip(reqResultDAO.getStrSQLText()); int intLine = StringUtils.countMatches(strSQL, "\n"); //$NON-NLS-1$ if (intLine >= 1) { int height = (intLine + 1) * 24; if (height > 100) item.setHeight(100); else item.setHeight(height); } item.setText(0, "" + i); //$NON-NLS-1$ item.setText(1, reqResultDAO.getDbName()); item.setText(2, reqResultDAO.getUserName()); item.setText(3, Utils.dateToStr(reqResultDAO.getStartDateExecute())); // logger.debug(Utils.convLineToHtml(strSQL)); item.setText(4, Utils.convLineToHtml(strSQL)); item.setToolTipText(4, strSQL); try { item.setText(5, "" + ((reqResultDAO.getEndDateExecute().getTime() //$NON-NLS-1$ - reqResultDAO.getStartDateExecute().getTime()))); } catch (Exception e) { item.setText(5, "-"); //$NON-NLS-1$ } item.setText(6, "" + reqResultDAO.getRows()); //$NON-NLS-1$ item.setText(7, reqResultDAO.getResult()); item.setText(8, Utils.convLineToHtml(reqResultDAO.getMesssage())); item.setToolTipText(8, reqResultDAO.getMesssage()); item.setText(9, reqResultDAO.getIpAddress()); if ("F".equals(reqResultDAO.getResult())) { //$NON-NLS-1$ item.setBackground(SWTResourceManager.getColor(240, 180, 167)); } } } catch (Exception ee) { logger.error("Executed SQL History call", ee); //$NON-NLS-1$ } }
From source file:com.doculibre.constellio.entities.search.SimpleSearch.java
public String getLuceneQuery(boolean withSingleValuedFacets, boolean withMultiValuedFacets) { StringBuffer sb = new StringBuffer(); boolean queryStarted = false; if (advancedSearchRule == null) { if (StringUtils.isNotEmpty(collectionName) && StringUtils.isNotEmpty(query)) { String escapedQuery = getEscapedQuery(); sb.append("("); if (SEARCH_ALL.equals(query)) { sb.append(escapedQuery); queryStarted = true;// w w w.j a va 2 s. c o m } else if (AT_LEAST_ONE_WORD.equals(searchType)) { String[] terms = escapedQuery.split(" "); for (int i = 0; i < terms.length; i++) { sb.append(SynonymUtils.addSynonyms(terms[i], collectionName, false)); queryStarted = true; if (i < terms.length - 1) { sb.append(" OR "); } } } else if (EXACT_EXPRESSION.equals(searchType)) { sb.append(SynonymUtils.addSynonyms(escapedQuery, collectionName, true)); queryStarted = true; } else { // TOUS_LES_MOTS sb.append(SynonymUtils.addSynonyms(escapedQuery, collectionName, false)); queryStarted = true; } sb.append(")"); } if (!tags.isEmpty()) { if (!queryStarted) { queryStarted = true; } else { sb.append(" AND "); } sb.append("("); for (Iterator<String> it = tags.iterator(); it.hasNext();) { String tag = it.next(); sb.append("("); sb.append(IndexField.FREE_TEXT_TAGGING_FIELD + ":" + tag); sb.append(" OR "); sb.append(IndexField.THESAURUS_TAGGING_FIELD + ":" + tag); sb.append(")"); if (it.hasNext()) { sb.append(" AND "); } } sb.append(")"); } } else { if (advancedSearchRule.isValid()) { sb.append(advancedSearchRule.toLuceneQuery()); } queryStarted = true; return sb.toString(); } if (withSingleValuedFacets || withMultiValuedFacets) { for (SearchedFacet searchedFacet : searchedFacets) { SearchableFacet searchableFacet = searchedFacet.getSearchableFacet(); if ((searchableFacet.isMultiValued() && withMultiValuedFacets) || (!searchableFacet.isMultiValued() && withSingleValuedFacets)) { if (!searchableFacet.isCluster()) { if (searchableFacet.isQuery()) { if (!searchedFacet.getIncludedValues().isEmpty()) { if (queryStarted) { sb.append(" +"); } else { queryStarted = true; } boolean first = true; sb.append("("); for (String includedValue : searchedFacet.getIncludedValues()) { if (first) { first = false; } else { sb.append(" OR "); } sb.append(""); sb.append(includedValue); // Nom requte sb.append(""); } sb.append(")"); } } else { String facetName = searchableFacet.getName(); if (!searchedFacet.getIncludedValues().isEmpty()) { if (queryStarted) { sb.append(" +"); } else { queryStarted = true; } boolean first = true; sb.append(facetName); sb.append(":("); for (String includedValue : searchedFacet.getIncludedValues()) { if (first) { first = false; } else { sb.append(" OR "); } sb.append("\""); sb.append(correctFacetValue(includedValue)); sb.append("\""); } sb.append(")"); } } } } } for (SearchedFacet searchedFacet : searchedFacets) { SearchableFacet searchableFacet = searchedFacet.getSearchableFacet(); if ((searchableFacet.isMultiValued() && withMultiValuedFacets) || (!searchableFacet.isMultiValued() && withSingleValuedFacets)) { if (!searchableFacet.isCluster()) { String facetName = searchableFacet.getName(); for (String excludedValue : searchedFacet.getExcludedValues()) { if (queryStarted) { sb.append(" "); } else { queryStarted = true; } sb.append("NOT "); if (searchableFacet.isQuery()) { sb.append(correctFacetValue(excludedValue)); } else { sb.append(facetName); sb.append(":\""); sb.append(correctFacetValue(excludedValue)); sb.append("\""); } } } } } SearchedFacet cluster = getCluster(); if (cluster != null) { RecordCollectionServices collectionServices = ConstellioSpringUtils.getRecordCollectionServices(); RecordCollection collection = collectionServices.get(collectionName); IndexField uniqueKeyIndexField = collection.getUniqueKeyIndexField(); for (String includedValue : cluster.getIncludedValues()) { if (queryStarted) { sb.append(" +"); } else { queryStarted = true; } boolean first = true; sb.append(uniqueKeyIndexField.getName()); sb.append(":("); StringTokenizer st = new StringTokenizer(includedValue, FacetValue.CONCAT_DELIM); while (st.hasMoreTokens()) { String docId = st.nextToken(); if (first) { first = false; } else { sb.append(" OR "); } sb.append("\""); sb.append(docId); sb.append("\""); } sb.append(")"); } for (String excludedValue : cluster.getExcludedValues()) { if (queryStarted) { sb.append(" "); } else { queryStarted = true; } StringTokenizer st = new StringTokenizer(excludedValue, FacetValue.CONCAT_DELIM); while (st.hasMoreTokens()) { String docId = st.nextToken(); sb.append("NOT "); sb.append(uniqueKeyIndexField.getName()); sb.append(":\""); sb.append(docId); sb.append("\""); if (st.hasMoreTokens()) { sb.append(" "); } } } } if (cloudKeyword != null) { if (queryStarted) { sb.append(" +"); } else { queryStarted = true; } sb.append("keyword:\""); sb.append(cloudKeyword.getKeyword()); sb.append("\""); } if (singleSearchLocale != null && StringUtils.isNotBlank(singleSearchLocale.getLanguage())) { if (queryStarted) { sb.append(" +"); } else { queryStarted = true; } sb.append(IndexField.LANGUAGE_FIELD); sb.append(":\""); sb.append(singleSearchLocale.getLanguage()); sb.append("\""); } } String luceneQuery = sb.toString(); int countOpen = StringUtils.countMatches(luceneQuery, "("); int countClose = StringUtils.countMatches(luceneQuery, ")"); if (countOpen == 1 && countClose == 1 && luceneQuery.startsWith("(") && luceneQuery.endsWith(")")) { luceneQuery = luceneQuery.substring(1, luceneQuery.length() - 1); } return luceneQuery; }
From source file:com.emc.storageos.driver.dellsc.helpers.DellSCProvisioning.java
/** * Remove volume exports to initiators./* w ww . j a v a 2 s . c o m*/ * * @param initiators The initiators to remove from. * @param volumes The volumes to remove. * @return The unexport task. */ public DriverTask unexportVolumesFromInitiators(List<Initiator> initiators, List<StorageVolume> volumes) { LOG.info("Unexporting volumes from initiators"); DriverTask task = new DellSCDriverTask("unexportVolumes"); ScServer server = null; StringBuilder errBuffer = new StringBuilder(); int volumesUnmapped = 0; for (StorageVolume volume : volumes) { String ssn = volume.getStorageSystemId(); boolean isSnapshot = StringUtils.countMatches(volume.getNativeId(), ".") == 2; try { StorageCenterAPI api = connectionManager.getConnection(ssn); // Find our actual volume ScVolume scVol = null; if (isSnapshot) { scVol = api.findReplayView(volume.getNativeId()); // For snapshot views we can just delete the view if (scVol != null) { api.deleteVolume(scVol.instanceId); volumesUnmapped++; continue; } } else { scVol = api.getVolume(volume.getNativeId()); } if (scVol == null) { throw new DellSCDriverException( String.format("Unable to find volume %s", volume.getNativeId())); } // Look up the server if needed if (server == null) { server = findScServer(api, ssn, initiators); } if (server == null) { // Unable to find the server, can't continue throw new DellSCDriverException(SERVER_CREATE_FAIL_MSG); } ScMappingProfile[] mappingProfiles = api.findMappingProfiles(server.instanceId, scVol.instanceId); for (ScMappingProfile mappingProfile : mappingProfiles) { api.deleteMappingProfile(mappingProfile.instanceId); } volumesUnmapped++; LOG.info("Volume '{}' unexported from server '{}'", scVol.name, server.name); } catch (StorageCenterAPIException | DellSCDriverException dex) { String error = String.format("Error unmapping volume %s: %s", volume.getDisplayName(), dex); LOG.error(error); errBuffer.append(String.format("%s%n", error)); if (SERVER_CREATE_FAIL_MSG.equals(dex.getMessage())) { // Game over break; } } } task.setMessage(errBuffer.toString()); if (volumesUnmapped == volumes.size()) { task.setStatus(TaskStatus.READY); } else if (volumesUnmapped == 0) { task.setStatus(TaskStatus.FAILED); } else { task.setStatus(TaskStatus.PARTIALLY_FAILED); } return task; }
From source file:info.magnolia.importexport.DataTransporter.java
/** * The opposite of {@link #createExportPath(String)}. * I.e. given a path like this <code>.foo.bar..baz.test.....dir.baz....bar</code>, this method will produce <code>/foo/bar.baz/test../dir/baz..bar</code>. *//*from w ww.j av a2s.c o m*/ public static String revertExportPath(String exportPath) { if (".".equals(exportPath)) { return "/"; } //TODO I have a feeling there's a simpler way to achieve our goal. Matcher matcher = DOT_NAME_PATTERN.matcher(exportPath); StringBuilder reversed = new StringBuilder(exportPath.length()); while (matcher.find()) { String group = matcher.group(); int dotsNumber = StringUtils.countMatches(group, "."); if (dotsNumber == 1) { reversed.append(group.replaceFirst("\\.", "/")); } else { String dots = StringUtils.substringBeforeLast(group, ".").replace("..", "."); String name = StringUtils.substringAfterLast(group, "."); reversed.append(dots); //if number is odd, the last dot has to be replaced with a slash if (dotsNumber % 2 != 0) { reversed.append("/"); } reversed.append(name); } } return reversed.toString(); }
From source file:net.javacoding.xsearch.config.ServerConfiguration.java
public void updateInstanceTimerJobs(String indexName) throws SchedulerException, IOException { Map<String, InstanceJobSchedule> instanceJobSchedules = ServerConfiguration.getInstanceJobSchedules(); InstanceJobSchedule instanceJobSchedule = null; String jobDataString = null;// ww w . j a v a 2 s. c om String subString = null; int endIndex; String groupName = "Instance Job"; ServerConfiguration sc = ServerConfiguration.getServerConfiguration(); Scheduler scheduler = WebserverStatic.getScheduler(); for (Map.Entry<String, InstanceJobSchedule> entry : instanceJobSchedules.entrySet()) { instanceJobSchedule = entry.getValue(); jobDataString = instanceJobSchedule.getJobDataString(); int index = jobDataString.indexOf(indexName); if (index > -1) { endIndex = jobDataString.indexOf("|", index); subString = jobDataString.substring(index, endIndex + 1); jobDataString = jobDataString.replace(subString, ""); if (StringUtils.countMatches(jobDataString, ",") >= 1) { instanceJobSchedule.setJobDataString(jobDataString); ServerConfiguration.setInstanceJobSchedule(instanceJobSchedule); } else { // Remove the Instance Job Schedule itself.. scheduler.deleteJob(new JobKey(instanceJobSchedule.getScheduleName(), groupName)); ServerConfiguration.removeInstanceJobSchedule(instanceJobSchedule); } sc.save(); } } }