Example usage for org.springframework.util StringUtils getFilename

List of usage examples for org.springframework.util StringUtils getFilename

Introduction

In this page you can find the example usage for org.springframework.util StringUtils getFilename.

Prototype

@Nullable
public static String getFilename(@Nullable String path) 

Source Link

Document

Extract the filename from the given Java resource path, e.g.

Usage

From source file:org.springframework.cloud.function.deployer.ApplicationBootstrap.java

private URLClassLoader createClassLoader(Class<?> mainClass) {
    URL[] urls = findClassPath(mainClass);
    if (urls.length == 1) {
        URL[] classpath = extractClasspath(urls[0]);
        if (classpath != null) {
            urls = classpath;//from  w  ww  .j  a  v a2s. c  om
        }
    }
    List<URL> child = new ArrayList<>();
    List<URL> parent = new ArrayList<>();
    for (URL url : urls) {
        child.add(url);
    }
    for (URL url : urls) {
        if (isRoot(StringUtils.getFilename(clean(url.toString())))) {
            parent.add(url);
            child.remove(url);
        }
    }
    logger.debug("Parent: " + parent);
    logger.debug("Child: " + child);
    ClassLoader base = getClass().getClassLoader();
    if (!parent.isEmpty()) {
        base = new URLClassLoader(parent.toArray(new URL[0]), base.getParent());
    }
    return new URLClassLoader(child.toArray(new URL[0]), base);
}

From source file:org.springframework.osgi.web.deployer.support.DefaultContextPathStrategy.java

private String getBundleLocation(String location) {
    // remove prefix (if there's any)
    int index = location.lastIndexOf(PREFIX_DELIMITER);
    String path = ((index > 0) ? location.substring(index + 1) : location);
    // clean up the path
    path = StringUtils.cleanPath(path);/*from w  w  w  .  ja va2  s.c  o m*/
    // check if it's a folder
    if (path.endsWith(SLASH)) {
        // remove trailing slash
        path = path.substring(0, path.length() - 1);
        int separatorIndex = path.lastIndexOf(SLASH);

        // if there is no other slash, consider the whole location, otherwise detect the folder
        path = (separatorIndex > -1 ? path.substring(separatorIndex + 1) : path);
    }
    path = StringUtils.getFilename(path);
    // remove file extension
    path = StringUtils.stripFilenameExtension(path);

    if (log.isTraceEnabled())
        log.trace("Bundle location [" + location + "] resulted in context path [" + path + "]");

    return path;
}

From source file:org.springframework.web.servlet.resource.PathExtensionResourceResolver.java

@Override
public Resource resolveResource(HttpServletRequest request, String requestPath, List<Resource> locations,
        ResourceResolverChain chain) {/*from  w  ww .j  ava2 s  .  com*/

    Resource resource = chain.resolveResource(request, requestPath, locations);
    if ((resource != null) && !this.compareTimeStamp) {
        return resource;
    }

    for (Resource location : locations) {
        String baseFilename = StringUtils.getFilename(requestPath);
        try {
            Resource basePath = location.createRelative(StringUtils.delete(requestPath, baseFilename));
            if (basePath.getFile().isDirectory()) {
                for (String fileName : basePath.getFile().list(new ExtensionFilenameFilter(baseFilename))) {
                    //Always use the first match
                    Resource matched = basePath.createRelative(fileName);
                    if ((resource == null) || (matched.lastModified() > resource.lastModified())) {
                        return matched;
                    } else {
                        return resource;
                    }
                }
            }
        } catch (IOException e) {
            logger.trace("Error occurred locating resource based on file extension mapping", e);
        }
    }

    return resource;
}