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

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

Introduction

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

Prototype

public static boolean containsIgnoreCase(final CharSequence str, final CharSequence searchStr) 

Source Link

Document

Checks if CharSequence contains a search CharSequence irrespective of case, handling null .

Usage

From source file:io.stallion.dataAccess.filtering.FilterChain.java

/**
 * Check whether the operation conditions match the object, without taking into account
 * isExcludes or "OR" subOperations./*from  w ww. j a  v a  2  s .c  o  m*/
 *
 * @param op
 * @param o
 * @return
 */
private boolean checkItemMatchesFilterConditions(FilterOperation op, T o) {

    Object propValue = null;
    if (op.hasDot()) {
        propValue = PropertyUtils.getDotProperty(o, op.getFieldName());
    } else {
        propValue = PropertyUtils.getPropertyOrMappedValue(o, op.getFieldName());
    }

    // Filter out nulls
    if (propValue == null && op.getOriginalValue() != null) {
        return false;
    }
    if (propValue == null && op.getOriginalValue() == null && op.getOperator().equals(FilterOperator.EQUAL)) {
        return true;
    }

    if (op.isCaseInsensitive() && propValue instanceof String) {
        propValue = ((String) propValue).toLowerCase();
    }

    // Handle the IN operator
    if (op.getOperator().equals(FilterOperator.IN)) {
        Boolean isIn = false;
        Iterable values = (Iterable) propValue;
        for (Object val : values) {
            if (val.equals(op.getOriginalValue())) {
                isIn = true;
                break;
            }
        }
        return isIn;
    }
    if (op.getOperator().equals(FilterOperator.ANY)) {
        Iterable vals = (Iterable) op.getOriginalValue();
        boolean matches = false;
        for (Object val : vals) {
            if (val.equals(propValue)) {
                matches = true;
                break;
            }
        }
        return matches;
    }

    // Apply a bunch of heuristics to make sure we are comparing like types,
    // we don't want to filter something out because we are comparing a Long to an Integer
    hydrateTypedValue(op, propValue);

    // Filter out nulls again, based on type conversion
    if (propValue == null && op.getTypedValue() != null) {
        Log.info("Null value: id:{0} field:{1} objVal:''{2}'' ", o.getId(), op.getFieldName(), propValue);
        return false;
    }
    Log.finest(
            "Compare id:{0} field:{1} objVal:''{2}'' objValType:{3} filterTypedVal:''{4}'' filterValType: {5}",
            o.getId(), op.getFieldName(), propValue, propValue.getClass().getCanonicalName(),
            op.getTypedValue(), op.getTypedValue().getClass().getName());

    // When comparing booleans the string "true" should be considered true, and "false" false, this
    // is important when applying a filter coming from an untyped query string.
    if (op.getTypedValue() instanceof Boolean && propValue instanceof String) {
        return op.getTypedValue().toString().toLowerCase().equals((String) propValue.toString().toLowerCase());
    }

    if (op.getOperator().equals(FilterOperator.EQUAL)) {
        return op.getTypedValue().equals(propValue);
    }
    if (op.getOperator().equals(FilterOperator.NOT_EQUAL)) {
        return !op.getTypedValue().equals(propValue);
    }

    if (op.getOperator().equals(FilterOperator.LIKE)) {
        return StringUtils.containsIgnoreCase(propValue.toString(), op.getTypedValue().toString());
    }

    int i;
    if (propValue instanceof ZonedDateTime) {
        i = ((ZonedDateTime) op.getTypedValue()).compareTo((ZonedDateTime) propValue);
    } else {
        i = op.getComparableValue().compareTo(propValue);
    }
    if (op.getOperator().equals(FilterOperator.GREATER_THAN)) {
        return i < 0;
    }
    if (op.getOperator().equals(FilterOperator.LESS_THAN)) {
        return i > 0;
    }
    if (op.getOperator().equals(FilterOperator.GREATER_THAN_OR_EQUAL)) {
        return i <= 0;
    }
    if (op.getOperator().equals(FilterOperator.LESS_THAN_OR_EQUAL)) {
        return i >= 0;
    }
    throw new UsageException("You used an uninplemented filter operation: " + op);
}

