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

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

Introduction

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

Prototype

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

Source Link

Document

Check if a CharSequence starts with a specified prefix.

null s are handled without exceptions.

Usage

From source file:net.thirdy.blackmarket.util.BlackmarketConfig.java

static boolean isLineNotComment(String line) {
    return !StringUtils.startsWith(line, "//") && !StringUtils.startsWith(line, ";");
}

From source file:nl.knaw.huygens.timbuctoo.security.TimbuctooAuthenticationHandler.java

private boolean isLocalSessionToken(String sessionId) {
    return StringUtils.startsWith(sessionId, LOCAL_SESSION_KEY_PREFIX);
}

From source file:nl.sidn.pcap.util.Settings.java

public static void createTldSuffixes(String value) {
    if (StringUtils.isEmpty(value)) {
        //no value found, do nothing
        return;/*from  w w w. j  a v a  2 s  .co m*/
    }

    String[] tlds = StringUtils.split(value, ",");
    //create list of DomainParents
    for (int i = 0; i < tlds.length; i++) {
        String parent = tlds[i];
        if (parent == null) {
            //skip nulls
            continue;
        }
        //start and end with a dot.
        if (!StringUtils.startsWith(parent, ".")) {
            parent = "." + parent;
        }

        int labelCount = StringUtils.split(parent, '.').length;
        if (StringUtils.endsWith(parent, ".")) {
            //remove last dot (will become the used tld suffix
            tldSuffixes.add(new DomainParent(parent, StringUtils.removeEnd(parent, "."), labelCount));
        } else {
            tldSuffixes.add(new DomainParent(parent + ".", parent, labelCount));
        }
    }

}

From source file:nl.vpro.jcr.criteria.query.xpath.utils.XPathTextUtils.java

/**
 * Convert a string to a JCR search expression literal, suitable for use in jcr:contains() (inside XPath queries).
 * The characters - and " have special meaning, and may be escaped with a backslash to obtain their literal value.
 * See JSR-170 spec v1.0, Sec. 6.6.5.2./*from w  ww.j a v  a  2s. co  m*/
 * @param str Any string.
 * @return A valid XPath 2.0 string literal suitable for use in jcr:contains(), including enclosing quotes.
 */
public static String stringToJCRSearchExp(String str) {
    if (StringUtils.isEmpty(str)) {
        return str;
    }

    String parseString = StringUtils.trimToEmpty(str);

    // workaround for https://issues.apache.org/jira/browse/JCR-2732
    parseString = StringUtils.replaceEach(parseString, new String[] { ":)", ":(" },
            new String[] { ": )", ": (" });

    /*
     * http://lucene.apache.org/java/2_4_0/queryparsersyntax.html#Escaping%20Special%20Characters
     * http://www.javalobby.org/java/forums/t86124.html
     */
    String escapeChars = "[\\\\+\\-\\!\\(\\)\\:\\^\\]\\{\\}\\~\\*\\?\"\\[\\]|]";
    parseString = parseString.replaceAll(escapeChars, "\\\\$0");
    parseString = parseString.replaceAll("\'", "\'\'");

    // workaround for https://issues.apache.org/jira/browse/JCR-2733
    if (StringUtils.startsWith(parseString, "OR ")) {
        parseString = parseString.replaceFirst("\\bOR\\b", "\"OR\"");
    }

    return parseString;

}

From source file:nz.co.fortytwo.signalk.processor.InputFilterProcessor.java

public void process(Exchange exchange) throws Exception {
    String msg = exchange.getIn().getBody(String.class);
    if (msg != null) {
        msg = msg.trim();//  w w w. j a  v a2 s.c o  m
        // stomp messages are prefixed with 'ascii:'
        if (msg.startsWith("ascii:"))
            msg = msg.substring(6).trim();
        msg = StringUtils.chomp(msg);
        boolean ok = false;
        if (msg.startsWith("!AIVDM")) {
            // AIS
            // !AIVDM,1,1,,B,15MwkRUOidG?GElEa<iQk1JV06Jd,0*6D
            exchange.getIn().setBody(msg);
            sendNmea(exchange);
            ok = true;
        } else if (msg.startsWith("$")) {
            // NMEA - good
            // System.out.println(msg);
            exchange.getIn().setBody(msg);
            if (logger.isDebugEnabled())
                logger.debug(msg.toString());
            sendNmea(exchange);
            ok = true;
        } else if (msg.startsWith("{") && msg.endsWith("}")) {
            Json json = Json.read(msg);
            // n2k
            if (json.has(SignalKConstants.pgn)) {
                exchange.getIn().setHeader(SignalKConstants.N2K_MESSAGE, msg);
            }
            // full or delta format
            if (exchange.getIn().getHeader(SignalKConstants.SIGNALK_FORMAT) == null) {
                if (json.has(SignalKConstants.CONTEXT)) {
                    exchange.getIn().setHeader(SignalKConstants.SIGNALK_FORMAT, SignalKConstants.FORMAT_DELTA);
                }
                if (json.has(SignalKConstants.vessels) || json.has(SignalKConstants.resources)) {
                    exchange.getIn().setHeader(SignalKConstants.SIGNALK_FORMAT, SignalKConstants.FORMAT_FULL);
                }
            }
            // compensate for MQTT and STOMP sessionid
            if (json.has(WebsocketConstants.CONNECTION_KEY)) {
                exchange.getIn().setHeader(WebsocketConstants.CONNECTION_KEY,
                        json.at(WebsocketConstants.CONNECTION_KEY).asString());
            }
            // deal with REPLY_TO
            Map<String, Object> headers = exchange.getIn().getHeaders();
            if (headers != null && headers.containsKey(ConfigConstants.REPLY_TO)) {
                exchange.getIn().setHeader(ConfigConstants.DESTINATION, headers.get(ConfigConstants.REPLY_TO));
                // headers.remove(Constants.REPLY_TO);
            }
            // for MQTT
            if (json.has(ConfigConstants.REPLY_TO)) {
                exchange.getIn().setHeader(ConfigConstants.DESTINATION,
                        (json.at(ConfigConstants.REPLY_TO).asString()));
            }
            //if it has a config object, flag it as such
            if (json.has(SignalKConstants.CONFIG) || (json.has(SignalKConstants.CONTEXT) && StringUtils
                    .startsWith(json.at(SignalKConstants.CONTEXT).toString(), SignalKConstants.CONFIG))) {
                exchange.getIn().setHeader(SignalKConstants.CONFIG_ACTION, SignalKConstants.CONFIG_ACTION_SAVE);
            }
            // json
            exchange.getIn().setBody(json);
            ok = true;
        }
        if (ok) {
            return;
        }
        // uh-oh log it, squash it
        exchange.getUnitOfWork().done(exchange);
        // System.out.println("Dropped invalid message:"+msg);
        logger.info("Dropped invalid message:" + msg);
        exchange.getIn().setBody(null);
        // throw new CamelExchangeException("Invalid msg", exchange);
    }

}

