Class AssetUrlGenerationHelper
java.lang.Object
com.broadleafcommerce.asset.service.support.AssetUrlGenerationHelper
A class containing convenience methods pertaining to the generation of
Asset.getUrl()
.- Author:
- Samarth Dhruva (samarthd)
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionapplyIncrementingSuffix
(String assetUrl, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Accepts anassetUrl
(this should typically be the output ofcreateUrl(String, String)
) and suffixes it with an incrementing integer value if it is found to be in use by other assets.Accepts a filename and strips any path prefix from it, returning just the file's actual name prefixed with a"/"
.If no folder name is passed, accepts a filename and strips any path prefix from it, returning just the file's actual name prefixed with a"/"
.protected AssetService<Asset>
-
Constructor Details
-
AssetUrlGenerationHelper
-
-
Method Details
-
createUrl
Accepts a filename and strips any path prefix from it, returning just the file's actual name prefixed with a"/"
. For example:- "name" becomes "/name"
- "/name" becomes "/name"
- "/name/" becomes "/name"
- "/some/path/name" becomes "/name"
- "\some\path\name" becomes "/name"
- "\some\path\name\" becomes "/name"
- Returns:
- the file name with path prefixes removed and replaced by just a single
"/"
prefix - Throws:
IllegalArgumentException
- if the filename only contains whitespace and file separator characters
-
createUrl
If no folder name is passed, accepts a filename and strips any path prefix from it, returning just the file's actual name prefixed with a"/"
. If a folder name is passed, accepts the filename and folder name/path and generates a complete url path. For example:- filename "name" becomes "/name"
- filename "name" & folder name "folder" becomes "/folder/name"
- filename "name" & folder path "folder/folder" becomes "/folder/folder/name"
- filename "/name" becomes "/name"
- filename "/name/" becomes "/name"
- filename "/some/path/name" becomes "/name"
- filename "\some\path\name" becomes "/name"
- filename "\some\path\name\" becomes "/name"
- Returns:
- the file name with path prefixes removed and replaced by just a single
"/"
prefix - Throws:
IllegalArgumentException
- if the filename only contains whitespace and file separator characters
-
applyIncrementingSuffix
public String applyIncrementingSuffix(@NonNull String assetUrl, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Accepts anassetUrl
(this should typically be the output ofcreateUrl(String, String)
) and suffixes it with an incrementing integer value if it is found to be in use by other assets.For example, if
assetUrl
is "/url.txt", and "/url.txt" exists in the data store, then the returned value is "/url-1.txt".If "/url-1.txt" exists in the data store, then the returned value is "/url-2.txt".
If "/url.txt" does not already exist in the data store, then the returned value is just "/url.txt".
This method relies on
AssetService.readByUrlStartsWithAndStorageType(String, String, ContextInfo)
to find duplicates in the data store.- Parameters:
assetUrl
- the asset URL for which duplicates need to be identified, and to which the incrementing suffix should be appliedcontextInfo
- context information surrounding the sandboxing and mulittenant state- Returns:
- the given asset URL, with an incrementing suffix appended to it if there are duplicates present in the data store
-
getAssetService
-