Class AssetStorageUtils
java.lang.Object
com.broadleafcommerce.asset.service.support.AssetStorageUtils
Utility class containing helpful functionality pertaining to the storage and processing of
Assets
by the StorageService
.- Author:
- Nathan Moore (nathandmoore)
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected String
determineAssetTypeFromApplicationMimeType
(@NonNull com.google.common.net.MediaType mediaType) Takes the extension part of the mime type (after the slash) and determines what type of application document it is, e.g., "pdf", "json", etc.protected String
determineAssetTypeFromAudioMimeType
(@NonNull com.google.common.net.MediaType mediaType) Takes the extension part of the mime type (after the slash) and determines what type of audio document it is, e.g., "mpeg", "midi", etc.protected String
determineAssetTypeFromImageMimeType
(@NonNull com.google.common.net.MediaType mediaType) Takes the extension part of the mime type (after the slash) and determines what type of image document it is, e.g., "png", "jpeg", etc.determineAssetTypeFromMimeType
(String mimeType) Takes a valid mime type (for example, "image/png") and converts it to a generalDefaultAssetType
for use asAsset.getType()
.protected String
determineAssetTypeFromOtherMimeType
(@NonNull com.google.common.net.MediaType mediaType) Takes the extension part of the mime type (after the slash) and determines what type of other document it is.protected String
determineAssetTypeFromTextMimeType
(@NonNull com.google.common.net.MediaType mediaType) Takes the extension part of the mime type (after the slash) and determines what type of text document it is, e.g., "csv", "plain", etc.protected String
determineAssetTypeFromVideoMimeType
(@NonNull com.google.common.net.MediaType mediaType) Takes the extension part of the mime type (after the slash) and determines what type of video document it is, e.g., "webm", "mp4", etc.getContextAwareAssetUrlPrefix
(com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Returns the tenant discrimination prefix that would be applied to an asset URL for the given context.getContextAwareUrl
(Asset asset, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Returns theAsset.getUrl()
prepended with a tenant discriminated prefix based on theContextInfo
.prependContextAwarePrefix
(String assetUrl, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Returns theassetUrl
prepended with a tenant discriminated prefix based on theContextInfo
.
-
Constructor Details
-
AssetStorageUtils
public AssetStorageUtils()
-
-
Method Details
-
determineAssetTypeFromMimeType
Takes a valid mime type (for example, "image/png") and converts it to a generalDefaultAssetType
for use asAsset.getType()
.- Parameters:
mimeType
- the mime type to examine and determine the general type for- Returns:
- the best guess for the general asset type, or
DefaultAssetType.UNKNOWN
if it cannot be determined
-
getContextAwareUrl
public String getContextAwareUrl(@NonNull Asset asset, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Returns theAsset.getUrl()
prepended with a tenant discriminated prefix based on theContextInfo
. This is purely a convenience method equivalent to callingprependContextAwarePrefix(String, ContextInfo)
withAsset.getUrl()
as the first argument.- Parameters:
asset
- theAsset
for which to create a context-aware URLcontextInfo
- context information surrounding multitenant state- Returns:
- the
Asset.getUrl()
prepended with a tenant discriminated prefix based on theContextInfo
- See Also:
-
prependContextAwarePrefix
public String prependContextAwarePrefix(@NonNull String assetUrl, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Returns theassetUrl
prepended with a tenant discriminated prefix based on theContextInfo
. This mostly delegates togetContextAwareAssetUrlPrefix(ContextInfo)
.If
ContextInfo
is null or has a null application ID and null tenant ID, the output will be{assetUrl}
. IfContextInfo
has a null application ID but present tenant ID, the output will be"/tenants/{tenantId}/" + {assetUrl}
. IfContextInfo
does have a application ID, the output will be"/applications/{applicationId}/" + {assetUrl}
.- Parameters:
assetUrl
- the url to which the tenant-discriminated prefix should be prependedcontextInfo
- context information surrounding multitenant state- Returns:
- the
assetUrl
prepended with a tenant discriminated prefix based on theContextInfo
- See Also:
-
getContextAwareAssetUrlPrefix
public String getContextAwareAssetUrlPrefix(@Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Returns the tenant discrimination prefix that would be applied to an asset URL for the given context.If
ContextInfo
is null or has a null application ID and null tenant ID, the output will be""
. IfContextInfo
has a null application ID but present tenant ID, the output will be"/tenants/{tenantId}"
. IfContextInfo
does have a application ID, the output will be"/applications/{applicationId}"
.- Parameters:
contextInfo
- context information surrounding multitenant state- Returns:
- the tenant discrimination prefix that would be applied to an asset URL for the given context
- See Also:
-
determineAssetTypeFromImageMimeType
protected String determineAssetTypeFromImageMimeType(@NonNull @NonNull com.google.common.net.MediaType mediaType) Takes the extension part of the mime type (after the slash) and determines what type of image document it is, e.g., "png", "jpeg", etc.- Parameters:
mediaType
- The parsed media type- Returns:
- The type of asset based on the image document's extension.
-
determineAssetTypeFromAudioMimeType
protected String determineAssetTypeFromAudioMimeType(@NonNull @NonNull com.google.common.net.MediaType mediaType) Takes the extension part of the mime type (after the slash) and determines what type of audio document it is, e.g., "mpeg", "midi", etc.- Parameters:
mediaType
- The parsed media type- Returns:
- The type of asset based on the audio document's extension.
-
determineAssetTypeFromVideoMimeType
protected String determineAssetTypeFromVideoMimeType(@NonNull @NonNull com.google.common.net.MediaType mediaType) Takes the extension part of the mime type (after the slash) and determines what type of video document it is, e.g., "webm", "mp4", etc.- Parameters:
mediaType
- The parsed media type- Returns:
- The type of asset based on the video document's extension.
-
determineAssetTypeFromTextMimeType
protected String determineAssetTypeFromTextMimeType(@NonNull @NonNull com.google.common.net.MediaType mediaType) Takes the extension part of the mime type (after the slash) and determines what type of text document it is, e.g., "csv", "plain", etc.- Parameters:
mediaType
- The parsed media type- Returns:
- The type of asset based on the text document's extension.
-
determineAssetTypeFromApplicationMimeType
protected String determineAssetTypeFromApplicationMimeType(@NonNull @NonNull com.google.common.net.MediaType mediaType) Takes the extension part of the mime type (after the slash) and determines what type of application document it is, e.g., "pdf", "json", etc.- Parameters:
mediaType
- The parsed media type- Returns:
- The type of asset based on the application document's extension.
-
determineAssetTypeFromOtherMimeType
protected String determineAssetTypeFromOtherMimeType(@NonNull @NonNull com.google.common.net.MediaType mediaType) Takes the extension part of the mime type (after the slash) and determines what type of other document it is. This is an extension point and will returnDefaultAssetType.UNKNOWN
by default.- Parameters:
mediaType
- The parsed media type- Returns:
- The type of asset based on the other document's extension.
-