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

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

Introduction

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

Prototype

public static boolean containsAny(CharSequence cs, CharSequence... searchCharSequences) 

Source Link

Document

Checks if the CharSequence contains any of the CharSequences in the given array.

A null CharSequence will return false .

Usage

From source file:com.norconex.collector.core.data.store.impl.mongo.MongoUtil.java

/**
 * Return or generate a DB name/*from   ww  w .  j  av a2  s . c  o  m*/
 * 
 * If a valid dbName is provided, it is returned as is. If none is provided,
 * a name is generated from the crawl ID (provided in HttpCrawlerConfig)
 * 
 * @param dbName database name
 * @param crawlerId crawler id
 * @throws IllegalArgumentException
 *             if the dbName provided contains invalid characters
 * @return DB name
 */
public static String getDbNameOrGenerate(String dbName, String crawlerId) {

    // If we already have a name, try to use it
    if (dbName != null && dbName.length() > 0) {
        // Validate it
        if (StringUtils.containsAny(dbName, MONGO_INVALID_DBNAME_CHARACTERS)
                || StringUtils.containsWhitespace(dbName)) {
            throw new IllegalArgumentException("Invalid Mongo DB name: " + dbName);
        }
        return dbName;
    }

    // Generate a name from the crawl ID
    String dbIdName = crawlerId;
    // Replace invalid character with '_'
    for (int i = 0; i < MONGO_INVALID_DBNAME_CHARACTERS.length(); i++) {
        char c = MONGO_INVALID_DBNAME_CHARACTERS.charAt(i);
        dbIdName = dbIdName.replace(c, '_');
    }
    // Replace whitespaces
    dbIdName = dbIdName.replaceAll("\\s", "_");
    return dbIdName;
}

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

public boolean process(String cs, String searchChars) {
    return StringUtils.containsAny(cs, searchChars);
}

From source file:ch.cyberduck.cli.DeletePathFinder.java

@Override
public Set<TransferItem> find(final CommandLine input, final TerminalAction action, final Path remote)
        throws AccessDeniedException {
    if (StringUtils.containsAny(remote.getName(), '*')) {
        // Treat asterisk as wildcard
        return Collections.singleton(new TransferItem(remote.getParent()));
    }/* w w w  . j av  a  2  s .c  o  m*/
    return Collections.singleton(new TransferItem(remote));
}

From source file:ch.cyberduck.cli.DownloadTransferItemFinder.java

@Override
public Set<TransferItem> find(final CommandLine input, final TerminalAction action, final Path remote) {
    final Local local = LocalFactory.get(input.getOptionValues(action.name())[1]);
    if (StringUtils.containsAny(remote.getName(), '*')) {
        // Treat asterisk as wildcard
        return Collections.singleton(new TransferItem(remote.getParent(), local));
    }//from   w  w  w.j a va2 s. c  o  m
    if (remote.isDirectory()) {
        // Remote path resolves to directory
        if (local.exists()) {
            return Collections.singleton(new TransferItem(remote, LocalFactory.get(local, remote.getName())));
        }
        return Collections.singleton(new TransferItem(remote, local));
    }
    // Remote path resolves to file
    if (local.isDirectory()) {
        // Append remote filename to local target
        return Collections.singleton(new TransferItem(remote, LocalFactory.get(local, remote.getName())));
    }
    // Keep from input
    return Collections.singleton(new TransferItem(remote, local));
}

From source file:com.yevster.spdxtra.Validate.java

public static void baseUrl(String baseUrl) {
    boolean valid = (StringUtils.isNotBlank(baseUrl) && !StringUtils.containsAny(baseUrl, '#'));
    if (!valid)/*ww  w .  j a  v  a 2s  . c  o m*/
        throw exceptionFactory.apply("Illegal namespace URL :" + baseUrl);
}

From source file:ch.cyberduck.cli.TerminalTransferFactory.java

public Transfer create(final CommandLine input, final Host host, final Path remote,
        final List<TransferItem> items) throws BackgroundException {
    final Transfer transfer;
    final TerminalAction type = TerminalActionFinder.get(input);
    if (null == type) {
        throw new BackgroundException(LocaleFactory.localizedString("Unknown"), "Unknown transfer type");
    }/*from www. j a  va  2 s  .c  o  m*/
    switch (type) {
    case download:
        if (StringUtils.containsAny(remote.getName(), '*')) {
            transfer = new DownloadTransfer(host, items, new DownloadGlobFilter(remote.getName()));
        } else {
            transfer = new DownloadTransfer(host, items);
        }
        break;
    case upload:
        transfer = new UploadTransfer(host, items);
        break;
    case synchronize:
        transfer = new SyncTransfer(host, items.iterator().next());
        break;
    default:
        throw new BackgroundException(LocaleFactory.localizedString("Unknown"),
                String.format("Unknown transfer type %s", type.name()));
    }
    if (input.hasOption(TerminalOptionsBuilder.Params.throttle.name())) {
        try {
            transfer.setBandwidth(
                    Float.valueOf(input.getOptionValue(TerminalOptionsBuilder.Params.throttle.name())));
        } catch (NumberFormatException ignore) {
            //
        }
    }
    return transfer;
}

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

/**
 * @param element//from   w ww .  j  a  v a2s .c o  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:com.cronutils.parser.field.FieldParser.java

/**
 * Parse given expression for a single cron field
 * @param expression - String//from ww w .j  a  v a  2 s . c o m
 * @return CronFieldExpression object that with interpretation of given String parameter
 */
public FieldExpression parse(String expression) {
    if (!StringUtils.containsAny(expression, specialCharsMinusStar)) {
        if ("*".equals(expression)) {//all crons support asterisk
            return new Always(constraints);
        } else {
            if ("?".equals(expression)) {
                return new QuestionMark(constraints);
            }
            return parseOn(expression);
        }
    } else {
        String[] array = expression.split(",");
        if (array.length > 1) {
            And and = new And();
            for (String exp : array) {
                and.and(parse(exp));
            }
            return and;
        } else {
            array = expression.split("-");
            if (array.length > 1) {
                return parseBetween(array);
            } else {
                String value = expression.split("/")[1];
                constraints.validateAllCharsValid(value);
                return new Every(constraints, new IntegerFieldValue(Integer.parseInt(value)));
            }
        }
    }
}

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

/** Returns whether or not the {@code character} is a dash character. */
public static boolean isDashCharacter(char c) {
    return StringUtils.containsAny(String.valueOf(c), kDashes);
}

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

/** Returns the index of the <i>first</i> character that's not one of {@code trimChars}; -1 otherwise. */
public static int findFirstNotOfAny(String string, String trimChars) {
    if (StringUtils.isEmpty(string) || StringUtils.isEmpty(trimChars))
        return -1;
    for (int i = 0; i < string.length(); i++) {
        if (!StringUtils.containsAny(String.valueOf(string.charAt(i)), trimChars)) {
            return i;
        }//from w  w  w .  j  a va  2  s.  c o m
    }

    return -1;
}