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

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

Introduction

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

Prototype

public static int indexOfAny(String str, String[] searchStrs) 

Source Link

Document

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

Usage

From source file:com.ms.app.web.commons.utils.DeviceUtils.java

/**
 * ?UA??/*from ww  w . ja va2s . c o  m*/
 * 
 * @param ua
 * @return :0 ():1
 */
public static int getDeviceByUa(String ua) {
    if (StringUtils.isBlank(ua)) {
        return 1;
    }
    ua = StringUtils.lowerCase(ua);
    // ?
    if (StringUtils.indexOfAny(ua, DEVICES) < 0) {
        return 1;
    }
    return 0;
}

From source file:ips1ap101.lib.core.db.util.DBUtils.java

/**
 * Busca el nombre del constraint en el mensaje que envia el RDBMS cuando se produce un conflicto
 *
 * @param message Cadena correspondiente al mensaje que envia el RDBMS
 * @param status Entero correspondiente al tipo de conflicto (cualquiera de las constantes ROW_CONFLICT de SyncResolver)
 * @return Si se consigue, el nombre del constraint; de lo contratio retorna null
 *//*from w ww.j ava  2  s  .  c  om*/
public static String getConstraintMessageKey(String message, int status) {
    String trimmed = StringUtils.trimToNull(message);
    if (trimmed != null) {
        trimmed = trimmed.replaceAll("[^a-zA-Z0-9_]", " ");
        trimmed = trimmed.trim().toLowerCase();
        String[] tokens = StringUtils.split(trimmed);
        if (tokens != null && tokens.length > 0) {
            String key, string;
            for (int i = 0; i < tokens.length; i++) {
                key = tokens[i];
                if (key.endsWith(SUFIJO) && StringUtils.indexOfAny(key, INFIJOS) > 0) {
                    key = StringUtils.removeEnd(key, SUFIJO);
                    if (key.contains("_fk_")) {
                        key += status == 1 ? ".1" : ".2";
                    }
                    string = BundleMensajes.getString(key);
                    return isKey(string) ? string : "<" + key + ">";
                }
            }
        }
    }
    return null;
}

From source file:de.hybris.platform.acceleratorservices.urldecoder.impl.BaseFrontendPathMatcherUrlDecoder.java

@Override
public T decode(final String urlIn) {
    final URL url;
    try {/*from  w w w.  j  a  v a  2  s  .c om*/
        url = new URL(urlIn);
    } catch (final MalformedURLException e) {
        LOG.warn("unable to parse url [" + urlIn + "] as it was malformed");
        return null;
    }
    final int paramsIndex = StringUtils.indexOfAny(url.getPath(), ";?&");
    final String cleanedUrl = paramsIndex > -1 ? url.getPath().substring(0, paramsIndex) : url.getPath();
    if (getPathMatcher().match(getPathMatchPattern(), cleanedUrl)) {
        final Map<String, String> pathParams = getPathMatcher()
                .extractUriTemplateVariables(getPathMatchPattern(), cleanedUrl);

        if (pathParams == null || pathParams.size() > 1) {
            LOG.warn("unable to extract id from path " + url.getPath() + " and pattern "
                    + getPathMatchPattern());
            return null;
        }
        return translateId(pathParams.get(pathParams.keySet().iterator().next()));
    }
    return null;
}

From source file:com.adobe.acs.commons.quickly.Command.java

public Command(final String raw) {
    this.raw = StringUtils.stripToEmpty(raw);

    String opWithPunctuation = StringUtils
            .stripToEmpty(StringUtils.lowerCase(StringUtils.substringBefore(this.raw, " ")));
    int punctuationIndex = StringUtils.indexOfAny(opWithPunctuation, PUNCTUATIONS);

    if (punctuationIndex > 0) {
        this.punctuation = StringUtils.substring(opWithPunctuation, punctuationIndex).split("(?!^)");
        this.operation = StringUtils.substring(opWithPunctuation, 0, punctuationIndex);
    } else {/*from w  w w  .  j  a  v a  2s  . co  m*/
        this.punctuation = new String[] {};
        this.operation = opWithPunctuation;
    }

    this.param = StringUtils.stripToEmpty(StringUtils.removeStart(this.raw, opWithPunctuation));
    this.params = StringUtils.split(this.param);

    if (log.isTraceEnabled()) {
        log.trace("Raw: {}", this.raw);
        log.trace("Operation: {}", this.operation);
        log.trace("Punctuation: {}", Arrays.toString(this.punctuation));
        log.trace("Param: {}", this.param);
        log.trace("Params: {}", Arrays.toString(this.params));
    }
}

