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

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

Introduction

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

Prototype

public static boolean contains(String str, String searchStr) 

Source Link

Document

Checks if String contains a search String, handling null.

Usage

From source file:com.yougou.api.service.impl.ApiAnalyzeServiceImpl.java

public List<AppKeyMetadata> getAppkeyByUser(String appKeyUser) {
    Map<String, String> map = hashOperations.entries(RedisKeyUtils.API_APPKEY_HASH);
    List<AppKeyMetadata> list = new ArrayList<AppKeyMetadata>();
    Set<Entry<String, String>> set = map.entrySet();
    for (Entry<String, String> entity : set) {
        String key = entity.getKey();
        String value = entity.getValue();
        if (StringUtils.contains(value, appKeyUser)) {
            list.add(new AppKeyMetadata(key, value));
        }/*w  w  w  . j  a  va  2s  .c om*/
    }
    return list;
}

From source file:com.cubusmail.mail.util.MessageUtils.java

/**
 * @param mailFolder/*from  www  .  j  av  a  2  s  . c o m*/
 * @param msgs
 * @param extendedSearchFields
 * @param params
 * @return
 */
public static Message[] filterMessages(IMailFolder mailFolder, Message[] msgs, String extendedSearchFields,
        String[][] params) {

    if (!StringUtils.isEmpty(extendedSearchFields)) {
        String[] fields = StringUtils.split(extendedSearchFields, ',');

        List<Message> filteredMsgs = new ArrayList<Message>();
        String fromValue = getParamValue(params, SearchFields.FROM.name());
        String toValue = getParamValue(params, SearchFields.TO.name());
        String ccValue = getParamValue(params, SearchFields.CC.name());
        String subjectValue = getParamValue(params, SearchFields.SUBJECT.name());
        String contentValue = getParamValue(params, SearchFields.CONTENT.name());
        String dateFromValue = getParamValue(params, SearchFields.DATE_FROM.name());
        String dateToValue = getParamValue(params, SearchFields.DATE_TO.name());

        try {
            // Body search
            if (StringUtils.contains(extendedSearchFields, SearchFields.CONTENT.name())) {
                BodyTerm term = new BodyTerm(contentValue);
                msgs = mailFolder.search(term, msgs);
                if (msgs == null) {
                    msgs = new Message[0];
                }
            }

            for (Message message : msgs) {
                boolean contains = true;
                for (String searchField : fields) {
                    if (SearchFields.FROM.name().equals(searchField)) {
                        String from = MessageUtils.getMailAdressString(message.getFrom(),
                                AddressStringType.COMPLETE);
                        contains = StringUtils.containsIgnoreCase(from, fromValue);
                    }
                    if (contains && SearchFields.TO.name().equals(searchField)) {
                        String to = MessageUtils.getMailAdressString(
                                message.getRecipients(Message.RecipientType.TO), AddressStringType.COMPLETE);
                        if (!StringUtils.isEmpty(to)) {
                            contains = StringUtils.containsIgnoreCase(to, toValue);
                        } else {
                            contains = false;
                        }
                    }
                    if (contains && SearchFields.CC.name().equals(searchField)) {
                        String cc = MessageUtils.getMailAdressString(
                                message.getRecipients(Message.RecipientType.CC), AddressStringType.COMPLETE);
                        if (!StringUtils.isEmpty(cc)) {
                            contains = StringUtils.containsIgnoreCase(cc, ccValue);
                        } else {
                            contains = false;
                        }
                    }
                    if (contains && SearchFields.SUBJECT.name().equals(searchField)) {
                        if (!StringUtils.isEmpty(message.getSubject())) {
                            contains = StringUtils.containsIgnoreCase(message.getSubject(), subjectValue);
                        } else {
                            contains = false;
                        }
                    }
                    if (contains && SearchFields.DATE_FROM.name().equals(searchField)) {
                        Date dateFrom = new Date(Long.parseLong(dateFromValue));
                        if (message.getSentDate() != null) {
                            contains = !message.getSentDate().before(dateFrom);
                        } else {
                            contains = false;
                        }
                    }
                    if (contains && SearchFields.DATE_TO.name().equals(searchField)) {
                        Date dateTo = new Date(Long.parseLong(dateToValue));
                        if (message.getSentDate() != null) {
                            contains = !message.getSentDate().after(dateTo);
                        } else {
                            contains = false;
                        }
                    }
                }
                if (contains) {
                    filteredMsgs.add(message);
                }
            }
        } catch (MessagingException ex) {
            log.warn(ex.getMessage());
        }

        return filteredMsgs.toArray(new Message[0]);
    }

    return msgs;
}

From source file:info.magnolia.cms.security.SecurityUtil.java

public static String stripParameterFromCacheLog(String log, String parameter) {
    if (StringUtils.isBlank(log)) {
        return null;
    } else if (!StringUtils.contains(log, parameter)) {
        return log;
    }//from ww  w  .j  a v a 2  s  . co  m
    String value = null;
    value = StringUtils.substringBefore(log, parameter);
    String afterString = StringUtils.substringAfter(log, parameter);
    if (StringUtils.indexOf(afterString, " ") < StringUtils.indexOf(afterString, "}")) {
        value = value + StringUtils.substringAfter(afterString, " ");
    } else {
        value = value + "}" + StringUtils.substringAfter(afterString, "}");
    }
    return value;
}

From source file:com.haulmont.cuba.web.gui.components.WebComponentsHelper.java

@Nullable
public static Resource getIcon(String iconName) {
    if (StringUtils.isEmpty(iconName)) {
        return null;
    }//from   w  ww . j av  a 2  s. c o  m

    Configuration configuration = AppBeans.get(Configuration.NAME);
    WebConfig webConfig = configuration.getConfig(WebConfig.class);

    if (webConfig.getUseFontIcons()) {
        String fontIcon;

        if (StringUtils.contains(iconName, ":")) {
            fontIcon = iconName;
        } else {
            ThemeConstants themeConstants = App.getInstance().getThemeConstants();
            String iconKey = "cuba.web." + StringUtils.replace(iconName, "/", ".");
            fontIcon = themeConstants.get(iconKey);
        }

        try {
            Resource resource = getFontIconResource(fontIcon);
            if (resource != null) {
                return resource;
            }
        } catch (NoSuchFieldException | IllegalAccessException e) {
            LoggerFactory.getLogger(WebComponentsHelper.class).warn("Unable to use font icon {}", fontIcon);
        }
    }
    return new VersionedThemeResource(iconName);
}

From source file:at.pagu.soldockr.core.query.Criteria.java

private String processWhiteSpaces(String criteriaValue) {
    if (StringUtils.contains(criteriaValue, CRITERIA_VALUE_SEPERATOR)) {
        return DOUBLEQUOTE + criteriaValue + DOUBLEQUOTE;
    }//from www.  ja v a 2  s .c  o m
    return criteriaValue;
}

From source file:com.ning.metrics.collector.jaxrs.TestResources.java

protected void verifyBadRequest(final Response response) {
    Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode());
    Assert.assertEquals(response.getMetadata().get("Warning").size(), 1);
    Assert.assertTrue(StringUtils.contains(((String) response.getMetadata().get("Warning").get(0)), "199"));

    verifyCacheControl(response);//  w  w w.  j  a va 2 s  .c o  m
}

From source file:net.kamhon.ieagle.dao.HibernateDao.java

@SuppressWarnings("unchecked")
public void findForDatagrid(DatagridModel<T> datagridModel, String alias, String queryString,
        Object... objectArray) {/*from w  ww  . j av a  2s.  c om*/
    Assert.isTrue(StringUtils.isNotBlank(alias), "The alias can not be BLANK!!");
    Assert.isTrue(StringUtils.isNotBlank(queryString), "The queryString can not be BLANK!!");

    if (CollectionUtil.isNotEmpty(datagridModel.getFilters())) {
        Assert.doesNotContain(queryString, BasicDao.FILTER_PARAMS, "The " + BasicDao.FILTER_PARAMS
                + " is not found in Query [" + queryString + "] if FILTERS is not EMPTY!!");
    }
    /*************************
     * END VALIDATION
     ************************/
    String finalQuery = queryString.trim();
    List<Object> params = new ArrayList<Object>();
    if (objectArray != null) {
        if (objectArray.length == 1 && objectArray[0] instanceof List)
            params = (List<Object>) objectArray[0];
        else
            params = Arrays.asList(objectArray);
    }

    if (CollectionUtil.isNotEmpty(datagridModel.getFilters())) {
        for (Filter filter : datagridModel.getFilters()) {
            if (filter != null)
                throw new DataException("The Filter features still not implemented yet");
        }
    }

    List<Object> countParams = new ArrayList<Object>(params);
    String countQuery = "SELECT COUNT(" + alias + ") ";

    if (finalQuery.toUpperCase().startsWith("SELECT")) {
        int ind = finalQuery.toUpperCase().indexOf("FROM");
        countQuery += finalQuery.substring(ind);
    } else {
        countQuery += finalQuery;
    }

    if (!datagridModel.isDisableSort() && CollectionUtil.isNotEmpty(datagridModel.getSorters())) {
        if (StringUtils.contains(finalQuery.toUpperCase(), "ORDER BY")) {
            finalQuery += ", ";
        } else {
            finalQuery += " ORDER BY ";
        }

        for (Iterator<Sorter> iter = datagridModel.getSorters().iterator(); iter.hasNext();) {
            Sorter sorter = iter.next();
            finalQuery += alias + "." + sorter.getColumn() + " " + sorter.getDirection();
            if (iter.hasNext()) {
                finalQuery += ", ";
            }
        }
    }

    // log.debug("countParams = " + countParams);
    // log.debug("countQuery = " + countQuery);

    // log.debug("params = " + params);
    // log.debug("finalQuery = " + finalQuery);

    List<T> result = (List<T>) findBlock(finalQuery, datagridModel.getRecordOffset(),
            datagridModel.getPageSize(), params.toArray());
    datagridModel.setRecords(result);

    Long count = (Long) this.findUnique(countQuery, countParams.toArray());
    datagridModel.setTotalRecords(count);
}

