|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.core.io.support.PathMatchingResourcePatternResolver
ResourcePatternResolver that applies Ant-style path matching, using Spring's PathMatcher class.
Locations can either be suitable for ResourceLoader.getResource
(URLs like "file:C:/context.xml", pseudo-URLs like "classpath:/context.xml",
relative file paths like "/WEB-INF/context.xml"), or Ant-style patterns
like "/WEB-INF/*-context.xml".
In the pattern case, the locations have to be resolvable to java.io.File, to allow for searching though the specified directory tree. In particular, this will neither work with WAR files that are not expanded nor with class path resources in a JAR file.
There is special support for retrieving multiple class path resources with the same name, via the "classpath*" prefix. For example, "classpath*:/beans.xml" will find all beans.xml files in the class path, be it in "classes" directories or in JAR files. This is particularly useful for auto-detecting config files.
If neither given a PathMatcher pattern nor a "classpath*:" location, this resolver will return a single resource via the underlying ResourceLoader.
ResourcePatternResolver.CLASSPATH_URL_PREFIX
,
PathMatcher
,
ResourceLoader.getResource(java.lang.String)
Field Summary | |
protected org.apache.commons.logging.Log |
logger
|
Fields inherited from interface org.springframework.core.io.support.ResourcePatternResolver |
CLASSPATH_URL_PREFIX |
Constructor Summary | |
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. |
|
PathMatchingResourcePatternResolver(ResourceLoader resourceLoader,
java.lang.ClassLoader classLoader)
Create a new PathMatchingResourcePatternResolver. |
Method Summary | |
protected java.lang.String |
determineRootDir(java.lang.String location)
Determine the root directory for the given location. |
protected void |
doRetrieveMatchingFiles(java.lang.String fullPattern,
java.io.File dir,
java.util.List 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[] |
findPathMatchingFileResources(java.lang.String locationPattern)
Find all file resources that match the given location pattern via the Ant-style PathMatcher utility. |
java.lang.ClassLoader |
getClassLoader()
Return the ClassLoader that this pattern resolver works with, or null if using the thread context class loader on actual access (applying to the thread that does the "getResources" call). |
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 java.util.List |
retrieveMatchingFiles(java.io.File rootDir,
java.lang.String pattern)
Retrieve files that match the given path pattern, checking the given directory and its subdirectories. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected final org.apache.commons.logging.Log logger
Constructor Detail |
public PathMatchingResourcePatternResolver()
ClassLoader access will happen via the thread context class loader on actual access (applying to the thread that does the "getResources" call)
DefaultResourceLoader
public PathMatchingResourcePatternResolver(java.lang.ClassLoader classLoader)
classLoader
- the ClassLoader to load classpath resources with,
or null for using the thread context class loader on actual access
(applying to the thread that does the "getResources" call)DefaultResourceLoader
public PathMatchingResourcePatternResolver(ResourceLoader resourceLoader)
ClassLoader access will happen via the thread context class loader on actual access (applying to the thread that does the "getResources" call)
resourceLoader
- ResourceLoader to load root directories
and actual resources withpublic PathMatchingResourcePatternResolver(ResourceLoader resourceLoader, java.lang.ClassLoader classLoader)
resourceLoader
- ResourceLoader to load root directories
and actual resources withclassLoader
- the ClassLoader to load classpath resources with,
or null for using the thread context class loader on actual access
(applying to the thread that does the "getResources" call)Method Detail |
public ResourceLoader getResourceLoader()
public java.lang.ClassLoader getClassLoader()
public Resource[] getResources(java.lang.String locationPattern) throws java.io.IOException
ResourcePatternResolver
getResources
in interface ResourcePatternResolver
locationPattern
- the location pattern to resolve
java.io.IOException
- in case of I/O errorsprotected Resource[] findAllClassPathResources(java.lang.String location) throws java.io.IOException
location
- the absolute path within the classpath
java.io.IOException
- in case of I/O errorsClassLoader.getResources(java.lang.String)
protected Resource[] findPathMatchingFileResources(java.lang.String locationPattern) throws java.io.IOException
locationPattern
- the location pattern to match
java.io.IOException
- in case of I/O errorsPathMatcher
protected 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 check
retrieveMatchingFiles(java.io.File, java.lang.String)
protected java.util.List 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 directory
java.io.IOException
- if directory contents could not be retrievedprotected void doRetrieveMatchingFiles(java.lang.String fullPattern, java.io.File dir, java.util.List result) throws java.io.IOException
fullPattern
- the pattern to match against,
with preprended root directory pathdir
- the current directoryresult
- the list of matching files to add to
java.io.IOException
- if directory contents could not be retrieved
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |