public class PathMatchingResourcePatternResolver extends java.lang.Object implements ResourcePatternResolver
Title: PathMatchingResourcePatternResolver.java
Description:
bboss workgroup
Copyright (c) 2007
CLASSPATH_ALL_URL_PREFIXCLASSPATH_URL_PREFIX| Constructor and Description |
|---|
PathMatchingResourcePatternResolver()
Create a new PathMatchingResourcePatternResolver with a DefaultResourceLoader.
|
PathMatchingResourcePatternResolver(java.lang.ClassLoader classLoader)
Create a new PathMatchingResourcePatternResolver with a DefaultResourceLoader.
|
PathMatchingResourcePatternResolver(ResourceLoader resourceLoader)
Create a new PathMatchingResourcePatternResolver.
|
| Modifier and Type | Method and Description |
|---|---|
protected Resource |
convertClassLoaderURL(java.net.URL url)
Convert the given URL as returned from the ClassLoader into a Resource object.
|
protected java.lang.String |
determineRootDir(java.lang.String location)
Determine the root directory for the given location.
|
protected java.util.Set |
doFindMatchingFileSystemResources(java.io.File rootDir,
java.lang.String subPattern)
Find all resources in the file system that match the given location pattern
via the Ant-style PathMatcher.
|
protected java.util.Set |
doFindPathMatchingFileResources(Resource rootDirResource,
java.lang.String subPattern)
Find all resources in the file system that match the given location pattern
via the Ant-style PathMatcher.
|
protected java.util.Set |
doFindPathMatchingJarResources(Resource rootDirResource,
java.lang.String subPattern)
Find all resources in jar files that match the given location pattern
via the Ant-style PathMatcher.
|
protected void |
doRetrieveMatchingFiles(java.lang.String fullPattern,
java.io.File dir,
java.util.Set result)
Recursively retrieve files that match the given pattern,
adding them to the given result list.
|
protected Resource[] |
findAllClassPathResources(java.lang.String location)
Find all class location resources with the given location via the ClassLoader.
|
protected Resource[] |
findPathMatchingResources(java.lang.String locationPattern)
Find all resources that match the given location pattern via the
Ant-style PathMatcher.
|
java.lang.ClassLoader |
getClassLoader()
Return the ClassLoader that this pattern resolver works with
(never
null). |
protected java.util.jar.JarFile |
getJarFile(java.lang.String jarFileUrl)
Resolve the given jar file URL into a JarFile object.
|
PathMatcher |
getPathMatcher()
Return the PathMatcher that this resource pattern resolver uses.
|
Resource |
getResource(java.lang.String location)
Return a Resource handle for the specified resource.
|
ResourceLoader |
getResourceLoader()
Return the ResourceLoader that this pattern resolver works with.
|
Resource[] |
getResources(java.lang.String locationPattern)
Resolve the given location pattern into Resource objects.
|
protected boolean |
isJarResource(Resource resource)
Return whether the given resource handle indicates a jar resource
that the
doFindPathMatchingJarResources method can handle. |
protected Resource |
resolveRootDirResource(Resource original)
Resolve the specified resource for path matching.
|
protected java.util.Set |
retrieveMatchingFiles(java.io.File rootDir,
java.lang.String pattern)
Retrieve files that match the given path pattern,
checking the given directory and its subdirectories.
|
void |
setPathMatcher(PathMatcher pathMatcher)
Set the PathMatcher implementation to use for this
resource pattern resolver.
|
public PathMatchingResourcePatternResolver()
ClassLoader access will happen via the thread context class loader.
DefaultResourceLoaderpublic PathMatchingResourcePatternResolver(java.lang.ClassLoader classLoader)
classLoader - the ClassLoader to load classpath resources with,
or null for using the thread context class loaderDefaultResourceLoaderpublic PathMatchingResourcePatternResolver(ResourceLoader resourceLoader)
ClassLoader access will happen via the thread context class loader.
resourceLoader - the ResourceLoader to load root directories and
actual resources withpublic ResourceLoader getResourceLoader()
public java.lang.ClassLoader getClassLoader()
null).getClassLoader in interface ResourceLoadernull)public void setPathMatcher(PathMatcher pathMatcher)
org.frameworkset.web.util.AntPathMatcherpublic PathMatcher getPathMatcher()
public Resource getResource(java.lang.String location)
ResourceLoaderInputStreamSource.getInputStream() calls.
Note that a Resource handle does not imply an existing resource;
you need to invoke Resource.exists() to check for existence.
getResource in interface ResourceLoaderlocation - the resource locationResourceLoader.CLASSPATH_URL_PREFIX,
Resource.exists(),
InputStreamSource.getInputStream()public Resource[] getResources(java.lang.String locationPattern) throws java.io.IOException
ResourcePatternResolverOverlapping resource entries that point to the same physical resource should be avoided, as far as possible. The result should have set semantics.
getResources in interface ResourcePatternResolverlocationPattern - the location pattern to resolvejava.io.IOException - in case of I/O errorsprotected Resource[] findAllClassPathResources(java.lang.String location) throws java.io.IOException
location - the absolute path within the classpathjava.io.IOException - in case of I/O errorsClassLoader.getResources(java.lang.String),
convertClassLoaderURL(java.net.URL)protected Resource convertClassLoaderURL(java.net.URL url)
The default implementation simply creates a UrlResource instance.
url - a URL as returned from the ClassLoaderClassLoader.getResources(java.lang.String),
Resourceprotected Resource[] findPathMatchingResources(java.lang.String locationPattern) throws java.io.IOException
locationPattern - the location pattern to matchjava.io.IOException - in case of I/O errorsdoFindPathMatchingJarResources(org.frameworkset.util.io.Resource, java.lang.String),
doFindPathMatchingFileResources(org.frameworkset.util.io.Resource, java.lang.String),
PathMatcherprotected java.lang.String determineRootDir(java.lang.String location)
Used for determining the starting point for file matching,
resolving the root directory location to a java.io.File
and passing it into retrieveMatchingFiles, with the
remainder of the location as pattern.
Will return "/WEB-INF" for the pattern "/WEB-INF/*.xml", for example.
location - the location to checkretrieveMatchingFiles(java.io.File, java.lang.String)protected Resource resolveRootDirResource(Resource original) throws java.io.IOException
The default implementation detects an Equinox OSGi "bundleresource:" / "bundleentry:" URL and resolves it into a standard jar file URL that can be traversed using 's standard jar file traversal algorithm.
original - the resource to resolfejava.io.IOException - in case of resolution failureprotected boolean isJarResource(Resource resource) throws java.io.IOException
doFindPathMatchingJarResources method can handle.
The default implementation checks against the URL protocols "jar", "zip" and "wsjar" (the latter are used by BEA WebLogic Server and IBM WebSphere, respectively, but can be treated like jar files).
resource - the resource handle to check
(usually the root directory to start path matching from)java.io.IOExceptiondoFindPathMatchingJarResources(org.frameworkset.util.io.Resource, java.lang.String),
ResourceUtils.isJarURL(java.net.URL)protected java.util.Set doFindPathMatchingJarResources(Resource rootDirResource, java.lang.String subPattern) throws java.io.IOException
rootDirResource - the root directory as ResourcesubPattern - the sub pattern to match (below the root directory)java.io.IOException - in case of I/O errorsJarURLConnection,
PathMatcherprotected java.util.jar.JarFile getJarFile(java.lang.String jarFileUrl)
throws java.io.IOException
java.io.IOExceptionprotected java.util.Set doFindPathMatchingFileResources(Resource rootDirResource, java.lang.String subPattern) throws java.io.IOException
rootDirResource - the root directory as ResourcesubPattern - the sub pattern to match (below the root directory)java.io.IOException - in case of I/O errorsretrieveMatchingFiles(java.io.File, java.lang.String),
PathMatcherprotected java.util.Set doFindMatchingFileSystemResources(java.io.File rootDir,
java.lang.String subPattern)
throws java.io.IOException
rootDir - the root directory in the file systemsubPattern - the sub pattern to match (below the root directory)java.io.IOException - in case of I/O errorsretrieveMatchingFiles(java.io.File, java.lang.String),
PathMatcherprotected java.util.Set retrieveMatchingFiles(java.io.File rootDir,
java.lang.String pattern)
throws java.io.IOException
rootDir - the directory to start frompattern - the pattern to match against,
relative to the root directoryjava.io.IOException - if directory contents could not be retrievedprotected void doRetrieveMatchingFiles(java.lang.String fullPattern,
java.io.File dir,
java.util.Set result)
throws java.io.IOException
fullPattern - the pattern to match against,
with preprended root directory pathdir - the current directoryresult - the Set of matching File instances to add tojava.io.IOException - if directory contents could not be retrieved