From source file:nz.net.orcon.kanban.automation.VariableInterpreter.java

public boolean isVariableExpression(String variableExpression) {
    return StringUtils.startsWith(variableExpression, VARIABLE_TEMPLATE_TOKEN);
}

From source file:nz.net.orcon.kanban.automation.VariableInterpreter.java

public Object resolve(Map<String, Object> context, String variableExpression) {
    if (StringUtils.isNotBlank(variableExpression)
            && StringUtils.startsWith(variableExpression, VARIABLE_TEMPLATE_TOKEN)) {

        final Object returnValue = context.get(variableExpression.substring(1));
        if (returnValue != null)
            return returnValue;
    }/*from www. j  av  a  2  s  .c  om*/
    return variableExpression;
}

From source file:org.alfresco.dataprep.CMISUtil.java

/**
 * Get the node ref for a item by path//from  w w  w.  j a va  2  s .com
 * @param session the session
 * @param pathToContent String path to item (e.g. /Sites/siteId/documentLibrary/doc.txt)
 * @return String node ref of the item
 */
public String getNodeRefByPath(Session session, String pathToContent) {
    if (StringUtils.isEmpty(pathToContent)) {
        throw new CmisRuntimeException("Path to content is missing");
    }
    try {
        if (!StringUtils.startsWith(pathToContent, "/")) {
            pathToContent = "/" + pathToContent;
        }
        if (StringUtils.endsWith(pathToContent, "/")) {
            pathToContent = StringUtils.removeEnd(pathToContent, "/");
        }
        CmisObject content = session.getObjectByPath(pathToContent);
        return content.getId().split(";")[0];
    } catch (CmisObjectNotFoundException nf) {
        return "";
    }
}

From source file:org.alfresco.dataprep.CMISUtil.java

/**
 * Get cmis object by path//from w  w w . j a va2  s. c  om
 * 
 * @param session {@link Session} the session
 * @param pathToItem String path to item
 * @return CmisObject cmis object
 */
public CmisObject getCmisObject(final Session session, String pathToItem) {
    try {
        if (!StringUtils.startsWith(pathToItem, "/")) {
            pathToItem = "/" + pathToItem;
        }
        if (StringUtils.endsWith(pathToItem, "/")) {
            pathToItem = StringUtils.removeEnd(pathToItem, "/");
        }
        if (pathToItem.isEmpty()) {
            // set root folder
            pathToItem = "/";
        }
        return session.getObjectByPath(pathToItem);
    } catch (CmisObjectNotFoundException nf) {
        throw new CmisRuntimeException("Path doesn't exist " + pathToItem);
    }
}

From source file:org.alfresco.dataprep.CMISUtil.java

/**
 * Get cmis object by path//  w ww  .  ja va  2s.co m
 * 
 * @param userName String user name
 * @param password String user password
 * @param pathToItem String path to item
 * @return CmisObject cmis object
 */
public CmisObject getCmisObject(final String userName, final String password, String pathToItem) {
    try {
        if (!StringUtils.startsWith(pathToItem, "/")) {
            pathToItem = "/" + pathToItem;
        }
        if (StringUtils.endsWith(pathToItem, "/")) {
            pathToItem = StringUtils.removeEnd(pathToItem, "/");
        }
        Session session = getCMISSession(userName, password);
        return session.getObjectByPath(pathToItem);
    } catch (CmisObjectNotFoundException nf) {
        throw new CmisRuntimeException("Path doesn't exist " + pathToItem);
    }
}