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:$.MessageLogParser.java
/** * Gets lines which corresponds with specified correlation ID from the specified log file. */*from ww w .j a va 2s . c om*/ * @param logFile the log file * @param correlationId the correlation ID * @return log lines * @throws IOException when error occurred during file reading */ private List<String> getLogLines(File logFile, String correlationId) throws IOException { List<String> logLines = new ArrayList<String>(); Log.debug("Go through the following log file: " + logFile); int year = Calendar.getInstance().get(Calendar.YEAR); String[] possibleYears = new String[] { String.valueOf(year - 1), String.valueOf(year) }; InputStream stream = null; try { if (logFile.getName().endsWith(GZIP_FILE_EXTENSION)) { stream = new GZIPInputStream(new BufferedInputStream(new FileInputStream(logFile))); } else { stream = new BufferedInputStream(new FileInputStream(logFile)); } LineIterator it = IOUtils.lineIterator(stream, Charset.defaultCharset()); String requestId = null; boolean lastCorrectLine = false; // if previous log line belongs to requestId while (it.hasNext()) { String line = it.nextLine(); if (requestId == null) { if (StringUtils.contains(line, correlationId)) { logLines.add(formatLogLine(line)); // finds requestID requestId = getRequestId(line); if (requestId != null) { Log.debug("correlationId (" + correlationId + ") => requestId (" + requestId + ")"); } } } else { // adds lines with requestID and lines that belongs to previous log record (e.g. XML request) // it's better to check also correlationID because it's not one request ID // for all repeated scheduled jobs for processing of partly failed messages // 2013-05-23 20:22:36,754 [MACHINE_IS_UNDEFINED, ajp-bio-8009-exec-19, /esb/ws/account/v1, ... // <checkCustomerCreditRequest xmlns="cleverbus.org/ws/AccountService-v1"> // <firstName>csd</firstName> // <lastName>acs</lastName> // <birthNumber>111111/1111</birthNumber> // </checkCustomerCreditRequest> if (StringUtils.contains(line, requestId) || (StringUtils.contains(line, correlationId)) || (lastCorrectLine && !StringUtils.startsWithAny(line, possibleYears))) { logLines.add(formatLogLine(line)); lastCorrectLine = true; } else { lastCorrectLine = false; } } } } finally { IOUtils.closeQuietly(stream); } return logLines; }
From source file:com.bluexml.xforms.generator.forms.renderable.common.association.selection.multiple.RenderableSMultiple.java
@Override public Rendered render(String path, Stack<Renderable> parents, Stack<Rendered> renderedParents, boolean isInIMultRepeater) { ModelElementBindHolder bindRepeater = getBindRepeater(); ModelElementBindSimple bindActions = getBindActions(); ModelElementBindSimple bindLabel = new ModelElementBindSimple(MsgId.INT_INSTANCE_SIDELABEL.getText()); ModelElementBindSimple bindId = new ModelElementBindSimple(MsgId.INT_INSTANCE_SIDEID.getText()); ModelElementBindSimple bindEdit = getBindEdit(); bindEdit.setNodeset(MsgId.INT_INSTANCE_SIDEEDIT.getText()); ModelElementBindSimple bindType = getBindType(); bindType.setNodeset(MsgId.INT_INSTANCE_SIDETYPE.getText()); bindRepeater.addSubBind(bindLabel);/*from ww w.j a va 2 s. c o m*/ bindRepeater.addSubBind(bindId); bindRepeater.addSubBind(bindEdit); setBindEdit(bindEdit); bindRepeater.addSubBind(bindType); setBindType(bindType); String nodeSetActions = computeNodeSetActions(path); Rendered rendered = new RenderedLine(); rendered.setOptionalData(XFormsGenerator.getId(bean.getName() + "Repeater")); Element div = rendered.getXformsElement(); div.setAttribute("class", getWidgetStyle()); // e.g.: Paragraphe1310/field_12/modelcyvel.Video (usual suffix is [position()!=last()]) bindActions.setNodeset(nodeSetActions); bindActions.setRepeaterRootBind(true); // #1241 if (bean.isItemSelector()) { String nodeSetItems = computeNodeSetItems(nodeSetActions); bindRepeater.setNodeset(nodeSetItems); rendered.addModelElement(bindRepeater); if (getFormGenerator().isInReadOnlyMode() == false) { // for plain select widget, this is done in RenderableSelectorList if (bean.isMandatory()) { // #978 bindId.setRequired(true); bindLabel.setRequired(true); int pos = path.length() - 1; String pathShortened = path.charAt(pos) == '/' ? path.substring(0, pos) : path; String constraint = "instance('minstance')/" + pathShortened + "[1]/" + bindId.getNodeset() + " ne ''"; if (StringUtils.contains(selector.getBindId().getConstraint(), constraint) == false) { selector.getBindId().setConstraint(constraint); } } } } rendered.addModelElement(bindActions); return rendered; }
From source file:com.sonar.it.jenkins.orchestrator.container.JenkinsWrapper.java
private void failInCaseOfError(Exception e) { if (StringUtils.contains(e.getMessage(), "HTTP error: 5")) { throw new IllegalStateException(e); }//from w w w . j av a 2 s . c o m if ((resultHandler.hasResult()) && (resultHandler.getException() != null)) { throw new IllegalStateException(resultHandler.getException()); } if ((resultHandler.hasResult()) && (resultHandler.getExitValue() != 0)) { throw new IllegalStateException(); } }
From source file:eionet.meta.dao.domain.DataElement.java
/** * indicates if element is taken from an external schema. * * @return true if identifier contains colon, for example geo:lat *///from www. j ava 2 s . c om public boolean isExternalSchema() { return StringUtils.contains(identifier, ":"); }
From source file:info.magnolia.cms.taglibs.util.SearchResultSnippetTag.java
/** * Extract a collection of snippets from any paragraph in the given page. * @return a collection of Strings.//from w w w. j ava2 s . c om * @todo avoid overlapping snippets (use regexp insted of simple indexOfs) * @todo only extract snippets from user-configured properties * @todo abbreviate on whitespace and puntuation, detect start of sentences * @todo replace ampersand in regexp * @todo break methods and write junits */ public Collection getSnippets() { if (log.isDebugEnabled()) { log.debug("collecting snippets"); //$NON-NLS-1$ } Collection snippets = new ArrayList(); String[] searchTerms = StringUtils.split(this.query); Collection paragraphCollections = this.page.getChildren(ItemType.CONTENTNODE); Iterator iterator = paragraphCollections.iterator(); outer: while (iterator.hasNext()) { Content paragraphCollection = (Content) iterator.next(); Collection paragraphs = paragraphCollection.getChildren(); Iterator parIterator = paragraphs.iterator(); while (parIterator.hasNext()) { Content paragraph = (Content) parIterator.next(); if (log.isDebugEnabled()) { log.debug("Iterating on paragraph " + paragraph); //$NON-NLS-1$ } Collection properties = paragraph.getNodeDataCollection(); Iterator dataIterator = properties.iterator(); while (dataIterator.hasNext()) { NodeData property = (NodeData) dataIterator.next(); if (property.getType() != PropertyType.BINARY) { String resultString = property.getString(); if (log.isDebugEnabled()) { log.debug("Iterating on property " + property.getName()); //$NON-NLS-1$ log.debug("Property value is " + resultString); //$NON-NLS-1$ } // a quick and buggy way to avoid configuration properties, we should allow the user to // configure a list of nodeData to search for... if (resultString.length() < 20) { continue; } for (int j = 0; j < searchTerms.length; j++) { String searchTerm = StringUtils.lowerCase(searchTerms[j]); // exclude keywords and words with less than 2 chars if (!ArrayUtils.contains(SimpleSearchTag.KEYWORDS, searchTerm) && searchTerm.length() > 2) { if (log.isDebugEnabled()) { log.debug("Looking for search term [" + searchTerm + "] in [" + resultString //$NON-NLS-1$//$NON-NLS-2$ + "]"); //$NON-NLS-1$ } // first check, avoid using heavy string replaceAll operations if the search term is not // there if (!StringUtils.contains(resultString.toLowerCase(), searchTerm)) { continue; } // strips out html tags using a regexp resultString = resultString.replaceAll("\\<.*?\\>", ""); //$NON-NLS-1$ //$NON-NLS-2$ // only get first matching keyword int pos = resultString.toLowerCase().indexOf(searchTerm); if (pos > -1) { int posEnd = pos + searchTerm.length(); int from = (pos - chars / 2); if (from < 0) { from = 0; } int to = from + chars; if (to > resultString.length()) { to = resultString.length(); } StringBuffer snippet = new StringBuffer(); snippet.append(StringUtils.substring(resultString, from, pos)); snippet.append("<strong>"); //$NON-NLS-1$ snippet.append(StringUtils.substring(resultString, pos, posEnd)); snippet.append("</strong>"); //$NON-NLS-1$ snippet.append(StringUtils.substring(resultString, posEnd, to)); if (from > 0) { snippet.insert(0, "... "); //$NON-NLS-1$ } if (to < resultString.length()) { snippet.append("... "); //$NON-NLS-1$ } if (log.isDebugEnabled()) { log.debug("Search term found, adding snippet " + snippet); //$NON-NLS-1$ } snippets.add(snippet); if (snippets.size() >= this.maxSnippets) { if (log.isDebugEnabled()) { log.debug("Maximum number of snippets (" //$NON-NLS-1$ + this.maxSnippets + ") reached, exiting"); //$NON-NLS-1$ } break outer; } } } } } } } } return snippets; }
From source file:com.haulmont.cuba.web.gui.data.OptionsDsWrapper.java
@Override public Collection getItemIds() { if (executeAutoRefreshInvalid) { if (UI.getCurrent().getConnectorTracker().isWritingResponse()) { try { CollectionDsHelper.autoRefreshInvalid(datasource, autoRefresh); } catch (IllegalStateException ex) { if (StringUtils.contains(ex.getMessage(), "A connector should not be marked as dirty while a response is being written")) { // explain exception String message = String.format( "Some datasource listener has modified the component while it is in rendering state. Please refresh datasource '%s' explicitly", datasource.getId()); throw new IllegalStateException(message, ex); }//from w w w .j a v a 2s . c om throw ex; } } else { CollectionDsHelper.autoRefreshInvalid(datasource, autoRefresh); } } return datasource.getItems(); }
From source file:com.nridge.ds.solr.SolrParentChild.java
private String extractLimit(String aValue) { String fetchLimit = FIELD_FETCH_LIMIT_DEFAULT; if (StringUtils.isNotEmpty(aValue)) { int offset1 = aValue.lastIndexOf("("); int offset2 = aValue.lastIndexOf(")"); if ((offset1 != -1) && (offset2 != -1)) { String countString = aValue.substring(offset1 + 1, offset2); if (StringUtils.contains(countString, StrUtl.CHAR_COMMA)) { ArrayList<String> offsetLimitList = StrUtl.expandToList(countString, StrUtl.CHAR_COMMA); if (offsetLimitList.size() > 1) { String limitValue = offsetLimitList.get(1); if (StringUtils.isNumeric(limitValue)) fetchLimit = limitValue; }// ww w . j a va 2s .c o m } else { if (StringUtils.isNumeric(countString)) fetchLimit = countString; } } } return fetchLimit; }
From source file:au.org.ala.sds.model.SensitiveTaxonStore.java
public SensitiveTaxon findByExactMatch(String name) { // Do binary search int idx = Collections.binarySearch(taxonList, new SensitiveTaxon(name, StringUtils.contains(name, ' ') ? RankType.SPECIES : RankType.GENUS)); if (idx >= 0 && taxonList.get(idx).getName().equalsIgnoreCase(name)) { return taxonList.get(idx); } else {//w w w. j a v a 2s . co m return null; } }
From source file:com.microsoft.alm.plugin.external.commands.SyncCommand.java
/** * An error will be in the following form where there are duplicates for each error. The duplicates only differ * by the fact that the first reference of the error refers to only the file name and the second reference refers * to the entire path of the file. All the file name errors are the first listed followed by all the path errors. * Only make exceptions out of the path errors and ignore the file name errors so we see no duplicates. Example * of an error message will look like this: * <p/>/*w w w. j a v a2 s . c om*/ * Warning - Unable to refresh testHereRename.txt because you have a pending edit. * Conflict TestAdd.txt - Unable to perform the get operation because you have a conflicting edit * Warning - Unable to refresh /Users/user/tfvc-tfs/tfsTest_01/addFold/testHereRename.txt because you have a pending edit. * Conflict /Users/user/tfvc-tfs/tfsTest_01/TestAdd.txt - Unable to perform the get operation because you have a conflicting edit * * @param stderr * @return */ private List<SyncException> parseException(final String stderr) { final List<SyncException> exceptions = new ArrayList<SyncException>(); final String[] exceptionLines = getLines(stderr); for (int i = exceptionLines.length / 2; i < exceptionLines.length; i++) { // skip empty lines and don't treat conflicts as exceptions if (StringUtils.isNotEmpty(exceptionLines[i]) && !StringUtils.contains(exceptionLines[i], CONFLICT_MESSAGE)) { //TODO: what if warning is that file was skipped (but only shows up when force was used) final SyncException exception = new SyncException(exceptionLines[i], StringUtils.startsWith(exceptionLines[i], WARNING_PREFIX)); exceptions.add(exception); } } return exceptions; }
From source file:com.prowidesoftware.swift.model.field.Field50F.java
/** * Serializes the fields' components into the single string value (SWIFT format) *///from w ww .j a v a2s.c o m @Override public String getValue() { final StringBuilder result = new StringBuilder(); if (StringUtils.isNotEmpty(getComponent1())) { if (!StringUtils.contains(getComponent1(), "/")) { result.append("/"); } result.append(StringUtils.trimToEmpty(getComponent1())); } if (StringUtils.isNotEmpty(getComponent2()) || StringUtils.isNotEmpty(getComponent3())) { result.append(com.prowidesoftware.swift.io.writer.FINWriterVisitor.SWIFT_EOL); result.append(StringUtils.trimToEmpty(getComponent2())); result.append("/"); result.append(StringUtils.trimToEmpty(getComponent3())); } if (StringUtils.isNotEmpty(getComponent4()) || StringUtils.isNotEmpty(getComponent5())) { result.append(com.prowidesoftware.swift.io.writer.FINWriterVisitor.SWIFT_EOL); result.append(StringUtils.trimToEmpty(getComponent4())); result.append("/"); result.append(StringUtils.trimToEmpty(getComponent5())); } if (StringUtils.isNotEmpty(getComponent6()) || StringUtils.isNotEmpty(getComponent7())) { result.append(com.prowidesoftware.swift.io.writer.FINWriterVisitor.SWIFT_EOL); result.append(StringUtils.trimToEmpty(getComponent6())); result.append("/"); result.append(StringUtils.trimToEmpty(getComponent7())); } if (StringUtils.isNotEmpty(getComponent8()) || StringUtils.isNotEmpty(getComponent9())) { result.append(com.prowidesoftware.swift.io.writer.FINWriterVisitor.SWIFT_EOL); result.append(StringUtils.trimToEmpty(getComponent8())); result.append("/"); result.append(StringUtils.trimToEmpty(getComponent9())); } return result.toString(); }