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:org.yamj.core.service.metadata.nfo.InfoReader.java

/**
 * Parse Certification from the XML NFO file
 *
 * @param eCommon/*w  ww  .java 2s  . co m*/
 * @param movie
 */
private void parseCertification(Element eCommon, InfoDTO dto) {
    boolean certificationMPAA = this.configServiceWrapper.getBooleanProperty("yamj3.certification.mpaa", false);
    String tempCert;

    if (certificationMPAA) {
        tempCert = DOMHelper.getValueFromElement(eCommon, "mpaa");
        if (StringUtils.isNotBlank(tempCert)) {
            String mpaa = MetadataTools.processMpaaCertification(tempCert);
            dto.addCertificatioInfo("MPAA", StringUtils.trimToNull(mpaa));
        }
    }

    tempCert = DOMHelper.getValueFromElement(eCommon, "certification");
    if (StringUtils.isNotBlank(tempCert)) {
        // scan for given countries
        List<String> countries = this.configServiceWrapper.getCertificationCountries();
        for (String country : countries) {
            int countryPos = StringUtils.lastIndexOfIgnoreCase(tempCert, country);
            if (countryPos >= 0) {
                // We've found the country, so extract just that tag
                String certification = tempCert.substring(countryPos);
                int pos = certification.indexOf(':');
                if (pos > 0) {
                    int endPos = certification.indexOf("/");
                    if (endPos > 0) {
                        // this is in the middle of the string
                        certification = certification.substring(pos + 1, endPos);
                    } else {
                        // this is at the end of the string
                        certification = certification.substring(pos + 1);
                    }
                }
                dto.addCertificatioInfo(country, StringUtils.trimToNull(certification));
            }

            if (certificationMPAA && StringUtils.containsIgnoreCase(tempCert, "Rated")) {
                // extract the MPAA rating from the certification
                String mpaa = MetadataTools.processMpaaCertification(tempCert);
                dto.addCertificatioInfo("MPAA", StringUtils.trimToNull(mpaa));
            }
        }
    }
}

From source file:org.yamj.core.service.metadata.online.ImdbScanner.java

private void parseReleaseData(AbstractMetadata metadata, String imdbId) {

    String releaseInfoXML = null;

    // RELEASE DATE
    if (metadata instanceof VideoData) {
        VideoData videoData = (VideoData) metadata;
        if (OverrideTools.checkOverwriteReleaseDate(videoData, SCANNER_ID)) {
            // load the release page from IMDb
            releaseInfoXML = getReleasInfoXML(releaseInfoXML, imdbId);
            if (releaseInfoXML != null) {
                String preferredCountry = this.configServiceWrapper.getProperty("imdb.aka.preferred.country",
                        "USA");
                Pattern pRelease = Pattern.compile("(?:.*?)\\Q" + preferredCountry
                        + "\\E(?:.*?)\\Qrelease_date\">\\E(.*?)(?:<.*?>)(.*?)(?:</a>.*)");
                Matcher mRelease = pRelease.matcher(releaseInfoXML);

                if (mRelease.find()) {
                    String strReleaseDate = mRelease.group(1) + " " + mRelease.group(2);
                    Date releaseDate = MetadataTools.parseToDate(strReleaseDate);
                    videoData.setReleaseDate(releaseDate, SCANNER_ID);
                }//from  w w w  .ja  v  a2  s .co m
            }
        }
    }

    // ORIGINAL TITLE / AKAS
    // Store the AKA list
    Map<String, String> akas = null;

    if (OverrideTools.checkOverwriteOriginalTitle(metadata, SCANNER_ID)) {
        // load the release page from IMDb
        releaseInfoXML = getReleasInfoXML(releaseInfoXML, imdbId);
        if (releaseInfoXML != null) {
            // get the AKAs from release info XML
            akas = getAkaMap(akas, releaseInfoXML);

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

            metadata.setTitleOriginal(foundValue, SCANNER_ID);
        }
    }

    // TITLE for preferred country from AKAS
    boolean akaScrapeTitle = configServiceWrapper.getBooleanProperty("imdb.aka.scrape.title", Boolean.FALSE);
    if (akaScrapeTitle && OverrideTools.checkOverwriteTitle(metadata, SCANNER_ID)) {
        List<String> akaIgnoreVersions = configServiceWrapper.getPropertyAsList("imdb.aka.ignore.versions", "");
        String preferredCountry = this.configServiceWrapper.getProperty("imdb.aka.preferred.country", "USA");
        String fallbacks = configServiceWrapper.getProperty("imdb.aka.fallback.countries", "");

        List<String> akaMatchingCountries;
        if (StringUtils.isBlank(fallbacks)) {
            akaMatchingCountries = Collections.singletonList(preferredCountry);
        } else {
            akaMatchingCountries = Arrays.asList((preferredCountry + "," + fallbacks).split(","));
        }

        // load the release page from IMDb
        releaseInfoXML = getReleasInfoXML(releaseInfoXML, imdbId);
        if (releaseInfoXML != null) {
            // get the AKAs from release info XML
            akas = getAkaMap(akas, releaseInfoXML);

            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;
                }
            }

            metadata.setTitle(foundValue, SCANNER_ID);
        }
    }
}

