Top Description Fields Constructors Methods
org.springframework.web.context.support

public Class ServletContextResourcePatternResolver

extends PathMatchingResourcePatternResolver
Class Inheritance
Imports
java.io.IOException, java.util.Enumeration, .LinkedHashSet, .Set, java.util.jar.JarEntry, .JarFile, jakarta.servlet.ServletContext, org.apache.commons.logging.Log, .LogFactory, org.springframework.core.io.Resource, .ResourceLoader, .UrlResource, org.springframework.core.io.support.PathMatchingResourcePatternResolver, org.springframework.util.ResourceUtils, .StringUtils

ServletContext-aware subclass of PathMatchingResourcePatternResolver, able to find matching resources below the web application root directory via ServletContext#getResourcePaths. Falls back to the superclass' file system checking for other resources.
Author
Juergen Hoeller
Since
1.1.2

Field Summary

Modifier and TypeField and Description
private static final Log

Constructor Summary

AccessConstructor and Description
public
ServletContextResourcePatternResolver(ServletContext
the ServletContext to load resources with
servletContext
)

Create a new ServletContextResourcePatternResolver.

public
ServletContextResourcePatternResolver(ResourceLoader
the ResourceLoader to load root directories and actual resources with
resourceLoader
)

Create a new ServletContextResourcePatternResolver.

Method Summary

Modifier and TypeMethod and Description
protected Set<Resource>
doFindPathMatchingFileResources(Resource
the root directory as a Resource
rootDirResource
,
String
the sub pattern to match (below the root directory)
subPattern
)

Overrides org.springframework.core.io.support.PathMatchingResourcePatternResolver.doFindPathMatchingFileResources.

Overridden version which checks for ServletContextResource and uses ServletContext.getResourcePaths to find matching resources below the web application root directory.

private void
doRetrieveMatchingJarEntries(String
the path to the jar file
jarFilePath
,
String
the pattern for jar entries to match
entryPattern
,
Set<Resource>
the Set of matching Resources to add to
result
)

Extract entries from the given jar by pattern.

protected void
doRetrieveMatchingServletContextResources(ServletContext
the ServletContext to work on
servletContext
,
String
the pattern to match against, with prepended root directory path
fullPattern
,
String
the current directory
dir
,
Set<Resource>
the Set of matching Resources to add to
result
)

Recursively retrieve ServletContextResources that match the given pattern, adding them to the given result set.

Inherited from org.springframework.core.io.support.PathMatchingResourcePatternResolver:
addAllClassLoaderJarRootsaddClassPathManifestEntriesconvertClassLoaderURLdetermineRootDirdoFindAllClassPathResourcesdoFindPathMatchingJarResourcesfindAllClassPathResourcesfindAllModulePathResourcesfindPathMatchingResourcesgetClassLoadergetJarFilegetPathMatchergetResourcegetResourceLoadergetResourcesisJarResourceresolveRootDirResourcesetPathMatcher

Field Detail

loggerback to summary
private static final Log logger

Hides org.springframework.core.io.support.PathMatchingResourcePatternResolver.logger.

Constructor Detail

ServletContextResourcePatternResolverback to summary
public ServletContextResourcePatternResolver(ServletContext servletContext)

Create a new ServletContextResourcePatternResolver.

Parameters
servletContext:ServletContext

the ServletContext to load resources with

See Also
ServletContextResourceLoader#ServletContextResourceLoader(jakarta.servlet.ServletContext)
ServletContextResourcePatternResolverback to summary
public ServletContextResourcePatternResolver(ResourceLoader resourceLoader)

Create a new ServletContextResourcePatternResolver.

Parameters
resourceLoader:ResourceLoader

the ResourceLoader to load root directories and actual resources with

Method Detail

doFindPathMatchingFileResourcesback to summary
protected Set<Resource> doFindPathMatchingFileResources(Resource rootDirResource, String subPattern) throws IOException

Overrides org.springframework.core.io.support.PathMatchingResourcePatternResolver.doFindPathMatchingFileResources.

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.

Parameters
rootDirResource:Resource

Doc from org.springframework.core.io.support.PathMatchingResourcePatternResolver.doFindPathMatchingFileResources.

the root directory as a Resource

subPattern:String

Doc from org.springframework.core.io.support.PathMatchingResourcePatternResolver.doFindPathMatchingFileResources.

the sub pattern to match (below the root directory)

Returns:Set<Resource>

Doc from org.springframework.core.io.support.PathMatchingResourcePatternResolver.doFindPathMatchingFileResources.

a mutable Set of matching Resource instances

Annotations
@Override
Exceptions
IOException:

Doc from org.springframework.core.io.support.PathMatchingResourcePatternResolver.doFindPathMatchingFileResources.

in case of I/O errors

See Also
doRetrieveMatchingServletContextResources, ServletContextResource, jakarta.servlet.ServletContext#getResourcePaths
doRetrieveMatchingJarEntriesback to summary
private void doRetrieveMatchingJarEntries(String jarFilePath, String entryPattern, Set<Resource> result)

Extract entries from the given jar by pattern.

Parameters
jarFilePath:String

the path to the jar file

entryPattern:String

the pattern for jar entries to match

result:Set<Resource>

the Set of matching Resources to add to

doRetrieveMatchingServletContextResourcesback to summary
protected void doRetrieveMatchingServletContextResources(ServletContext servletContext, String fullPattern, String dir, Set<Resource> result) throws IOException

Recursively retrieve ServletContextResources that match the given pattern, adding them to the given result set.

Parameters
servletContext:ServletContext

the ServletContext to work on

fullPattern:String

the pattern to match against, with prepended root directory path

dir:String

the current directory

result:Set<Resource>

the Set of matching Resources to add to

Exceptions
IOException:
if directory contents could not be retrieved
See Also
ServletContextResource, jakarta.servlet.ServletContext#getResourcePaths