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:com.adobe.acs.commons.dispatcher.impl.PermissionSensitiveCacheServlet.java

public boolean isUriValid(String requestUri) {
    boolean isValidUri = true;

    if (!StringUtils.startsWith(requestUri, "/")) {
        isValidUri = false;/*from  w w w .j  av  a 2 s  . c om*/
    }

    return isValidUri;
}

From source file:com.sonicle.webtop.core.app.shiro.filter.JWTSignatureVerifier.java

@Override
protected boolean onPreHandle(ServletRequest request, ServletResponse response, Object mappedValue)
        throws Exception {
    // Retrieve signing key
    SecretKey signingKey = getSigningKey(request);
    if (signingKey == null) {
        logger.warn("Missing JWT secret. Please check '{}' context attribute.", SECRET_CONTEXT_ATTRIBUTE);
        return true;
    }//w ww.  j  a  v  a  2 s.  c  om

    // Extracts the JWT string
    String authz = getAuthzHeader(request);
    if (!StringUtils.startsWith(authz, AUTHORIZATION_SCHEME_BEARER)) {
        if (logger.isTraceEnabled()) {
            logger.trace("Authorization header is missing or malformed");
            logger.trace("{}: {}", AUTHORIZATION_HEADER, authz);
        }
        WebUtils.toHttp(response).sendError(HttpServletResponse.SC_FORBIDDEN,
                "Authorization header is missing or malformed");
        return false;
    }
    String jwts = authz.substring(authz.indexOf(" ") + 1).trim();

    try {
        Jwts.parser().setSigningKey(signingKey).parseClaimsJws(jwts);
        return true;

    } catch (JwtException ex) {
        logger.trace("Unable to parse JWT string [{}]", ex, jwts);
        WebUtils.toHttp(response).sendError(HttpServletResponse.SC_FORBIDDEN, "JWT token not signed correctly");
        return false;
    }
}

From source file:com.sonicle.webtop.core.sdk.bol.js.JsOptions.java

public Map<String, Object> getWithPrefix(String prefix) {
    JsOptions map = new JsOptions();
    for (Map.Entry<String, Object> entry : entrySet()) {
        if (StringUtils.startsWith(entry.getKey(), prefix)) {
            map.put(WordUtils.uncapitalize(StringUtils.removeStart(entry.getKey(), prefix)), entry.getValue());
        }//w ww  . ja  v  a2s  .c om
    }
    return map;
}

From source file:com.neatresults.mgnltweaks.app.status.ConfigStatusPresenter.java

@Override
public void refreshData() {
    List<String> fails = new ArrayList<String>();
    final AtomicInteger totalCount = new AtomicInteger();
    final AtomicInteger absCount = new AtomicInteger();
    final AtomicInteger overrideCount = new AtomicInteger();
    try {/*  w ww.j  a v  a 2s.co  m*/
        Session session = MgnlContext.getJCRSession(RepositoryConstants.CONFIG);
        NodeIterator results = QueryUtil.search(RepositoryConstants.CONFIG,
                "select * from [nt:base] where extends is not null");
        filterData(results, n -> {
            try {
                String path = n.getProperty("extends").getString();
                if (StringUtils.startsWith(path, "/")) {
                    absCount.incrementAndGet();
                    return session.itemExists(path);
                } else if ("override".equals(path)) {
                    overrideCount.incrementAndGet();
                    return true;
                } else {
                    return session.itemExists(n.getPath() + "/" + path);
                }
            } catch (RepositoryException e) {
                log.debug("Ooops, error while checking existence of extends target for {} with {}", n,
                        e.getMessage(), e);
                return false;
            }
        }, t -> totalCount.incrementAndGet(), f -> {
            try {
                fails.add(f.getPath());
            } catch (RepositoryException e) {
                log.debug("Ooops, error while reporting misconfigured extends target for {} with {}", f,
                        e.getMessage(), e);
            }
        });
    } catch (RepositoryException e) {
        log.debug("Ooops, error while searching for extends targets with {}", e.getMessage(), e);
    }
    sourceData(ConfigStatusView.EXTENDS_FAIL_COUNT, "" + fails.size());
    sourceData(ConfigStatusView.EXTENDS_FAIL_LIST, fails);
    sourceData(ConfigStatusView.EXTENDS_COUNT, "" + totalCount.get());
    sourceData(ConfigStatusView.ABS_EXTENDS_COUNT, "" + absCount.get());
    sourceData(ConfigStatusView.REL_EXTENDS_COUNT,
            "" + (totalCount.get() - absCount.get() - overrideCount.get()));
    sourceData(ConfigStatusView.OVR_EXTENDS_COUNT, "" + overrideCount.get());
}

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

