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

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

Introduction

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

Prototype

public static int indexOfAny(final CharSequence str, final CharSequence... searchStrs) 

Source Link

Document

Find the first index of any of a set of potential substrings.

A null CharSequence will return -1 .

Usage

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

public int process(String cs, String searchChars) {
    return StringUtils.indexOfAny(cs, searchChars);
}

From source file:de.micromata.genome.logging.DocLogEntryKey.java

/**
 * Strip const message.//from  w  w w  .  j av  a2s.c  o m
 *
 * @param msg the msg
 * @return the string
 */
private String stripConstMessage(String msg) {
    String smsg = StringUtils.substring(msg, 0, 10);
    int idx = StringUtils.indexOfAny(smsg, ",:.(");
    if (idx == -1) {
        return smsg;
    }
    return smsg.substring(0, idx);
}

From source file:com.xylocore.copybook.generator.domain.WildcardElementFilter.java

/**
 * FILLIN/*from  ww  w.  jav a  2 s. c o m*/
 */
private void compilePattern() {
    String myPattern = pattern;

    if (StringUtils.indexOfAny(myPattern, "*?/") == -1) {
        myPattern = "**/" + myPattern;
    } else if (myPattern.endsWith("/")) {
        myPattern += "**";
    }

    int myIndex = 0;
    while ((myIndex = myPattern.indexOf('*', myIndex)) != -1) {
        String myRemainder = myPattern.substring(myIndex + 1);
        if (myRemainder.startsWith("*")) {
            if ((myIndex != 0 && myPattern.charAt(myIndex - 1) != '/')
                    || (myIndex + 2 < myPattern.length() && myPattern.charAt(myIndex + 2) != '/')) {
                // TODO: invalid pattern - better exception
                throw new RuntimeException("invalid element filter pattern: " + pattern);
            }

            int myLast = StringUtils.indexOfAnyBut(myRemainder, "*");
            myRemainder = myRemainder.substring((myLast != -1) ? myLast : myRemainder.length());
            myPattern = myPattern.substring(0, myIndex) + "\t" + myRemainder;
        }

        myIndex++;
    }

    compiledPattern = myPattern;
}

From source file:com.nhncorp.lucy.security.xss.listener.SecurityUtils.java

/**
 * @param element/*from  w w w . j  a  v  a2 s.co  m*/
 * @param srcUrl
 * @param isWhiteUrl
 * @return
 */
public static boolean checkVulnerable(Element element, String srcUrl, boolean isWhiteUrl) {
    boolean isVulnerable = false;

    // embed/object   ? (XSSFILTERSUS-109)
    if (isWhiteUrl) {

    } else {
        String type = element.getAttributeValue("type").trim();
        type = StringUtils.strip(type, "'\"");

        if (type != null && type.length() != 0) {

            //? type ??
            if (!(isAllowedType(type) || props.values().contains(type))) {
                isVulnerable = true;
            }
        } else {
            //? ?
            String url = StringUtils.strip(srcUrl, "'\"");
            String extension = getExtension(url);

            if (StringUtils.containsAny(extension, specialCharArray)) {
                int pos = StringUtils.indexOfAny(extension, specialCharArray);
                if (pos != -1) {
                    extension = StringUtils.substring(extension, 0, pos);
                }
            }

            if (StringUtils.isEmpty(extension)) {
                // ?  MIME TYPE ? ?  ,  . ? hole ? ? ? ? .
            } else {
                type = getTypeFromExtension(extension);

                if (StringUtils.isEmpty(type)) {
                    type = props.getProperty(extension);

                    if (type != null) {
                        type = type.trim();
                    }
                }

                //? type ??
                if (StringUtils.isEmpty(type)) {
                    isVulnerable = true;
                } else {
                    element.putAttribute("type", "\"" + type + "\"");
                }
            }

        }
    }
    return isVulnerable;
}

From source file:de.micromata.genome.gwiki.page.impl.wiki.MacroAttributes.java

public String escapeValue(String value) {
    if (StringUtils.indexOfAny(value, new char[] { '|', '}', '{', '=' }) == -1) {
        return value;
    }/*from w  ww  . ja  v a 2  s.c o  m*/
    return '"' + WebUtils.escapeJavaScript(value) + '"';
}

From source file:com.adguard.commons.lang.Wildcard.java

/**
 * Extracts longest string that does not contain * or ? symbols.
 *
 * @param pattern Wildcard pattern/*from  www.  j  a v  a2s .c  om*/
 * @return Longest string without special symbols
 */
private static String extractShortcut(String pattern) {
    char[] wildcardChars = new char[] { '*', '?' };
    int startIndex = 0;
    int endIndex = StringUtils.indexOfAny(pattern, wildcardChars);

    if (endIndex < 0) {
        return pattern;
    }
    String shortcut = endIndex == startIndex ? StringUtils.EMPTY
            : pattern.substring(startIndex, endIndex - startIndex);

    while (endIndex >= 0) {
        startIndex = startIndex + endIndex + 1;
        if (pattern.length() <= startIndex) {
            break;
        }

        endIndex = StringUtils.indexOfAny(pattern.substring(startIndex), wildcardChars);
        String tmpShortcut = endIndex < 0 ? pattern.substring(startIndex)
                : pattern.substring(startIndex, endIndex + startIndex);

        if (tmpShortcut.length() > shortcut.length()) {
            shortcut = tmpShortcut;
        }
    }

    return shortcut;
}

From source file:com.dgtlrepublic.anitomyj.ParserHelper.java

