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

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

Introduction

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

Prototype

public static int indexOfIgnoreCase(final CharSequence str, final CharSequence searchStr) 

Source Link

Document

Case in-sensitive find of the first index within a CharSequence.

A null CharSequence will return -1 .

Usage

From source file:org.lazydog.jdnsaas.utility.RecordFilter.java

/**
 * Does the value match the search string?
 * /*from   w w w .j av a  2s.  co m*/
 * @param  value  the value.
 * 
 * @return  true if the value matches, otherwise false.
 */
private boolean matchString(final String value) {
    boolean match = true;
    String[] searchTokens = StringUtils.split(this.searchString, SEARCH_STRING_WILDCARD);
    String stringValue = value;
    for (String searchToken : searchTokens) {
        if (StringUtils.indexOfIgnoreCase(stringValue, searchToken) != -1) {
            stringValue = StringUtils.substringAfter(stringValue, searchToken);
        } else {
            match = false;
            break;
        }
    }
    return match;
}

From source file:org.n52.ses.filter.epl.EPLFilterImpl.java

public EPLFilterImpl(XmlObject obj) throws SubscribeCreationFailedFault {
    if (obj instanceof EPLFiltersDocument) {
        this.filterXml = (EPLFiltersDocument) obj;
        EPLFilter[] filters = ((EPLFiltersDocument) obj).getEPLFilters().getEPLFilterArray();

        for (EPLFilter epl : filters) {
            String stmt = StringEscapeUtils.unescapeXml(epl.getStatement().getStringValue()).trim();
            int fromIndex = StringUtils.indexOfIgnoreCase(stmt, " from ");
            String subFrom = stmt.substring(fromIndex).trim();
            subFrom = subFrom.substring(subFrom.indexOf(" "), subFrom.length()).trim();

            fromIndex = subFrom.indexOf(" ");
            if (fromIndex > 0) {
                subFrom = subFrom.substring(0, fromIndex).trim();
            }//from  ww w.  j ava  2s . c o  m

            String streamName;
            if (subFrom.contains(".") || subFrom.contains(":")) {
                int i = Math.min(subFrom.indexOf("."), subFrom.indexOf(":"));
                streamName = subFrom.substring(0, i);
            } else {
                streamName = subFrom;
            }

            String statement = StringEscapeUtils.unescapeXml(epl.getStatement().getStringValue()).trim();

            String newEventName = null;
            if (epl.isSetNewEventName()) {
                newEventName = epl.getNewEventName();
            }

            boolean doOutput = false;
            if (epl.getStatement().isSetDoOutput()) {
                doOutput = epl.getStatement().getDoOutput();
            }

            boolean external = epl.getStatement().getExternalInput();
            if (external) {
                if (this.externalInputName != null && !this.externalInputName.equals(streamName)) {
                    throw new SubscribeCreationFailedFault(
                            "Multiple externalInputs set for one EPLFilter subscription");
                } else {
                    this.externalInputName = streamName;
                }
            }

            this.eplFilters.put(new EPLFilterInstance(statement, newEventName, doOutput, external), streamName);
        }
    } else {
        throw new SubscribeCreationFailedFault("Could not parse EPLFilter markup.");
    }
}

From source file:org.openbase.bco.ontology.lib.utility.StringModifier.java

/**
 * Method extracts the service type name of the input state method name (e.g. getPowerState to powerStateService).
 *
 * @param stateMethodName is the state method name, which includes the needed service type name.
 * @return the service type name in camel case (first char lower case, e.g. powerStateService)
 * @throws NotAvailableException is thrown in case the input is null or no valid state (name).
 *///from  w  ww  .  j  a v  a  2  s. c om
