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

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

Introduction

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

Prototype

public static boolean startsWithIgnoreCase(String str, String prefix) 

Source Link

Document

Case insensitive check if a String starts with a specified prefix.

Usage

From source file:ninja.text.TextImpl.java

@Override
public boolean startsWithIgnoreCase(CharSequence other) {
    return StringUtils.startsWithIgnoreCase(data.toString(), other.toString());
}

From source file:nl.nn.adapterframework.pipes.CreateRestViewPipe.java

private XmlBuilder createImagelinkElement(String srcPrefix, String href, String type, String alt) {
    XmlBuilder imagelink = new XmlBuilder("imagelink");
    if (StringUtils.startsWithIgnoreCase(href, "javascript:") || StringUtils.startsWithIgnoreCase(href, "?")) {
        imagelink.addAttribute("href", href);
    } else {/*from   w  w  w.  java 2 s . co  m*/
        imagelink.addAttribute("href", srcPrefix + href);
    }
    imagelink.addAttribute("type", type);
    imagelink.addAttribute("alt", alt);
    return imagelink;
}

From source file:nl.nn.adapterframework.util.XmlBuilder.java

public void addAttribute(String name, String value) {
    if (value != null) {
        if (name.equalsIgnoreCase("xmlns")) {
            element.setNamespace(Namespace.getNamespace(value));
        } else if (StringUtils.startsWithIgnoreCase(name, "xmlns:")) {
            String prefix = name.substring(6);
            element.addNamespaceDeclaration(Namespace.getNamespace(prefix, value));
        } else {//from  w  w  w .ja va 2 s . c om
            element.setAttribute(new Attribute(name, value));
        }
    }
}

From source file:nlp.wikipedia.lang.TemplateConfig.java

public WikipediaPageType classifyPageType(Page page) {
    switch (page.getNamespace()) {
    case 0:/*from  w  ww  .j ava2  s .  co  m*/
        String data = page.getContent();
        if (page.getContent().startsWith(" "))
            data = data.trim();

        for (String redirect : getCI18nAlias("redirect")) {
            if (StringUtils.startsWithIgnoreCase(data, redirect))
                return WikipediaPageType.REDIRECT;
        }
        if (StringUtils.startsWithIgnoreCase(data, "#REDIRECT"))
            return WikipediaPageType.REDIRECT;

        return WikipediaPageType.ARTICLE;
    case 10:
        return WikipediaPageType.TEMPLATE;
    case 14:
        return WikipediaPageType.CATEGORY;
    default:
        return WikipediaPageType.OTHER;
    }
}

From source file:org.apache.atlas.web.filters.AtlasKnoxSSOAuthenticationFilter.java

private boolean isWebUserAgent(String userAgent) {
    boolean isWeb = false;
    if (jwtProperties != null) {
        String userAgentList[] = jwtProperties.getUserAgentList();
        if (userAgentList != null && userAgentList.length > 0) {
            for (String ua : userAgentList) {
                if (StringUtils.startsWithIgnoreCase(userAgent, ua)) {
                    isWeb = true;//ww w  .  jav  a2 s  . co  m
                    break;
                }
            }
        }
    }
    return isWeb;
}

From source file:org.apache.ranger.plugin.resourcematcher.RangerAbstractResourceMatcher.java

@Override
boolean isMatch(String resourceValue, Map<String, Object> evalContext) {
    return StringUtils.startsWithIgnoreCase(resourceValue, getExpandedValue(evalContext));
}

From source file:org.apache.servicecomb.demo.signature.SignatureUtils.java

public static String genSignature(HttpServletRequestEx requestEx) {
    Hasher hasher = Hashing.sha256().newHasher();
    hasher.putString(requestEx.getRequestURI(), StandardCharsets.UTF_8);
    for (String paramName : paramNames) {
        String paramValue = requestEx.getHeader(paramName);
        if (paramValue != null) {
            hasher.putString(paramName, StandardCharsets.UTF_8);
            hasher.putString(paramValue, StandardCharsets.UTF_8);
            System.out.printf("%s %s\n", paramName, paramValue);
        }/*from w  w  w . j av a 2s  . co  m*/
    }

    if (!StringUtils.startsWithIgnoreCase(requestEx.getContentType(), MediaType.APPLICATION_FORM_URLENCODED)) {
        byte[] bytes = requestEx.getBodyBytes();
        if (bytes != null) {
            hasher.putBytes(bytes, 0, requestEx.getBodyBytesLength());
        }
    }

    return hasher.hash().toString();
}

From source file:org.apache.servicecomb.foundation.vertx.http.StandardHttpServletRequestEx.java

private Map<String, String[]> parseParameterMap() {
    // 1.post method already parsed by servlet
    // 2.not APPLICATION_FORM_URLENCODED, no need to enhance
    if (getMethod().equalsIgnoreCase(HttpMethod.POST)
            || !StringUtils.startsWithIgnoreCase(getContentType(), MediaType.APPLICATION_FORM_URLENCODED)) {
        return super.getParameterMap();
    }//from   w w w.j  a  va2 s.c o m

    Map<String, List<String>> listMap = parseUrlEncodedBody();
    mergeParameterMaptoListMap(listMap);
    return convertListMapToArrayMap(listMap);
}

