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:org.asqatasun.webapp.validator.PageAuditSetUpFormValidator.java

/**
 * @param url //from  w ww .ja v a 2 s.  co m
 * @return whether the current Url starts with a file prefix
 */
public boolean hasUrlFilePrefix(String url) {
    return StringUtils.startsWith(url, TgolKeyStore.FILE_PREFIX);
}

From source file:org.biokoframework.http.fields.impl.JsonFieldsParser.java

@Override
protected void checkContentType(String contentType) throws RequestNotSupportedException {
    if (!StringUtils.startsWith(contentType, JSON_TYPE)) {
        throw badContentType(contentType, JSON_TYPE);
    }/*www  . j  a v a2s  .  c  om*/
}

From source file:org.blocks4j.reconf.client.constructors.MapConstructor.java

public Object construct(MethodData data) throws Throwable {
    Class<?> returnClass;/*w  ww .j  a va2  s. c  om*/
    Type keyType = null;
    Type valueType = null;

    if (data.getReturnType() instanceof ParameterizedType) {
        ParameterizedType parameterized = (ParameterizedType) data.getReturnType();
        returnClass = (Class<?>) parameterized.getRawType();

        if (parameterized.getActualTypeArguments().length == 1) {
            Type first = parameterized.getActualTypeArguments()[0];
            if (returnClass.getGenericSuperclass() != null
                    && returnClass.getGenericSuperclass() instanceof ParameterizedType) {
                parameterized = (ParameterizedType) returnClass.getGenericSuperclass();
                if (parameterized.getActualTypeArguments().length != 2) {
                    throw new IllegalArgumentException(
                            msg.format("error.cant.build.type", data.getReturnType(), data.getMethod()));
                }
                if (parameterized.getActualTypeArguments()[0] instanceof TypeVariable) {
                    keyType = first;
                    valueType = parameterized.getActualTypeArguments()[1];

                } else if (parameterized.getActualTypeArguments()[1] instanceof TypeVariable) {
                    valueType = first;
                    keyType = parameterized.getActualTypeArguments()[0];

                } else {
                    throw new IllegalArgumentException(
                            msg.format("error.cant.build.type", data.getReturnType(), data.getMethod()));
                }
            }

        } else {
            keyType = parameterized.getActualTypeArguments()[0];
            valueType = parameterized.getActualTypeArguments()[1];
        }

    } else if (data.getReturnType() instanceof Class) {
        returnClass = (Class<?>) data.getReturnType();

        if (returnClass.getGenericSuperclass() != null
                && returnClass.getGenericSuperclass() instanceof ParameterizedType) {
            ParameterizedType parameterized = (ParameterizedType) returnClass.getGenericSuperclass();
            if (parameterized.getActualTypeArguments().length != 2) {
                throw new IllegalArgumentException(
                        msg.format("error.cant.build.type", data.getReturnType(), data.getMethod()));
            }
            keyType = parameterized.getActualTypeArguments()[0];
            valueType = parameterized.getActualTypeArguments()[1];

        } else {
            keyType = Object.class;
            valueType = Object.class;
        }

    } else {
        throw new IllegalArgumentException(msg.format("error.return", data.getMethod()));
    }

    if (returnClass.isInterface()) {
        returnClass = getDefaultImplementation(data, returnClass);
    }

    Constructor<?> constructor = returnClass.getConstructor(ArrayUtils.EMPTY_CLASS_ARRAY);
    Map<Object, Object> mapInstance = (Map<Object, Object>) constructor
            .newInstance(ArrayUtils.EMPTY_OBJECT_ARRAY);

    if (null == data.getValue() || StringUtils.isEmpty(data.getValue())) {
        return mapInstance;
    }

    if ((!(keyType instanceof Class))
            || (!StringUtils.startsWith(data.getValue(), "[") || !StringUtils.endsWith(data.getValue(), "]"))) {
        throw new IllegalArgumentException(msg.format("error.build", data.getValue(), data.getMethod()));
    }

    StringParser parser = new StringParser(data);
    for (Entry<String, String> each : parser.getTokensAsMap().entrySet()) {
        Object value = ObjectConstructorFactory.get(valueType)
                .construct(new MethodData(data.getMethod(), valueType, each.getValue()));
        mapInstance.put(ObjectConstructorFactory.get(keyType)
                .construct(new MethodData(data.getMethod(), keyType, each.getKey())), value);
    }

    return mapInstance;
}

From source file:org.broadleafcommerce.common.web.processor.ResourceBundleProcessor.java

