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:gobblin.util.PropertiesUtils.java

/**
 * Extract all the keys that start with a <code>prefix</code> in {@link Properties} to a new {@link Properties}
 * instance./*  w w w.j  a v a  2 s.c  om*/
 *
 * @param properties the given {@link Properties} instance
 * @param prefix of keys to be extracted
 * @return a {@link Properties} instance
 */
public static Properties extractPropertiesWithPrefix(Properties properties, Optional<String> prefix) {
    Preconditions.checkNotNull(properties);
    Preconditions.checkNotNull(prefix);

    Properties extractedProperties = new Properties();
    for (Map.Entry<Object, Object> entry : properties.entrySet()) {
        if (StringUtils.startsWith(entry.getKey().toString(), prefix.or(StringUtils.EMPTY))) {
            extractedProperties.put(entry.getKey().toString(), entry.getValue());
        }
    }

    return extractedProperties;
}

From source file:com.adeptj.runtime.tools.logging.ExtThreadConverter.java

@Override
public String convert(ILoggingEvent event) {
    String threadName = super.convert(event);
    if (StringUtils.startsWith(threadName, "CM Event Dispatcher")) {
        return "CM Event Dispatcher";
    } else if (StringUtils.startsWith(threadName, "Background Update")) {
        return "Background Update";
    }/*from   ww w .j av  a 2s  .c  o m*/
    return threadName;
}

From source file:com.nesscomputing.service.discovery.client.ServiceURI.java

public ServiceURI(final URI uri) throws URISyntaxException {
    if (!"srvc".equals(uri.getScheme())) {
        throw new URISyntaxException(uri.toString(), "ServiceURI only supports srvc:// URIs");
    }/*  ww  w. j  a  v a2 s.  c  o  m*/
    if (!StringUtils.startsWith(uri.getSchemeSpecificPart(), "//")) {
        throw new URISyntaxException(uri.toString(), "ServiceURI only supports srvc:// URIs");
    }

    final String schemeSpecificPart = uri.getSchemeSpecificPart().substring(2);
    final int slashIndex = schemeSpecificPart.indexOf('/');
    if (slashIndex == -1) {
        throw new URISyntaxException(uri.toString(), "ServiceURI requires a slash at the end of the service!");
    }
    final int colonIndex = schemeSpecificPart.indexOf(':');
    if (colonIndex == -1 || colonIndex > slashIndex) {
        serviceName = schemeSpecificPart.substring(0, slashIndex);
        serviceType = null;
    } else {
        serviceName = schemeSpecificPart.substring(0, colonIndex);
        serviceType = schemeSpecificPart.substring(colonIndex + 1, slashIndex);
    }

    path = uri.getRawPath();
    query = uri.getRawQuery();
    fragment = uri.getRawFragment();
}

From source file:com.glaf.shiro.MyShiroFilterFactoryBean.java

@Override
public Map<String, String> getFilterChainDefinitionMap() {
    logger.debug("load system security properties...");
    logger.debug("filterChain size:" + filterChainDefinitionMap.size());
    LinkedHashMap<String, String> props = SecurityConfig.getProperties();
    Iterator<String> it = props.keySet().iterator();
    while (it.hasNext()) {
        String key = it.next();//from w  ww . j av a  2  s.com
        String value = props.get(key);
        if (StringUtils.startsWith("**", key) || StringUtils.startsWith("/**", key)) {
            continue;
        }
        filterChainDefinitionMap.put(key, value);
        logger.debug("add security filter chain:" + key + "=" + value);
    }
    /**
     * ??
     */
    filterChainDefinitionMap.put("/rs/**", "authc");
    filterChainDefinitionMap.put("/mx/**", "authc");
    logger.debug(filterChainDefinitionMap);
    return filterChainDefinitionMap;
}

From source file:alfio.util.Validator.java

public static ValidationResult validateEventHeader(Optional<Event> event, EventModification ev, Errors errors) {

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "shortName", "error.shortname");
    if (ev.getOrganizationId() < 0) {
        errors.rejectValue("organizationId", "error.organizationId");
    }/*from   w w w .  j ava  2  s  .c o m*/
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "location", "error.location");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "websiteUrl", "error.websiteurl");

    if (isInternal(event, ev)) {
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "description", "error.description");
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "termsAndConditionsUrl",
                "error.termsandconditionsurl");
    } else {
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "externalUrl", "error.externalurl");
    }

    if (ev.getFileBlobId() == null) {
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "imageUrl", "error.imageurl");
        if (!StringUtils.startsWith(ev.getImageUrl(), "https://")) {
            errors.rejectValue("imageUrl", "error.imageurl");
        }
    }
    return evaluateValidationResult(errors);
}

From source file:com.adeptj.modules.jaxrs.core.jwt.JwtExtractor.java

private static String cleanseJwt(String jwt) {
    return StringUtils.startsWith(jwt, AUTH_SCHEME_BEARER) ? StringUtils.substring(jwt, JWT_START_POS)
            : StringUtils.trim(jwt);/*from   ww w  .ja v a  2s .  c  o m*/
}

From source file:com.erudika.para.storage.LocalFileStore.java

@Override
public InputStream load(String path) {
    if (StringUtils.startsWith(path, File.separator)) {
        path = path.substring(1);/*www .  ja v  a2s  . co m*/
    }
    if (!StringUtils.isBlank(path)) {
        try {
            File f = new File(folder + File.separator + path);
            return f.canRead() ? new BufferedInputStream(new FileInputStream(f)) : null;
        } catch (FileNotFoundException ex) {
            logger.error(null, ex);
        }
    }
    return null;
}

From source file:com.simpligility.maven.plugins.android.asm.DescendantFinder.java

@Override
public void visit(int version, int access, String name, String signature, String superName,
        String[] interfaces) {/*from  www . jav  a 2s  .c  om*/
    for (String testPackage : parentPackages) {
        if (StringUtils.startsWith(superName, testPackage)) {
            flagAsFound();
            //                System.out.println(name + " extends " + superName);
        }
    }
}

From source file:ductive.parse.parsers.TokenParser.java

@Override
public Result<T> doApply(ParseContext ctx) {
    try {/*from w  w w.jav a2s  . co  m*/
        return delegate.apply(ctx);
    } catch (NoMatchException e) {
        if (ctx.isCompleting() && ctx.isOriginalEof(e.ctx.locate(e.pos))) { // FIXME: locatepos
            CharSequence inp = ctx.input();

            List<CharSequence> suggestions = new ArrayList<>();
            for (CharSequence suggestion : delegate.suggest(ctx))
                if (StringUtils.startsWith(suggestion, inp))
                    suggestions.add(suggestion);

            throw new SuggestException(new CompleteResult(suggestions, (int) ctx.locate(0)), e); // FIXME: suggestionpos
        }

        throw e;
    }
}

From source file:io.wcm.handler.link.type.ExternalLinkType.java

@Override
public boolean accepts(String linkRef) {
    // accept as external link if the ref contains "://" and mailto links
    return StringUtils.contains(linkRef, "://") || StringUtils.startsWith(linkRef, "mailto:");
}