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

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

Introduction

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

Prototype

public static boolean startsWithIgnoreCase(final CharSequence str, final CharSequence prefix) 

Source Link

Document

Case insensitive check if a CharSequence starts with a specified prefix.

null s are handled without exceptions.

Usage

From source file:org.thelq.pircbotx.commands.api.CommandCall.java

protected static List<String> trySplitCommandNoPrefix(String input, String prefix) {
    if (StringUtils.startsWithIgnoreCase(input, prefix))
        return splitCommandQuotable(input.substring(prefix.length()));
    return null;//from   w w w  . j a  v  a  2 s . c  o m
}

From source file:org.thelq.pircbotx.commands.HelpCommand.java

@Override
public void onMessage(MessageEvent event) throws Exception {
    String message = event.getMessage();
    if (!ListenerUtils.isCommand(message, "help"))
        return;//from   ww w  .j  a v a2s.c o  m

    ListenerUtils.incrimentCommands(event);
    String[] messageParts = message.split(" ");
    if (messageParts.length > 2)
        event.respond("Too many arguments");
    else if (messageParts.length == 2) {
        //User gave us a command, find it and show the help
        for (Listener curListener : event.getBot().getConfiguration().getListenerManager().getListeners()) {
            if (!(curListener instanceof BasicCommand))
                continue;

            BasicCommand command = (BasicCommand) curListener;
            if (StringUtils.startsWithIgnoreCase(getCommandName(command), messageParts[1])) {
                //Found it!
                event.respond(getCommandName(command) + " help: " + command.getHelp());
                return;
            }
        }
        //If we get here then nothing was found
        event.respond("Command " + messageParts[1] + " doesn't exist");
    } else {
        //Build a list of names of all the available commands
        List<String> commands = Lists.newArrayList();
        for (Listener curListener : event.getBot().getConfiguration().getListenerManager().getListeners())
            if (curListener instanceof BasicCommand)
                commands.add(getCommandName((BasicCommand) curListener));

        //Compile and send
        event.respond("Available commands: " + StringUtils.join(commands, ", "));
    }
}

From source file:org.thelq.pircbotx.commands.NewYearsCommand.java

protected static String getExtendedNames(Collection<DateTimeZone> tzList) {
    if (tzList.isEmpty())
        return null;
    //Prebuild long form of timezones
    long nowTime = System.currentTimeMillis();
    Set<String> tzExtendedSet = Sets.newHashSet();
    for (DateTimeZone curTz : tzList) {
        if (StringUtils.startsWithIgnoreCase(curTz.getID(), "Etc/"))
            continue;
        tzExtendedSet.add(curTz.getName(nowTime) + "(" + curTz.getShortName(nowTime) + ")");
    }/*from w ww . j av a  2 s  .c o m*/
    return StringUtils.defaultIfBlank(StringUtils.join(tzExtendedSet, ", "), null);
}

From source file:org.thelq.pircbotx.commands.NewYearsCommand.java

protected static String getShortNames(Collection<DateTimeZone> tzList) {
    //Prebuild long form of timezones
    long nowTime = System.currentTimeMillis();
    Set<String> tzShortSet = Sets.newHashSet();
    for (DateTimeZone curTz : tzList) {
        if (StringUtils.startsWithIgnoreCase(curTz.getID(), "Etc/"))
            continue;
        tzShortSet.add(curTz.getShortName(nowTime));
    }/*from  ww w  .  j a v a2 s  .c om*/
    return StringUtils.defaultIfBlank(StringUtils.join(tzShortSet, ", "), null);
}

From source file:org.thorn.emma.model.HttpResponse.java

public Set<String> getNewCookie() {
    List<String> setCookie = headers.get("Set-Cookie");

    Set<String> newCookie = new HashSet<String>();

    if (setCookie != null) {

        for (String cookie : setCookie) {

            String[] array = StringUtils.split(cookie, ";");

            for (String str : array) {
                str = str.trim();//from  w w  w . j  av a2s  .c  om

                if (StringUtils.startsWithIgnoreCase(str, "path")
                        || StringUtils.startsWithIgnoreCase(str, "domain")) {
                    continue;
                }

                newCookie.add(str);
            }
        }
    }

    return newCookie;
}

From source file:org.wrml.werminal.component.HistoryCheckListBox.java

