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:org.jahia.services.search.jcr.JahiaJCRSearchProvider.java

private void addTermConstraints(SearchCriteria params, StringBuilder constraints, boolean xpath) {

    for (Term textSearch : params.getTerms()) {

        if (!textSearch.isEmpty()) {
            String searchExpression = getSearchExpressionForMatchType(textSearch.getTerm(),
                    textSearch.getMatch(), textSearch.isApplyFilter());

            SearchFields searchFields = textSearch.getFields();
            StringBuilder textSearchConstraints = new StringBuilder(256);
            if (searchFields.isSiteContent() || (!searchFields.isTags() && !searchFields.isFileContent()
                    && !searchFields.isDescription() && !searchFields.isTitle() && !searchFields.isKeywords()
                    && !searchFields.isFilename())) {
                addConstraint(textSearchConstraints, OR, xpath ? ("jcr:contains(., " + searchExpression + ")")
                        : ("contains(n, " + searchExpression + ")"));
            }/*  www. jav a 2s  .c  o m*/
            if (searchFields.isFileContent()) {
                if (xpath) {
                    addConstraint(textSearchConstraints, OR,
                            "jcr:contains(jcr:content," + searchExpression + ")");
                } else {
                    addConstraint(textSearchConstraints, OR,
                            getContainsExpr("jcr:content", searchExpression, xpath));
                }
            }
            if (searchFields.isDescription()) {
                addConstraint(textSearchConstraints, OR,
                        getContainsExpr(Constants.JCR_DESCRIPTION, searchExpression, xpath));
            }
            if (searchFields.isTitle()) {
                addConstraint(textSearchConstraints, OR,
                        getContainsExpr(Constants.JCR_TITLE, searchExpression, xpath));
            }
            if (searchFields.isKeywords()) {
                addConstraint(textSearchConstraints, OR,
                        getContainsExpr(Constants.KEYWORDS, searchExpression, xpath));
            }

            String[] terms = null;
            String constraint = "or";
            if (searchFields.isFilename() || searchFields.isTags()) {
                if (textSearch.getMatch() == MatchType.ANY_WORD || textSearch.getMatch() == MatchType.ALL_WORDS
                        || textSearch.getMatch() == MatchType.WITHOUT_WORDS) {
                    terms = Patterns.SPACE.split(cleanMultipleWhiteSpaces(textSearch.getTerm()));
                    if (textSearch.getMatch() == MatchType.ALL_WORDS
                            || textSearch.getMatch() == MatchType.WITHOUT_WORDS) {
                        constraint = AND;
                    }
                } else {
                    terms = new String[] { textSearch.getTerm() };
                }
            }
            if (searchFields.isFilename()) {
                StringBuilder nameSearchConstraints = new StringBuilder(256);
                for (String term : terms) {
                    final String likeTerm = term.contains("*")
                            ? stringToQueryLiteral(StringUtils.replaceChars(term, '*', '%'))
                            : stringToQueryLiteral("%" + term + "%");
                    String termConstraint = xpath ? ("jcr:like(fn:name(), " + likeTerm + ")")
                            : ("localname(n) like " + likeTerm);
                    if (textSearch.getMatch() == MatchType.WITHOUT_WORDS) {
                        termConstraint = "not(" + termConstraint + ")";
                    }
                    addConstraint(nameSearchConstraints, constraint, termConstraint);
                }
                addConstraint(textSearchConstraints, OR, nameSearchConstraints.toString());
            }
            if (searchFields.isTags() && getTaggingService() != null
                    && (params.getSites().getValue() != null || params.getOriginSiteKey() != null)
                    && !StringUtils.containsAny(textSearch.getTerm(), "?*")) {
                for (String term : terms) {
                    String tag = taggingService.getTagHandler().execute(term);
                    if (!StringUtils.isEmpty(tag)) {
                        addConstraint(textSearchConstraints, OR,
                                getPropertyName("j:tagList", xpath) + "=" + stringToJCRSearchExp(tag));
                    }
                }
                if (terms.length > 1) {
                    String tag = taggingService.getTagHandler().execute(textSearch.getTerm());
                    if (!StringUtils.isEmpty(tag)) {
                        addConstraint(textSearchConstraints, OR,
                                getPropertyName("j:tagList", xpath) + "=" + stringToJCRSearchExp(tag));
                    }
                }
            }
            if (textSearchConstraints.length() > 0) {
                addConstraint(constraints, AND, "(" + textSearchConstraints.toString() + ")");
            }
        }
    }
}

