Example usage for org.apache.commons.lang3 StringUtils indexOf

List of usage examples for org.apache.commons.lang3 StringUtils indexOf

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils indexOf.

Prototype

public static int indexOf(final CharSequence seq, final CharSequence searchSeq, final int startPos) 

Source Link

Document

Finds the first index within a CharSequence, handling null .

Usage

From source file:kenh.expl.functions.IndexOf.java

public int process(String seq, String searchSeq, int startPos, boolean ignoreCase) {
    if (ignoreCase)
        return StringUtils.indexOfIgnoreCase(seq, searchSeq, startPos);
    else//from  ww  w .  ja  v a  2s  .  co m
        return StringUtils.indexOf(seq, searchSeq, startPos);
}

From source file:com.google.testing.pogen.generator.template.TemplateUpdaterWithClassAttribute.java

protected StringBuilder buildModifiedTag(String template, HtmlTagInfo tagInfo) {
    StringBuilder tag = new StringBuilder(template.substring(tagInfo.getStartIndex(), tagInfo.getEndIndex()));
    tagInfo.setAttributeValue(generateUniqueValue());
    if (tagInfo.hasAttributeValue()) {
        int space = StringUtils.indexOfAny(tag, ' ', '\t', '\r', '\n');
        int equal;
        while (space > 0 && (equal = StringUtils.indexOf(tag, '=', space + 1)) > 0) {
            String name = tag.substring(space + 1, equal).trim();
            int leftQuote = StringUtils.indexOfAny(tag.substring(space + 1), '"', '\'') + space + 1;
            if (name.equals("class")) {
                tag.insert(leftQuote + 1, tagInfo.getAttributeValue() + " ");
                return tag;
            }/*from www .  j  a va2 s  .  c  o m*/
            space = StringUtils.indexOf(tag, tag.charAt(leftQuote), leftQuote + 1) + 1;
        }
    }
    // Deal with closed tag such as <br />
    int insertIndex = tag.length() - 2;
    String tail = ">";
    if (tag.charAt(insertIndex) == '/') {
        --insertIndex;
        tail = " />";
    }
    // Remove redundant space
    while (tag.charAt(insertIndex) == ' ') {
        insertIndex--;
    }
    // Insert the generated id attribute
    tag.setLength(insertIndex + 1);
    tag.append(" class=\"" + tagInfo.getAttributeValue() + "\"" + tail);
    return tag;
}

From source file:com.norconex.commons.lang.file.FileUtil.java

/**
 * Converts a "safe" file name originally created with 
 * {@link #toSafeFileName(String)} into its original string.
 * @param safeFileName the file name to convert to its origianl form
 * @return original string//from w  w w . java  2 s.  c  o  m
 */
public static String fromSafeFileName(String safeFileName) {
    if (safeFileName == null) {
        return null;
    }
    StringBuilder b = new StringBuilder();
    for (int i = 0; i < safeFileName.length(); i++) {
        char ch = safeFileName.charAt(i);
        if (ch == '_') {
            String intVal = StringUtils.substring(safeFileName, i + 1,
                    StringUtils.indexOf(safeFileName, '_', i + 1));
            b.append((char) NumberUtils.toInt(intVal));
            i += intVal.length() + 1;
        } else {
            b.append(ch);
        }
    }
    return b.toString();
}

From source file:com.chenyang.proxy.http.HttpUserAgentForwardHandler.java

private String getPartialUrl(String fullUrl) {
    if (StringUtils.startsWith(fullUrl, "http")) {
        int idx = StringUtils.indexOf(fullUrl, "/", 7);
        return idx == -1 ? "/" : StringUtils.substring(fullUrl, idx);
    }//  ww  w. ja  v  a  2 s .c  o  m

    return fullUrl;
}

From source file:com.moviejukebox.plugin.ImdbPlugin.java

/**
 * Look for the tagline in the XML// ww  w.j  a v a2  s  .  c  o  m
 *
 * @param xml The source XML
 * @return The tagline found (or UNKNOWN)
 */
