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.dgtlrepublic.anitomyj.StringHelper.java

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

    return -1;
}

From source file:com.cronutils.parser.FieldParser.java

/**
 * Parse given expression for a single cron field
 * // www  .  j  a  va  2s  .c o m
 * @param expression
 *            - String
 * @return CronFieldExpression object that with interpretation of given String parameter
 */
public FieldExpression parse(String expression) {
    if (!StringUtils.containsAny(expression, SPECIAL_CHARS_MINUS_STAR)) {
        return noSpecialCharsNorStar(expression);
    } else {
        String[] array = expression.split(",");
        if (array.length > 1) {
            return commaSplitResult(array);
        } else {
            String[] betWeenArray = expression.split("-");
            return dashSplitResult(expression, betWeenArray);
        }
    }
}

From source file:de.unentscheidbar.validation.builtin.FileNameValidator.java

@Override
protected void validateNonEmptyString(ValidationResult problems, String text) {

    boolean invalid = StringUtils.containsAny(text, ILLEGAL_CHARACTERS);
    if (!invalid)
        try {//from   www.j  a  v  a 2 s. c  o  m
            /* Catch stuff like "PRN" on windows */
            new File(text).getCanonicalPath();
        } catch (IOException ignored) {
            invalid = true;
        }
    if (invalid) {
        problems.add(Id.INVALID_FILE_NAME, text);
    }
}

From source file:co.foxdev.foxbot.utils.CommandManager.java

private boolean runCustomCommand(String channel, String command) {
    if (command == null || command.isEmpty()) {
        return false;
    }//from w ww  .  j  a  va  2 s.c o  m

    // Prevent filesystem access
    if (StringUtils.containsAny(channel, restrictedChars)
            || StringUtils.containsAny(command, restrictedChars)) {
        return false;
    }

    File file = new File(String.format("data/custcmds/%s/%s", channel.substring(1), command));
    StringBuilder message = new StringBuilder();

    if (file.exists()) {
        try {
            BufferedReader reader = new BufferedReader(new FileReader(file));

            String line;

            while ((line = reader.readLine()) != null) {
                message.append(line);
            }
            reader.close();
        } catch (IOException ex) {
            foxbot.getLogger().error(
                    String.format("Error occurred while running command '%s' for %s", command, channel), ex);
            return false;
        }

        String strMessage = message.toString();

        if (!strMessage.isEmpty()) {
            String[] lines = strMessage.split("\\\\n");

            for (int i = 0; i < lines.length && i < 3; i++) {
                foxbot.bot().getUserChannelDao().getChannel(channel).send()
                        .message(foxbot.getConfig().getCommandPrefix() + command + ": " + lines[i]);
            }
            return true;
        }
    }
    return false;
}

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

/** Returns then delimiters found in a token range. */
private String getDelimiters(TokenRange range) {
    final StringBuilder delimiters = new StringBuilder();

    Function<Integer, Boolean> isDelimiter = c -> {
        if (!StringHelper.isAlphanumericChar((char) c.intValue())) {
            if (StringUtils.containsAny(String.valueOf((char) c.intValue()), options.allowedDelimiters)) {
                if (!StringUtils.containsAny(delimiters.toString(), String.valueOf((char) c.intValue()))) {
                    return true;
                }/*from w  w  w .j  a  v  a  2s .  co m*/
            }
        }

        return false;
    };

    IntStream.range(range.getOffset(), Math.min(filename.length(), range.getOffset() + range.getSize()))
            .filter(value -> isDelimiter.apply((int) filename.charAt(value)))
            .forEach(value -> delimiters.append(filename.charAt(value)));

    return delimiters.toString();
}

From source file:com.github.nlloyd.hornofmongo.adaptor.DB.java

private void validateDbName(String name) {
    if (StringUtils.containsAny(name, "/\\. \""))
        throw Context.throwAsScriptRuntimeEx(
                new MongoScriptException("[" + name + "] is not a valid database name"));
}

From source file:com.cognifide.aet.vs.mongodb.MongoDBClient.java

/**
 * Get collection of companies in AET system
 *
 * @return collection of companies names unless database names matches convention: $company_$project and
 * $company dosen't contain any underscrore characters
 *//*  www.  j a v  a2s  . c  om*/
public Collection<String> getCompanies() {
    final Collection<String> companies = new ArrayList<>();

    for (String dbName : getAetsDBNames()) {
        if (!StringUtils.containsAny(dbName, DB_NAME_SEPARATOR)) {
            LOGGER.error(
                    "Database name format is incorrect. It must contain at least one underscore character. Couldn't fetch company name from database name. Skip.");
        }
        String companyName = StringUtils.substringBefore(dbName, DB_NAME_SEPARATOR);
        if (StringUtils.isBlank(companyName)) {
            LOGGER.error("Comapny name is blank. It couldn't've been fetched from database name [{}] ", dbName);
        } else if (StringUtils.isNotBlank(companyName)) {
            companies.add(companyName);
        }

    }

    return companies;
}

From source file:de.micromata.genome.gwiki.pagelifecycle_1_0.action.CreateBranchActionBean.java

private boolean isBranchIdValid() {
    if (StringUtils.isBlank(this.branchId) == true) {
        wikiContext.addSimpleValidationError("branch id not valid. It must have at least one character");
        return false;
    }/*from   w  ww  . j av a  2s.  c o m*/
    if (StringUtils.containsAny(this.branchId, new char[] { '/', ',', '*', '#', '"', '\'', ' ' })) {
        wikiContext.addSimpleValidationError("Branch-Id not valid. It contains invalid chracters.");
        return false;
    }
    if (this.branchId.length() > 50) {
        wikiContext.addSimpleValidationError("Branch-Id not valid. There are too many characters.");
        return false;
    }
    return true;
}

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

/**
 * @param element/* w ww .  j  a va2  s. c om*/
 * @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.threewks.thundr.google.analytics.admin.AnalyticsController.java

private String simpleCsvRow(List<String> data) {
    List<String> escapedData = new ArrayList<String>(data.size());
    for (String cell : data) {
        if (StringUtils.containsAny(cell, ",\"")) {
            cell = "\"" + cell.replaceAll("\"", "\\\"") + "\"";
        }//from w ww.  j  ava2 s  .  c  o m
        escapedData.add(cell);
    }
    return StringUtils.join(escapedData, ", ") + "\n";
}