org.springframework.core.io.support
Class PathMatchingResourcePatternResolver

java.lang.Object
  extended byorg.springframework.core.io.support.PathMatchingResourcePatternResolver
All Implemented Interfaces:
ResourcePatternResolver

public class PathMatchingResourcePatternResolver
extends java.lang.Object
implements ResourcePatternResolver

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.

Since:
01.05.2004
Author:
Juergen Hoeller
See Also:
PathMatcher, ResourceLoader.getResource(java.lang.String)

Field Summary
protected  org.apache.commons.logging.Log logger
           
 
Constructor Summary
PathMatchingResourcePatternResolver(ResourceLoader resourceLoader)
          Create 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.
 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

logger

protected final org.apache.commons.logging.Log logger
Constructor Detail

PathMatchingResourcePatternResolver

public PathMatchingResourcePatternResolver(ResourceLoader resourceLoader)
Create new PathMatchingResourcePatternResolver.

Parameters:
resourceLoader - ResourceLoader to load root directories and actual resources with
Method Detail

getResources

public Resource[] getResources(java.lang.String locationPattern)
                        throws java.io.IOException
Description copied from interface: ResourcePatternResolver
Resolve the given location pattern into Resource objects.

Specified by:
getResources in interface ResourcePatternResolver
Parameters:
locationPattern - the location pattern to resolve
Returns:
the corresponding Resource objects
Throws:
java.io.IOException - in case of I/O errors

determineRootDir

protected java.lang.String determineRootDir(java.lang.String location)
Determine the root directory for the given 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.

Parameters:
location - the location to check
Returns:
the part of the location that denotes the root directory
See Also:
retrieveMatchingFiles(java.io.File, java.lang.String)

retrieveMatchingFiles

protected java.util.List retrieveMatchingFiles(java.io.File rootDir,
                                               java.lang.String pattern)
                                        throws java.io.IOException
Retrieve files that match the given path pattern, checking the given directory and its subdirectories.

Parameters:
rootDir - the directory to start from
pattern - the pattern to match against, relative to the root directory
Returns:
the List of matching File instances
Throws:
java.io.IOException - if directory contents could not be retrieved

doRetrieveMatchingFiles

protected void doRetrieveMatchingFiles(java.lang.String fullPattern,
                                       java.io.File dir,
                                       java.util.List result)
                                throws java.io.IOException
Recursively retrieve files that match the given pattern, adding them to the given result list.

Parameters:
fullPattern - the pattern to match against, with preprended root directory path
dir - the current directory
result - the list of matching files to add to
Throws:
java.io.IOException - if directory contents could not be retrieved


Copyright (C) 2003-2004 The Spring Framework Project.