From source file:at.pagu.soldockr.core.query.Criteria.java

private void assertNoBlankInWildcardedQuery(String searchString, boolean leadingWildcard,
        boolean trailingWildcard) {
    if (StringUtils.contains(searchString, CRITERIA_VALUE_SEPERATOR)) {
        throw new ApiUsageException(
                "Cannot constructQuery '" + (leadingWildcard ? "*" : "") + "\"" + searchString + "\""
                        + (trailingWildcard ? "*" : "") + "'. Use epxression or mulitple clauses instead.");
    }// w  ww. j a  va2  s  . c o m
}

From source file:com.ning.metrics.collector.jaxrs.TestResources.java

protected void verifyGoodRequest(final Response response, final boolean warningHeaderPresent) {
    Assert.assertEquals(response.getStatus(), Response.Status.ACCEPTED.getStatusCode());
    if (warningHeaderPresent) {
        Assert.assertEquals(response.getMetadata().get("Warning").size(), 1);
        Assert.assertTrue(StringUtils.contains(((String) response.getMetadata().get("Warning").get(0)), "199"));
    } else {//from   www  .j  a v  a 2s . co  m
        Assert.assertNull(response.getMetadata().get("Warning"));
    }

    verifyCacheControl(response);
}

From source file:com.pearson.openideas.cq5.components.filters.LandingPageList.java

/**
 * This method builds the filter lists used on the landing page.
 *
 * @param resource/*w  w  w. j a v  a2s  . c  o m*/
 *            the resource to pull tags from
 * @param tagManager
 *            the tag manager instance
 * @param article
 *            the article we're pulling info from
 */
