Class AssetStorageUtils

java.lang.Object
com.broadleafcommerce.asset.service.support.AssetStorageUtils

public class AssetStorageUtils extends Object
Utility class containing helpful functionality pertaining to the storage and processing of Assets by the StorageService.
Author:
Nathan Moore (nathandmoore)
  • Constructor Details

    • AssetStorageUtils

      public AssetStorageUtils()
  • Method Details

    • determineAssetTypeFromMimeType

      public String determineAssetTypeFromMimeType(@Nullable String mimeType)
      Takes a valid mime type (for example, "image/png") and converts it to a general DefaultAssetType for use as Asset.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 the Asset.getUrl() prepended with a tenant discriminated prefix based on the ContextInfo. This is purely a convenience method equivalent to calling prependContextAwarePrefix(String, ContextInfo) with Asset.getUrl() as the first argument.
      Parameters:
      asset - the Asset for which to create a context-aware URL
      contextInfo - context information surrounding multitenant state
      Returns:
      the Asset.getUrl() prepended with a tenant discriminated prefix based on the ContextInfo
      See Also:
    • prependContextAwarePrefix

      public String prependContextAwarePrefix(@NonNull String assetUrl, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Returns the assetUrl prepended with a tenant discriminated prefix based on the ContextInfo. This mostly delegates to getContextAwareAssetUrlPrefix(ContextInfo).

      If ContextInfo is null or has a null application ID and null tenant ID, the output will be {assetUrl}. If ContextInfo has a null application ID but present tenant ID, the output will be "/tenants/{tenantId}/" + {assetUrl}. If ContextInfo does have a application ID, the output will be "/applications/{applicationId}/" + {assetUrl}.

      Parameters:
      assetUrl - the url to which the tenant-discriminated prefix should be prepended
      contextInfo - context information surrounding multitenant state
      Returns:
      the assetUrl prepended with a tenant discriminated prefix based on the ContextInfo
      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 "". If ContextInfo has a null application ID but present tenant ID, the output will be "/tenants/{tenantId}". If ContextInfo 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 return DefaultAssetType.UNKNOWN by default.
      Parameters:
      mediaType - The parsed media type
      Returns:
      The type of asset based on the other document's extension.