/**
 * Adds the context path to the bundleUrl.    We don't use the Thymeleaf "@" syntax or any other mechanism to 
 * encode this URL as the resolvers could have a conflict.   
 * /*from ww w .j  av  a2  s . co m*/
 * For example, resolving a bundle named "style.css" that has a file also named "style.css" creates problems as
 * the TF or version resolvers both want to version this file.
 *  
 * @param arguments
 * @param bundleName
 * @return
 */
protected String getBundleUrl(Arguments arguments, String bundleName) {
    String bundleUrl = bundleName;

    if (!StringUtils.startsWith(bundleUrl, "/")) {
        bundleUrl = "/" + bundleUrl;
    }

    IWebContext context = (IWebContext) arguments.getContext();
    HttpServletRequest request = context.getHttpServletRequest();
    String contextPath = request.getContextPath();

    if (StringUtils.isNotEmpty(contextPath)) {
        bundleUrl = contextPath + bundleUrl;
    }

    return bundleUrl;
}

From source file:org.codehaus.mojo.license.utils.HttpRequester.java

/**
 * will download a external resource and read the content of the file that will then be translated into a
 * new list. <br>/*from w  w w. j  a va2  s  .c o m*/
 * Lines starting with the character '#' will be omitted from the list <br>
 * <br>
 * <b>NOTE:</b><br>
 * certificate checking for this request will be disabled because some resources might be present on some
 * local servers in the internal network that do not use a safe connection
 *
 * @param url the URL to the external resource
 * @return a new list with all license entries from the remote resource
 */
public static List<String> downloadList(String url) throws MojoExecutionException {
    List<String> list = new ArrayList<>();
    BufferedReader bufferedReader = null;
    try {
        bufferedReader = new BufferedReader(new CharArrayReader(getFromUrl(url).toCharArray()));
        String line;
        while ((line = bufferedReader.readLine()) != null) {
            if (StringUtils.isNotBlank(line)) {
                if (!StringUtils.startsWith(line, "#") && !list.contains(line)) {
                    list.add(line);
                }
            }
        }
    } catch (IOException e) {
        throw new MojoExecutionException("could not open connection to URL: " + url, e);
    } finally {
        if (bufferedReader != null) {
            try {
                bufferedReader.close();
            } catch (IOException e) {
                throw new MojoExecutionException(e.getMessage(), e);
            }
        }
    }
    return list;
}

From source file:org.cryptomator.filesystem.crypto.CryptoFolder.java

private Predicate<String> startsWithDirPrefix() {
    return (String encryptedFolderName) -> StringUtils.startsWith(encryptedFolderName, DIR_PREFIX);
}

From source file:org.dkpro.core.io.nif.internal.DKPro2Nif.java