From source file:ec.edu.chyc.manejopersonal.managebean.GestorArticulo.java

public boolean filtrarPorAutores(Object value, Object filter, Locale locale) {
    String filterText = (filter == null) ? null : filter.toString().trim();
    if (filterText == null || filterText.equals("")) {
        return true;
    }/*from   ww w . j a v a 2 s  .  c o m*/
    if (value == null) {
        return false;
    }

    Collection<PersonaArticulo> autores = (Collection) value;
    for (PersonaArticulo per : autores) {
        if (StringUtils.containsIgnoreCase(per.getPersona().getNombres(), filterText)
                || StringUtils.containsIgnoreCase(per.getPersona().getApellidos(), filterText)) {
            return true;
        }
    }
    return false;
}

From source file:br.com.ararati.faces.nfe.NFeDigitacaoFaces.java

public List<NFeTipoMotivoDesoneracaoICMS> completeNFeMotivosDesoneracaoIcms(String query) {
    if (this.produtoServico != null && this.produtoServico.getCsticms() != null) {
        switch (this.produtoServico.getCsticms()) {
        case COD20:
        case COD70:
        case COD90:
            return NFeTipoMotivoDesoneracaoICMS.getMotivosDesoneracaoICMS20().stream()
                    .filter(v -> StringUtils.containsIgnoreCase(v.getDescricao(), query))
                    .collect(Collectors.toList());
        case COD30:
            return NFeTipoMotivoDesoneracaoICMS.getMotivosDesoneracaoICMS30().stream()
                    .filter(v -> StringUtils.containsIgnoreCase(v.getDescricao(), query))
                    .collect(Collectors.toList());
        case COD40:
        case COD41:
        case COD50:
            return NFeTipoMotivoDesoneracaoICMS.getMotivosDesoneracaoICMS40().stream()
                    .filter(v -> StringUtils.containsIgnoreCase(v.getDescricao(), query))
                    .collect(Collectors.toList());
        default://from ww  w.ja v a  2 s .c om
            break;
        }
    }

    return null;

}

From source file:com.moviejukebox.plugin.ImdbPlugin.java

/**
 * Scrape info which is common for old and new IMDb.
 *
 * @param movie//from www  .  j a v a2 s . c om
 * @param xml
 * @param imdbNewVersion
 */
