Java Code Examples for org.apache.commons.lang3.StringUtils#indexOfIgnoreCase()
The following examples show how to use
org.apache.commons.lang3.StringUtils#indexOfIgnoreCase() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ResponseUtils.java From XS2A-Sandbox with Apache License 2.0 | 6 votes |
private String cookie(String cookieStringIn, String name) { String cookieString = cookieStringIn; if(cookieString==null) { return null; } String cookieParamName=name+"="; // Fix Java: rfc2965 want cookie to be separated by comma. // SOmehow i am receiving some semicolon separated cookies. // Quick Fix: First strip the preceeding cookies if not the first. if(!StringUtils.startsWithIgnoreCase(cookieString, cookieParamName)) { int indexOfIgnoreCase = StringUtils.indexOfIgnoreCase(cookieString, cookieParamName); cookieString = cookieString.substring(indexOfIgnoreCase); } // The proce List<HttpCookie> cookies = HttpCookie.parse(cookieString); for (HttpCookie httpCookie : cookies) { if(StringUtils.equalsIgnoreCase(httpCookie.getName(), name)){ return httpCookie.getValue(); } } return null; }
Example 2
Source File: DockingToolBarUtils.java From ghidra with Apache License 2.0 | 6 votes |
private static String combingToolTipTextWithKeyBinding(String toolTipText, String keyBindingText) { StringBuilder buffy = new StringBuilder(toolTipText); if (StringUtilities.startsWithIgnoreCase(toolTipText, "<HTML>")) { String endHTMLTag = "</HTML>"; int closeTagIndex = StringUtils.indexOfIgnoreCase(toolTipText, endHTMLTag); if (closeTagIndex < 0) { // no closing tag, which is acceptable buffy.append(START_KEYBINDING_TEXT) .append(keyBindingText) .append(END_KEYBINDNIG_TEXT); } else { // remove the closing tag, put on our text, and then put the tag back on buffy.delete(closeTagIndex, closeTagIndex + endHTMLTag.length() + 1); buffy.append(START_KEYBINDING_TEXT) .append(keyBindingText) .append(END_KEYBINDNIG_TEXT) .append(endHTMLTag); } return buffy.toString(); } // plain text (not HTML) return toolTipText + " (" + keyBindingText + ")"; }
Example 3
Source File: CertificateUtils.java From localization_nifi with Apache License 2.0 | 6 votes |
/** * Extracts the username from the specified DN. If the username cannot be extracted because the CN is in an unrecognized format, the entire CN is returned. If the CN cannot be extracted because * the DN is in an unrecognized format, the entire DN is returned. * * @param dn the dn to extract the username from * @return the exatracted username */ public static String extractUsername(String dn) { String username = dn; // ensure the dn is specified if (StringUtils.isNotBlank(dn)) { // determine the separate final String separator = StringUtils.indexOfIgnoreCase(dn, "/cn=") > 0 ? "/" : ","; // attempt to locate the cd final String cnPattern = "cn="; final int cnIndex = StringUtils.indexOfIgnoreCase(dn, cnPattern); if (cnIndex >= 0) { int separatorIndex = StringUtils.indexOf(dn, separator, cnIndex); if (separatorIndex > 0) { username = StringUtils.substring(dn, cnIndex + cnPattern.length(), separatorIndex); } else { username = StringUtils.substring(dn, cnIndex + cnPattern.length()); } } } return username; }
Example 4
Source File: CertificateUtils.java From nifi-registry with Apache License 2.0 | 6 votes |
/** * Extracts the username from the specified DN. If the username cannot be extracted because the CN is in an unrecognized format, the entire CN is returned. If the CN cannot be extracted because * the DN is in an unrecognized format, the entire DN is returned. * * @param dn the dn to extract the username from * @return the exatracted username */ public static String extractUsername(String dn) { String username = dn; // ensure the dn is specified if (StringUtils.isNotBlank(dn)) { // determine the separate final String separator = StringUtils.indexOfIgnoreCase(dn, "/cn=") > 0 ? "/" : ","; // attempt to locate the cd final String cnPattern = "cn="; final int cnIndex = StringUtils.indexOfIgnoreCase(dn, cnPattern); if (cnIndex >= 0) { int separatorIndex = StringUtils.indexOf(dn, separator, cnIndex); if (separatorIndex > 0) { username = StringUtils.substring(dn, cnIndex + cnPattern.length(), separatorIndex); } else { username = StringUtils.substring(dn, cnIndex + cnPattern.length()); } } } return username; }
Example 5
Source File: CertificateUtils.java From nifi with Apache License 2.0 | 6 votes |
/** * Extracts the username from the specified DN. If the username cannot be extracted because the CN is in an unrecognized format, the entire CN is returned. If the CN cannot be extracted because * the DN is in an unrecognized format, the entire DN is returned. * * @param dn the dn to extract the username from * @return the exatracted username */ public static String extractUsername(String dn) { String username = dn; // ensure the dn is specified if (StringUtils.isNotBlank(dn)) { // determine the separate final String separator = StringUtils.indexOfIgnoreCase(dn, "/cn=") > 0 ? "/" : ","; // attempt to locate the cd final String cnPattern = "cn="; final int cnIndex = StringUtils.indexOfIgnoreCase(dn, cnPattern); if (cnIndex >= 0) { int separatorIndex = StringUtils.indexOf(dn, separator, cnIndex); if (separatorIndex > 0) { username = StringUtils.substring(dn, cnIndex + cnPattern.length(), separatorIndex); } else { username = StringUtils.substring(dn, cnIndex + cnPattern.length()); } } } return username; }
Example 6
Source File: TextSearchIndex.java From jadx with Apache License 2.0 | 6 votes |
private int searchNext(FlowableEmitter<CodeNode> emitter, String text, JavaNode javaClass, String code, int startPos, boolean ignoreCase) { int pos; if (ignoreCase) { pos = StringUtils.indexOfIgnoreCase(code, text, startPos); } else { pos = code.indexOf(text, startPos); } if (pos == -1) { return -1; } int lineStart = 1 + code.lastIndexOf(CodeWriter.NL, pos); int lineEnd = code.indexOf(CodeWriter.NL, pos + text.length()); StringRef line = StringRef.subString(code, lineStart, lineEnd == -1 ? code.length() : lineEnd); emitter.onNext(new CodeNode(nodeCache.makeFrom(javaClass), -pos, line.trim())); return lineEnd; }
Example 7
Source File: OAuthUtil.java From arcusplatform with Apache License 2.0 | 5 votes |
public static Optional<String> extractTokenFromBearer(FullHttpRequest req) { String header = req.headers().get(HttpHeaders.AUTHORIZATION); if(StringUtils.isBlank(header) || !StringUtils.containsIgnoreCase(header, OAuthUtil.AUTH_BEARER)) { return Optional.empty(); } int idx = StringUtils.indexOfIgnoreCase(header, OAuthUtil.AUTH_BEARER); return Optional.of(header.substring(idx + OAuthUtil.AUTH_BEARER.length()).trim()); }
Example 8
Source File: DoctypePositionChecker.java From Asqatasun with GNU Affero General Public License v3.0 | 5 votes |
@Override protected void doCheck( SSPHandler sspHandler, Elements elements, TestSolutionHandler testSolutionHandler) { SSP ssp = sspHandler.getSSP(); // if the page doesn't have any doctype declaration, the test is // not applicable if (StringUtils.isBlank(ssp.getDoctype())) { testSolutionHandler.addTestSolution(TestSolution.NOT_APPLICABLE); return; } String sourcePage = ssp.getAdaptedContent(); int indexOfDoctype = StringUtils.indexOfIgnoreCase(sourcePage,DOCTYPE_KEY); int indexOfHtmlTag = StringUtils.indexOfIgnoreCase(sourcePage,HTML_ELEMENT_KEY); if (indexOfHtmlTag < indexOfDoctype || StringUtils.indexOfIgnoreCase(sourcePage,DOCTYPE_KEY, indexOfHtmlTag) != -1) { testSolutionHandler.addTestSolution(getFailureSolution()); addProcessRemark(getFailureSolution(), BAD_DOCTYPE_LOCATION_MSG); } else { testSolutionHandler.addTestSolution(getSuccessSolution()); } }
Example 9
Source File: SecurityUtil.java From lutece-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Check if the value contains terms used for XML External Entity Injection * * @param strValue * The value * @return true if */ public static boolean containsXmlExternalEntityInjectionTerms( String strValue ) { for ( String strTerm : XXE_TERMS ) { if ( StringUtils.indexOfIgnoreCase( strValue, strTerm ) >= 0 ) { Logger logger = Logger.getLogger( LOGGER_NAME ); logger.warn( "SECURITY WARNING : XXE TERMS DETECTED : " + dumpRequest( LocalVariables.getRequest( ) ) ); return true; } } return false; }
Example 10
Source File: KeyBindingUtils.java From ghidra with Apache License 2.0 | 4 votes |
private static int indexOf(String source, String search, int offset) { return StringUtils.indexOfIgnoreCase(source, search, offset); }
Example 11
Source File: GenericCompositeDataTypeLocationDescriptor.java From ghidra with Apache License 2.0 | 4 votes |
@Override Highlight[] getHighlights(String text, Object object, Class<? extends FieldFactory> fieldFactoryClass, Color highlightColor) { Address currentAddress = getAddressForHighlightObject(object); if (!isInAddresses(currentAddress)) { return EMPTY_HIGHLIGHTS; } if (MnemonicFieldFactory.class.isAssignableFrom(fieldFactoryClass) && (object instanceof Data)) { // Not sure if we should ever highlight the mnemonic. It would only be for data. // But, we are always looking for the field of a type, then mnemonic will only hold // the parent's name and not the field's name. } else if (LabelFieldFactory.class.isAssignableFrom(fieldFactoryClass)) { // It would be nice to highlight the label that points into data structures. // However, the label is on the parent address, which is not in our list of matches // when we are offcut. Further, using the program to lookup each address that // comes in to see if it is our paren't address seems too expensive, as highlighting // code is called for every paint operation. // // We could add the parent match to the list of known addresses and then use that // to lookup in real-time later. To do this we would need the current list of // reference addresses and a new list of parent data addresses. That seems a bit // involved just for highlighting a label. } else if (OperandFieldFactory.class.isAssignableFrom(fieldFactoryClass)) { // Not sure how to get the correct part of the text. This is a hack for now. int offset = StringUtils.indexOfIgnoreCase(text, typeAndFieldName, 0); if (offset != -1) { return new Highlight[] { new Highlight(offset, offset + typeAndFieldName.length() - 1, highlightColor) }; } } else if (FieldNameFieldFactory.class.isAssignableFrom(fieldFactoryClass)) { if (text.equalsIgnoreCase(fieldName)) { return new Highlight[] { new Highlight(0, text.length(), highlightColor) }; } String typeName = getDataTypeName(); if (text.equalsIgnoreCase(typeName)) { return new Highlight[] { new Highlight(0, text.length(), highlightColor) }; } } return EMPTY_HIGHLIGHTS; }
Example 12
Source File: IndexOfIgnoreCase.java From vscrawler with Apache License 2.0 | 4 votes |
@Override protected int handleIndex(CharSequence str, CharSequence searchStr, int startPos) { return StringUtils.indexOfIgnoreCase(str, searchStr, startPos); }
Example 13
Source File: FindReplacePane.java From markdown-writer-fx with BSD 2-Clause "Simplified" License | 4 votes |
private void findAll(String text, String find, boolean selectActiveHit) { findInfoLabel.setText(null); if (find.isEmpty()) { clearHits(); return; } boolean matchCase = matchCaseButton.isSelected(); boolean regex = regexButton.isSelected(); hits.clear(); // find if (regex) { String pattern = matchCase ? find : ("(?i)" + find); try { Matcher matcher = Pattern.compile(pattern).matcher(text); while (matcher.find()) hits.add(new Range(matcher.start(), matcher.end())); } catch (PatternSyntaxException ex) { findInfoLabel.setText(Messages.get("FindReplacePane.infoLabel.regexError")); } } else { int fromIndex = 0; int hitIndex; while ((hitIndex = matchCase ? text.indexOf(find, fromIndex) : StringUtils.indexOfIgnoreCase(text, find, fromIndex)) >= 0) { hits.add(new Range(hitIndex, hitIndex + find.length())); fromIndex = hitIndex + find.length(); } } if (hits.isEmpty()) { setActiveHitIndex(-1, selectActiveHit); updateOverviewRuler(); return; } // find active hit index after current selection int anchor = textArea.getAnchor(); int index = Collections.binarySearch(hits, new Range(anchor, anchor), (r1, r2) -> { return r1.end - r2.start; }); if (index < 0) { index = -index - 1; if (index >= hits.size()) index = 0; // wrap } setActiveHitIndex(index, selectActiveHit); updateOverviewRuler(); }
Example 14
Source File: SiteHandler.java From sakai with Educational Community License v2.0 | 4 votes |
/** * Attempts to find the HTML head and body in the document and return them back. * @param responseStr The HTML to be parse * @param debug If <code>true</code> then log where we found the head and body. * * @return <code>null</code> if we failed to parse the page or a PageParts object. */ PageParts parseHtmlParts(String responseStr, boolean debug) { // We can't lowercase the string and search in it as then the offsets don't match when a character is a // different length in upper and lower case int headStart = StringUtils.indexOfIgnoreCase(responseStr, "<head"); headStart = findEndOfTag(responseStr, headStart); int headEnd = StringUtils.indexOfIgnoreCase(responseStr, "</head"); int bodyStart = StringUtils.indexOfIgnoreCase(responseStr, "<body"); bodyStart = findEndOfTag(responseStr, bodyStart); // Some tools (Blogger for example) have multiple // head-body pairs - browsers seem to not care much about // this so we will do the same - so that we can be // somewhat clean - we search for the "last" end // body tag - for the normal case there will only be one int bodyEnd = StringUtils.indexOfIgnoreCase(responseStr, "</body"); // If there is no body end at all or it is before the body // start tag we simply - take the rest of the response if ( bodyEnd < bodyStart ) bodyEnd = responseStr.length() - 1; if(debug) log.info("Frameless HS="+headStart+" HE="+headEnd+" BS="+bodyStart+" BE="+bodyEnd); if (bodyEnd > bodyStart && bodyStart > headEnd && headEnd > headStart && headStart > 1) { PageParts pp = new PageParts(); pp.head = responseStr.substring(headStart + 1, headEnd); // SAK-29908 // Titles come twice to view and tool title overwrites main title because // it is printed before. int titleStart = pp.head.indexOf("<title"); int titleEnd = pp.head.indexOf("</title"); titleEnd = findEndOfTag(pp.head, titleEnd); pp.head = (titleStart != -1 && titleEnd != -1) ? pp.head.substring(0, titleStart) + pp.head.substring(titleEnd + 1) : pp.head; // End SAK-29908 pp.body = responseStr.substring(bodyStart + 1, bodyEnd); return pp; } return null; }
Example 15
Source File: SiteHandler.java From sakai with Educational Community License v2.0 | 4 votes |
/** * Attempts to find the HTML head and body in the document and return them back. * @param responseStr The HTML to be parse * @param debug If <code>true</code> then log where we found the head and body. * * @return <code>null</code> if we failed to parse the page or a PageParts object. */ PageParts parseHtmlParts(String responseStr, boolean debug) { // We can't lowercase the string and search in it as then the offsets don't match when a character is a // different length in upper and lower case int headStart = StringUtils.indexOfIgnoreCase(responseStr, "<head"); headStart = findEndOfTag(responseStr, headStart); int headEnd = StringUtils.indexOfIgnoreCase(responseStr, "</head"); int bodyStart = StringUtils.indexOfIgnoreCase(responseStr, "<body"); bodyStart = findEndOfTag(responseStr, bodyStart); // Some tools (Blogger for example) have multiple // head-body pairs - browsers seem to not care much about // this so we will do the same - so that we can be // somewhat clean - we search for the "last" end // body tag - for the normal case there will only be one int bodyEnd = StringUtils.indexOfIgnoreCase(responseStr, "</body"); // If there is no body end at all or it is before the body // start tag we simply - take the rest of the response if ( bodyEnd < bodyStart ) bodyEnd = responseStr.length() - 1; if(debug) log.info("Frameless HS="+headStart+" HE="+headEnd+" BS="+bodyStart+" BE="+bodyEnd); if (bodyEnd > bodyStart && bodyStart > headEnd && headEnd > headStart && headStart > 1) { PageParts pp = new PageParts(); pp.head = responseStr.substring(headStart + 1, headEnd); // SAK-29908 // Titles come twice to view and tool title overwrites main title because // it is printed before. int titleStart = pp.head.indexOf("<title"); int titleEnd = pp.head.indexOf("</title"); titleEnd = findEndOfTag(pp.head, titleEnd); pp.head = (titleStart != -1 && titleEnd != -1) ? pp.head.substring(0, titleStart) + pp.head.substring(titleEnd + 1) : pp.head; // End SAK-29908 pp.body = responseStr.substring(bodyStart + 1, bodyEnd); return pp; } return null; }