public class LookupAwareRelativePathResolver extends Object implements RelativePathResolver
If the relative path is not absolute (doesn't start with /) and the base path ends with / then the relative path is appended to the base path.
If the relative path is not absolute (doesn't start with /) and the base path doesn't end with / then the relative path replaces the last part of the base path.
If the relative path is absolute (starts with /) then the relative path is is used.
If the relative path has lookup prefix (like "classpath:") then this lookup prefix is used.
If the relative path has no lookup prefix then the lookup prefix of base path is used (if any).
If the relative path has different lookup prefix than base path lookup then relative path is considered like an absolute path.
description | base path | relative path | result |
---|---|---|---|
resolve as child | classpath:/template/ | images/foo.png | classpath:/template/images/foo.png |
resolve as sibling | classpath:/template/register.html | images/foo.png | classpath:/template/images/foo.png |
resolve as sibling | classpath:/template | images/foo.png | classpath:/images/foo.png |
absolute path | /template/ | /images/foo.png | /images/foo.png |
absolute path (keep lookup) | classpath:/template/ | /images/foo.png | classpath:/images/foo.png |
different lookups | classpath:/template/ | file:images/foo.png | file:images/foo.png |
This implementation that requires the list of known lookups.
Constructor and Description |
---|
LookupAwareRelativePathResolver(Map<String,List<String>> lookupsIndexedByType)
Initializes with the list of known lookups (indexed by type).
|
Modifier and Type | Method and Description |
---|---|
RelativePath |
resolve(ResourcePath source,
ResourcePath relativePath)
Resolve relative path against the base path:
|
RelativePath |
resolve(ResourcePath source,
String relativePath)
Resolve relative path against the base path:
|
public RelativePath resolve(ResourcePath source, ResourcePath relativePath)
RelativePathResolver
If the relative path is not absolute (doesn't start with /) and the base path ends with / then the relative path is appended to the base path.
If the relative path is not absolute (doesn't start with /) and the base path doesn't end with / then the relative path replaces the last part of the base path.
If the relative path is absolute (starts with /) then the relative path is is used.
If the relative path has lookup prefix (like "classpath:") then this lookup prefix is used.
If the relative path has no lookup prefix then the lookup prefix of base path is used (if any).
If the relative path has different lookup prefix than base path lookup then relative path is considered like an absolute path.
resolve
in interface RelativePathResolver
source
- the base pathrelativePath
- the relative path to resolvepublic RelativePath resolve(ResourcePath source, String relativePath)
RelativePathResolver
If the relative path is not absolute (doesn't start with /) and the base path ends with / then the relative path is appended to the base path.
If the relative path is not absolute (doesn't start with /) and the base path doesn't end with / then the relative path replaces the last part of the base path.
If the relative path is absolute (starts with /) then the relative path is is used.
If the relative path has lookup prefix (like "classpath:") then this lookup prefix is used.
If the relative path has no lookup prefix then the lookup prefix of base path is used (if any).
If the relative path has different lookup prefix than base path lookup then relative path is considered like an absolute path.
resolve
in interface RelativePathResolver
source
- the base pathrelativePath
- the relative path as string to resolveCopyright © 2021. All rights reserved.