public static void convert(JCas aJCas, OntModel aTarget) {
    // Shorten down variable name for model
    OntModel m = aTarget;/*from  w w  w.  j  ava 2  s . com*/

    // Set up query instances
    final Resource tContext = m.createResource(NIF.TYPE_CONTEXT);
    final Resource tSentence = m.createResource(NIF.TYPE_SENTENCE);
    final Resource tWord = m.createResource(NIF.TYPE_WORD);
    final Resource tTitle = m.createResource(NIF.TYPE_TITLE);
    final Resource tParagraph = m.createResource(NIF.TYPE_PARAGRAPH);
    final Resource tEntityOccurrence = m.createResource(NIF.TYPE_ENTITY_OCCURRENCE);

    final Property pReferenceContext = m.createProperty(NIF.PROP_REFERENCE_CONTEXT);
    final Property pIsString = m.createProperty(NIF.PROP_IS_STRING);
    final Property pAnchorOf = m.createProperty(NIF.PROP_ANCHOR_OF);
    final Property pBeginIndex = m.createProperty(NIF.PROP_BEGIN_INDEX);
    final Property pEndIndex = m.createProperty(NIF.PROP_END_INDEX);
    final Property pStem = m.createProperty(NIF.PROP_STEM);
    final Property pLemma = m.createProperty(NIF.PROP_LEMMA);
    final Property pPosTag = m.createProperty(NIF.PROP_POS_TAG);
    final Property pWord = m.createProperty(NIF.PROP_WORD);
    final Property pNextWord = m.createProperty(NIF.PROP_NEXT_WORD);
    final Property pPreviousWord = m.createProperty(NIF.PROP_PREVIOUS_WORD);
    final Property pSentence = m.createProperty(NIF.PROP_SENTENCE);
    final Property pNextSentence = m.createProperty(NIF.PROP_NEXT_SENTENCE);
    final Property pPreviousSentence = m.createProperty(NIF.PROP_PREVIOUS_SENTENCE);
    final Property pTaIdentRef = m.createProperty(ITS.PROP_TA_IDENT_REF);
    final Property pTaClassRef = m.createProperty(ITS.PROP_TA_CLASS_REF);

    // Get a URI for the document
    DocumentMetaData dmd = DocumentMetaData.get(aJCas);
    String docuri = dmd.getDocumentUri() != null ? dmd.getDocumentUri() : "urn:" + dmd.getDocumentId();

    // Convert document -> context node
    Individual context;
    {
        String uri = String.format("%s#offset_%d_%d", docuri, 0, aJCas.getDocumentText().length());
        context = m.createIndividual(uri, tContext);
        context.addLiteral(pIsString, m.createTypedLiteral(aJCas.getDocumentText(), XSDstring));
        context.addLiteral(pBeginIndex, m.createTypedLiteral(0, XSDnonNegativeInteger));
        context.addLiteral(pEndIndex,
                m.createTypedLiteral(aJCas.getDocumentText().length(), XSDnonNegativeInteger));
    }

    // Convert headings/titles
    for (Heading uimaHeading : select(aJCas, Heading.class)) {
        String headingUri = String.format("%s#offset_%d_%d", docuri, uimaHeading.getBegin(),
                uimaHeading.getEnd());
        Individual nifTitle = m.createIndividual(headingUri, tTitle);
        nifTitle.addProperty(pReferenceContext, context);
        nifTitle.addLiteral(pAnchorOf, uimaHeading.getCoveredText());
        nifTitle.addLiteral(pBeginIndex, m.createTypedLiteral(uimaHeading.getBegin(), XSDnonNegativeInteger));
        nifTitle.addLiteral(pEndIndex, m.createTypedLiteral(uimaHeading.getEnd(), XSDnonNegativeInteger));
    }

    // Convert paragraphs
    for (Paragraph uimaParagraph : select(aJCas, Paragraph.class)) {
        String paragraphUri = String.format("%s#offset_%d_%d", docuri, uimaParagraph.getBegin(),
                uimaParagraph.getEnd());
        Individual nifParagraph = m.createIndividual(paragraphUri, tParagraph);
        nifParagraph.addProperty(pReferenceContext, context);
        nifParagraph.addLiteral(pAnchorOf, uimaParagraph.getCoveredText());
        nifParagraph.addLiteral(pBeginIndex,
                m.createTypedLiteral(uimaParagraph.getBegin(), XSDnonNegativeInteger));
        nifParagraph.addLiteral(pEndIndex, m.createTypedLiteral(uimaParagraph.getEnd(), XSDnonNegativeInteger));
    }

    // Convert sentences
    Individual previousNifSentence = null;
    for (Sentence uimaSentence : select(aJCas, Sentence.class)) {
        String sentenceUri = String.format("%s#offset_%d_%d", docuri, uimaSentence.getBegin(),
                uimaSentence.getEnd());
        Individual nifSentence = m.createIndividual(sentenceUri, tSentence);
        nifSentence.addProperty(pReferenceContext, context);
        nifSentence.addLiteral(pAnchorOf, uimaSentence.getCoveredText());
        nifSentence.addLiteral(pBeginIndex,
                m.createTypedLiteral(uimaSentence.getBegin(), XSDnonNegativeInteger));
        nifSentence.addLiteral(pEndIndex, m.createTypedLiteral(uimaSentence.getEnd(), XSDnonNegativeInteger));

        // Link word sequence
        if (previousNifSentence != null) {
            previousNifSentence.addProperty(pNextSentence, nifSentence);
            nifSentence.addProperty(pPreviousSentence, previousNifSentence);
        }
        previousNifSentence = nifSentence;

        // Convert tokens
        Individual previousNifWord = null;
        for (Token uimaToken : selectCovered(Token.class, uimaSentence)) {
            String wordUri = String.format("%s#offset_%d_%d", docuri, uimaToken.getBegin(), uimaToken.getEnd());
            Individual nifWord = m.createIndividual(wordUri, tWord);
            nifWord.addProperty(pReferenceContext, context);
            nifWord.addLiteral(pAnchorOf, uimaToken.getCoveredText());
            nifWord.addLiteral(pBeginIndex, m.createTypedLiteral(uimaToken.getBegin(), XSDnonNegativeInteger));
            nifWord.addLiteral(pEndIndex, m.createTypedLiteral(uimaToken.getEnd(), XSDnonNegativeInteger));

            // Link sentence <-> word
            nifWord.addProperty(pSentence, nifSentence);
            nifSentence.addProperty(pWord, nifWord);

            // Link word sequence
            if (previousNifWord != null) {
                previousNifWord.addProperty(pNextWord, nifWord);
                nifWord.addProperty(pPreviousWord, previousNifWord);
            }
            previousNifWord = nifWord;

            // Convert stem
            if (uimaToken.getStemValue() != null) {
                nifWord.addProperty(pStem, uimaToken.getStemValue());
            }

            // Convert lemma
            if (uimaToken.getLemmaValue() != null) {
                nifWord.addProperty(pLemma, uimaToken.getLemmaValue());
            }

            // Convert posTag (this is discouraged, the better alternative should be oliaLink)
            if (uimaToken.getPosValue() != null) {
                nifWord.addProperty(pPosTag, uimaToken.getPosValue());
            }
        }
    }

    // Convert named entities
    //
    // Actually, the named entity in NIF is different from the one in DKPro Core. NIF uses
    // taIdentRef to link to a unique instance of an entity. Named entity recognizers in DKPro
    // Core just categorizes the entity, e.g. as a person, location, or whatnot. For what NIF
    // uses, we'd need a named entity linker, not just a recognizer.
    //
    // We create NEs using the NIF 2.1 class "EntityOccurence".
    // 
    // So here, we check if the DKPro Core NE value/identifier looks like a URI and if yes, then
    // we store it into the NIF taIdentRef property - otherwise we ignore it because NIF does
    // not have the concept of a NE category.
    for (NamedEntity uimaNamedEntity : select(aJCas, NamedEntity.class)) {
        String neClass = uimaNamedEntity.getValue();
        String neIdentifier = uimaNamedEntity.getValue();

        boolean neClassIsUri = StringUtils.startsWith(neClass, "http://");
        boolean neIdentifierIsUri = StringUtils.startsWith(neIdentifier, "http://");

        // The crudest form of checking for a URI, but since "http://" appears to be the default
        // prefix in the semantic web, let's just stick with it for the moment.
        if (!neClassIsUri && !neIdentifierIsUri) {
            continue;
        }

        String neUri = String.format("%s#offset_%d_%d", docuri, uimaNamedEntity.getBegin(),
                uimaNamedEntity.getEnd());
        Individual nifNamedEntity = m.createIndividual(neUri, tEntityOccurrence);
        nifNamedEntity.addProperty(pReferenceContext, context);
        nifNamedEntity.addLiteral(pAnchorOf, uimaNamedEntity.getCoveredText());
        nifNamedEntity.addLiteral(pBeginIndex,
                m.createTypedLiteral(uimaNamedEntity.getBegin(), XSDnonNegativeInteger));
        nifNamedEntity.addLiteral(pEndIndex,
                m.createTypedLiteral(uimaNamedEntity.getEnd(), XSDnonNegativeInteger));

        if (neClassIsUri) {
            nifNamedEntity.addProperty(pTaClassRef, m.createResource(neClass));
        }

        if (neIdentifierIsUri) {
            nifNamedEntity.addProperty(pTaClassRef, m.createResource(neIdentifier));
        }
    }
}