/**
 * @param path Content path//  w ww.  j a  v  a2s. co m
 * @return true if Path is located below DAM default root folders.
 */
public static boolean isDefaultMediaContentPath(String path) {
    return StringUtils.startsWith(path, DEFAULT_DAM_ROOT);
}

From source file:ee.ria.xroad.proxyui.WSDLParser.java

private static boolean identicalOperationsUnderSamePort(Exception e) {
    return (e instanceof IllegalArgumentException)
            && StringUtils.startsWith(e.getMessage(), "Duplicate operation with name=");

}

From source file:com.nridge.core.app.mgr.ServiceTimer.java

/**
 * Convenience method that returns the value of an application
 * manager property using the concatenation of the property
 * prefix and suffix values.//  w  ww .  j av a2 s.  c  om
 *
 * @param aSuffix Property name suffix.
 *
 * @return Matching property value.
 */
public String getAppString(String aSuffix) {
    String propertyName;

    if (StringUtils.startsWith(aSuffix, "."))
        propertyName = mPropertyPrefix + aSuffix;
    else
        propertyName = mPropertyPrefix + "." + aSuffix;

    return mAppMgr.getString(propertyName);
}

From source file:de.micromata.mgc.javafx.SystemService.java

public OsType getOsType() {
    String osName = System.getProperty("os.name");
    //    if (true) {
    //      return OsType.Mac;
    //    }//from ww  w .  j av  a2 s. c  o  m
    OsType osType = OsType.Other;
    if (StringUtils.startsWith(osName, "Windows") == true) {
        osType = OsType.Windows;
    } else if (StringUtils.startsWith(osName, "Mac") == true) {
        osType = OsType.Mac;
    }
    return osType;

}

From source file:io.wcm.handler.mediasource.dam.impl.DefaultRenditionHandler.java

/**
 * adds rendition to the list of candidates, if it should be available for resolving
 * @param candidates//from  w  w w  .j  a va 2  s. c om
 * @param rendition
 */
private void addRendition(Set<RenditionMetadata> candidates, Rendition rendition) {
    // ignore CQ thumbnail renditions
    if (!StringUtils.startsWith(rendition.getName(), DamConstants.PREFIX_ASSET_THUMBNAIL + ".")) {
        RenditionMetadata renditionMetadata = createRenditionMetadata(rendition);
        candidates.add(renditionMetadata);
    }
}

From source file:com.nridge.core.base.std.FilUtl.java

/**
 * Generates a unique path and file name combination based on the parameters
 * provided.//from w w  w .  j a v a2 s .  c  o  m
 *
 * @param aPathName Path name.
 * @param aFilePrefix File name prefix (appended with random id)
 * @param aFileExtension File name extension.
 *
 * @return A unique path and file name combination.
 */
static public String generateUniquePathFileName(String aPathName, String aFilePrefix, String aFileExtension) {
    String pathFileName;

    if (StringUtils.isNotEmpty(aPathName))
        pathFileName = String.format("%s%c%s", aPathName, File.separatorChar, aFilePrefix);
    else
        pathFileName = aFilePrefix;

    // http://www.javapractices.com/topic/TopicAction.do?Id=56

    UUID uniqueId = UUID.randomUUID();
    byte idBytes[] = uniqueId.toString().getBytes();
    Checksum checksumValue = new CRC32();
    checksumValue.update(idBytes, 0, idBytes.length);
    long longValue = checksumValue.getValue();

    if (StringUtils.startsWith(aFileExtension, "."))
        return String.format("%s_%d%s", pathFileName, longValue, aFileExtension);
    else
        return String.format("%s_%d.%s", pathFileName, longValue, aFileExtension);
}