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

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

Introduction

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

Prototype

public static boolean startsWith(String str, String prefix) 

Source Link

Document

Check if a String starts with a specified prefix.

Usage

From source file:com.microsoft.alm.plugin.external.tools.TfTool.java

/**
 * Check if PATH contains the path to the tf command
 *
 * @return//from   w w w .  ja  va 2s.  c  o m
 */
private static String getExeFromPath(final String[] exeNames) {
    final String envPath = SystemHelper.getEnvironmentVariable(PATH_ENV);

    if (StringUtils.isNotEmpty(envPath)) {
        final String[] paths = envPath.split(";");
        for (final String path : paths) {
            final File filePath = new File(path);
            if (StringUtils.startsWith(filePath.getName(), TF_DIRECTORY_PREFIX) && filePath.isDirectory()) {
                final String verifiedPath = checkTfPath(filePath.getPath(), exeNames);
                if (verifiedPath != null) {
                    return verifiedPath;
                }
            }
        }
    }
    return null;
}

From source file:com.steeleforge.aem.ironsites.xss.XSSUtil.java

/**
 * @param request//w  ww.  j a va2 s . c o m
 * @param policy
 * @return anti-samy policy path
 */
private static String findPolicyPath(SlingHttpServletRequest request, String policy) {
    String path = null;
    if (StringUtils.isBlank(policy)) {
        return path;
    }
    ResourceResolver resolver = request.getResourceResolver();
    Resource resource = request.getResource();
    String resourceType = resource.getResourceType();
    if (StringUtils.startsWith(policy, "/")) {
        path = policy;
    } else {
        if ((StringUtils.startsWith(resourceType, "./")) || (StringUtils.startsWith(resourceType, "../"))) {
            resourceType = ResourceUtil.normalize(resource.getResourceType() + "/" + resourceType);
        }
        path = resourceType + "/" + policy;
    }
    path = ResourceUtil.normalize(path);
    if (!StringUtils.endsWith(path, ".xml")) {
        path = path + ".xml";
    }
    if (null == resolver.getResource(path)) {
        LOG.debug("Could not find XSS policy at {}", path);
        path = null;
    }
    return path;
}

From source file:com.wwinsoft.modules.security.jcaptcha.JCaptchaFilter.java

/**
 * Filter?.//from  www .  j  ava  2s. co m
 */
public void doFilter(final ServletRequest theRequest, final ServletResponse theResponse,
        final FilterChain chain) throws IOException, ServletException {
    HttpServletRequest request = (HttpServletRequest) theRequest;
    HttpServletResponse response = (HttpServletResponse) theResponse;
    String servletPath = request.getServletPath();

    //?filterProcessesUrl??,??.
    if (StringUtils.startsWith(servletPath, filterProcessesUrl)) {
        boolean validated = validateCaptchaChallenge(request);
        if (validated) {
            chain.doFilter(request, response);
        } else {
            redirectFailureUrl(request, response);
        }
    } else {
        genernateCaptchaImage(request, response);
    }
}

From source file:com.adobe.acs.commons.users.impl.Ace.java

protected void validate(String type, String path, List<String> privilegeNames)
        throws EnsureAuthorizableException {
    if (!ArrayUtils.contains(new String[] { "allow", "deny" }, type)) {
        throw new EnsureAuthorizableException(
                "Ensure Service User requires valid type. [ " + type + " ] type is invalid");
    } else if (!StringUtils.startsWith(path, "/")) {
        throw new EnsureAuthorizableException(
                "Ensure Service User requires an absolute path. [ " + path + " ] path is invalid");
    } else if (privilegeNames.size() < 1) {
        throw new EnsureAuthorizableException("Ensure Service User requires at least 1 privilege to apply.");
    }/*from ww  w .j  a  v  a 2s .com*/
}

From source file:com.adobe.acs.commons.replication.dispatcher.DispatcherFlushFilter.java

/**
 * Checks if the agent has a valid dispatcher headers.
 *
 * @param agent Agent to check/*from  w  w  w. j a  va 2  s .com*/
 * @return true if the Agent's headers contain the proper values
 */
private boolean isDispatcherHeaders(final Agent agent) {
    final ValueMap properties = agent.getConfiguration().getProperties();
    final String[] headers = properties.get(AgentConfig.PROTOCOL_HTTP_HEADERS, new String[] {});

    for (final String header : headers) {
        if (StringUtils.startsWith(header, CQ_ACTION_HEADER)) {
            return true;
        }
    }

    return false;
}

From source file:com.steeleforge.aem.ironsites.wcm.page.IronSitemap.java