/** Returns whether or not the {@code string} is a resolution. */
public static boolean isResolution(String string) {
    if (StringUtils.isEmpty(string))
        return false;
    int minWidthSize = 3;
    int minHeightSize = 3;

    // *###x###*/*from  w  w  w . jav a 2  s .c o  m*/
    if (string.length() >= minWidthSize + 1 + minHeightSize) {
        int pos = StringUtils.indexOfAny(string, "xX\u00D7");
        if (pos != -1 && pos >= minWidthSize && pos <= string.length() - (minHeightSize + 1)) {
            for (int i = 0; i < string.length(); i++) {
                if (i != pos && !Character.isDigit(string.charAt(i)))
                    return false;
            }

            return true;
        }

        // *###p
    } else if (string.length() >= minHeightSize + 1) {
        if (Character.toLowerCase(string.charAt(string.length() - 1)) == 'p') {
            for (int i = 0; i < string.length() - 1; i++) {
                if (!Character.isDigit(string.charAt(i)))
                    return false;
            }

            return true;
        }
    }

    return false;
}

From source file:com.nhncorp.lucy.security.xss.listener.SecurityUtils.java

/**
 * @param element/*from www. j  ava 2  s  . c o m*/
 * @param srcUrl
 * @param isWhiteUrl
 * @return
 */
public static boolean checkVulnerableWithHttp(Element element, String srcUrl, boolean isWhiteUrl,
        ContentTypeCacheRepo contentTypeCacheRepo) {
    boolean isVulnerable = false;

    // embed/object   ? (XSSFILTERSUS-109)
    if (isWhiteUrl) {

    } else {
        String type = element.getAttributeValue("type").trim();
        type = StringUtils.strip(type, "'\"");

        if (type != null && !"".equals(type)) {

            //? type ??
            if (!(isAllowedType(type) || props.values().contains(type))) {
                isVulnerable = true;
            }
        } else {
            //? ?
            String url = StringUtils.strip(srcUrl, "'\"");
            String extension = getExtension(url);

            if (StringUtils.containsAny(extension, specialCharArray)) {
                int pos = StringUtils.indexOfAny(extension, specialCharArray);
                if (pos != -1) {
                    extension = StringUtils.substring(extension, 0, pos);
                }
            }

            if (StringUtils.isEmpty(extension)) {
                // ?  MIME TYPE ? ?  ,  url ? head HTTP Method  ? content-type ?
                type = getContentTypeFromUrlConnection(url, contentTypeCacheRepo);

                //? type ??
                if (!isAllowedType(type)) {
                    isVulnerable = true;
                } else {
                    element.putAttribute("type", "\"" + type + "\"");
                }

            } else {
                type = getTypeFromExtension(extension);

                if (StringUtils.isEmpty(type)) {
                    type = props.getProperty(extension);

                    if (type != null) {
                        type = type.trim();
                    }
                }

                //? type ??
                if (StringUtils.isEmpty(type)) {
                    isVulnerable = true;
                } else {
                    element.putAttribute("type", "\"" + type + "\"");
                }
            }

        }
    }
    return isVulnerable;
}

From source file:com.jkoolcloud.tnt4j.streams.transform.FuncGetObjectName.java

private static String resolveObjectName(String objectName, List<?> args) {
    String option = args.size() > 1 ? (String) args.get(1) : null;
    Options opt;/*from   w w  w.  j  a v  a  2s . c  om*/

    try {
        opt = StringUtils.isEmpty(option) ? Options.DEFAULT : Options.valueOf(option.toUpperCase());
    } catch (IllegalArgumentException exc) {
        opt = Options.DEFAULT;
    }

    switch (opt) {
    case FULL:
        break;
    case BEFORE:
        String sSymbol = args.size() > 2 ? (String) args.get(2) : null;
        if (StringUtils.isNotEmpty(sSymbol)) {
            objectName = StringUtils.substringBefore(objectName, sSymbol);
        }
        break;
    case AFTER:
        sSymbol = args.size() > 2 ? (String) args.get(2) : null;
        if (StringUtils.isNotEmpty(sSymbol)) {
            objectName = StringUtils.substringAfter(objectName, sSymbol);
        }
        break;
    case REPLACE:
        sSymbol = args.size() > 2 ? (String) args.get(2) : null;
        if (StringUtils.isNotEmpty(sSymbol)) {
            String rSymbol = args.size() > 3 ? (String) args.get(3) : null;
            objectName = StringUtils.replaceChars(objectName, sSymbol, rSymbol == null ? "" : rSymbol);
        }
        break;
    case SECTION:
        String idxStr = args.size() > 2 ? (String) args.get(2) : null;
        int idx;
        try {
            idx = Integer.parseInt(idxStr);
        } catch (Exception exc) {
            idx = -1;
        }

        if (idx >= 0) {
            sSymbol = args.size() > 3 ? (String) args.get(3) : null;
            String[] onTokens = StringUtils.split(objectName,
                    StringUtils.isEmpty(sSymbol) ? OBJ_NAME_TOKEN_DELIMITERS : sSymbol);
            objectName = idx < ArrayUtils.getLength(onTokens) ? onTokens[idx] : objectName;
        }
        break;
    case DEFAULT:
    default:
        idx = StringUtils.indexOfAny(objectName, OBJ_NAME_TOKEN_DELIMITERS);
        if (idx > 0) {
            objectName = StringUtils.substring(objectName, 0, idx);
        }
        break;
    }

    return objectName;
}

From source file:de.jfachwert.post.PLZ.java

private static String toLongString(String plz) {
    int i = StringUtils.indexOfAny(plz, "0123456789");
    if (i < 0) {
        throw new InvalidValueException(plz, "postal_code");
    }/*from  w  w  w  .  j a  v a 2  s .  c om*/
    return plz.substring(0, i) + "-" + plz.substring(i);
}