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

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

Introduction

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

Prototype

public static boolean contains(final CharSequence seq, final CharSequence searchSeq) 

Source Link

Document

Checks if CharSequence contains a search CharSequence, handling null .

Usage

From source file:de.micromata.genome.gwiki.page.search.expr.SearchUtils.java

public static String escapeSearchLiteral(String text) {

    if (StringUtils.contains(text, "\"") == false) {
        return "\"" + text + "\"";
    }//from  w w w.  j  a  v a2s . c  o m
    if (text.length() == 1) {
        return text;
    }
    if (text.charAt(0) == '"' && text.charAt(text.length() - 1) == '"') {
        return text;
    }
    return "\"" + text + "\"";
}

From source file:com.norconex.commons.lang.url.HttpURL.java

/**
 * Constructor./*  ww w.  j a  v a 2s.  c  o m*/
 * @param url a URL
 */
public HttpURL(String url) {
    if (url.startsWith("http")) {
        URL urlwrap;
        try {
            urlwrap = new URL(url);
        } catch (MalformedURLException e) {
            throw new URLException("Could not interpret URL: " + url, e);
        }
        protocol = urlwrap.getProtocol();
        host = urlwrap.getHost();
        port = urlwrap.getPort();
        path = urlwrap.getPath();
    }

    // Parameters
    if (StringUtils.contains(url, "?")) {
        queryString = new QueryString(url);
    }
}

From source file:com.adguard.commons.lang.Wildcard.java

/**
 * Returns "true" if input text is matching wildcard.
 * This method first checking shortcut -- if shortcut exists in input string -- than it checks regexp.
 *
 * @param input Input string//from ww  w.  j  a  v  a 2 s.  com
 * @return true if input string matches wildcard
 */
public boolean matches(String input) {
    if (StringUtils.isEmpty(input)) {
        return false;
    }

    boolean matchCase = ((regexpOptions & Pattern.CASE_INSENSITIVE) == Pattern.CASE_INSENSITIVE);

    if (matchCase && !StringUtils.contains(input, shortcut)) {
        return false;
    }

    if (!matchCase && !StringUtils.containsIgnoreCase(input, shortcut)) {
        return false;
    }

    return regexp.matcher(input).matches();
}

From source file:com.glaf.activiti.mail.SendSimpleMailTaskBean.java

public void sendAllRunningTasks() {
    Map<String, User> userMap = IdentityFactory.getUserMap();
    Iterator<User> iterator = userMap.values().iterator();
    while (iterator.hasNext()) {
        User user = iterator.next();/*  w w w  .  j  a  va2s. c o m*/
        logger.debug(user.getActorId() + " " + user.getMail());
        if (StringUtils.isNotEmpty(user.getMail()) && StringUtils.contains(user.getMail(), "@")) {
            this.sendRunningTasks(user);
        }
    }
}

From source file:io.wcm.wcm.parsys.componentinfo.impl.AllowedComponentsProviderImpl.java

/**
 * Get allowed components for given resource path
 * @param resourcePath Resource path inside content page
 * @return Set of component paths (absolute resource types)
 *///from   ww w  . ja v  a2 s  .c o m
@Override
public Set<String> getAllowedComponents(String resourcePath, ResourceResolver resolver) {
    Set<String> allowedComponents = new HashSet<>();
    Set<String> deniedComponents = new HashSet<>();

    PageManager pageManager = resolver.adaptTo(PageManager.class);
    Page page = pageManager.getContainingPage(resourcePath);
    if (page == null && StringUtils.contains(resourcePath, "/" + JcrConstants.JCR_CONTENT)) {
        // if resource does not exist (e.g. inherited parsys) get page from resource path manually
        page = pageManager.getPage(StringUtils.substringBefore(resourcePath, "/" + JcrConstants.JCR_CONTENT));
    }
    if (page != null) {
        String pageComponentPath = page.getContentResource().getResourceType();
        String relativePath = resourcePath.substring(page.getPath().length() + 1);

        Iterable<ParsysConfig> parSysConfigs = parsysConfigManager.getParsysConfigs(pageComponentPath,
                relativePath, resolver);

        Resource parentResource = null;
        Resource grandParentResource = null;

        for (ParsysConfig pathDef : parSysConfigs) {

            boolean includePathDef = false;
            if (pathDef.getAllowedParents().size() == 0) {
                includePathDef = true;
            } else {
                Resource checkResource = null;
                if (pathDef.getParentAncestorLevel() == 1) {
                    if (parentResource == null) {
                        parentResource = resolver.getResource(resourcePath);
                    }
                    checkResource = parentResource;
                }
                if (pathDef.getParentAncestorLevel() == 2) {
                    if (grandParentResource == null) {
                        grandParentResource = resolver.getResource(resourcePath + "/..");
                    }
                    checkResource = grandParentResource;
                }
                if (checkResource != null) {
                    String resourceType = ResourceType.makeAbsolute(checkResource.getResourceType(), resolver);
                    includePathDef = pathDef.getAllowedParents().contains(resourceType);
                }
            }

            if (includePathDef) {
                allowedComponents.addAll(makeAbsolute(pathDef.getAllowedChildren(), resolver));
                deniedComponents.addAll(makeAbsolute(pathDef.getDeniedChildren(), resolver));
            }

        }

    }

    // filter out denied components
    allowedComponents.removeAll(deniedComponents);

    return allowedComponents;
}

