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

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

Introduction

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

Prototype

public static boolean containsAny(String str, String searchChars) 

Source Link

Document

Checks if the String contains any character in the given set of characters.

Usage

From source file:de.berlios.jhelpdesk.web.preferences.PersonalDataEditController.java

private boolean passwordsAreSameAndValid(String p1, String p2) {
    boolean containsNumber = StringUtils.containsAny(p1, "0123456789");
    boolean containsSpecial = StringUtils.containsAny(p1, "!@#$%^&*()_+-=/*,.;:\\\"'`~'");

    return (p1.length() < 6 && p1.equals(p2) && containsNumber && containsSpecial);
}

From source file:mitm.djigzo.web.grid.UserGridDataSource.java

private String getSearch() {
    String search = filter;/* w ww  .j  a va 2s  .co m*/

    if (search != null) {
        if (search.trim().length() == 0) {
            search = null;
        } else {
            /*
             * If the filter string does not contain a LIKE special symbol ('%' or '_') the search
             * string will be embedded in %%.
             */
            if (!StringUtils.containsAny(search, "%_")) {
                search = "%" + search + "%";
            }
        }
    }

    return search;
}

From source file:eionet.cr.util.sql.VirtuosoFullTextQuery.java

/**
 * @throws ParseException/*from   w  w  w  .  j av a2s  . co  m*/
 *
 */
private void parse() throws ParseException {

    if (query == null) {
        return;
    }

    query = query.trim();
    if (query.length() == 0) {
        return;
    }

    // parse phrases first

    int unclosedQuotes = -1;
    int len = query.length();
    for (int i = 0; i < len; i++) {
        if (query.charAt(i) == '"') {
            if (unclosedQuotes != -1) {
                String phrase = query.substring(unclosedQuotes + 1, i);
                if (phrase.trim().length() >= MIN_WORD_LENGTH) {
                    if (StringUtils.containsAny(phrase, " \t\r\n\f")) {
                        phrases.add(query.substring(unclosedQuotes + 1, i));
                    }
                }
                unclosedQuotes = -1;
            } else {
                unclosedQuotes = i;
            }
        }
    }

    // remove phrases from expression
    if (phrases != null) {
        for (String phrase : phrases) {
            query = query.replaceAll("\"" + phrase + "\"", "");
        }
    }

    // there must be no unclosed quotes left
    if (unclosedQuotes != -1) {
        throw new ParseException("Unclosed quotes at index " + unclosedQuotes, unclosedQuotes);
    }

    String prevToken = null;
    StringTokenizer st = new StringTokenizer(query, " \t\r\n\f\"");
    // remove any redundant logical operands and too short words from the beginning of query
    query = removeOperands(st);
    st = new StringTokenizer(query, " \t\r\n\f\"");
    while (st.hasMoreTokens()) {

        String token = st.nextToken();

        if (token.equals("&"))
            token = "AND";
        if (token.equals("|"))
            token = "OR";

        // If this token is a VirtuosoSQL full-text query's boolean operator
        // then append it to the parsed query only if the previous token
        // was not null and wasn't already a boolean operator itself.
        //
        // However, if this token is NOT a a VirtuosoSQL full-text query's boolean operator,
        // then append it to the parsed query, but first make sure that the previous
        // token was a boolean operator. If it wasn't then append the default operator.

        boolean appendThisToken = false;

        if (isBooleanOperator(token)) {
            if (prevToken != null && !isBooleanOperator(prevToken)) {
                appendThisToken = true;
            }
        } else {
            if (token.length() >= MIN_WORD_LENGTH) {

                appendThisToken = true;
                if (prevToken != null && !isBooleanOperator(prevToken)) {
                    parsedQuery.append(" ").append(DEFAULT_BOOLEAN_OPERATOR);
                }
            }
        }

        if (appendThisToken) {

            if (parsedQuery.length() > 0) {
                parsedQuery.append(" ");
            }

            if (isBooleanOperator(token))
                parsedQuery.append(token);
            else
                parsedQuery.append("'").append(token).append("'");

            prevToken = token;
        }
    }

    // add phrases to query
    if (phrases != null && phrases.size() > 0) {
        for (String phrase : phrases) {
            if (parsedQuery != null && parsedQuery.length() > 0)
                parsedQuery.append(" and ");
            parsedQuery.append("'").append(phrase).append("'");
        }
    }
}