private void buildFilterLists(Resource resource, TagManager tagManager, Article article) {
    Tag[] tags = tagManager.getTags(resource);
    for (Tag tagFromPage : tags) {
        String tagPath = tagFromPage.getPath();

        //let's create a list for each tag's relationships
        List<String> tagList = new ArrayList<String>();
        //if the list has already been started, we'll pull it and add to it
        if (relationshipMap.get(tagFromPage.getTitle()) != null) {
            tagList = relationshipMap.get(tagFromPage.getTitle());
        } else if (relationshipMap.get(tagFromPage.getName()) != null) {
            tagList = relationshipMap.get(tagFromPage.getName());
        }

        if (tagPath.contains(NamespaceEnum.THEME.getNamespace())) {

            // if this isn't a theme landing page, create the filter list
            if (!namespace.contains(NamespaceEnum.THEME.getNamespace())) {

                if (themeTags.containsKey(tagFromPage)) {
                    themeTags.put(tagFromPage, themeTags.get(tagFromPage) + 1);
                } else {
                    themeTags.put(tagFromPage, 1L);
                }

                for (Tag tag : tags) {
                    if (!tagList.contains(tag.getTitle()) || !tagList.contains(tag.getName())) {
                        if (tag.getPath().contains(NamespaceEnum.REGION.getNamespace())
                                || tag.getPath().contains(NamespaceEnum.COUNTRY.getNamespace())) {
                            tagList.add(tag.getName());
                        } else {
                            tagList.add(tag.getTitle());
                        }
                    }
                }
                relationshipMap.put(tagFromPage.getTitle(), tagList);
            }
        } else if (tagPath.contains(NamespaceEnum.CATEGORY.getNamespace())) {
            // if this isn't a category landing page, create the filter list
            if (!namespace.contains(NamespaceEnum.CATEGORY.getNamespace())) {
                if (categoryTags.containsKey(tagFromPage)) {
                    categoryTags.put(tagFromPage, categoryTags.get(tagFromPage) + 1);
                } else {
                    categoryTags.put(tagFromPage, 1L);
                }

                for (Tag tag : tags) {
                    if (!tagList.contains(tag.getTitle()) || !tagList.contains(tag.getName())) {
                        if (tag.getPath().contains(NamespaceEnum.REGION.getNamespace())
                                || tag.getPath().contains(NamespaceEnum.COUNTRY.getNamespace())) {
                            tagList.add(tag.getName());
                        } else {
                            tagList.add(tag.getTitle());
                        }
                    }
                }
                relationshipMap.put(tagFromPage.getTitle(), tagList);
            }
        } else if (tagPath.contains(NamespaceEnum.REGION.getNamespace())) {
            // if this isn't a region landing page, create the filter list
            if (article != null) {
                article.setRegion(tagFromPage.getName());
            }
            if (!namespace.contains(NamespaceEnum.REGION.getNamespace())) {
                if (!regionTagList.contains(tagFromPage)) {
                    regionTagList.add(tagFromPage);
                }
                for (Tag tag : tags) {
                    if (!tagList.contains(tag.getTitle()) || !tagList.contains(tag.getName())) {
                        if (tag.getPath().contains(NamespaceEnum.REGION.getNamespace())
                                || tag.getPath().contains(NamespaceEnum.COUNTRY.getNamespace())) {
                            tagList.add(tag.getName());
                        } else {
                            tagList.add(tag.getTitle());
                        }
                    }
                }
                relationshipMap.put(tagFromPage.getTitle(), tagList);
            }
        } else if (tagPath.contains(NamespaceEnum.COUNTRY.getNamespace())) {
            // no matter what, create the country filter list
            if (article != null) {
                if (tagFromPage.getName().equalsIgnoreCase(selectedCountryFilter)) {
                    article.setCountry(tagFromPage.getName());
                }
            }
            if (!countryTagList.contains(tagFromPage)) {
                if (!StringUtils.contains(tagFromPage.getTagID(), "/")) {
                    countryTagList.add(tagFromPage);
                }
            }
            for (Tag tag : tags) {
                if (tag.getPath().contains(NamespaceEnum.REGION.getNamespace())
                        || tag.getPath().contains(NamespaceEnum.THEME.getNamespace())
                        || tag.getPath().contains(NamespaceEnum.CATEGORY.getNamespace())) {
                    if (!tagList.contains(tag.getTitle()) || !tagList.contains(tag.getName())) {
                        if (tag.getPath().contains(NamespaceEnum.REGION.getNamespace())
                                || tag.getPath().contains(NamespaceEnum.COUNTRY.getNamespace())) {
                            tagList.add(tag.getName());
                        } else {
                            tagList.add(tag.getTitle());
                        }
                    }
                }
            }
            relationshipMap.put(tagFromPage.getTitle(), tagList);
        }
        for (Tag tag : tags) {
            if (tag.getPath().contains(NamespaceEnum.REGION.getNamespace())
                    || tag.getPath().contains(NamespaceEnum.THEME.getNamespace())
                    || tag.getPath().contains(NamespaceEnum.CATEGORY.getNamespace())) {
                if (!tagList.contains(tag.getTitle())) {
                    tagList.add(tag.getTitle());
                }
            }
        }
        if (tagFromPage.getPath().contains(NamespaceEnum.REGION.getNamespace())
                || tagFromPage.getPath().contains(NamespaceEnum.COUNTRY.getNamespace())) {
            relationshipMap.put(tagFromPage.getName(), tagList);
        } else if (tagFromPage.getPath().contains(NamespaceEnum.THEME.getNamespace())
                || tagFromPage.getPath().contains(NamespaceEnum.CATEGORY.getNamespace())) {
            relationshipMap.put(tagFromPage.getTitle(), tagList);
        }
    }

    //create a JSON object to store these relationships for use on the front end
    JSONObject jsonObject = new JSONObject(relationshipMap);
    //create a string for the front end
    relationshipJSON = jsonObject.toString();
}