List of usage examples for org.apache.commons.lang3 StringUtils indexOfIgnoreCase
public static int indexOfIgnoreCase(final CharSequence str, final CharSequence searchStr)
Case in-sensitive find of the first index within a CharSequence.
A null CharSequence will return -1 .
From source file:com.netflix.metacat.connector.jdbc.services.JdbcConnectorTableService.java
/** * Rebuild a source type definition.// ww w . j a v a 2s . com * * @param type The base type e.g. VARCHAR * @param size The size if applicable to the {@code type} * @param precision The precision if applicable to the {@code type} e.g. DECIMAL's * @return The representation of source type e.g. INTEGER, VARCHAR(50) or DECIMAL(20, 10) * @throws SQLDataException When size or precision can't be parsed to integers if non null */ protected String buildSourceType(@Nonnull @NonNull final String type, @Nullable final String size, @Nullable final String precision) throws SQLDataException { if (size != null) { final int sizeInt; try { sizeInt = Integer.parseInt(size); } catch (final NumberFormatException nfe) { throw new SQLDataException("Size field could not be converted to integer", nfe); } // Make sure if the type is unsigned it's created correctly final String baseType; final String afterMagnitude; final int unsignedIndex = StringUtils.indexOfIgnoreCase(type, UNSIGNED); if (unsignedIndex != -1) { baseType = StringUtils.trim(type.substring(0, unsignedIndex)); afterMagnitude = type.substring(unsignedIndex); } else { baseType = type; afterMagnitude = null; } if (precision != null) { final int precisionInt; try { precisionInt = Integer.parseInt(precision); } catch (final NumberFormatException nfe) { throw new SQLDataException("Precision field could not be converted to integer", nfe); } return baseType + LEFT_PAREN + sizeInt + COMMA_SPACE + precisionInt + RIGHT_PAREN + (afterMagnitude != null ? SPACE + afterMagnitude : EMPTY); } else { return baseType + LEFT_PAREN + sizeInt + RIGHT_PAREN + (afterMagnitude != null ? SPACE + afterMagnitude : EMPTY); } } else { return type; } }
From source file:com.moviejukebox.tools.HTMLTools.java
public static List<String> extractTags(String src, String sectionStart, String sectionEnd, String startTag, String endTag, boolean forceCloseTag) { List<String> tags = new ArrayList<>(); int startIndex = StringUtils.indexOfIgnoreCase(src, sectionStart); if (startIndex == -1) { return tags; }/*from ww w. j a v a 2 s .c o m*/ startIndex += sectionStart.length(); int endIndex = (sectionEnd == null) ? src.length() : StringUtils.indexOfIgnoreCase(src, sectionEnd, startIndex); if (endIndex == -1) { return tags; } String sectionText = src.substring(startIndex, endIndex); int lastIndex = sectionText.length(); startIndex = 0; int startLen = 0; int endLen = endTag.length(); if (startTag != null) { startIndex = sectionText.indexOf(startTag); startLen = startTag.length(); } while (startIndex != -1) { startIndex += startLen; if (forceCloseTag) { int close = sectionText.indexOf('>', startIndex); if (close != -1) { startIndex = close + 1; } } endIndex = sectionText.indexOf(endTag, startIndex); if (endIndex == -1) { endIndex = lastIndex; } String text = sectionText.substring(startIndex, endIndex); tags.add(HTMLTools.decodeHtml(text.trim())); endIndex += endLen; if (endIndex > lastIndex) { break; } if (startTag != null) { startIndex = sectionText.indexOf(startTag, endIndex); } else { startIndex = endIndex; } } return tags; }
From source file:com.moviejukebox.plugin.ImdbPlugin.java
private boolean extractWritersFromFullCredits(Movie movie, String fullcreditsXML, boolean overrideNormal, boolean overridePeople) { // count for already set writers int count = 0; // flag to indicate if writers must be cleared boolean clearWriters = Boolean.TRUE; boolean clearPeopleWriters = Boolean.TRUE; // flag to indicate if match has been found boolean found = Boolean.FALSE; for (String writerMatch : new String[] { "Writing credits", "Writer", "Writers" }) { if (StringUtils.indexOfIgnoreCase(fullcreditsXML, HTML_GT + writerMatch) >= 0) { for (String member : HTMLTools.extractTags(fullcreditsXML, HTML_GT + writerMatch, HTML_TABLE_END, HTML_A_START, HTML_A_END, Boolean.FALSE)) { int beginIndex = member.indexOf("href=\"/name/"); if (beginIndex > -1) { String personID = member.substring(beginIndex + 12, member.indexOf("/", beginIndex + 12)); String name = StringUtils .trimToEmpty(member.substring(member.indexOf(HTML_GT, beginIndex) + 1)); if (!name.contains("more credit")) { if (overrideNormal) { // clear writers if not already done if (clearWriters) { movie.clearWriters(); clearWriters = Boolean.FALSE; }//from w w w . j av a 2 s .c o m // add writer movie.addWriter(name, IMDB_PLUGIN_ID); } if (overridePeople) { // clear writers if not already done if (clearPeopleWriters) { movie.clearPeopleWriters(); clearPeopleWriters = Boolean.FALSE; } // add writer movie.addWriter(IMDB_PLUGIN_ID + ":" + personID, name, imdbInfo.getImdbSite() + IMDB_NAME + personID + "/", IMDB_PLUGIN_ID); } found = Boolean.TRUE; count++; if (count == writerMax) { break; } } } } } if (found) { // We found a match, so stop search. break; } } return found; }
From source file:com.sonicle.webtop.mail.Service.java
private String getBodyInnerHtml(String body) { int ix1 = StringUtils.indexOfIgnoreCase(body, "<BODY"); if (ix1 >= 0) { int ix2 = body.indexOf(">", ix1 + 1); if (ix2 < 0) { ix2 = ix1 + 4;/*from ww w .j av a 2s . c o m*/ } int ix3 = StringUtils.indexOfIgnoreCase(body, "</BODY", ix2 + 1); if (ix3 > 0) { body = body.substring(ix2 + 1, ix3); } else { body = body.substring(ix2 + 1); } } return body; }
From source file:net.sourceforge.pmd.properties.PropertyDescriptorTest.java
private static Matcher<String> containsIgnoreCase(final String substring) { return new SubstringMatcher(substring) { @Override/*from w w w . j a va 2 s . co m*/ protected boolean evalSubstringOf(String string) { return StringUtils.indexOfIgnoreCase(string, substring) != -1; } @Override protected String relationship() { return "containing (ignoring case)"; } }; }
From source file:net.tsz.afinal.http.HttpHandler.java
/** * ?//from w w w.j a v a 2s.c om * */ private String replaceParam(String rawData, String paramName, String newParamValue) { if (rawData == null) { return ""; } int index = StringUtils.indexOfIgnoreCase(rawData, paramName); if (index > 0) { int endIndex = rawData.indexOf("&", index + 1); String newData; if (endIndex > 0) newData = rawData.substring(0, index) + paramName + "=" + newParamValue + rawData.substring(endIndex); else newData = rawData.substring(0, index) + paramName + "=" + newParamValue; return newData; } return rawData; }
From source file:net.tsz.afinal.http.HttpHandler.java
/** * URL??AjaxParams//from ww w . j a v a2 s. c o m * @param rawData name1:value1&name2:value2&... * */ private AjaxParams convertToAjaxParams(String rawData) { AjaxParams ajaxParams = new AjaxParams(); try { if (rawData != null) { return ajaxParams; } String[] params = rawData.split("&"); if (params != null && params.length > 0) { String name, value; for (String param : params) { if (!param.contains("=")) { continue; } int index = StringUtils.indexOfIgnoreCase(param, "="); name = param.substring(0, index); value = param.substring(index + 1); ajaxParams.put(name, value); } } } catch (Exception e) { ZLogger.e("convertToAjaxParams:" + e.toString()); } return ajaxParams; }
From source file:org.apache.nifi.registry.security.util.CertificateUtils.java
/** * 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// w w w . j ava 2 s .c o m */ 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; }
From source file:org.asqatasun.rules.elementchecker.doctype.DoctypePositionChecker.java
@Override protected void doCheck(SSPHandler sspHandler, Elements elements, TestSolutionHandler testSolutionHandler) { SSP ssp = sspHandler.getSSP();/*from w ww . ja v a 2 s . co m*/ // 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()); } }
From source file:org.dbgl.util.searchengine.WebSearchEngine.java
protected static String removeTag(final String openTag, final String closeTag, final String htmlChunk) { StringBuffer result = new StringBuffer(htmlChunk); int openingIndex = StringUtils.indexOfIgnoreCase(result, openTag); while (openingIndex != -1) { result.delete(openingIndex, result.indexOf(">", openingIndex + openTag.length()) + 1); int closingIndex = StringUtils.indexOfIgnoreCase(result, closeTag); result.delete(closingIndex, closingIndex + closeTag.length()); openingIndex = StringUtils.indexOfIgnoreCase(result, openTag); }/*ww w. j a v a 2s.c o m*/ return result.toString(); }