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

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

Introduction

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

Prototype

public static boolean startsWithAny(final CharSequence string, final CharSequence... searchStrings) 

Source Link

Document

Check if a CharSequence starts with any of an array of specified strings.

 StringUtils.startsWithAny(null, null)      = false StringUtils.startsWithAny(null, new String[] {"abc"})  = false StringUtils.startsWithAny("abcxyz", null)     = false StringUtils.startsWithAny("abcxyz", new String[] {""}) = false StringUtils.startsWithAny("abcxyz", new String[] {"abc"}) = true StringUtils.startsWithAny("abcxyz", new String[] {null, "xyz", "abc"}) = true 

Usage

From source file:org.maodian.flyingcat.netty.handler.XMLFragmentDecoder.java

@Override
protected Object decode(ChannelHandlerContext ctx, String msg) throws Exception {
    if (StringUtils.endsWithAny(msg, INVALID_ELEMENT_TAILS)) {
        throw new XmppException(StreamError.RESTRICTED_XML).set("xml", msg);
    }//ww w.  j  a v  a  2  s.  c  om

    if (StringUtils.endsWith(msg, PROCESS_INSTRUCTION_TAIL) && !StringUtils.startsWith(msg, "<?xml ")) {
        throw new XmppException(StreamError.RESTRICTED_XML).set("xml", msg);
    }

    if (StringUtils.startsWithAny(msg, INVALID_ELEMENT_HEADS)) {
        throw new XmppException(StreamError.RESTRICTED_XML).set("xml", msg);
    }

    // always accept xml declaration to improve compability with some client
    if (StringUtils.startsWith(msg, "<?xml ")) {
        return msg;
        /*if (acceptXMLDeclaration) {
          acceptXMLDeclaration = false;
          return msg;
        } else {
          throw new XmppException("XML declaration has been already received before", StreamError.NOT_WELL_FORMED).set("xml", msg);
        }*/
    }

    // deal with stream tag
    if (StringUtils.contains(msg, ":stream")
            && (StringUtils.contains(msg, "<") || StringUtils.contains(msg, "</"))) {
        if (depth != 0) {
            throw new XmppException("Stream Open/Close Tag can only be root element", StreamError.INVALID_XML);
        }
        return msg;
    }

    // deal with empty element at first level
    if (depth == 0 && StringUtils.endsWith(msg, "/>")) {
        return msg;
    }

    if (xml == null) {
        xml = new StringBuilder(msg);
    } else {
        xml.append(msg);
    }

    // deal with nested empty element
    if (StringUtils.endsWith(msg, "/>")) {
        return null;
    }

    if (StringUtils.contains(msg, "</")) {
        depth--;
    } else if (StringUtils.contains(msg, "<")) {
        depth++;
    }

    if (depth == 0) {
        String fragment = xml.toString();
        xml = null;
        return fragment;
    }
    return null;
}

From source file:org.sakaiproject.service.gradebook.shared.GradebookHelper.java

/**
 * Validate a grade item title by checking against the reserved characters
 * @param title/*from   w  w w  .  j a v  a 2s . c  om*/
 * @throws InvalidGradeItemNameException
 */
public static void validateGradeItemName(final String title) throws InvalidGradeItemNameException {
    if (StringUtils.isBlank(title)
            || StringUtils.startsWithAny(title, GradebookService.INVALID_CHARS_AT_START_OF_GB_ITEM_NAME)) {
        throw new InvalidGradeItemNameException("Grade Item name is invalid: " + title);
    }
}

From source file:org.wikipedia.nirvana.NirvanaBasicBot.java

public static boolean textOptionsToMap(String text, Map<String, String> parameters,
        String... commentSeparators) {
    String lines[] = text.split("\r|\n");
    for (String line : lines) {
        if (line.trim().isEmpty())
            continue;
        log.debug(line);//from  w w  w .  jav a2  s  .  c  o  m
        if (commentSeparators != null && commentSeparators.length > 0) {
            if (StringUtils.startsWithAny(line.trim(), commentSeparators)) {
                continue;
            }
        }
        int index = line.indexOf("=");
        if (index < 0)
            return false;
        parameters.put(line.substring(0, index).trim(), line.substring(index + 1).trim());
    }
    return true;
}

From source file:org.wurstworks.tools.pinto.AbstractPintoBean.java

private boolean isParameter(final String argument) {
    return StringUtils.startsWithAny(argument, OPTION_DELIMITERS);
}

From source file:therian.operator.immutablecheck.DefaultImmutableChecker.java

private static void addImmutableTypeTo(final Set<Class<?>> target, final Class<?> type) {
    if (target.contains(type)) {
        return;/*from  w w  w  .jav  a2  s.c  o m*/
    }
    Class<?> c = type;
    while (c.isAnonymousClass()) {
        c = c.getEnclosingClass();
    }
    if (target.contains(c) && !target.equals(c)
            || StringUtils.startsWithAny(c.getSimpleName().toLowerCase(Locale.US), KNOWN_IMMUTABLE_PREFIXES)) {
        target.add(type);
    }
}