From source file:org.flowable.dmn.spring.configurator.test.TestRuleBean.java

public boolean startsWith(Object input, String value) {
    return StringUtils.startsWith(input.toString(), value);
}

From source file:org.goko.controller.grbl.v08.GrblCommunicator.java

/**
 * Handling of incoming data//from  w  w  w  .  ja  v  a  2 s. co  m
 * @param data the received data
 * @throws GkException GkException
 */
protected void handleIncomingData(String data) throws GkException {
    String trimmedData = StringUtils.trim(data);
    if (StringUtils.isNotEmpty(trimmedData)) {
        /* Received OK response */
        if (StringUtils.equals(trimmedData, Grbl.OK_RESPONSE)) {
            grbl.handleOkResponse();

            /* Received error  */
        } else if (StringUtils.startsWith(trimmedData, "error:")) {
            grbl.handleError(trimmedData);

            /* Received status report  */
        } else if (StringUtils.startsWith(trimmedData, "<") && StringUtils.endsWith(trimmedData, ">")) {
            grbl.handleStatusReport(parseStatusReport(trimmedData));

            /* Received Grbl header */
        } else if (StringUtils.startsWith(trimmedData, "Grbl")) {
            handleHeader(trimmedData);
            grbl.initialiseConnectedState();
            //   refreshStatus();

            /* Received a configuration confirmation */
        } else if (StringUtils.defaultString(trimmedData).matches("\\$[0-9]*=.*")) {
            grbl.handleConfigurationReading(trimmedData);

            /* Received a work position report */
        } else if (StringUtils.defaultString(trimmedData).matches("\\[G5.*\\]")) {
            Tuple6b targetPoint = new Tuple6b().setNull();
            String offsetName = parseCoordinateSystem(trimmedData, targetPoint);
            grbl.setOffsetCoordinate(offsetName, targetPoint);

            /* Received an offset position report */
        } else if (StringUtils.defaultString(trimmedData).matches("\\[(G92|G28|G30).*\\]")) {
            //            Tuple6b targetPoint = new Tuple6b().setNull();
            //            String coordinateSystemName = parseCoordinateSystem(trimmedData, targetPoint);
            //            grbl.setOffsetCoordinate(coordinateSystemName, targetPoint);
            // TODO Handle G92
            /* Parser state report */
        } else if (StringUtils.defaultString(trimmedData).matches("\\[(G0|G1|G2|G3).*\\]")) {
            grbl.receiveParserState(StringUtils.substringBetween(trimmedData, "[", "]"));
            /* Unkown format received */
        } else {
            LOG.error("Ignoring received data " + trimmedData);
            grbl.getApplicativeLogService().warning("Ignoring received data " + trimmedData,
                    GrblControllerService.SERVICE_ID);
        }
    }
}