private boolean itemLastSegementStartsWith(int itemIndex, CharSequence charSequence) {

    final Object historyItem = getItemAt(itemIndex);

    if (!(historyItem instanceof URI)) {
        return false;
    }/*w w w  . j  a va 2s  .c o  m*/

    final URI uri = (URI) historyItem;
    final String lastPathElement = RestUtils.getLastPathElement(uri);
    return StringUtils.startsWithIgnoreCase(lastPathElement, charSequence);
}

From source file:org.wso2.analytics.esb.siddhi.extension.CompressedEventProcessor.java

/**
 * Get the definition of the output fields
 * //from  www.j a  v  a2  s. co m
 * @return  Name and type of decompressed fields
 */
private static Map<String, String> getOutputFields() {
    Map<String, String> fields = new LinkedHashMap<String, String>();
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    try {
        String[] lines = IOUtils.toString(classLoader.getResourceAsStream("decompressedEventDefinition"))
                .split("\n");
        for (String line : lines) {
            if (!StringUtils.startsWithIgnoreCase(line, "#") && StringUtils.isNotEmpty(line)) {
                String[] fieldDef = StringUtils.deleteWhitespace(line).split(":");
                if (fieldDef.length == 2) {
                    fields.put(fieldDef[0], fieldDef[1]);
                }
            }
        }
    } catch (IOException e) {
        new ExecutionPlanCreationException(
                "Error occured while reading decompressed event definitions: " + e.getMessage(), e);
    }
    return fields;
}

From source file:org.xlrnet.metadict.engines.heinzelnisse.HeinzelnisseEngine.java

/**
 * Extracts information from the "other"-fields of the response. This field may contain information about plural
 * forms or irregular verb forms.//from  ww  w  .j av  a  2 s. co m
 * <p>
 * Examples:
 * <ul>
 * <li>Plural: Mtter</li>
 * <li>fl.: mdre</li>
 * <li>syn.: tschs</li>
 * <li>Dialekt (sddeutsch/sterreichisch)</li>
 * <li>presens: kommer, preteritum: kom, partisipp perfekt: kommet</li>
 * <li>bestemt form: lille, intetkjnn: lite, flertall: sm</li>
 * <li>komparativ: frre, superlativ: frrest</li>
 * <li>Komparativ: weniger, Superlativ: am wenigsten</li>
 * </ul>
 *
 * @param otherInformation
 *         The source string
 * @param builder
 *         The target builder to write into.
 */
protected void extractOtherInformation(@NotNull String otherInformation,
        @NotNull DictionaryObjectBuilder builder) {
    // Try to extract plural forms
    if (StringUtils.startsWith(otherInformation, "Plural:")
            || StringUtils.startsWith(otherInformation, "fl.:")) {
        String pluralForm = StringUtils.substringAfter(otherInformation, ":");
        builder.setAdditionalForm(GrammaticalNumber.PLURAL, StringUtils.strip(pluralForm));
    }
    // Try to extract verb forms
    else if (StringUtils.startsWith(otherInformation, "presens")) {
        extractVerbForms(otherInformation, builder);
    }
    // Try to extract adjective comparisons
    else if (StringUtils.startsWithIgnoreCase(otherInformation, "komparativ")) {
        extractComparisonForms(otherInformation, builder);
    }
    // Try to extract adjective forms
    else if (StringUtils.startsWithIgnoreCase(otherInformation, "bestemt form")) {
        extractAdjectiveForms(otherInformation, builder);
    }
    // Write to description string otherwise...
    else if (StringUtils.isNotEmpty(otherInformation)) {
        builder.setDescription(StringUtils.strip(otherInformation));
    }
}

From source file:org.xlrnet.metadict.engines.nobordbok.OrdbokEngine.java

/**
 * Try to resolve the {@link EntryType} with a given "word class" string from the bokmaalordboka.
 * <p>// w ww  . ja v a  2s  . c om
 * Supported entries: <ul> <li>mX -> male noun (X is any int)</li> <li>fX -> female noun (X is any int</li> <li>nX
 * -> neuter noun (X is any int)</li> <li>adv. -> adverb</li>> <li>adj. -> adjective</li> <li>aX -> adjective (X is
 * any int)</li> <li>prep. -> preposition</li> <li>konj. -> conjuction</li> <li>vX -> verb (X is any int)</li>
 * <li>verb -> verb</li> </ul>
 *
 * @param wordClass
 *         The word class.
 * @return a valid metadict entry type.
 */
