org.springframework.web.context.support
Class ServletContextResourcePatternResolver

java.lang.Object
  extended byorg.springframework.core.io.support.PathMatchingResourcePatternResolver
      extended byorg.springframework.web.context.support.ServletContextResourcePatternResolver
All Implemented Interfaces:
ResourceLoader, ResourcePatternResolver

public class ServletContextResourcePatternResolver
extends PathMatchingResourcePatternResolver

ServletContext-aware subclass of PathMatchingResourcePatternResolver, able to find matching resources below the web application root directory via Servlet 2.3's ServletContext.getResourcePaths. Falls back to the superclass' file system checking for other resources.

The advantage of using ServletContext.getResourcePaths to find matching files is that it will work in a WAR file which has not been expanded too. For Servlet containers that do not support Servlet 2.3 or above, this resolver will always fall back to file system checking, which requires an expanded WAR file.

Since:
1.1.2
Author:
Juergen Hoeller

Field Summary
 
Fields inherited from class org.springframework.core.io.support.PathMatchingResourcePatternResolver
logger
 
Fields inherited from interface org.springframework.core.io.support.ResourcePatternResolver
CLASSPATH_URL_PREFIX
 
Constructor Summary
ServletContextResourcePatternResolver(ResourceLoader resourceLoader)
          Create a new ServletContextResourcePatternResolver.
 
Method Summary
protected  List doFindPathMatchingFileResources(Resource rootDirResource, String subPattern)
          Overridden version which checks for ServletContextResource and uses ServletContext.getResourcePaths to find matching resources below the web application root directory.
protected  void doRetrieveMatchingServletContextResources(ServletContext servletContext, String fullPattern, String dir, List result)
          Recursively retrieve ServletContextResources that match the given pattern, adding them to the given result list.
 
Methods inherited from class org.springframework.core.io.support.PathMatchingResourcePatternResolver
determineRootDir, doFindPathMatchingJarResources, doRetrieveMatchingFiles, findAllClassPathResources, findPathMatchingResources, getClassLoader, getResource, getResourceLoader, getResources, retrieveMatchingFiles
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ServletContextResourcePatternResolver

public ServletContextResourcePatternResolver(ResourceLoader resourceLoader)
Create a new ServletContextResourcePatternResolver.

ClassLoader access will happen via the thread context class loader on actual access (applying to the thread that does the "getResources" call)

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

doFindPathMatchingFileResources

protected List doFindPathMatchingFileResources(Resource rootDirResource,
                                               String subPattern)
                                        throws IOException
Overridden version which checks for ServletContextResource and uses ServletContext.getResourcePaths to find matching resources below the web application root directory. In case of other resources, delegates to the superclass version.

Overrides:
doFindPathMatchingFileResources in class PathMatchingResourcePatternResolver
Parameters:
rootDirResource - the root directory as Resource
subPattern - the sub pattern to match (below the root directory)
Returns:
the List of matching Resource instances
Throws:
IOException - in case of I/O errors
See Also:
doRetrieveMatchingServletContextResources(javax.servlet.ServletContext, java.lang.String, java.lang.String, java.util.List), ServletContextResource, ServletContext.getResourcePaths(java.lang.String)

doRetrieveMatchingServletContextResources

protected void doRetrieveMatchingServletContextResources(ServletContext servletContext,
                                                         String fullPattern,
                                                         String dir,
                                                         List result)
                                                  throws IOException
Recursively retrieve ServletContextResources that match the given pattern, adding them to the given result list.

Parameters:
servletContext - the ServletContext to work on
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:
IOException - if directory contents could not be retrieved
See Also:
ServletContextResource, ServletContext.getResourcePaths(java.lang.String)


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