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 Summary
FieldsModifier and TypeFieldDescriptionThis has to use an @Resource annotation because Spring's @Autowired cannot work with the type erasure from the Map<String, List> type. protected org.springframework.context.ApplicationContext
protected ConcurrentHashMap<String,
BundledResourceInfo> protected org.springframework.web.servlet.resource.ResourceHttpRequestHandler
protected org.springframework.core.env.Environment
protected BroadleafFileService
protected org.springframework.web.servlet.resource.ResourceHttpRequestHandler
These properties are looked up manually withininitializeResources(ContextRefreshedEvent)
protected static final org.apache.commons.logging.Log
protected StatisticsService
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected String
addVersion
(String requestPath, String version) Copied from Spring 4.1 AbstractVersionStrategyboolean
checkForRegisteredBundleFile
(String versionedBundleName) Tells if the given versioned bundle existsprotected 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) 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) protected void
createBundleIfNeeded
(String versionedBundleName, List<String> filePaths, org.springframework.web.servlet.resource.ResourceResolverChain resolverChain, List<org.springframework.core.io.Resource> locations) protected void
createBundleIfNeeded
(String versionedBundleName, List<String> filePaths, org.springframework.web.servlet.resource.ResourceResolverChain resolverChain, List<org.springframework.core.io.Resource> locations, String bundleAppend) findBundlesNameByResourceFileName
(String fileName) Returns names of bundles which contain the given fileprotected org.springframework.web.servlet.resource.ResourceHttpRequestHandler
findResourceHttpRequestHandler
(String resourceName) getAdditionalBundleFiles
(String bundleName) Through configuration, you can provide additional files that will be automatically included for any bundle.protected Charset
protected org.springframework.core.io.Resource
getBundledResource
(String versionedBundleName) protected String
getBundleName
(String bundleName, String version) protected String
getBundleVersion
(LinkedHashMap<String, org.springframework.core.io.Resource> foundResources) protected String
getCacheKey
(String unversionedBundleName, List<String> files) protected String
getResourcePath
(String name) Returns the resource path for the given name in URL-format (meaning, / separators)void
initializeResources
(org.springframework.context.event.ContextRefreshedEvent event) Initalize the blJsResources and blCssResources.protected boolean
isCSSResource
(String resourceName) protected boolean
isJavaScriptResource
(String resourceName) protected String
lookupBundlePath
(String requestPath) protected org.springframework.core.io.Resource
readBundle
(String versionedBundleName) org.springframework.core.io.Resource
rebuildBundledResource
(String requestedBundleName) Returns a newly rebuilt bundled resource given that the passed requestedBundleName had previously been built and cached/persisted via theResourceBundlingService.resolveBundleResourceName(String, String, List)
method.boolean
removeBundle
(String bundleName) org.springframework.core.io.Resource
resolveBundleResource
(String versionedBundleResourceName) Returns a Resource for passed in versionedBundleResourceName.resolveBundleResourceName
(String requestedBundleName, String mappingPrefix, List<String> files) Returns a file name representing a versioned copy of the bundle.resolveBundleResourceName
(String requestedBundleName, String mappingPrefix, List<String> files, String bundleAppend) Returns a file name representing a versioned copy of the bundle with thebundleAppend
text appended to the end of the bundle.protected void
saveBundle
(org.springframework.core.io.Resource resource) void
setAdditionalBundleFiles
(Map<String, List<String>> additionalBundleFiles)
-
Field Details
-
LOG
protected static final org.apache.commons.logging.Log LOG -
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
-
jsResourceHandler
protected org.springframework.web.servlet.resource.ResourceHttpRequestHandler jsResourceHandlerThese properties are looked up manually withininitializeResources(ContextRefreshedEvent)
-
cssResourceHandler
protected org.springframework.web.servlet.resource.ResourceHttpRequestHandler cssResourceHandler -
appctx
@Autowired protected org.springframework.context.ApplicationContext appctx -
statisticsService
-
environment
@Autowired protected org.springframework.core.env.Environment environment -
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
Description copied from interface:ResourceBundlingService
Returns a newly rebuilt bundled resource given that the passed requestedBundleName had previously been built and cached/persisted via theResourceBundlingService.resolveBundleResourceName(String, String, List)
method.- Specified by:
rebuildBundledResource
in interfaceResourceBundlingService
- 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 interfaceResourceBundlingService
- Parameters:
requestedBundleName
- the requested bundle namemappingPrefix
- the path prefix for the bundlefiles
- 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 thebundleAppend
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 interfaceResourceBundlingService
- Parameters:
requestedBundleName
- the requested bundle namemappingPrefix
- the path prefix for the bundlefiles
- the files the bundle should containbundleAppend
- 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 interfaceResourceBundlingService
- Parameters:
versionedBundleResourceName
- the versioned bundle resource name- Returns:
- the bundle resource
-
checkForRegisteredBundleFile
Description copied from interface:ResourceBundlingService
Tells if the given versioned bundle exists- Specified by:
checkForRegisteredBundleFile
in interfaceResourceBundlingService
- Parameters:
versionedBundleName
- the versioned bundle name- Returns:
- true if the bundle exists, false otherwise
-
getBundledResource
-
lookupBundlePath
-
createBundleIfNeeded
-
createBundleIfNeeded
-
createBundle
-
createBundle
-
saveBundle
protected void saveBundle(org.springframework.core.io.Resource resource) -
getCacheKey
-
getBundleName
-
getBundleVersion
protected String getBundleVersion(LinkedHashMap<String, org.springframework.core.io.Resource> foundResources) throws IOException- Throws:
IOException
-
getAdditionalBundleFiles
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 interfaceResourceBundlingService
- Parameters:
bundleName
- the name of the bundle to get additional files for- Returns:
- list of additional files
-
setAdditionalBundleFiles
-
addVersion
Copied from Spring 4.1 AbstractVersionStrategy- Parameters:
requestPath
-version
-- Returns:
-
readBundle
-
findResourceHttpRequestHandler
protected org.springframework.web.servlet.resource.ResourceHttpRequestHandler findResourceHttpRequestHandler(String resourceName) -
isJavaScriptResource
-
isCSSResource
-
getResourcePath
Returns the resource path for the given name in URL-format (meaning, / separators)- Parameters:
name
-- Returns:
-
getBundleCharSet
-
findBundlesNameByResourceFileName
Description copied from interface:ResourceBundlingService
Returns names of bundles which contain the given file- Specified by:
findBundlesNameByResourceFileName
in interfaceResourceBundlingService
- Parameters:
fileName
- file to find in the bungle- Returns:
- first bundle name that has file, null otherwise
-
removeBundle
- Specified by:
removeBundle
in interfaceResourceBundlingService
-