From source file:com.googlecode.l10nmavenplugin.validators.PropertiesKeyConventionValidator.java

protected boolean matches(String key) {
    return (StringUtils.indexOfAny(key, keysPattern) != -1);
}

From source file:com.bstek.dorado.view.resolver.SkinSettingManager.java

protected synchronized SkinSetting doGetSkinSetting(DoradoContext context, String skin) throws Exception {
    SkinSetting skinSetting = skinSettingMap.get(skin);
    if (skinSetting == null) {
        boolean shouldCache = true;
        String metaInfoPath = null;
        String customSkinPath = WebConfigure.getString("view.skin." + skin);
        if (StringUtils.isNotEmpty(customSkinPath)) {
            metaInfoPath = PathUtils.concatPath(customSkinPath, META_INFO_FILE);
        } else {//w w w.jav a 2s. c om
            String libraryRoot = Configure.getString("view.libraryRoot");

            if ("debug".equals(Configure.getString("core.runMode")) && libraryRoot != null
                    && StringUtils.indexOfAny(libraryRoot, RESOURCE_PREFIX_DELIM) >= 0) {
                String[] roots = StringUtils.split(libraryRoot, RESOURCE_PREFIX_DELIM);
                for (String root : roots) {
                    String tempPath = PathUtils.concatPath(root, SKINS, skin, META_INFO_FILE);
                    if (context.getResource(tempPath).exists()) {
                        metaInfoPath = tempPath;
                        break;
                    }
                }
            } else {
                metaInfoPath = PathUtils.concatPath(libraryRoot, SKINS, skin, META_INFO_FILE);
            }
        }

        if (StringUtils.isNotEmpty(metaInfoPath)) {
            Resource metaInfoResource = context.getResource(metaInfoPath);
            if (metaInfoResource.exists()) {
                InputStream in = metaInfoResource.getInputStream();
                try {
                    Map<String, Object> map = objectMapper.readValue(in,
                            new TypeReference<Map<String, Object>>() {
                            });

                    if (VariantUtils.toBoolean(map.remove("tempSkin"))) {
                        shouldCache = false;
                    }

                    skinSetting = new SkinSetting();

                    String clientTypes = (String) map.remove("clientType");
                    if (StringUtils.isNotEmpty(clientTypes)) {
                        skinSetting.setClientTypes(ClientType.parseClientTypes(clientTypes));
                    } else {
                        skinSetting.setClientTypes(ClientType.DESKTOP);
                    }

                    BeanUtils.copyProperties(skinSetting, map);
                } finally {
                    in.close();
                }
            }
        }

        if (shouldCache) {
            if (skinSetting == null) {
                skinSettingMap.put(skin, NULL_SKIN_SETTING);
            } else {
                skinSettingMap.put(skin, skinSetting);
            }
        }
    } else if (skinSetting == NULL_SKIN_SETTING) {
        skinSetting = null;
    }
    return skinSetting;
}

From source file:com.bstek.dorado.web.resolver.WebFileResolver.java

protected Resource[] getResourcesByFileName(DoradoContext context, String resourcePrefix, String fileName,
        String resourceSuffix) throws Exception {
    String path;//from  w w w .  j a  v a  2 s  . c o  m
    Resource[] resources = null;
    if ("debug".equals(Configure.getString("core.runMode")) && resourcePrefix != null
            && StringUtils.indexOfAny(resourcePrefix, RESOURCE_PREFIX_DELIM) >= 0) {
        String[] prefixs = StringUtils.split(resourcePrefix, RESOURCE_PREFIX_DELIM);
        for (String prefix : prefixs) {
            boolean allExists = true;
            path = PathUtils.concatPath(prefix, fileName);
            if (resourceSuffix != null) {
                path = path + resourceSuffix;
            }
            resources = context.getResources(path);
            if (resources != null && resources.length > 0) {
                for (int i = 0; i < resources.length; i++) {
                    Resource resource = resources[i];
                    if (!resource.exists()) {
                        allExists = false;
                        break;
                    }
                }
            }
            if (allExists) {
                break;
            }
        }
    } else {
        path = PathUtils.concatPath(resourcePrefix, fileName);
        if (resourceSuffix != null) {
            path = path + resourceSuffix;
        }
        resources = context.getResources(path);
    }
    return resources;
}

