类 PathResourceResolver
java.lang.Object
cn.taketoday.web.resource.AbstractResourceResolver
cn.taketoday.web.resource.PathResourceResolver
- 所有已实现的接口:
ResourceResolver
A simple
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.
- 从以下版本开始:
- 4.0
- 作者:
- Jeremy Grelle, Rossen Stoyanchev, Sam Brannen
-
字段概要
字段修饰符和类型字段说明private cn.taketoday.core.io.Resource[]private boolean从类继承的字段 cn.taketoday.web.resource.AbstractResourceResolver
logger -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明protected booleancheckResource(cn.taketoday.core.io.Resource resource, cn.taketoday.core.io.Resource location) Perform additional checks on a resolved resource beyond checking whether the resources exists and is readable.private StringencodeOrDecodeIfNecessary(String path, RequestContext request, cn.taketoday.core.io.Resource location) cn.taketoday.core.io.Resource[]Return charsets associated with static resource locations.protected cn.taketoday.core.io.ResourcegetResource(String resourcePath, cn.taketoday.core.io.Resource location) Find the resource under the given location.private cn.taketoday.core.io.ResourcegetResource(String resourcePath, RequestContext request, List<? extends cn.taketoday.core.io.Resource> locations) private booleanisInvalidEncodedPath(String resourcePath) private booleanisResourceUnderLocation(cn.taketoday.core.io.Resource resource, cn.taketoday.core.io.Resource location) booleanWhether to decode the request URI when determining the lookup path.protected cn.taketoday.core.io.ResourceresolveResourceInternal(RequestContext request, String requestPath, List<? extends cn.taketoday.core.io.Resource> locations, ResourceResolvingChain chain) protected StringresolveUrlPathInternal(String resourcePath, List<? extends cn.taketoday.core.io.Resource> locations, ResourceResolvingChain chain) voidsetAllowedLocations(cn.taketoday.core.io.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.voidsetLocationCharsets(Map<cn.taketoday.core.io.Resource, Charset> locationCharsets) Configure charsets associated with locations.voidsetUrlDecode(boolean urlDecode) Whether the resource-path should be decodedprivate booleanshouldDecodeRelativePath(cn.taketoday.core.io.Resource location) private booleanshouldEncodeRelativePath(cn.taketoday.core.io.Resource location) 从类继承的方法 cn.taketoday.web.resource.AbstractResourceResolver
resolveResource, resolveUrlPath
-
字段详细资料
-
allowedLocations
@Nullable private cn.taketoday.core.io.Resource[] allowedLocations -
urlDecode
private boolean urlDecode -
locationCharsets
-
-
构造器详细资料
-
PathResourceResolver
public PathResourceResolver()
-
-
方法详细资料
-
setAllowedLocations
public void setAllowedLocations(@Nullable cn.taketoday.core.io.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. However sometimes that may not be the case, e.g. whenCssLinkResourceTransformerresolves 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
ResourceHttpRequestHandlerinitializes this property to match its list of locations.- 参数:
locations- the list of allowed locations- 另请参阅:
-
getAllowedLocations
@Nullable public cn.taketoday.core.io.Resource[] getAllowedLocations() -
setLocationCharsets
Configure charsets associated with locations. If a static resource is found under aURL resourcelocation the charset is used to encode the relative path -
setUrlDecode
public void setUrlDecode(boolean urlDecode) Whether the resource-path should be decoded -
isUrlDecode
public boolean isUrlDecode()Whether to decode the request URI when determining the lookup path. -
getLocationCharsets
Return charsets associated with static resource locations. -
resolveResourceInternal
protected cn.taketoday.core.io.Resource resolveResourceInternal(@Nullable RequestContext request, String requestPath, List<? extends cn.taketoday.core.io.Resource> locations, ResourceResolvingChain chain) -
resolveUrlPathInternal
protected String resolveUrlPathInternal(String resourcePath, List<? extends cn.taketoday.core.io.Resource> locations, ResourceResolvingChain chain) -
getResource
@Nullable private cn.taketoday.core.io.Resource getResource(String resourcePath, @Nullable RequestContext request, List<? extends cn.taketoday.core.io.Resource> locations) -
getResource
@Nullable protected cn.taketoday.core.io.Resource getResource(String resourcePath, cn.taketoday.core.io.Resource location) throws IOException Find the resource under the given location.The default implementation checks if there is a readable
Resourcefor the given path relative to the location.- 参数:
resourcePath- the path to the resourcelocation- the location to check- 返回:
- the resource, or
nullif none found - 抛出:
IOException
-
checkResource
protected boolean checkResource(cn.taketoday.core.io.Resource resource, cn.taketoday.core.io.Resource location) throws IOException Perform additional checks on a resolved resource beyond checking whether the resources exists and is readable. The default implementation also verifies the resource is either under the location relative to which it was found or is under one of theallowed locations.- 参数:
resource- the resource to checklocation- the location relative to which the resource was found- 返回:
- "true" if resource is in a valid location, "false" otherwise.
- 抛出:
IOException
-
isResourceUnderLocation
private boolean isResourceUnderLocation(cn.taketoday.core.io.Resource resource, cn.taketoday.core.io.Resource location) throws IOException - 抛出:
IOException
-
encodeOrDecodeIfNecessary
private String encodeOrDecodeIfNecessary(String path, @Nullable RequestContext request, cn.taketoday.core.io.Resource location) -
shouldDecodeRelativePath
private boolean shouldDecodeRelativePath(cn.taketoday.core.io.Resource location) -
shouldEncodeRelativePath
private boolean shouldEncodeRelativePath(cn.taketoday.core.io.Resource location) -
isInvalidEncodedPath
-