static String getServiceTypeNameFromStateMethodName(final String stateMethodName) throws NotAvailableException {
    Preconditions.checkNotNull(stateMethodName, "Couldn't get service type name, cause input string is null.");
    String serviceTypeName = stateMethodName;

    if (StringUtils.containsIgnoreCase(serviceTypeName, MethodRegEx.GET.getName())) {
        final int indexOfGet = StringUtils.indexOfIgnoreCase(serviceTypeName, MethodRegEx.GET.getName());
        final int lengthOfGet = MethodRegEx.GET.getName().length();

        serviceTypeName = serviceTypeName.substring(indexOfGet + lengthOfGet);
        serviceTypeName = firstCharToLowerCase(serviceTypeName);

        if (StringUtils.contains(serviceTypeName, MethodRegEx.STATE.getName())) {
            final int indexOfState = serviceTypeName.indexOf(MethodRegEx.STATE.getName());
            final int lengthOfState = MethodRegEx.STATE.getName().length();

            serviceTypeName = serviceTypeName.substring(0, indexOfState + lengthOfState);
            serviceTypeName += MethodRegEx.SERVICE.getName();
        }
    }

    if (OntConfig.SERVICE_NAME_MAP.keySet().contains(serviceTypeName)) {
        return serviceTypeName;
    } else {
        throw new NotAvailableException("Input string is no state (method) name! " + serviceTypeName);
    }
}

From source file:org.pesc.cds.web.TranscriptRequestController.java

private PhoneType createPhone(String phoneNumber) {
    org.pesc.sdk.sector.academicrecord.v1_9.ObjectFactory academicRecordObjectFactory = new org.pesc.sdk.sector.academicrecord.v1_9.ObjectFactory();
    PhoneType phone = academicRecordObjectFactory.createPhoneType();//Provided by Source Institution - optional
    if (StringUtils.isNotBlank(phoneNumber)) {
        int extensionIndex = StringUtils.indexOfIgnoreCase(phoneNumber, "x");//has extension?
        if (extensionIndex != -1) {
            if ((phoneNumber.length() - 1) > extensionIndex) {
                String extension = phoneNumber.substring(extensionIndex + 1);
                phone.setPhoneNumberExtension(extension);
            }/*  w w w.  j  ava 2  s . c  o  m*/
            phoneNumber = phoneNumber.substring(0, extensionIndex - 1);
        }
        phoneNumber = phoneNumber.replaceAll("\\D", "");
        if (phoneNumber.length() > 7) {
            String basePhoneNumber = phoneNumber.substring(phoneNumber.length() - 7);
            phone.setPhoneNumber(basePhoneNumber);
            String areaCode = phoneNumber.length() > 10
                    ? phoneNumber.substring(phoneNumber.length() - 10, phoneNumber.length() - 7)
                    : phoneNumber.substring(0, phoneNumber.length() - 7);
            phone.setAreaCityCode(areaCode);
            if (phoneNumber.length() > 10) {
                String countryCode = phoneNumber.substring(0, phoneNumber.length() - 10);
                phone.setCountryPrefixCode(countryCode);
            }
        }
    }
    return phone;
}

From source file:org.xwiki.query.internal.TextQueryFilter.java

private List<String> getFilterableColumns(String statement) {
    List<String> columns = new ArrayList<>();
    String selectClause = statement
            .substring("select ".length(), StringUtils.indexOfIgnoreCase(statement, " from ")).trim();
    selectClause = StringUtils.removeStartIgnoreCase(selectClause, "distinct ");
    for (String column : COLUMN_SEPARATOR.split(selectClause)) {
        // Remove the column alias.
        String columnWithoutAlias = column;
        int aliasPosition = column.lastIndexOf(" as ");
        if (aliasPosition > 0) {
            columnWithoutAlias = column.substring(0, aliasPosition).trim();
            String alias = column.substring(aliasPosition + 4).trim();
            if (alias.startsWith("unfilterable")) {
                continue;
            }/*from  ww w.  ja v a  2  s.  c om*/
        }
        columns.add(columnWithoutAlias);
    }
    return columns;
}

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

