public class ContentBasedVersionStrategy extends AbstractVersionStrategy
VersionStrategy
that handles version strings as a Hex MD5 hash in resource file names.
For example the path "styles/foo-e36d2e05253c6c7085a91522ce43a0b4.css" will match to "styles/foo.css" assuming the hash computed from the content of "foo.css" matches the hash in the path.
VersionResourceResolver
logger
Constructor and Description |
---|
ContentBasedVersionStrategy() |
Modifier and Type | Method and Description |
---|---|
java.lang.String |
addVersionToUrl(java.lang.String baseUrl,
java.util.List<? extends Resource> locations,
ResourceResolverChain chain)
Adds a version string to the given baseUrl.
|
private java.lang.String |
calculateHash(Resource resource) |
java.lang.String |
deleteVersionFromPath(java.lang.String requestPath,
java.lang.String candidateVersion)
Deletes the given candidate version string from the given request path.
|
java.lang.String |
extractVersionFromPath(java.lang.String requestPath)
Extracts a version string from the request path.
|
boolean |
resourceVersionMatches(Resource baseResource,
java.lang.String candidateVersion)
Checks whether the given
Resource matches the candidate version string. |
addVersionAsPrefix, addVersionToFilename, deleteVersionAsPrefix, deleteVersionFromFilename, extractVersionAsPrefix, extractVersionFromFilename
public java.lang.String extractVersionFromPath(java.lang.String requestPath)
VersionStrategy
requestPath
- the request path of the resource being resolvedpublic java.lang.String deleteVersionFromPath(java.lang.String requestPath, java.lang.String candidateVersion)
VersionStrategy
requestPath
- the request path of the resource being resolvedcandidateVersion
- the candidate version stringpublic boolean resourceVersionMatches(Resource baseResource, java.lang.String candidateVersion)
VersionStrategy
Resource
matches the candidate version string.
Useful when the version string is managed on a per-resource basis.baseResource
- the resource to check against the given versioncandidateVersion
- the candidate version for the given resourcepublic java.lang.String addVersionToUrl(java.lang.String baseUrl, java.util.List<? extends Resource> locations, ResourceResolverChain chain)
VersionStrategy
baseUrl
- the baseUrl of the requested resourcelocations
- the resource locations to resolve resources fromchain
- the chain of resource resolversprivate java.lang.String calculateHash(Resource resource)