[OmniFaces utilities] The
isDirectory()
method checks if the given resource path obtained from ServletContext#getResourcePaths(String)
represents a directory.Method:
Usage:
Below you can see a recursive example of using the ResourcePaths#isDirectory():
import
org.omnifaces.util.ResourcePaths;
...
ServletContext
servletContext = (ServletContext) Faces.getExternalContext().getContext();
Set<String>
resourcePaths = servletContext.getResourcePaths("/resources");
scanPaths(servletContext,
resourcePaths);
public void
scanPaths(ServletContext servletContext, Set<String> resourcePaths) {
resourcePaths.stream().forEach((resourcePath)
-> {
if (ResourcePaths.isDirectory(resourcePath)) {
LOG.log(Level.INFO, "Found directory:
{0}", resourcePath);
scanPaths(servletContext,
servletContext.getResourcePaths(resourcePath));
} else {
LOG.log(Level.INFO, "Found file:
{0}", resourcePath);
}
});
}
Some
output sample:
Found
directory: /resources/default/
Found
directory: /resources/default/css/
Found file:
/resources/default/css/rafa.css
Found
directory: /resources/default/images/
Found file:
/resources/default/images/rafa.jpg
Found
directory: /resources/default/videos/
Found file:
/resources/default/videos/rafa.avi
...
Niciun comentariu :
Trimiteți un comentariu