From source file:com.dtolabs.rundeck.core.cli.CLIUtils.java

/**
 * Return true if the string contains any whitespace
 * @param arg/*from  w  ww .j ava  2 s.c o  m*/
 * @return
 */
public static boolean containsSpace(String arg) {
    return StringUtils.containsAny(arg, " ");
}

From source file:cz.cvut.portal.kos.services.RestKOSapiService.java

private void validateArgument(String str) {
    if (StringUtils.isBlank(str)) {
        throw new IllegalArgumentException("Argument is blank");
    }// w  ww.  j ava 2  s  .c  om
    if (StringUtils.containsAny(str, ILLEGAL_CHARS)) {
        throw new IllegalArgumentException("Argument contains illegal characters");
    }
}

From source file:com.dtolabs.rundeck.core.cli.CLIUtils.java

/**
 * Return true if the string contains any whitespace
 * @param arg/*ww  w.  j a  va  2  s .com*/
 * @return
 */
public static boolean containsQuote(String arg) {
    return StringUtils.containsAny(arg, "'");
}

From source file:mitm.djigzo.web.grid.MailRepositoryGridDataSource.java

private String getSearchKey() {
    String result = StringUtils.defaultString(searchKey);

    if (result.isEmpty()) {
        /*//from  w  w  w  .  j a  v a 2s .  c om
         * If search is empty search for all everything
         */
        result = "%%";
    } else {
        /*
         * If the filter string does not contain a LIKE special symbol ('%' or '_') the search
         * string will be embedded in %%.
         */
        if (!StringUtils.containsAny(result, "%_")) {
            result = "%" + result + "%";
        }
    }

    return result;
}

From source file:eu.annocultor.utils.SparqlQueryHelper.java

private void writeStatementIntoSeparateFileByNamespace(Statement statement, String outputFilePrefix,
        Namespaces namespaces) throws Exception {
    String subject = statement.getSubject().stringValue();
    String nsFull = subject.substring(namespacePrefix.length());
    String nss[] = nsFull.split("/");
    String first = nss[0];/*from   w  w  w .j a  v  a 2 s.  c o m*/
    String second = nss[1];
    if (StringUtils.containsAny(second, "0123456789")) {
        second = "";
    } else {
        second = "_" + second;
    }
    String ns = first + second;
    if (!filesPerNamespace.containsKey(ns)) {
        File nsFile = new File(outputFilePrefix + "_" + ns + ".1.rdf");
        SesameWriter writer = SesameWriter.createRDFXMLWriter(nsFile, namespaces, "id",
                "Exported items belonging to " + nsFull, 1000, 1000);
        writer.startRDF();
        filesPerNamespace.put(ns, writer);
    }

    SesameWriter writer = filesPerNamespace.get(ns);
    writer.handleStatement(statement);
}

From source file:com.taobao.metamorphosis.client.producer.SimpleXAMessageProducer.java

private void checkUniqueQualifier(String prefix) {
    if (StringUtils.isBlank(prefix)) {
        throw new IllegalArgumentException("Blank unique qualifier for SimpleXAMessageProducer");
    }/*from   w ww .  ja va 2 s .c o  m*/
    if (StringUtils.containsAny(prefix, "\r\n\t: ")) {
        throw new IllegalArgumentException(
                "Invalid unique qualifier,it should not contains newline,':' or blank characters.");
    }
}

From source file:eionet.cr.util.sesame.SPARQLQueryUtil.java

/**
 * Determines if it is valid IRI (for SPARQL).
 *
 * @param str given URI/*from w w  w. j a  v  a2  s .co m*/
 * @return true if the URI is valid IRI
 */
public static boolean isIRI(String str) {

    if (StringUtils.containsAny(str, BAD_CHARS)) {
        return false;
    }
    return true;
}