@NotNull
private EntryType resolveEntryTypeWithWordClass(@NotNull String wordClass) {
    EntryType entryType = EntryType.UNKNOWN;

    if (ENTRY_TYPE_MAP.containsKey(wordClass))
        entryType = ENTRY_TYPE_MAP.get(wordClass);
    else if (StringUtils.startsWithIgnoreCase(wordClass, "a"))
        entryType = EntryType.ADJECTIVE;
    else if (StringUtils.startsWithIgnoreCase(wordClass, "m"))
        entryType = EntryType.NOUN;
    else if (StringUtils.startsWithIgnoreCase(wordClass, "f"))
        entryType = EntryType.NOUN;
    else if (StringUtils.startsWithIgnoreCase(wordClass, "n"))
        entryType = EntryType.NOUN;
    else if (StringUtils.startsWithIgnoreCase(wordClass, "v"))
        entryType = EntryType.VERB;

    return entryType;
}

From source file:org.xwiki.rest.internal.resources.search.AbstractDatabaseSearchSource.java

@Override
public List<SearchResult> search(String partialQueryString, String wikiName, String wikis,
        boolean hasProgrammingRights, String orderField, String order, boolean distinct, int number, int start,
        Boolean withPrettyNames, String className, UriInfo uriInfo) throws Exception {
    XWikiContext xwikiContext = this.xcontextProvider.get();
    XWiki xwikiApi = new XWiki(xwikiContext.getWiki(), xwikiContext);

    if (partialQueryString == null || StringUtils.startsWithIgnoreCase(partialQueryString, "select")) {
        return Collections.emptyList();
    }/*  w ww  .j a  v a  2s  .  c o  m*/

    String queryString = resolveQuery(distinct, partialQueryString);

    Query query = this.queryManager.createQuery(queryString, this.queryLanguage);

    query.setLimit(number).setOffset(start);
    query.setWiki(wikiName);

    List<Object> queryResult = query.execute();

    WikiReference wikiReference = new WikiReference(wikiName);

    /* Build the result. */
    List<SearchResult> result = new ArrayList<>();
    for (Object object : queryResult) {
        Object[] fields = (Object[]) object;

        String fullName = (String) fields[0];
        String language = (String) fields[3];

        DocumentReference documentReference = this.resolver.resolve(fullName, wikiReference);

        /* Check if the user has the right to see the found document */
        if (this.authorization.hasAccess(Right.VIEW, documentReference)) {
            Document doc = xwikiApi.getDocument(documentReference);
            String title = doc.getDisplayTitle();

            SearchResult searchResult = this.objectFactory.createSearchResult();
            searchResult.setType("page");
            searchResult.setId(doc.getPrefixedFullName());
            searchResult.setPageFullName(doc.getFullName());
            searchResult.setTitle(title);
            searchResult.setWiki(wikiName);
            searchResult.setSpace(doc.getSpace());
            searchResult.setPageName(doc.getName());
            searchResult.setVersion(doc.getVersion());
            searchResult.setAuthor(doc.getAuthor());
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(doc.getDate());
            searchResult.setModified(calendar);

            if (withPrettyNames) {
                searchResult.setAuthorName(xwikiApi.getUserName(doc.getAuthor(), false));
            }

            /*
             * Avoid to return object information if the user is not authenticated. This will prevent crawlers to
             * retrieve information such as email addresses and passwords from user's profiles.
             */
            if (StringUtils.isNotEmpty(className) && xwikiContext.getUserReference() != null) {
                XWikiDocument xdocument = xwikiContext.getWiki().getDocument(doc.getDocumentReference(),
                        xwikiContext);
                BaseObject baseObject = xdocument.getObject(className);
                if (baseObject != null) {
                    searchResult.setObject(this.modelFactory.toRestObject(uriInfo.getBaseUri(), doc, baseObject,
                            false, false));
                }
            }

            String pageUri;
            if (StringUtils.isBlank(language)) {
                pageUri = Utils.createURI(uriInfo.getBaseUri(), PageResource.class, wikiName,
                        Utils.getSpacesHierarchy(documentReference.getLastSpaceReference()),
                        documentReference.getName()).toString();
            } else {
                searchResult.setLanguage(language);
                pageUri = Utils.createURI(uriInfo.getBaseUri(), PageTranslationResource.class, wikiName,
                        Utils.getSpacesHierarchy(documentReference.getLastSpaceReference()),
                        documentReference.getName(), language).toString();
            }

            Link pageLink = new Link();
            pageLink.setHref(pageUri);
            pageLink.setRel(Relations.PAGE);
            searchResult.getLinks().add(pageLink);

            result.add(searchResult);
        }
    }

    return result;
}