From source file:org.goko.controller.grbl.v09.GrblCommunicator.java

/**
 * Handling of incoming data/*from w  w w  . jav  a  2  s.  c  o  m*/
 * @param data the received data
 * @throws GkException GkException
 */
protected void handleIncomingData(String data) throws GkException {
    String trimmedData = StringUtils.trim(data);
    if (StringUtils.isNotEmpty(trimmedData)) {
        /* Received OK response */
        if (StringUtils.equals(trimmedData, Grbl.OK_RESPONSE)) {
            grbl.handleOkResponse();

            /* Received error  */
        } else if (StringUtils.startsWith(trimmedData, "error:")) {
            grbl.handleError(trimmedData);

            /* Received status report  */
        } else if (StringUtils.startsWith(trimmedData, "<") && StringUtils.endsWith(trimmedData, ">")) {
            grbl.handleStatusReport(parseStatusReport(trimmedData));

            /* Received Grbl header */
        } else if (StringUtils.startsWith(trimmedData, "Grbl")) {
            handleHeader(trimmedData);
            grbl.initialiseConnectedState();
            //   refreshStatus();

            /* Received a configuration confirmation */
        } else if (StringUtils.defaultString(trimmedData).matches("\\$[0-9]*=.*")) {
            grbl.handleConfigurationReading(trimmedData);

            /* Received a probe result */
        } else if (StringUtils.defaultString(trimmedData).matches("\\$[PRB*]")) {
            //[PRB:0.000,0.000,0.000:0]
            ProbeResult probeResult = parseProbeResult(StringUtils.defaultString(trimmedData));
            grbl.handleProbeResult(probeResult);
            /* Received a work position report */
        } else if (StringUtils.defaultString(trimmedData).matches("\\[G5.*\\]")) {
            Tuple6b targetPoint = new Tuple6b().setNull();
            String offsetName = parseCoordinateSystem(trimmedData, targetPoint);
            grbl.setOffsetCoordinate(offsetName, targetPoint);

            /* Received an offset position report */
        } else if (StringUtils.defaultString(trimmedData).matches("\\[(G92|G28|G30).*\\]")) {
            //            Tuple6b targetPoint = new Tuple6b().setNull();
            //            String coordinateSystemName = parseCoordinateSystem(trimmedData, targetPoint);
            //            grbl.setOffsetCoordinate(coordinateSystemName, targetPoint);
            // TODO Handle G92
            /* Parser state report */
        } else if (StringUtils.defaultString(trimmedData).matches("\\[(G0|G1|G2|G3).*\\]")) {
            grbl.receiveParserState(StringUtils.substringBetween(trimmedData, "[", "]"));
            /* Unkown format received */
        } else {
            LOG.error("Ignoring received data " + trimmedData);
            grbl.getApplicativeLogService().warning("Ignoring received data " + trimmedData,
                    GrblControllerService.SERVICE_ID);
        }
    }
}