From source file:com.nridge.core.ds.rdbms.SQLIndex.java

/**
 * Returns a schema name for index objects based on the DB name
 * assigned to the bag and the persistent field.
 *
 * @param aBag Field bag with DB name assigned.
 * @param aField Field to base the index name on.
 *
 * @return Schema name of the index object.
 *
 * @throws NSException Catch-all exception for any SQL related issue.
 *//*from   w w w  .j  a  va 2s.  c om*/
public String schemaName(DataBag aBag, DataField aField) throws NSException {
    String dbName = aBag.getName();
    if (StringUtils.isEmpty(dbName))
        throw new NSException("The name for the persistent bag is undefined.");

    String indexName;
    String fieldName = aField.getName();
    if (mSQLConnection.isAutoNamingEnabled()) {
        if (StringUtils.startsWith(dbName, NS_INDEX_PREFIX)) {
            if (StringUtils.contains(dbName, fieldName))
                indexName = dbName;
            else
                indexName = String.format("%s_%s_%s", NS_INDEX_PREFIX, dbName, fieldName);
        } else
            indexName = String.format("%s_%s_%s", NS_INDEX_PREFIX, dbName, fieldName);
    } else
        indexName = String.format("%s_%s", dbName, fieldName);

    return indexName;
}

From source file:com.handpay.ibenefit.framework.util.WebUtils.java

public static boolean checkAccetptGzip(HttpServletRequest request) {
    // Http1.1 header
    String acceptEncoding = request.getHeader("Accept-Encoding");

    if (StringUtils.contains(acceptEncoding, "gzip")) {
        return true;
    } else {//w  ww  .ja  v  a  2 s . c  o  m
        return false;
    }
}

From source file:info.magnolia.ui.framework.setup.ReplaceMultiLinkFieldDefinitionTask.java

@Override
protected void operateOnNode(InstallContext installContext, Node fieldNodeDefinition) {
    String nodePath = NodeUtil.getPathIfPossible(fieldNodeDefinition);
    try {/* w w  w .j  a v  a2  s  . co  m*/
        if (StringUtils.contains(nodePath, "fields")) {

            // Create a field child node
            Node field = fieldNodeDefinition.addNode("field", NodeTypes.ContentNode.NAME);
            field.setProperty("class", LinkFieldDefinition.class.getName());

            // Move IdentifierToPathConverter to the field node
            if (fieldNodeDefinition.hasNode("identifierToPathConverter")) {
                NodeUtil.moveNode(fieldNodeDefinition.getNode("identifierToPathConverter"), field);
            }

            // Move the properties to the field definition
            copyAndRemoveProperty(fieldNodeDefinition, field, "appName");
            copyAndRemoveProperty(fieldNodeDefinition, field, "buttonSelectNewLabel");
            copyAndRemoveProperty(fieldNodeDefinition, field, "buttonSelectOtherLabel");
            copyAndRemoveProperty(fieldNodeDefinition, field, "fieldEditable");
            copyAndRemoveProperty(fieldNodeDefinition, field, "targetWorkspace");
            copyAndRemoveProperty(fieldNodeDefinition, field, "type");

            // Change the class property
            fieldNodeDefinition.setProperty("class", MultiValueFieldDefinition.class.getName());

        } else {
            log.debug("The following node {} is not a field definition. ", nodePath);
        }
    } catch (RepositoryException re) {
        log.warn("Could not Migrate 'MultiLinkFieldDefinition' of the following node {}.", nodePath);
    }
}

From source file:com.thoughtworks.go.server.functional.helpers.CSVResponse.java

public boolean containsColumn(String... columns) {
    List<String> targetColumn = null;
    for (List column : this.allColumns) {
        targetColumn = Arrays.asList(columns);
        if (StringUtils.contains(column.toString(), targetColumn.toString())) {
            return true;
        }/*from w w  w .ja  va2s .co  m*/
    }
    return false;
}

From source file:io.wcm.handler.media.CropDimension.java

/**
 * Get crop dimension from crop string./*from ww  w.  j a v  a2 s  . c  om*/
 * Please note: Crop string contains not width/height as 3rd/4th parameter but right, bottom.
 * @param cropString Cropping string from CQ5 smartimage widget
 * @return Crop dimension instance
 * @throws IllegalArgumentException if crop string syntax is invalid
 */
public static CropDimension fromCropString(String cropString) {
    if (StringUtils.isEmpty(cropString)) {
        throw new IllegalArgumentException("Invalid crop string: '" + cropString + "'.");
    }

    // strip off optional size parameter after "/"
    String crop = cropString;
    if (StringUtils.contains(crop, "/")) {
        crop = StringUtils.substringBefore(crop, "/");
    }

    String[] parts = StringUtils.split(crop, ",");
    if (parts.length != 4) {
        throw new IllegalArgumentException("Invalid crop string: '" + cropString + "'.");
    }
    long x1 = NumberUtils.toLong(parts[0]);
    long y1 = NumberUtils.toLong(parts[1]);
    long x2 = NumberUtils.toLong(parts[2]);
    long y2 = NumberUtils.toLong(parts[3]);
    long width = x2 - x1;
    long height = y2 - y1;
    if (x1 < 0 || y1 < 0 || width <= 0 || height <= 0) {
        throw new IllegalArgumentException("Invalid crop string: '" + cropString + "'.");
    }
    return new CropDimension(x1, y1, width, height);
}