From source file:org.jahia.services.search.jcr.JahiaJCRSearchProvider.java

private String getSearchExpressionForMatchType(String term, MatchType matchType, boolean applyFilter,
        String postfix) {//from  ww w  .j  ava2 s. c  o m
    // as Lucene does not analyze wildcard terms, check whether integrator requested Jahia
    // to apply this accent filter 
    if (applyFilter && StringUtils.containsAny(term, "?*")) {
        term = removeAccents(term);
    }

    if (Term.MatchType.AS_IS != matchType) {
        term = QueryParser.escape(NOT_PATTERN
                .matcher(OR_PATTERN.matcher(AND_PATTERN.matcher(term).replaceAll(" and ")).replaceAll(" or "))
                .replaceAll(" not "));
    }

    if (MatchType.ANY_WORD == matchType) {
        term = StringUtils.replace(cleanMultipleWhiteSpaces(term), " ", " OR ");

    } else if (MatchType.EXACT_PHRASE == matchType) {
        term = "\"" + term.trim() + "\"";
    } else if (MatchType.WITHOUT_WORDS == matchType) {
        // because of the underlying Lucene limitations a star '*' (means
        // 'match all') is added to the query string
        term = "* -" + StringUtils.replace(cleanMultipleWhiteSpaces(term), " ", " -");
    }

    return stringToJCRSearchExp(postfix != null ? term + postfix : term);
}

From source file:org.janusgraph.diskstorage.configuration.ConfigElement.java

public ConfigElement(ConfigNamespace namespace, String name, String description) {
    Preconditions.checkArgument(StringUtils.isNotBlank(name), "Name cannot be empty: %s", name);
    Preconditions.checkArgument(!StringUtils.containsAny(name, ILLEGAL_CHARS),
            "Name contains illegal character: %s (%s)", name, ILLEGAL_CHARS);
    Preconditions.checkArgument(namespace != null || this instanceof ConfigNamespace,
            "Need to specify namespace for ConfigOption");
    Preconditions.checkArgument(StringUtils.isNotBlank(description));
    this.namespace = namespace;
    this.name = name;
    this.description = description;
    if (namespace != null)
        namespace.registerChild(this);
}

From source file:org.janusgraph.diskstorage.configuration.ConfigElement.java

public static String getPath(ConfigElement element, boolean includeRoot, String... umbrellaElements) {
    Preconditions.checkNotNull(element);
    if (umbrellaElements == null)
        umbrellaElements = new String[0];
    String path = element.getName();
    int umbrellaPos = umbrellaElements.length - 1;
    while (!element.isRoot() && !element.getNamespace().isRoot()) {
        ConfigNamespace parent = element.getNamespace();
        if (parent.isUmbrella()) {
            Preconditions.checkArgument(umbrellaPos >= 0, "Missing umbrella element path for element: %s",
                    element);//  www  .ja  v  a  2 s. com
            String umbrellaName = umbrellaElements[umbrellaPos];
            Preconditions.checkArgument(!StringUtils.containsAny(umbrellaName, ILLEGAL_CHARS),
                    "Invalid umbrella name provided: %s. Contains illegal chars", umbrellaName);
            path = umbrellaName + SEPARATOR + path;
            umbrellaPos--;
        }
        path = parent.getName() + SEPARATOR + path;
        element = parent;
    }
    if (includeRoot) {
        // Assumes that roots are not umbrellas
        // If roots could be umbrellas, we might have to change the interpretation of umbrellaElements
        path = (element.isRoot() ? element.getName() : element.getNamespace().getName()) + SEPARATOR + path;
    }
    //Don't make this check so that we can still access more general config items
    Preconditions.checkArgument(umbrellaPos < 0, "Found unused umbrella element: %s",
            umbrellaPos < 0 ? null : umbrellaElements[umbrellaPos]);
    return path;
}

From source file:org.janusgraph.diskstorage.es.ElasticSearchIndex.java