From source file:org.zanata.ui.FilterUtil.java

/**
 * Return true if//  www  .j  a  va 2 s .  c  o  m
 *
 * 1) Query is empty 2) hLocale is NOT in localeList and hLocale's display
 * name/localeId matches with query.
 *
 *
 *
 * @param localeList
 * @param hLocale
 * @param query
 * @return
 */
public static boolean isIncludeLocale(Collection<HLocale> localeList, HLocale hLocale, String query) {
    return !localeList.contains(hLocale)
            && (StringUtils.startsWithIgnoreCase(hLocale.getLocaleId().getId(), query)
                    || StringUtils.containsIgnoreCase(hLocale.retrieveDisplayName(), query));
}

From source file:password.pwm.util.PwmPasswordRuleValidator.java

static boolean containsDisallowedValue(final String password, final String disallowedValue,
        final int threshold) {
    if (StringUtils.isNotBlank(disallowedValue)) {
        if (threshold > 0) {
            if (disallowedValue.length() >= threshold) {
                final String[] disallowedValueChunks = StringUtil.createStringChunks(disallowedValue,
                        threshold);// w  ww  .  j a  v  a2  s .  c  om
                for (final String chunk : disallowedValueChunks) {
                    if (StringUtils.containsIgnoreCase(password, chunk)) {
                        return true;
                    }
                }
            }
        } else {
            // No threshold?  Then the password can't contain the whole disallowed value
            return StringUtils.containsIgnoreCase(password, disallowedValue);
        }
    }

    return false;
}

From source file:pcgen.gui2.filter.SearchFilterPanel.java

@Override
public boolean accept(Object context, Object element) {
    String typeStr = ""; //$NON-NLS-1$
    String abbStr = ""; //$NON-NLS-1$
    if (element instanceof InfoFacade) {
        typeStr = ((InfoFacade) element).getType();
    } else if (element instanceof CampaignFacade) {
        typeStr = ((CampaignFacade) element).getBookTypes();
        abbStr = ((CampaignFacade) element).getSourceShort();
    }/*  w ww.j  a v a  2s. c  o m*/
    final String searchText = searchField.getText();
    return StringUtils.containsIgnoreCase(element.toString(), searchText)
            || StringUtils.containsIgnoreCase(typeStr, searchText)
            || StringUtils.containsIgnoreCase(abbStr, searchText);
}

From source file:se.trixon.mapollage.FileVisitor.java

@Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) {
    if (mExcludePatterns != null) {
        for (String excludePattern : mExcludePatterns) {
            if (IOCase.SYSTEM.isCaseSensitive()) {
                if (StringUtils.contains(dir.toString(), excludePattern)) {
                    return FileVisitResult.SKIP_SUBTREE;
                }/*from w w  w .j av  a  2s  . co m*/
            } else {
                if (StringUtils.containsIgnoreCase(dir.toString(), excludePattern)) {
                    return FileVisitResult.SKIP_SUBTREE;
                }
            }
        }
    }

    String[] filePaths = dir.toFile().list();

    mOperationListener.onOperationLog(dir.toString());
    mOperationListener.onOperationProgress(dir.toString());

    if (filePaths != null && filePaths.length > 0) {
        if (mUseExternalDescription) {
            Properties p = new Properties(mDefaultDescProperties);

            try {
                File file = new File(dir.toFile(), mExternalFileValue);
                if (file.isFile()) {
                    p.load(new InputStreamReader(new FileInputStream(file), Charset.defaultCharset()));
                }
            } catch (IOException ex) {
                // nvm
            }

            mDirToDesc.put(dir.toFile().getAbsolutePath(), p);
        }

        for (String fileName : filePaths) {
            try {
                TimeUnit.NANOSECONDS.sleep(1);
            } catch (InterruptedException ex) {
                mInterrupted = true;
                return FileVisitResult.TERMINATE;
            }
            File file = new File(dir.toFile(), fileName);
            if (file.isFile() && mPathMatcher.matches(file.toPath().getFileName())) {
                boolean exclude = false;
                if (mExcludePatterns != null) {
                    for (String excludePattern : mExcludePatterns) {
                        if (StringUtils.contains(file.getAbsolutePath(), excludePattern)) {
                            exclude = true;
                            break;
                        }
                    }
                }

                if (!exclude) {
                    mFiles.add(file);
                }
            }
        }
    }

    return FileVisitResult.CONTINUE;
}

