public class PathResourceResolver extends AbstractResourceResolver
ResourceResolver
that tries to find a resource under the given
locations matching to the request path.
This resolver does not delegate to the ResourceResolverChain
and is
expected to be configured at the end in a chain of resolvers.
logger
Constructor and Description |
---|
PathResourceResolver() |
Modifier and Type | Method and Description |
---|---|
protected boolean |
checkResource(Resource resource,
Resource location)
Perform additional checks on a resolved resource beyond checking whether the
resources exists and is readable.
|
Resource[] |
getAllowedLocations() |
java.util.Map<Resource,java.nio.charset.Charset> |
getLocationCharsets()
Return charsets associated with static resource locations.
|
protected Resource |
getResource(java.lang.String resourcePath,
Resource location)
Find the resource under the given location.
|
UrlPathHelper |
getUrlPathHelper()
The configured
UrlPathHelper . |
protected Resource |
resolveResourceInternal(HttpServletRequest request,
java.lang.String requestPath,
java.util.List<? extends Resource> locations,
ResourceResolverChain chain) |
protected java.lang.String |
resolveUrlPathInternal(java.lang.String resourcePath,
java.util.List<? extends Resource> locations,
ResourceResolverChain chain) |
void |
setAllowedLocations(Resource... locations)
By default when a Resource is found, the path of the resolved resource is
compared to ensure it's under the input location where it was found.
|
void |
setLocationCharsets(java.util.Map<Resource,java.nio.charset.Charset> locationCharsets)
Configure charsets associated with locations.
|
void |
setUrlPathHelper(UrlPathHelper urlPathHelper)
Provide a reference to the
UrlPathHelper used to map requests to
static resources. |
resolveResource, resolveUrlPath
public void setAllowedLocations(@Nullable Resource... locations)
CssLinkResourceTransformer
resolves public URLs of links it contains, the CSS file is the location
and the resources being resolved are css files, images, fonts and others
located in adjacent or parent directories.
This property allows configuring a complete list of locations under which resources must be so that if a resource is not under the location relative to which it was found, this list may be checked as well.
By default ResourceHttpRequestHandler
initializes this property
to match its list of locations.
locations
- the list of allowed locationsResourceHttpRequestHandler.initAllowedLocations()
public void setLocationCharsets(java.util.Map<Resource,java.nio.charset.Charset> locationCharsets)
URL resource
location the charset is used to encode the relative path
Note: the charset is used only if the
urlPathHelper
property is also configured and
its urlDecode
property is set to true.
public java.util.Map<Resource,java.nio.charset.Charset> getLocationCharsets()
public void setUrlPathHelper(@Nullable UrlPathHelper urlPathHelper)
UrlPathHelper
used to map requests to
static resources. This helps to derive information about the lookup path
such as whether it is decoded or not.@Nullable public UrlPathHelper getUrlPathHelper()
UrlPathHelper
.protected Resource resolveResourceInternal(@Nullable HttpServletRequest request, java.lang.String requestPath, java.util.List<? extends Resource> locations, ResourceResolverChain chain)
resolveResourceInternal
in class AbstractResourceResolver
protected java.lang.String resolveUrlPathInternal(java.lang.String resourcePath, java.util.List<? extends Resource> locations, ResourceResolverChain chain)
resolveUrlPathInternal
in class AbstractResourceResolver
@Nullable protected Resource getResource(java.lang.String resourcePath, Resource location) throws java.io.IOException
The default implementation checks if there is a readable
Resource
for the given path relative to the location.
resourcePath
- the path to the resourcelocation
- the location to checknull
if none foundjava.io.IOException
protected boolean checkResource(Resource resource, Resource location) throws java.io.IOException
allowed locations
.resource
- the resource to checklocation
- the location relative to which the resource was foundjava.io.IOException