public class ClasspathResourceOrigin extends AbstractResourceOrigin<ClasspathResource>
ResourceOrigin
which loads resources from the classpath.
Because the classpath does actually not know about folders but only about classes, this origin constructs a virtual folder/file structure of ClasspathResource
s.
For this to work the origin relies on the following assumptions:
ResourceOrigin.ResourceNotFoundException
Modifier and Type | Method and Description |
---|---|
protected Collection<URL> |
classpathUrls() |
protected void |
collectResources() |
protected ClasspathResource |
createResourcesFor(String resourcePath) |
protected InputStream |
doOpenStream(ClasspathResource resource) |
protected String[] |
excludedPackages() |
protected String[] |
excludedResourcesExtensions() |
protected String[] |
excludedUrlExtensions() |
protected String |
extensionsPattern(String[] extensions) |
ClasspathResource |
getByPath(String path)
Retrieves a
Resource object based on the given path. |
protected Charset |
getCharsetFor(ClasspathResource resource)
|
protected long |
getLastModified(ClasspathResource resource) |
protected String |
getName(ClasspathResource resource) |
protected ClasspathResource |
getParent(ClasspathResource resource) |
protected String |
getPath(ClasspathResource resource) |
ClasspathResource |
getRoot()
Returns the
Resource for this origin's declared root. |
protected URL |
getUrl(ClasspathResource resource) |
boolean |
hasPath(String path) |
protected boolean |
isDirectory(ClasspathResource resource) |
protected boolean |
isFile(ClasspathResource resource) |
protected List<ClasspathResource> |
listChildren(ClasspathResource resource) |
protected ClasspathResource |
newClasspathResource(String path,
boolean isFile) |
protected String |
observedResourcesPattern() |
protected com.google.common.base.Predicate<String> |
resourcesFilter() |
protected com.google.common.base.Predicate<? super URL> |
urlsFilter() |
protected String |
validatePath(String resource)
Verifies the given path is as-expected by this origin, and "prepares" it.
|
void |
watchForChanges(ResourceVisitor visitor)
Sets up observation for this origin, and hooks it to the given callback
ResourceVisitor . |
getName, isEditable, openReader, openStream, traverseWith
public ClasspathResource getRoot()
ResourceOrigin
Resource
for this origin's declared root.public void watchForChanges(ResourceVisitor visitor)
ResourceOrigin
ResourceVisitor
.ResourceVisitor
,
PredicatedResourceVisitor
protected String observedResourcesPattern()
public ClasspathResource getByPath(String path)
ResourceOrigin
Resource
object based on the given path. The given path may or may not start with a
leading /, but will always be considered relative to whatever root path this origin uses; for the user of this
class, such paths should thus be considered absolute, depending on the implementation, they may be relative
to some other path. Directory traversal navigation should be prohibited by implementations for security reasons.public boolean hasPath(String path)
protected boolean isFile(ClasspathResource resource)
isFile
in class AbstractResourceOrigin<ClasspathResource>
Resource.isFile()
protected boolean isDirectory(ClasspathResource resource)
isDirectory
in class AbstractResourceOrigin<ClasspathResource>
Resource.isDirectory()
protected String getPath(ClasspathResource resource)
getPath
in class AbstractResourceOrigin<ClasspathResource>
Resource.getPath()
protected String getName(ClasspathResource resource)
getName
in class AbstractResourceOrigin<ClasspathResource>
Resource.getName()
protected long getLastModified(ClasspathResource resource)
getLastModified
in class AbstractResourceOrigin<ClasspathResource>
Resource.getLastModified()
protected List<ClasspathResource> listChildren(ClasspathResource resource)
listChildren
in class AbstractResourceOrigin<ClasspathResource>
Resource.listChildren()
protected ClasspathResource getParent(ClasspathResource resource)
getParent
in class AbstractResourceOrigin<ClasspathResource>
Resource.getParent()
protected InputStream doOpenStream(ClasspathResource resource) throws IOException
doOpenStream
in class AbstractResourceOrigin<ClasspathResource>
IOException
protected Charset getCharsetFor(ClasspathResource resource)
AbstractResourceOrigin
getCharsetFor
in class AbstractResourceOrigin<ClasspathResource>
protected URL getUrl(ClasspathResource resource)
protected void collectResources()
protected Collection<URL> classpathUrls()
protected com.google.common.base.Predicate<? super URL> urlsFilter()
protected com.google.common.base.Predicate<String> resourcesFilter()
protected String[] excludedUrlExtensions()
protected String[] excludedResourcesExtensions()
protected String[] excludedPackages()
protected ClasspathResource createResourcesFor(String resourcePath)
protected ClasspathResource newClasspathResource(String path, boolean isFile)
Copyright © 2003–2015 Magnolia International Ltd.. All rights reserved.