Class ResourceBundlingServiceImpl

java.lang.Object
org.broadleafcommerce.common.resource.service.ResourceBundlingServiceImpl
All Implemented Interfaces:
ResourceBundlingService

@Service("blResourceBundlingService") public class ResourceBundlingServiceImpl extends Object implements ResourceBundlingService
Author:
Andre Azzolini (apazzolini), Brian Polster (bpolster)
See Also:
  • Field Details

    • LOG

      protected static final org.apache.commons.logging.Log LOG
    • additionalBundleFiles

      protected Map<String,List<String>> additionalBundleFiles
      This has to use an @Resource annotation because Spring's @Autowired cannot work with the type erasure from the Map<String, List> type.
    • fileService

      protected BroadleafFileService fileService
    • jsResourceHandler

      protected org.springframework.web.servlet.resource.ResourceHttpRequestHandler jsResourceHandler
      These properties are looked up manually within initializeResources(ContextRefreshedEvent)
    • cssResourceHandler

      protected org.springframework.web.servlet.resource.ResourceHttpRequestHandler cssResourceHandler
    • appctx

      @Autowired protected org.springframework.context.ApplicationContext appctx
    • statisticsService

      protected StatisticsService statisticsService
    • environment

      @Autowired protected org.springframework.core.env.Environment environment
    • createdBundles

      protected ConcurrentHashMap<String,BundledResourceInfo> createdBundles
  • Constructor Details

    • ResourceBundlingServiceImpl

      public ResourceBundlingServiceImpl()
  • Method Details

    • initializeResources

      @EventListener public void initializeResources(org.springframework.context.event.ContextRefreshedEvent event)
      Initalize the blJsResources and blCssResources. The reason that we are doing it this way and not via the normal autowiring process is because there is technically a circular dependency here: ResourceBundlingService -> blJsResources -> blSiteResourceResolvers/blAdminResourceResolvers -> blBundleResourceResolver -> ResourceBundlingService -> ... We can easily hit an IllegalStateException depending on the order in which things are initialized. This essentially breaks the circular dependency in Spring's auto-initialization and grabs those resources when they are initialized, since this should only be used at runtime in a web request anyway.
    • rebuildBundledResource

      public org.springframework.core.io.Resource rebuildBundledResource(String requestedBundleName)
      Description copied from interface: ResourceBundlingService
      Returns a newly rebuilt bundled resource given that the passed requestedBundleName had previously been built and cached/persisted via the ResourceBundlingService.resolveBundleResourceName(String, String, List) method.
      Specified by:
      rebuildBundledResource in interface ResourceBundlingService
      Parameters:
      requestedBundleName - the requested bundle name
      Returns:
      the rebuilt bundled resource
    • resolveBundleResourceName

      public String resolveBundleResourceName(String requestedBundleName, String mappingPrefix, List<String> files)
      Description copied from interface: ResourceBundlingService
      Returns a file name representing a versioned copy of the bundle.

      First computes the bundle version by examining the files in the bundle. If the bundle does not exist, this method will create it.

      Specified by:
      resolveBundleResourceName in interface ResourceBundlingService
      Parameters:
      requestedBundleName - the requested bundle name
      mappingPrefix - the path prefix for the bundle
      files - the files the bundle should contain
      Returns:
      the bundle's resource name
    • resolveBundleResourceName

      public String resolveBundleResourceName(String requestedBundleName, String mappingPrefix, List<String> files, String bundleAppend)
      Description copied from interface: ResourceBundlingService
      Returns a file name representing a versioned copy of the bundle with the bundleAppend text appended to the end of the bundle.

      First computes the bundle version by examining the files in the bundle. If the bundle does not exist, this method will create it.

      Specified by:
      resolveBundleResourceName in interface ResourceBundlingService
      Parameters:
      requestedBundleName - the requested bundle name
      mappingPrefix - the path prefix for the bundle
      files - the files the bundle should contain
      bundleAppend - the text to append at the end of the bundle
      Returns:
      the bundle's resource name
    • resolveBundleResource

      public org.springframework.core.io.Resource resolveBundleResource(String versionedBundleResourceName)
      Description copied from interface: ResourceBundlingService
      Returns a Resource for passed in versionedBundleResourceName.

      If the bundle does not exist, this method will attempt to create it by using the list of files that were registered with the initial call to ResourceBundlingService.resolveBundleResourceName(String, String, List)

      Specified by:
      resolveBundleResource in interface ResourceBundlingService
      Parameters:
      versionedBundleResourceName - the versioned bundle resource name
      Returns:
      the bundle resource
    • checkForRegisteredBundleFile

      public boolean checkForRegisteredBundleFile(String versionedBundleName)
      Description copied from interface: ResourceBundlingService
      Tells if the given versioned bundle exists
      Specified by:
      checkForRegisteredBundleFile in interface ResourceBundlingService
      Parameters:
      versionedBundleName - the versioned bundle name
      Returns:
      true if the bundle exists, false otherwise
    • getBundledResource

      protected org.springframework.core.io.Resource getBundledResource(String versionedBundleName)
    • lookupBundlePath

      protected String lookupBundlePath(String requestPath)
    • createBundleIfNeeded

      protected void createBundleIfNeeded(String versionedBundleName, List<String> filePaths, org.springframework.web.servlet.resource.ResourceResolverChain resolverChain, List<org.springframework.core.io.Resource> locations)
    • createBundleIfNeeded

      protected void createBundleIfNeeded(String versionedBundleName, List<String> filePaths, org.springframework.web.servlet.resource.ResourceResolverChain resolverChain, List<org.springframework.core.io.Resource> locations, String bundleAppend)
    • createBundle

      protected org.springframework.core.io.Resource createBundle(String versionedBundleName, List<String> filePaths, org.springframework.web.servlet.resource.ResourceResolverChain resolverChain, List<org.springframework.core.io.Resource> locations)
    • createBundle

      protected org.springframework.core.io.Resource createBundle(String versionedBundleName, List<String> filePaths, org.springframework.web.servlet.resource.ResourceResolverChain resolverChain, List<org.springframework.core.io.Resource> locations, String bundleAppend)
    • saveBundle

      protected void saveBundle(org.springframework.core.io.Resource resource)
    • getCacheKey

      protected String getCacheKey(String unversionedBundleName, List<String> files)
    • getBundleName

      protected String getBundleName(String bundleName, String version)
    • getBundleVersion

      protected String getBundleVersion(LinkedHashMap<String,org.springframework.core.io.Resource> foundResources) throws IOException
      Throws:
      IOException
    • getAdditionalBundleFiles

      public List<String> getAdditionalBundleFiles(String bundleName)
      Description copied from interface: ResourceBundlingService
      Through configuration, you can provide additional files that will be automatically included for any bundle. This method gets the list of configured additional files.
      Specified by:
      getAdditionalBundleFiles in interface ResourceBundlingService
      Parameters:
      bundleName - the name of the bundle to get additional files for
      Returns:
      list of additional files
    • setAdditionalBundleFiles

      public void setAdditionalBundleFiles(Map<String,List<String>> additionalBundleFiles)
    • addVersion

      protected String addVersion(String requestPath, String version)
      Copied from Spring 4.1 AbstractVersionStrategy
      Parameters:
      requestPath -
      version -
      Returns:
    • readBundle

      protected org.springframework.core.io.Resource readBundle(String versionedBundleName)
    • findResourceHttpRequestHandler

      protected org.springframework.web.servlet.resource.ResourceHttpRequestHandler findResourceHttpRequestHandler(String resourceName)
    • isJavaScriptResource

      protected boolean isJavaScriptResource(String resourceName)
    • isCSSResource

      protected boolean isCSSResource(String resourceName)
    • getResourcePath

      protected String getResourcePath(String name)
      Returns the resource path for the given name in URL-format (meaning, / separators)
      Parameters:
      name -
      Returns:
    • getBundleCharSet

      protected Charset getBundleCharSet()
    • findBundlesNameByResourceFileName

      public List<String> findBundlesNameByResourceFileName(String fileName)
      Description copied from interface: ResourceBundlingService
      Returns names of bundles which contain the given file
      Specified by:
      findBundlesNameByResourceFileName in interface ResourceBundlingService
      Parameters:
      fileName - file to find in the bungle
      Returns:
      first bundle name that has file, null otherwise
    • removeBundle

      public boolean removeBundle(String bundleName)
      Specified by:
      removeBundle in interface ResourceBundlingService