From source file:org.apache.shindig.gadgets.servlet.ProxyHandler.java

/**
 * Test for presence of flash/*from  ww w  .j av  a 2 s  .c  o m*/
 *
 * @param responseContentType the Content-Type header from the HttpResponseBuilder
 * @param resultsContentType the Content-Type header from the HttpResponse
 * @return true if either content type matches that of Flash
 */
private boolean isFlash(String responseContentType, String resultsContentType) {
    return StringUtils.startsWithIgnoreCase(responseContentType, FLASH_CONTENT_TYPE)
            || StringUtils.startsWithIgnoreCase(resultsContentType, FLASH_CONTENT_TYPE);
}

From source file:org.apache.tomcat.maven.plugin.tomcat8.run.RunMojo.java

@Override
protected void enhanceContext(final Context context) throws MojoExecutionException {
    super.enhanceContext(context);

    try {//  w  ww.  ja va2  s  .c  om
        ClassLoaderEntriesCalculatorRequest request = new ClassLoaderEntriesCalculatorRequest() //
                .setDependencies(dependencies) //
                .setLog(getLog()) //
                .setMavenProject(project) //
                .setAddWarDependenciesInClassloader(addWarDependenciesInClassloader) //
                .setUseTestClassPath(useTestClasspath);
        final ClassLoaderEntriesCalculatorResult classLoaderEntriesCalculatorResult = classLoaderEntriesCalculator
                .calculateClassPathEntries(request);
        final List<String> classLoaderEntries = classLoaderEntriesCalculatorResult.getClassPathEntries();
        final List<File> tmpDirectories = classLoaderEntriesCalculatorResult.getTmpDirectories();

        final List<String> jarPaths = extractJars(classLoaderEntries);

        List<URL> urls = new ArrayList<URL>(jarPaths.size());

        for (String jarPath : jarPaths) {
            try {
                urls.add(new File(jarPath).toURI().toURL());
            } catch (MalformedURLException e) {
                throw new MojoExecutionException(e.getMessage(), e);
            }
        }

        getLog().debug("classLoaderEntriesCalculator urls: " + urls);

        final URLClassLoader urlClassLoader = new URLClassLoader(urls.toArray(new URL[urls.size()]));

        final ClassRealm pluginRealm = getTomcatClassLoader();

        context.setResources(
                new MyDirContext(new File(project.getBuild().getOutputDirectory()).getAbsolutePath(), //
                        getPath(), //
                        getLog()) {
                    @Override
                    public WebResource getClassLoaderResource(String path) {

                        log.debug("RunMojo#getClassLoaderResource: " + path);
                        URL url = urlClassLoader.getResource(StringUtils.removeStart(path, "/"));
                        // search in parent (plugin) classloader
                        if (url == null) {
                            url = pluginRealm.getResource(StringUtils.removeStart(path, "/"));
                        }

                        if (url == null) {
                            // try in reactors
                            List<WebResource> webResources = findResourcesInDirectories(path, //
                                    classLoaderEntriesCalculatorResult.getBuildDirectories());

                            // so we return the first one
                            if (!webResources.isEmpty()) {
                                return webResources.get(0);
                            }
                        }

                        if (url == null) {
                            return new EmptyResource(this, getPath());
                        }

                        return urlToWebResource(url, path);
                    }

                    @Override
                    public WebResource getResource(String path) {
                        log.debug("RunMojo#getResource: " + path);
                        return super.getResource(path);
                    }

                    @Override
                    public WebResource[] getResources(String path) {
                        log.debug("RunMojo#getResources: " + path);
                        return super.getResources(path);
                    }

                    @Override
                    protected WebResource[] getResourcesInternal(String path, boolean useClassLoaderResources) {
                        log.debug("RunMojo#getResourcesInternal: " + path);
                        return super.getResourcesInternal(path, useClassLoaderResources);
                    }

                    @Override
                    public WebResource[] getClassLoaderResources(String path) {
                        try {
                            Enumeration<URL> enumeration = urlClassLoader
                                    .findResources(StringUtils.removeStart(path, "/"));
                            List<URL> urlsFound = new ArrayList<URL>();
                            List<WebResource> webResources = new ArrayList<WebResource>();
                            while (enumeration.hasMoreElements()) {
                                URL url = enumeration.nextElement();
                                urlsFound.add(url);
                                webResources.add(urlToWebResource(url, path));
                            }
                            log.debug("RunMojo#getClassLoaderResources: " + path + " found : "
                                    + urlsFound.toString());

                            webResources.addAll(findResourcesInDirectories(path,
                                    classLoaderEntriesCalculatorResult.getBuildDirectories()));

                            return webResources.toArray(new WebResource[webResources.size()]);

                        } catch (IOException e) {
                            throw new RuntimeException(e.getMessage(), e);
                        }
                    }

                    private List<WebResource> findResourcesInDirectories(String path,
                            List<String> directories) {
                        try {
                            List<WebResource> webResources = new ArrayList<WebResource>();

                            for (String directory : directories) {

                                File file = new File(directory, path);
                                if (file.exists()) {
                                    webResources.add(urlToWebResource(file.toURI().toURL(), path));
                                }

                            }

                            return webResources;
                        } catch (MalformedURLException e) {
                            throw new RuntimeException(e.getMessage(), e);
                        }
                    }

                    private WebResource urlToWebResource(URL url, String path) {
                        JarFile jarFile = null;

                        try {
                            // url.getFile is
                            // file:/Users/olamy/mvn-repo/org/springframework/spring-web/4.0.0.RELEASE/spring-web-4.0.0.RELEASE.jar!/org/springframework/web/context/ContextLoaderListener.class

                            int idx = url.getFile().indexOf('!');

                            if (idx >= 0) {
                                String filePath = StringUtils.removeStart(url.getFile().substring(0, idx),
                                        "file:");

                                jarFile = new JarFile(filePath);

                                JarEntry jarEntry = jarFile.getJarEntry(StringUtils.removeStart(path, "/"));

                                return new JarResource(this, //
                                        getPath(), //
                                        filePath, //
                                        url.getPath().substring(0, idx), //
                                        jarEntry, //
                                        "", //
                                        null);
                            } else {
                                return new FileResource(this, webAppPath, new File(url.getFile()), true);
                            }

                        } catch (IOException e) {
                            throw new RuntimeException(e.getMessage(), e);
                        } finally {
                            IOUtils.closeQuietly(jarFile);
                        }
                    }

                });

        Runtime.getRuntime().addShutdownHook(new Thread() {
            @Override
            public void run() {
                for (File tmpDir : tmpDirectories) {
                    try {
                        FileUtils.deleteDirectory(tmpDir);
                    } catch (IOException e) {
                        // ignore
                    }
                }
            }
        });

        if (classLoaderEntries != null) {
            WebResourceSet webResourceSet = new FileResourceSet() {
                @Override
                public WebResource getResource(String path) {

                    if (StringUtils.startsWithIgnoreCase(path, "/WEB-INF/LIB")) {
                        File file = new File(StringUtils.removeStartIgnoreCase(path, "/WEB-INF/LIB"));
                        return new FileResource(context.getResources(), getPath(), file, true);
                    }
                    if (StringUtils.equalsIgnoreCase(path, "/WEB-INF/classes")) {
                        return new FileResource(context.getResources(), getPath(),
                                new File(project.getBuild().getOutputDirectory()), true);
                    }

                    File file = new File(project.getBuild().getOutputDirectory(), path);
                    if (file.exists()) {
                        return new FileResource(context.getResources(), getPath(), file, true);
                    }

                    //if ( StringUtils.endsWith( path, ".class" ) )
                    {
                        // so we search the class file in the jars
                        for (String jarPath : jarPaths) {
                            File jar = new File(jarPath);
                            if (!jar.exists()) {
                                continue;
                            }

                            try (JarFile jarFile = new JarFile(jar)) {
                                JarEntry jarEntry = (JarEntry) jarFile
                                        .getEntry(StringUtils.removeStart(path, "/"));
                                if (jarEntry != null) {
                                    return new JarResource(context.getResources(), //
                                            getPath(), //
                                            jarFile.getName(), //
                                            jar.toURI().toString(), //
                                            jarEntry, //
                                            path, //
                                            jarFile.getManifest());
                                }
                            } catch (IOException e) {
                                getLog().debug("skip error building jar file: " + e.getMessage(), e);
                            }

                        }
                    }

                    return new EmptyResource(null, path);
                }

                @Override
                public String[] list(String path) {
                    if (StringUtils.startsWithIgnoreCase(path, "/WEB-INF/LIB")) {
                        return jarPaths.toArray(new String[jarPaths.size()]);
                    }
                    if (StringUtils.equalsIgnoreCase(path, "/WEB-INF/classes")) {
                        return new String[] { new File(project.getBuild().getOutputDirectory()).getPath() };
                    }
                    return super.list(path);
                }

                @Override
                public Set<String> listWebAppPaths(String path) {

                    if (StringUtils.equalsIgnoreCase("/WEB-INF/lib/", path)) {
                        // adding outputDirectory as well?
                        return new HashSet<String>(jarPaths);
                    }

                    File filePath = new File(getWarSourceDirectory(), path);

                    if (filePath.isDirectory()) {
                        Set<String> paths = new HashSet<String>();

                        String[] files = filePath.list();
                        if (files == null) {
                            return paths;
                        }

                        for (String file : files) {
                            paths.add(file);
                        }

                        return paths;

                    } else {
                        return Collections.emptySet();
                    }
                }

                @Override
                public boolean mkdir(String path) {
                    return super.mkdir(path);
                }

                @Override
                public boolean write(String path, InputStream is, boolean overwrite) {
                    return super.write(path, is, overwrite);
                }

                @Override
                protected void checkType(File file) {
                    //super.checkType( file );
                }

            };

            context.getResources().addJarResources(webResourceSet);
        }

    } catch (TomcatRunException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }

}