org.apache.catalina.util.ResourceSet Java Examples

The following examples show how to use org.apache.catalina.util.ResourceSet. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FileResourceSet.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Override
public Set<String> listWebAppPaths(String path) {
    checkPath(path);

    ResourceSet<String> result = new ResourceSet<>();

    if (path.charAt(path.length() - 1) != '/') {
        path = path + '/';
    }
    String webAppMount = getWebAppMount();

    if (webAppMount.startsWith(path)) {
        webAppMount = webAppMount.substring(path.length());
        if (webAppMount.equals(getFileBase().getName())) {
            result.add(path + getFileBase().getName());
        } else {
            // Virtual directory
            int i = webAppMount.indexOf('/');
            if (i > 0) {
                result.add(path + webAppMount.substring(0, i + 1));
            }
        }
    }

    result.setLocked(true);
    return result;
}
 
Example #2
Source File: DirResourceSet.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Override
public Set<String> listWebAppPaths(String path) {
    checkPath(path);
    String webAppMount = getWebAppMount();
    ResourceSet<String> result = new ResourceSet<>();
    if (path.startsWith(webAppMount)) {
        File f = file(path.substring(webAppMount.length()), true);
        if (f != null) {
            File[] list = f.listFiles();
            if (list != null) {
                for (File entry : list) {
                    StringBuilder sb = new StringBuilder(path);
                    if (path.charAt(path.length() - 1) != '/') {
                        sb.append('/');
                    }
                    sb.append(entry.getName());
                    if (entry.isDirectory()) {
                        sb.append('/');
                    }
                    result.add(sb.toString());
                }
            }
        }
    } else {
        if (!path.endsWith("/")) {
            path = path + "/";
        }
        if (webAppMount.startsWith(path)) {
            int i = webAppMount.indexOf('/', path.length());
            if (i == -1) {
                result.add(webAppMount + "/");
            } else {
                result.add(webAppMount.substring(0, i + 1));
            }
        }
    }
    result.setLocked(true);
    return result;
}
 
Example #3
Source File: ApplicationContext.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Internal implementation of getResourcesPath() logic.
 *
 * @param resources Directory context to search
 * @param path Collection path
 */
private Set<String> getResourcePathsInternal(DirContext resources,
        String path) {

    ResourceSet<String> set = new ResourceSet<String>();
    try {
        listCollectionPaths(set, resources, path);
    } catch (NamingException e) {
        return (null);
    }
    set.setLocked(true);
    return (set);

}
 
Example #4
Source File: ApplicationContext.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Internal implementation of getResourcesPath() logic.
 *
 * @param resources Directory context to search
 * @param path Collection path
 */
private Set<String> getResourcePathsInternal(DirContext resources,
        String path) {

    ResourceSet<String> set = new ResourceSet<String>();
    try {
        listCollectionPaths(set, resources, path);
    } catch (NamingException e) {
        return (null);
    }
    set.setLocked(true);
    return (set);

}
 
Example #5
Source File: AbstractArchiveResourceSet.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
@Override
public final Set<String> listWebAppPaths(String path) {
    checkPath(path);
    String webAppMount = getWebAppMount();

    ResourceSet<String> result = new ResourceSet<>();
    if (path.startsWith(webAppMount)) {
        String pathInJar =
                getInternalPath() + path.substring(webAppMount.length());
        // Always strip off the leading '/' to get the JAR path and make
        // sure it ends in '/'
        if (pathInJar.length() > 0) {
            if (pathInJar.charAt(pathInJar.length() - 1) != '/') {
                pathInJar = pathInJar.substring(1) + '/';
            }
            if (pathInJar.charAt(0) == '/') {
                pathInJar = pathInJar.substring(1);
            }
        }

        for (String name : getArchiveEntries(false).keySet()) {
            if (name.length() > pathInJar.length() && name.startsWith(pathInJar)) {
                int nextSlash = name.indexOf('/', pathInJar.length());
                if (nextSlash != -1 && nextSlash != name.length() - 1) {
                    name = name.substring(0, nextSlash + 1);
                }
                result.add(webAppMount + '/' + name.substring(getInternalPath().length()));
            }
        }
    } else {
        if (!path.endsWith("/")) {
            path = path + "/";
        }
        if (webAppMount.startsWith(path)) {
            int i = webAppMount.indexOf('/', path.length());
            if (i == -1) {
                result.add(webAppMount + "/");
            } else {
                result.add(webAppMount.substring(0, i + 1));
            }
        }
    }
    result.setLocked(true);
    return result;
}