/**
 * Link generation to support internal and external links. Supports URI=Title format.
 * //w  ww  .  jav a2  s.  c  o m
 * @param pageManger CQ API PageManager
 * @param path direct or relative URI
 * @param level sitemap level
 */
private Link createLink(PageManager pageManager, String path, int level) {
    Link link = null;
    // internal links
    if (StringUtils.startsWith(path, "/")) {
        Page page = pageManager.getPage(path);
        // prevent non-existent, invalid, and hidden pages
        if (getFilter().includes(page)) {
            link = new Link(WCMUtil.getPageURL(request, page.getPath()), WCMUtil.getPageTitle(page), level);
        }
    } else {
        // support external links with URL=title format
        String[] parts = StringUtils.split(path, "=");
        if (parts.length > 1) {
            link = new Link(WCMUtil.getExternalURL(request, parts[0], null, null), parts[1], level);
        } else {
            link = new Link(WCMUtil.getExternalURL(request, parts[0], null, null), parts[0], level);
        }
    }
    return link;
}

From source file:com.activecq.experiments.redis.impl.RedisResourceProviderImpl.java

/**
 * Checks if this Resource Provider is willing to handle the resource path
 *
 * @param path/*from   ww  w.ja  v a  2  s . co  m*/
 * @return
 */
protected boolean accepts(String path) {
    for (String root : this.roots) {
        if (StringUtils.startsWith(path, root.concat("/")) || this.isRoot(path)) {
            return true;
        }
    }

    return false;
}

From source file:ddf.catalog.transformer.input.tika.TikaInputTransformer.java

@Override
public Metacard transform(InputStream input, String id) throws IOException, CatalogTransformerException {
    LOGGER.debug("Transforming input stream using Tika.");

    if (input == null) {
        throw new CatalogTransformerException("Cannot transform null input.");
    }/*w w  w.  j ava 2s.co  m*/

    try (FileBackedOutputStream fileBackedOutputStream = new FileBackedOutputStream(1000000)) {
        try {
            IOUtils.copy(input, fileBackedOutputStream);
        } catch (IOException e) {
            throw new CatalogTransformerException("Could not copy bytes of content message.", e);
        }

        Parser parser = new AutoDetectParser();
        ToXMLContentHandler handler = new ToXMLContentHandler();
        TikaMetadataExtractor tikaMetadataExtractor = new TikaMetadataExtractor(parser, handler);

        Metadata metadata;
        try (InputStream inputStreamCopy = fileBackedOutputStream.asByteSource().openStream()) {
            metadata = tikaMetadataExtractor.parseMetadata(inputStreamCopy, new ParseContext());
        }

        String metadataText = handler.toString();
        if (templates != null) {
            metadataText = transformToXml(metadataText);
        }

        Metacard metacard = MetacardCreator.createBasicMetacard(metadata, id, metadataText);

        String metacardContentType = metacard.getContentTypeName();
        if (StringUtils.startsWith(metacardContentType, "image")) {
            try (InputStream inputStreamCopy = fileBackedOutputStream.asByteSource().openStream()) {
                createThumbnail(inputStreamCopy, metacard);
            }
        }

        LOGGER.debug("Finished transforming input stream using Tika.");
        return metacard;
    }
}

From source file:hydrograph.ui.expression.editor.composites.FunctionsComposite.java

private void performSelectionActivity(List methodsList) {
    if (methodsList.getItemCount() != 0
            && !StringUtils.startsWith(methodsList.getItem(0), Messages.CANNOT_SEARCH_INPUT_STRING)) {
        MethodDetails methodDetails = (MethodDetails) methodsList
                .getData(String.valueOf(methodsList.getSelectionIndex()));
        if (methodDetails != null && StringUtils.isNotBlank(methodDetails.getJavaDoc())) {
            descriptionStyledText.setText(methodDetails.getJavaDoc());
        } else {// w w  w.  j  av a  2  s.  com
            descriptionStyledText.setText(Messages.JAVA_DOC_NOT_AVAILABLE);
        }
    } else {

    }

}

From source file:com.nridge.ds.content.ds_content.ContentExtractor.java

/**
 * Returns a typed value for the property name identified
 * or the default value (if unmatched)./*from  w  ww.  j  a  v  a  2 s  .  com*/
 *
 * @param aSuffix Property name suffix.
 * @param aDefaultValue Default value to return if property
 *                      name is not matched.
 *
 * @return Value of the property.
 */
public int getCfgInteger(String aSuffix, int aDefaultValue) {
    String propertyName;

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

    return mAppMgr.getInt(propertyName, aDefaultValue);
}