From source file:se.trixon.mapollage.Operation.java

private String getPlacemarkDescription(File file, PhotoInfo photoInfo, Date exifDate) throws IOException {
    GpsDirectory gpsDirectory = photoInfo.getGpsDirectory();
    GpsDescriptor gpsDescriptor = null;//from  w  w  w .j a  v  a 2  s  .c om
    if (gpsDirectory != null) {
        gpsDescriptor = new GpsDescriptor(gpsDirectory);
    }

    String desc = "";
    switch (mProfileDescription.getMode()) {
    case CUSTOM:
        desc = mProfileDescription.getCustomValue();
        break;

    case EXTERNAL:
        desc = getExternalDescription(file);
        break;

    case NONE:
        //Do nothing
        break;

    case STATIC:
        desc = getStaticDescription();
        break;
    }

    if (mProfileDescription.getMode() != ProfileDescription.DescriptionMode.NONE) {
        if (StringUtils.containsIgnoreCase(desc, DescriptionSegment.PHOTO.toString())) {
            desc = StringUtils.replace(desc, DescriptionSegment.PHOTO.toString(),
                    getDescPhoto(file, photoInfo.getOrientation()));
        }

        desc = StringUtils.replace(desc, DescriptionSegment.FILENAME.toString(), file.getName());
        desc = StringUtils.replace(desc, DescriptionSegment.DATE.toString(), mDateFormatDate.format(exifDate));

        if (gpsDirectory != null && gpsDescriptor != null) {
            desc = StringUtils.replace(desc, DescriptionSegment.ALTITUDE.toString(),
                    gpsDescriptor.getGpsAltitudeDescription());
            desc = StringUtils.replace(desc, DescriptionSegment.COORDINATE.toString(),
                    gpsDescriptor.getDegreesMinutesSecondsDescription());

            String bearing = gpsDescriptor.getGpsDirectionDescription(GpsDirectory.TAG_DEST_BEARING);
            desc = StringUtils.replace(desc, DescriptionSegment.BEARING.toString(),
                    bearing == null ? "" : bearing);
        } else {
            desc = StringUtils.replace(desc, DescriptionSegment.ALTITUDE.toString(), "");
            desc = StringUtils.replace(desc, DescriptionSegment.COORDINATE.toString(), "");
            desc = StringUtils.replace(desc, DescriptionSegment.BEARING.toString(), "");
        }

        desc = getSafeXmlString(desc);
    }

    return desc;
}

From source file:se.trixon.mapollage.profile.ProfileDescription.java

public boolean hasPhotoStaticOrDynamic() {
    boolean hasPhoto = (mMode == DescriptionMode.CUSTOM
            && StringUtils.containsIgnoreCase(mCustomValue, "+photo"))
            || (mMode != DescriptionMode.STATIC && hasPhoto()) || mMode == DescriptionMode.EXTERNAL;

    return hasPhoto;
}

From source file:se.trixon.mapollage.ui.config.ModuleDescriptionPanel.java

private void notifyPhotoDescriptionListener() {
    boolean hasPhoto = (photoCheckBox.isSelected() && photoCheckBox.isEnabled())
            || (customRadioButton.isSelected()
                    && StringUtils.containsIgnoreCase(customTextArea.getText(), "+photo"))
            || mMode == DescriptionMode.EXTERNAL;

    if (mProfile != null) {
        try {/* w ww .j  a va 2  s.c om*/
            mPhotoDescriptionMonitor.onPhotoDescriptionChange(hasPhoto);
        } catch (NullPointerException e) {
            // nvm
        }
    }
}

From source file:server.NameGame.java

private String singleGuess(String guess) {
    //Single char guess            
    if (StringUtils.containsIgnoreCase(secretWord, guess)) {
        guessWord = addGuessChar(guess);
        if (StringUtils.equalsIgnoreCase(guessWord, secretWord))
            return wordGuess(guessWord);
        else/*from   w  w  w  .java 2 s  .  co  m*/
            return "Correct! " + guessWord + " Tries: " + attemptCounter + " - Total Score " + score;
    } else {
        attemptCounter -= 1;
        if (attemptCounter == 0) {
            return "Game Over - The word was: " + secretWord + " - Total Score " + score;
        } else {
            return "Wrong! " + guessWord + " Tries: " + attemptCounter + " - Total Score " + score;
        }
    }
}