From source file:com.homeadvisor.kafdrop.config.ini.IniFileReader.java

/**
 * Tries to find the index of the separator character in the given string.
 * This method checks for the presence of separator characters in the given
 * string. If multiple characters are found, the first one is assumed to be
 * the correct separator. If there are quoting characters, they are taken
 * into account, too./*  w  ww  .j a  va 2s  .com*/
 *
 * @param line the line to be checked
 * @return the index of the separator character or -1 if none is found
 */
private int findSeparator(String line) {
    int index = findSeparatorBeforeQuote(line, StringUtils.indexOfAny(line, QUOTE_CHARACTERS));
    if (index < 0) {
        index = StringUtils.indexOfAny(line, SEPARATOR_CHARS);
    }
    return index;
}

From source file:ips1ap101.lib.core.db.util.DBUtils.java

public static String[] getConstraintMessageKeys(String message) {
    String trimmed = StringUtils//  w w  w .j  a  v a2 s.  c  o  m
            .trimToEmpty(StringUtils.substringAfter(StringUtils.substringBefore(message, WHERE), ERROR));
    if (StringUtils.isNotBlank(trimmed)) {
        String[] tokens = StringUtils.split(trimmed, ';');
        if (tokens != null && tokens.length > 1) {
            String key = tokens[0].trim();
            if (key.matches("^[0-9]{1,3}$")) {
                int length = Integer.valueOf(key);
                if (length == tokens.length - 1) {
                    String string;
                    String[] keys = new String[length];
                    for (int i = 1; i < tokens.length; i++) {
                        key = tokens[i].trim();
                        if (key.endsWith(SUFIJO) && StringUtils.indexOfAny(key, INFIJOS) > 0) {
                            key = StringUtils.removeEnd(key, SUFIJO);
                            string = BundleMensajes.getString(key);
                            keys[i - 1] = isKey(string) ? string : "<" + key + ">";
                        } else {
                            return null;
                        }
                    }
                    return keys;
                }
            }
        }
        String key, string;
        String stripChars = BOMK + EOMK;
        List<String> list = new ArrayList<>();
        Pattern pattern = Pattern.compile("\\" + BOMK + ".*\\" + EOMK);
        Matcher matcher = pattern.matcher(trimmed);
        while (matcher.find()) {
            key = StringUtils.strip(matcher.group(), stripChars);
            if (key.endsWith(SUFIJO) && StringUtils.indexOfAny(key, INFIJOS) > 0) {
                key = StringUtils.removeEnd(key, SUFIJO);
                string = BundleMensajes.getString(key);
                key = isKey(string) ? string : "<" + key + ">";
                list.add(key);
            }
        }
        return (list.isEmpty()) ? null : list.toArray(new String[list.size()]);
    }
    return null;
}

From source file:com.ansorgit.plugins.bash.editor.codecompletion.BashCompletionContributor.java

/**
 * In a completion like "$abc<caret> def" the element is a word psi lead element, in this case to not expand the autocompletion after the whitespace character
 * https://code.google.com/p/bashsupport/issues/detail?id=51
 * a completion at the end of a line with an open string is parsed as string until the first quote in the next line(s)
 * in the case of a newline character in the string the end offset is set to the end of the string to avoid aggressive string replacements
 *//*from  w  w w. jav  a2s .  co m*/
private boolean fixReplacementOffsetInString(PsiElement element, OffsetMap offsetMap) {
    int endCharIndex = StringUtils.indexOfAny(element.getText(), new char[] { '\n', ' ' });
    if (endCharIndex > 0) {
        offsetMap.addOffset(IDENTIFIER_END_OFFSET, element.getTextOffset() + endCharIndex);
        return true;
    }

    return false;
}