@Override
public boolean scanNFO(String nfoContent, InfoDTO dto, boolean ignorePresentId) {
    // if we already have the ID, skip the scanning of the NFO file
    if (!ignorePresentId && StringUtils.isNotBlank(dto.getId(SCANNER_ID))) {
        return Boolean.TRUE;
    }//from w  w  w .j a va  2 s . co m

    // scan for IMDb ID
    ImdbScanner.scanImdbID(nfoContent, dto, ignorePresentId);

    LOG.trace("Scanning NFO for Allocine ID");

    // http://www.allocine.fr/...=XXXXX.html
    try {
        int beginIndex = StringUtils.indexOfIgnoreCase(nfoContent, "http://www.allocine.fr/");
        if (beginIndex != -1) {
            int beginIdIndex = nfoContent.indexOf('=', beginIndex);
            if (beginIdIndex != -1) {
                int endIdIndex = nfoContent.indexOf('.', beginIdIndex);
                if (endIdIndex != -1) {
                    String sourceId = nfoContent.substring(beginIdIndex + 1, endIdIndex);
                    LOG.debug("Allocine ID found in NFO: {}", sourceId);
                    dto.addId(SCANNER_ID, sourceId);
                    return Boolean.TRUE;
                }
            }
        }
    } catch (Exception ex) {
        LOG.trace("NFO scanning error", ex);
    }

    LOG.debug("No Allocine ID found in NFO");
    return Boolean.FALSE;
}

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  ww  w .  j  a  v  a  2  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.yamj.core.service.metadata.online.TheMovieDbScanner.java

/**
 * Remove unneeded text from the biography
 *
 * @param bio/*from w  ww.  jav  a2s .c o m*/
 * @return
 */
private static String cleanBiography(final String bio) {
    String newBio = StringUtils.trimToNull(bio);
    if (newBio == null) {
        return null;
    }

    newBio = newBio.replaceAll("\\s+", " ");

    int pos = StringUtils.indexOfIgnoreCase(newBio, FROM_WIKIPEDIA);
    if (pos >= 0) {
        // We've found the text, so remove it
        LOG.trace("Removing start wikipedia text from bio");
        newBio = newBio.substring(pos + FROM_WIKIPEDIA.length() + 1);
    }

    pos = StringUtils.indexOfIgnoreCase(newBio, WIKIPEDIA_DESCRIPTION_ABOVE);
    if (pos >= 0) {
        LOG.trace("Removing end wikipedia text from bio");
        newBio = newBio.substring(0, pos);
    }

    return newBio.trim();
}

From source file:org.yamj.core.service.plugin.TheMovieDbScanner.java

/**
 * Remove unneeded text from the biography
 *
 * @param bio//w w  w .j  a va2 s .  co  m
 * @return
 */
private String cleanBiography(final String bio) {
    String newBio = StringUtils.trimToNull(bio);
    if (newBio == null) {
        return null;
    }

    newBio = newBio.replaceAll("\\s+", " ");

    int pos = StringUtils.indexOfIgnoreCase(newBio, FROM_WIKIPEDIA);
    if (pos >= 0) {
        // We've found the text, so remove it
        LOG.trace("Removing start wikipedia text from bio");
        newBio = newBio.substring(pos + FROM_WIKIPEDIA.length() + 1);
    }

    pos = StringUtils.indexOfIgnoreCase(newBio, WIKIPEDIA_DESCRIPTION_ABOVE);
    if (pos >= 0) {
        LOG.trace("Removing end wikipedia text from bio");
        newBio = newBio.substring(0, pos);
    }

    return newBio.trim();
}

From source file:org.yamj.core.tools.MetadataTools.java

/**
 * Remove alternate name from role/*from www. j ava  2s.com*/
 *
 * @param role
 * @return
 */
public static String fixActorRole(final String role) {
    if (role == null) {
        return null;
    }
    String fixed = role;

    // (as = alternate name)
    int idx = StringUtils.indexOfIgnoreCase(fixed, "(as ");
    if (idx > 0) {
        fixed = fixed.substring(0, idx);
    }

    // double characters
    idx = StringUtils.indexOf(fixed, "/");
    if (idx > 0) {
        List<String> characters = StringTools.splitList(fixed, "/");
        fixed = StringUtils.join(characters.toArray(), " / ");
    }

    return fixed;
}