private void updateInfoCommon(Movie movie, String xml) {
    // Store the release info page for release info & AKAs
    String releaseInfoXML = UNKNOWN;
    // Store the aka list
    Map<String, String> akas = null;

    if (OverrideTools.checkOverwriteAspectRatio(movie, IMDB_PLUGIN_ID)) {
        // determine start and end string
        String startString;
        String endString;
        if (fullInfo) {
            startString = HTML_H5_START + "Aspect Ratio" + HTML_H5_END + "<div class=\"info-content\">";
            endString = "<a class";
        } else {
            startString = "<h4 class=\"inline\">Aspect Ratio" + HTML_H4_END;
            endString = HTML_DIV_END;
        }

        // find unclean aspect ratio
        String uncleanAspectRatio = HTMLTools.extractTag(xml, startString, endString).trim();

        if (StringTools.isValidString(uncleanAspectRatio)) {
            // remove spaces and replace , with .
            uncleanAspectRatio = uncleanAspectRatio.replace(" ", "").replace(",", ".");
            // set aspect ratio
            movie.setAspectRatio(aspectTools.cleanAspectRatio(uncleanAspectRatio), IMDB_PLUGIN_ID);
        }
    }

    // RELEASE DATE
    if (OverrideTools.checkOverwriteReleaseDate(movie, IMDB_PLUGIN_ID)) {
        // Load the release page from IMDB
        if (StringTools.isNotValidString(releaseInfoXML)) {
            releaseInfoXML = getImdbData(getImdbUrl(movie, SUFFIX_RELEASEINFO));
        }

        Matcher mRelease = pRelease.matcher(releaseInfoXML);

        // "contains" is a quick match before the slower find() is triggered.
        if (releaseInfoXML.contains(preferredCountry) && mRelease.find()) {
            String releaseDate = mRelease.group(1) + " " + mRelease.group(2);
            movie.setReleaseDate(releaseDate, IMDB_PLUGIN_ID);
        }
    }

    // ORIGINAL TITLE / AKAS
    if (OverrideTools.checkOverwriteOriginalTitle(movie, IMDB_PLUGIN_ID)) {
        // Load the AKA page from IMDb
        if (StringTools.isNotValidString(releaseInfoXML)) {
            releaseInfoXML = getImdbData(getImdbUrl(movie, SUFFIX_RELEASEINFO));
        }

        // The AKAs are stored in the format "title", "country"
        // therefore we need to look for the preferredCountry and then work backwards
        List<String> akaList = HTMLTools.extractTags(releaseInfoXML, "<a id=\"akas\" name=\"akas\">",
                HTML_TABLE_END, "<td>", HTML_TD_END, Boolean.FALSE);
        akas = buildAkaMap(akaList);

        String foundValue = null;
        for (Map.Entry<String, String> aka : akas.entrySet()) {
            if (aka.getKey().contains("original title")) {
                foundValue = aka.getValue().trim();
                break;
            }
        }
        movie.setOriginalTitle(foundValue, IMDB_PLUGIN_ID);
    }

    // TITLE for preferred country from AKAS
    if (akaScrapeTitle && OverrideTools.checkOverwriteTitle(movie, IMDB_PLUGIN_ID)) {
        // Load the AKA page from IMDb
        if (StringTools.isNotValidString(releaseInfoXML)) {
            releaseInfoXML = getImdbData(getImdbUrl(movie, SUFFIX_RELEASEINFO));
        }

        // The AKAs are stored in the format "title", "country"
        // therefore we need to look for the preferredCountry and then work backwards
        if (akas == null) {
            // Just extract the AKA section from the page
            List<String> akaList = HTMLTools.extractTags(releaseInfoXML, "<a id=\"akas\" name=\"akas\">",
                    HTML_TABLE_END, "<td>", HTML_TD_END, Boolean.FALSE);
            akas = buildAkaMap(akaList);
        }

        String foundValue = null;
        // NOTE: First matching country is the preferred country
        for (String matchCountry : akaMatchingCountries) {

            if (StringUtils.isBlank(matchCountry)) {
                // must be a valid country setting
                continue;
            }

            for (Map.Entry<String, String> aka : akas.entrySet()) {
                int startIndex = aka.getKey().indexOf(matchCountry);
                if (startIndex > -1) {
                    String extracted = aka.getKey().substring(startIndex);
                    int endIndex = extracted.indexOf('/');
                    if (endIndex > -1) {
                        extracted = extracted.substring(0, endIndex);
                    }

                    boolean valid = Boolean.TRUE;
                    for (String ignore : akaIgnoreVersions) {
                        if (StringUtils.isNotBlank(ignore)
                                && StringUtils.containsIgnoreCase(extracted, ignore.trim())) {
                            valid = Boolean.FALSE;
                            break;
                        }
                    }

                    if (valid) {
                        foundValue = aka.getValue().trim();
                        break;
                    }
                }
            }

            if (foundValue != null) {
                // we found a title for the country matcher
                break;
            }
        }
        movie.setTitle(foundValue, IMDB_PLUGIN_ID);
    }

    // holds the full credits page
    String fullcreditsXML = UNKNOWN;

    // DIRECTOR(S)
    boolean overrideNormal = OverrideTools.checkOverwriteDirectors(movie, IMDB_PLUGIN_ID);
    boolean overridePeople = OverrideTools.checkOverwritePeopleDirectors(movie, IMDB_PLUGIN_ID);
    if (overrideNormal || overridePeople) {
        boolean found = Boolean.FALSE;

        // get from combined page (same layout as full credits)
        if (fullInfo) {
            found = extractDirectorsFromFullCredits(movie, xml, overrideNormal, overridePeople);
        }

        // get from full credits
        if (!found) {
            if (isNotValidString(fullcreditsXML)) {
                fullcreditsXML = getImdbData(getImdbUrl(movie, SUFFIX_FULLCREDITS));
            }
            extractDirectorsFromFullCredits(movie, fullcreditsXML, overrideNormal, overridePeople);
        }
    }

    // WRITER(S)
    overrideNormal = OverrideTools.checkOverwriteWriters(movie, IMDB_PLUGIN_ID);
    overridePeople = OverrideTools.checkOverwritePeopleWriters(movie, IMDB_PLUGIN_ID);
    if (overrideNormal || overridePeople) {
        boolean found = Boolean.FALSE;

        // get from combined page (same layout as full credits)
        if (fullInfo) {
            found = extractWritersFromFullCredits(movie, xml, overrideNormal, overridePeople);
        }

        // get from full credits
        if (!found) {
            if (isNotValidString(fullcreditsXML)) {
                fullcreditsXML = getImdbData(getImdbUrl(movie, SUFFIX_FULLCREDITS));
            }
            extractWritersFromFullCredits(movie, fullcreditsXML, overrideNormal, overridePeople);
        }
    }

    // CAST
    overrideNormal = OverrideTools.checkOverwriteActors(movie, IMDB_PLUGIN_ID);
    overridePeople = OverrideTools.checkOverwritePeopleActors(movie, IMDB_PLUGIN_ID);
    if (overrideNormal || overridePeople) {
        boolean found = Boolean.FALSE;

        // get from combined page (same layout as full credits)
        if (fullInfo) {
            found = extractCastFromFullCredits(movie, xml, overrideNormal, overridePeople);
        }

        // get from full credits
        if (!found) {
            if (isNotValidString(fullcreditsXML)) {
                fullcreditsXML = getImdbData(getImdbUrl(movie, SUFFIX_FULLCREDITS));
            }
            extractCastFromFullCredits(movie, fullcreditsXML, overrideNormal, overridePeople);
        }
    }
}

