Class AbstractResourceProcessor

java.lang.Object
org.broadleafcommerce.presentation.dialect.AbstractBroadleafTagReplacementProcessor
org.broadleafcommerce.common.web.processor.AbstractResourceProcessor
All Implemented Interfaces:
org.broadleafcommerce.presentation.dialect.BroadleafProcessor, org.broadleafcommerce.presentation.dialect.BroadleafTagReplacementProcessor
Direct Known Subclasses:
ResourceBundleProcessor, ResourcePreloadProcessor

public abstract class AbstractResourceProcessor extends org.broadleafcommerce.presentation.dialect.AbstractBroadleafTagReplacementProcessor
An abstract tag replacement processor that provides methods to help get resource/bundle information
Author:
Jacob Mitash (jmitash)
  • Field Details

    • environment

      protected org.springframework.core.env.Environment environment
    • bundlingService

      protected ResourceBundlingService bundlingService
    • resourcesRequest

      protected ResourcesRequest resourcesRequest
  • Constructor Details

    • AbstractResourceProcessor

      public AbstractResourceProcessor()
  • Method Details

    • getBundleEnabled

      protected boolean getBundleEnabled()
      Tells if bundling is enabled
      Returns:
      true if enabled, false otherwise
    • getReplacementModel

      public org.broadleafcommerce.presentation.model.BroadleafTemplateModel getReplacementModel(String tagName, Map<String,String> tagAttributes, org.broadleafcommerce.presentation.model.BroadleafTemplateContext context)
    • buildModelUnbundled

      protected abstract org.broadleafcommerce.presentation.model.BroadleafTemplateModel buildModelUnbundled(List<String> attributeFiles, ResourceTagAttributes attributes, org.broadleafcommerce.presentation.model.BroadleafTemplateContext context)
      Builds the model that contains the unbundled resources the tag should be replaced with
      Parameters:
      attributeFiles - list of files that are to be included
      attributes - the attributes of the original tag this processor replaces
      context - the context of the original tag
      Returns:
      model containing resources the tag should be replaced with
    • buildModelBundled

      protected abstract org.broadleafcommerce.presentation.model.BroadleafTemplateModel buildModelBundled(List<String> attributeFiles, ResourceTagAttributes attributes, org.broadleafcommerce.presentation.model.BroadleafTemplateContext context)
      Builds the model that contains the bundled resources the tag should be replaced with
      Parameters:
      attributeFiles - list of files that are to be bundled
      attributes - the attributes of the original tag this processor replaces
      context - the context of the original tag
      Returns:
      model containing resources the tag should be replaced with
    • getRequestedFileNames

      protected List<String> getRequestedFileNames(String rawFileNames)
      Gets a list of the requested files for bundling
      Parameters:
      rawFileNames - comma separated list of files
      Returns:
      list of requested files with space trimmed or null if rawFileNames is null
    • buildResourceTagAttributes

      protected ResourceTagAttributes buildResourceTagAttributes(Map<String,String> tagAttributes)
      Builds the tag attributes of the bundle tag
      Parameters:
      tagAttributes - the original attributes of the bundle tag
      Returns:
      a ResourceTagAttributes containing the original bundle tag attributes
    • getFullUnbundledFileName

      protected String getFullUnbundledFileName(String fileName, ResourceTagAttributes resourceTagAttributes, org.broadleafcommerce.presentation.model.BroadleafTemplateContext context)
      Gets the full path of an unbundled file.
      Parameters:
      fileName - the file name to parse
      resourceTagAttributes - the tag attributes of the original bundle tag (fileName will be used instead of src)
      context - the template context
      Returns:
      the full path of the unbundled file
    • getBundleUrl

      protected String getBundleUrl(String bundleName, org.broadleafcommerce.presentation.model.BroadleafTemplateContext context)
      Adds the context path to the bundleUrl. We don't use the Thymeleaf "@" syntax or any other mechanism to encode this URL as the resolvers could have a conflict.

      For example, resolving a bundle named "style.css" that has a file also named "style.css" creates problems as the TF or version resolvers both want to version this file.

      Parameters:
      bundleName - the path of the bundle to add
      context - the context of the original bundle tag
      Returns:
      the full bundle URL
    • buildBundledFilesList

      protected List<String> buildBundledFilesList(ResourceTagAttributes tagAttributes)
      Gets all the files that should be included in the bundle
      Parameters:
      tagAttributes - the tag attributes of the resource tag to replace
      Returns:
      list of all the files to include in the bundle
    • getBundlePath

      protected String getBundlePath(ResourceTagAttributes attributes, List<String> files)
      Gets the bundle path. The path should still be put through getBundleUrl(String, BroadleafTemplateContext) to get the href/src appropriate for the HTML.
      Parameters:
      attributes - the attributes on the original resource tag
      files - the files requested with the bundle or null if not included
      Returns:
      the bundle path
    • postProcessUnbundledFileList

      protected List<String> postProcessUnbundledFileList(List<String> attributeFiles, ResourceTagAttributes tagAttributes, org.broadleafcommerce.presentation.model.BroadleafTemplateContext context)
      Performs post processing on an unbundled file list to either grab the file list stored on the request (see ResourcesRequest) or use the files from the tag attributes and save them so they can be used again later without the files attribute.
      Parameters:
      attributeFiles - the files that were on the attribute (and any additional files to include)
      tagAttributes - the attributes that were on the original resource tag
      context - the context of the original resource tag
      Returns:
      list of files to use as resources
    • getBundleAppendText

      protected String getBundleAppendText(ResourceTagAttributes attributes)
      Gets the bundle append text, text that will be appended to the end of a bundle
      Parameters:
      attributes - the original resource tag attributes
      Returns:
      bundle append text
    • getBundleCompleteEventJavaScript

      protected String getBundleCompleteEventJavaScript(ResourceTagAttributes attributes)
      Gets the JavaScript that fires an event when a bundle is completed
      Parameters:
      attributes - the attributes to build the event off of
      Returns:
      JavaScript that fires an event or null if none requested
    • validateTagAttributes

      protected void validateTagAttributes(ResourceTagAttributes resourceTagAttributes)
      Validates the requested tag attributes
      Parameters:
      resourceTagAttributes - the tag attributes from the original resource tag