private static String extractTagline(String xml) {
    String tagline = UNKNOWN;

    // Look for the tagline with upto 3 characters after the sitedef to ensure we get any plurals on the end
    Pattern pTagline = Pattern.compile("(Tagline.{0,3}?:</h\\d>)", Pattern.CASE_INSENSITIVE);
    Matcher m = pTagline.matcher(xml);

    if (m.find()) {
        int beginIndex = m.start();
        // We need to work out which of the two formats to use, this is dependent on which comes first "<span" or "</div"
        String endMarker;
        if (StringUtils.indexOf(xml, "<span", beginIndex) < StringUtils.indexOf(xml, HTML_DIV_END,
                beginIndex)) {
            endMarker = "<span";
        } else {
            endMarker = HTML_DIV_END;
        }

        // Now look for the right string
        tagline = HTMLTools.stripTags(HTMLTools.extractTag(xml, m.group(1), endMarker), false);
        tagline = cleanStringEnding(tagline);
    }

    return tagline;
}

From source file:org.apache.lens.cube.parse.TestQuery.java

/**
 * Get the next join query details from a given query
 *//*from   w ww . j  av  a 2s.co  m*/
private JoinDetails getNextJoinTypeDetails(String query) {
    int nextJoinIndex = Integer.MAX_VALUE;
    JoinType nextJoinTypePart = null;
    for (JoinType joinType : JoinType.values()) {
        int joinIndex = StringUtils.indexOf(query, joinType.name(), 1);
        if (joinIndex < nextJoinIndex && joinIndex > 0) {
            nextJoinIndex = joinIndex;
            nextJoinTypePart = joinType;
        }
    }
    JoinDetails joinDetails = new JoinDetails();
    joinDetails.setIndex(nextJoinIndex);
    if (nextJoinIndex != Integer.MAX_VALUE) {
        joinDetails.setJoinString(
                getJoinString(query.substring(nextJoinIndex + nextJoinTypePart.name().length())));
    }
    joinDetails.setJoinType(nextJoinTypePart);
    return joinDetails;
}

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/*from  w  w  w.ja v a  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.processing.ProcessRemarkServiceImpl.java

/**
* 
* @param originalElementHtml//from  w  w  w  .j  a  v  a2 s. com
* @param truncatedElementHtml
* @param indexOfElementToClose
* @return 
*/
private String closeInnerElement(String originalElementHtml, String truncatedElementHtml) {

    int startPos = truncatedElementHtml.length();

    int indexOfElementCloser = StringUtils.indexOf(originalElementHtml, ESCAPED_CLOSE_TAG, startPos);
    int indexOfElementAutoCloser = StringUtils.indexOf(originalElementHtml, AUTO_CLOSE_TAG_OCCUR, startPos);

    String innerClosedElement = StringUtils.substring(originalElementHtml, 0,
            (indexOfElementCloser + ESCAPED_CLOSE_TAG.length()));

    // if the current element is auto-close, return current well-closed element
    if (indexOfElementAutoCloser == (indexOfElementCloser - 1)) {
        return innerClosedElement;
    }

    // if the current element is not auto-close, get the name of it and 
    // and properly close it
    int indexOfElementOpenTagOpener = StringUtils.lastIndexOf(originalElementHtml, ESCAPED_OPEN_TAG, startPos);

    int indexOfElementOpenTagClose = StringUtils.indexOf(originalElementHtml, ' ', indexOfElementOpenTagOpener);

    String elementName = StringUtils.substring(originalElementHtml,
            indexOfElementOpenTagOpener + ESCAPED_OPEN_TAG.length(), indexOfElementOpenTagClose);

    return closeElement(innerClosedElement, elementName);
}

From source file:org.jevis.commons.unit.UnitFormula.java

private int[] getNextSubPartRange(String formula) {
    int start = StringUtils.indexOf(formula, PUNCTUATION_START, _lastPart);
    int end = getPartEnd(formula, _lastPart);

    _lastPart = end;/*from w ww. ja va 2 s  . co m*/
    int[] range = { start, end };
    return range;

}

From source file:org.yamj.core.service.metadata.online.ImdbScanner.java

private static String parseTagline(String xml) {
    int startTag = xml.indexOf("<h4 class=\"inline\">Tagline" + HTML_H4_END);
    if (startTag != -1) {
        // We need to work out which of the two formats to use, this is dependent on which comes first "<span" or "</div"
        String endMarker;/* w ww  .  j  av a 2 s. c  o m*/
        if (StringUtils.indexOf(xml, "<span", startTag) < StringUtils.indexOf(xml, HTML_DIV_END, startTag)) {
            endMarker = "<span";
        } else {
            endMarker = HTML_DIV_END;
        }

        // Now look for the right string
        String tagline = HTMLTools.extractTag(xml, "<h4 class=\"inline\">Tagline" + HTML_H4_END, endMarker);
        tagline = HTMLTools.stripTags(tagline);
        return cleanStringEnding(tagline);
    }
    return null;
}