From source file:ec.edu.chyc.manejopersonal.managebean.GestorArticulo.java

public boolean filtrarPorAutorPrincipal(Object value, Object filter, Locale locale) {
    String filterText = (filter == null) ? null : filter.toString().trim();
    if (filterText == null || filterText.equals("")) {
        return true;
    }/*  ww w  . ja  v a  2  s .co  m*/
    if (value == null) {
        return false;
    }
    //como el autor principal es siempre el primer elemento, solo revisar el primer elemento
    Optional<PersonaArticulo> primerElem = ((Collection<PersonaArticulo>) value).stream().findFirst();
    //PersonaArticulo perArticuloPrincipal = ((Collection<PersonaArticulo>) value).stream().findFirst().get();
    if (primerElem.isPresent()) {
        Persona autorPrincipal = primerElem.get().getPersona();
        return (StringUtils.containsIgnoreCase(autorPrincipal.getNombres(), filterText)
                || StringUtils.containsIgnoreCase(autorPrincipal.getApellidos(), filterText));
    }
    return false;
}

From source file:com.globalsight.everest.webapp.pagehandler.administration.users.UserMainHandler.java

private boolean matchCondition(String uCompanyFilter, String pName) {
    return StringUtils.isNotEmpty(uCompanyFilter)
            && !StringUtils.containsIgnoreCase(pName, uCompanyFilter.trim());
}

From source file:com.snaplogic.snaps.uniteller.util.Utilities.java

/**
 * @param method//w w  w  .  j  a  v a2s.co m
 * @return SnapType
 */
public SnapType getDataTypes(Method method) {
    String type = method.getGenericParameterTypes()[0].toString();
    if (StringUtils.containsIgnoreCase(type, String.class.getName())) {
        return SnapType.STRING;
    } else if (StringUtils.contains(type, INT)) {
        return SnapType.INTEGER;
    } else if (StringUtils.containsIgnoreCase(type, Float.class.getSimpleName())
            || StringUtils.containsIgnoreCase(type, Long.class.getSimpleName())
            || StringUtils.containsIgnoreCase(type, Double.class.getSimpleName())) {
        return SnapType.NUMBER;
    } else if (StringUtils.containsIgnoreCase(type, Calendar.class.getName())) {
        return SnapType.DATETIME;
    }
    return SnapType.ANY;
}

From source file:com.glaf.oa.budget.web.springmvc.BudgetController.java