@Override
public String mapKey2Field(String key, KeyInformation information) {
    Preconditions.checkArgument(!StringUtils.containsAny(key, new char[] { ' ' }),
            "Invalid key name provided: %s", key);
    return key;//from w w  w.  j  a v  a2s  .  c  om
}

From source file:org.janusgraph.diskstorage.indexing.IndexProvider.java

static void checkKeyValidity(String key) {
    Preconditions.checkArgument(!StringUtils.containsAny(key, new char[] { IndexProvider.REPLACEMENT_CHAR }),
            "Invalid key name containing reserved character %c provided: %s", IndexProvider.REPLACEMENT_CHAR,
            key);//from  www . ja va 2  s.c om
}

From source file:org.janusgraph.diskstorage.solr.SolrIndex.java

@Override
public String mapKey2Field(String key, KeyInformation keyInfo) {
    Preconditions.checkArgument(!StringUtils.containsAny(key, new char[] { ' ' }),
            "Invalid key name provided: %s", key);
    if (!dynFields)
        return key;
    if (ParameterType.MAPPED_NAME.hasParameter(keyInfo.getParameters()))
        return key;
    String postfix;//from  w w w  . j  a  va  2s  .  com
    Class datatype = keyInfo.getDataType();
    if (AttributeUtil.isString(datatype)) {
        Mapping map = getStringMapping(keyInfo);
        switch (map) {
        case TEXT:
            postfix = "_t";
            break;
        case STRING:
            postfix = "_s";
            break;
        default:
            throw new IllegalArgumentException("Unsupported string mapping: " + map);
        }
    } else if (AttributeUtil.isWholeNumber(datatype)) {
        if (datatype.equals(Long.class))
            postfix = "_l";
        else
            postfix = "_i";
    } else if (AttributeUtil.isDecimal(datatype)) {
        if (datatype.equals(Float.class))
            postfix = "_f";
        else
            postfix = "_d";
    } else if (datatype.equals(Geoshape.class)) {
        postfix = "_g";
    } else if (datatype.equals(Date.class) || datatype.equals(Instant.class)) {
        postfix = "_dt";
    } else if (datatype.equals(Boolean.class)) {
        postfix = "_b";
    } else if (datatype.equals(UUID.class)) {
        postfix = "_uuid";
    } else
        throw new IllegalArgumentException("Unsupported data type [" + datatype + "] for field: " + key);
    return key + postfix;
}

From source file:org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.java

public static String getOrGenerateUniqueInstanceId(Configuration config) {
    String uid;//from   w ww. j a  v  a 2 s.c  o  m
    if (!config.has(UNIQUE_INSTANCE_ID)) {
        uid = computeUniqueInstanceId(config);
        log.info("Generated {}={}", UNIQUE_INSTANCE_ID.getName(), uid);
    } else {
        uid = config.get(UNIQUE_INSTANCE_ID);
    }
    Preconditions.checkArgument(!StringUtils.containsAny(uid, ConfigElement.ILLEGAL_CHARS),
            "Invalid unique identifier: %s", uid);
    return uid;
}

From source file:org.janusgraph.graphdb.configuration.GraphDatabaseConfigurationTest.java

@Test
public void testUniqueNames() {
    assertFalse(StringUtils.containsAny(
            GraphDatabaseConfiguration.getOrGenerateUniqueInstanceId(Configuration.EMPTY),
            ConfigElement.ILLEGAL_CHARS));
}

From source file:org.janusgraph.graphdb.idmanagement.UniqueInstanceIdRetriever.java

public String getOrGenerateUniqueInstanceId(Configuration config) {
    String uid;//from ww w. j  a  v  a  2 s.c o  m
    if (!config.has(GraphDatabaseConfiguration.UNIQUE_INSTANCE_ID)) {
        uid = computeUniqueInstanceId(config);
        log.info("Generated {}={}", GraphDatabaseConfiguration.UNIQUE_INSTANCE_ID.getName(), uid);
    } else {
        uid = config.get(GraphDatabaseConfiguration.UNIQUE_INSTANCE_ID);
    }
    Preconditions.checkArgument(!StringUtils.containsAny(uid, ConfigElement.ILLEGAL_CHARS),
            "Invalid unique identifier: %s", uid);
    return uid;
}