@RequestMapping("/review")
public ModelAndView review(HttpServletRequest request, ModelMap modelMap) {
    User user = RequestUtils.getUser(request);
    String actorId = user.getActorId();
    RequestUtils.setRequestParameterToAttribute(request);
    request.removeAttribute("canSubmit");

    Budget budget = budgetService.getBudget(RequestUtils.getLong(request, "budgetid"));
    if (budget != null) {
        request.setAttribute("budget", budget);
        JSONObject rowJSON = budget.toJsonObject();
        request.setAttribute("x_json", rowJSON.toJSONString());
        // ???//from   w w  w  .j a  v a 2 s  . c om
        String appusername = BaseDataManager.getInstance().getStringValue(budget.getAppuser(), "SYS_USERS");
        request.setAttribute("appusername", appusername);
        // ?
        // ?
        List<BaseDataInfo> brandlist = BaseDataManager.getInstance().getDataList("Brand");
        BaseDataInfo brand1 = null;
        BaseDataInfo brand2 = null;
        for (BaseDataInfo info : brandlist) {
            if ("1".equals(info.getValue())) {
                request.setAttribute("brand1", info.getName());
                brand1 = info;
            } else if ("2".equals(info.getValue())) {
                request.setAttribute("brand2", info.getName());
                brand2 = info;
            }
        }
        if (budget != null) {
            if ("".equals(budget.getBrands1().trim()) && "".equals(budget.getBrands2().trim())) {
                request.setAttribute("Brands", "MUL");
            } else if (!"".equals(budget.getBrands1().trim()) && "".equals(budget.getBrands2().trim())) {
                request.setAttribute("Brands", brand1.getCode());
            } else if (!"".equals(budget.getBrands2().trim()) && "".equals(budget.getBrands1().trim())) {
                request.setAttribute("Brands", brand2.getCode());
            } else if (!"".equals(budget.getBrands2().trim()) && !"".equals(budget.getBrands1().trim())) {
                request.setAttribute("Brands", "MUL");
            }
        }
    } else {
        // ? 
        long deptId01 = user.getDeptId();
        SysDepartment curdept = sysDepartmentService.findById(deptId01);
        // ?
        String curAreadeptCode = curdept.getCode().substring(0, 2);

        request.setAttribute("area", curAreadeptCode);
        budget = new Budget();
        budget.setArea(curAreadeptCode);
        budget.setStatus(-1);
        budget.setCreateBy(actorId);
        budget.setAppdate(new Date());
        budget.setCreateDate(new Date());
        budgetService.save(budget);
        request.setAttribute("budget", budget);
    }
    boolean canUpdate = false;
    String x_method = request.getParameter("x_method");
    if (StringUtils.equals(x_method, "submit")) {

    }

    if (StringUtils.containsIgnoreCase(x_method, "update")) {
        if (budget != null) {
            if (budget.getStatus() == 0 || budget.getStatus() == -1) {
                canUpdate = true;
            }
        }
    }

    request.setAttribute("canUpdate", canUpdate);

    String view = request.getParameter("view");
    if (StringUtils.isNotEmpty(view)) {
        return new ModelAndView(view, modelMap);
    }

    String x_view = ViewProperties.getString("budget.edit");
    if (StringUtils.isNotEmpty(x_view)) {
        return new ModelAndView(x_view, modelMap);
    }

    return new ModelAndView("/oa/budget/budgetReview", modelMap);
}

From source file:br.com.ararati.faces.nfe.NFeDigitacaoFaces.java

public List<NFeTipoOperacao> completeNFeTipoOperacao(String query) {
    return NFeTipoOperacao.valuesAsList().stream()
            .filter(v -> StringUtils.containsIgnoreCase(v.getDescricao(), query)).collect(Collectors.toList());
}

From source file:br.com.ararati.faces.nfe.NFeDigitacaoFaces.java

public List<NFeTipoOperacaoConsumidor> completeNFeTipoOperacaoConsumidor(String query) {
    return NFeTipoOperacaoConsumidor.valuesAsList().stream()
            .filter(v -> StringUtils.containsIgnoreCase(v.getDescricao(), query)).collect(Collectors.toList());
}