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.ApplicationContextprotected ConcurrentHashMap<String,BundledResourceInfo> protected org.springframework.web.servlet.resource.ResourceHttpRequestHandlerprotected org.springframework.core.env.Environmentprotected BroadleafFileServiceprotected org.springframework.web.servlet.resource.ResourceHttpRequestHandlerThese properties are looked up manually withininitializeResources(ContextRefreshedEvent)protected static final org.apache.commons.logging.Logprotected StatisticsService -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected StringaddVersion(String requestPath, String version) Copied from Spring 4.1 AbstractVersionStrategybooleancheckForRegisteredBundleFile(String versionedBundleName) Tells if the given versioned bundle existsprotected org.springframework.core.io.ResourcecreateBundle(String versionedBundleName, List<String> filePaths, org.springframework.web.servlet.resource.ResourceResolverChain resolverChain, List<org.springframework.core.io.Resource> locations) protected org.springframework.core.io.ResourcecreateBundle(String versionedBundleName, List<String> filePaths, org.springframework.web.servlet.resource.ResourceResolverChain resolverChain, List<org.springframework.core.io.Resource> locations, String bundleAppend) protected voidcreateBundleIfNeeded(String versionedBundleName, List<String> filePaths, org.springframework.web.servlet.resource.ResourceResolverChain resolverChain, List<org.springframework.core.io.Resource> locations) protected voidcreateBundleIfNeeded(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.ResourceHttpRequestHandlerfindResourceHttpRequestHandler(String resourceName) getAdditionalBundleFiles(String bundleName) Through configuration, you can provide additional files that will be automatically included for any bundle.protected Charsetprotected org.springframework.core.io.ResourcegetBundledResource(String versionedBundleName) protected StringgetBundleName(String bundleName, String version) protected StringgetBundleVersion(LinkedHashMap<String, org.springframework.core.io.Resource> foundResources) protected StringgetCacheKey(String unversionedBundleName, List<String> files) protected StringgetResourcePath(String name) Returns the resource path for the given name in URL-format (meaning, / separators)voidinitializeResources(org.springframework.context.event.ContextRefreshedEvent event) Initalize the blJsResources and blCssResources.protected booleanisCSSResource(String resourceName) protected booleanisJavaScriptResource(String resourceName) protected StringlookupBundlePath(String requestPath) protected org.springframework.core.io.ResourcereadBundle(String versionedBundleName) org.springframework.core.io.ResourcerebuildBundledResource(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.booleanremoveBundle(String bundleName) org.springframework.core.io.ResourceresolveBundleResource(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 thebundleAppendtext appended to the end of the bundle.protected voidsaveBundle(org.springframework.core.io.Resource resource) voidsetAdditionalBundleFiles(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:ResourceBundlingServiceReturns 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:
rebuildBundledResourcein 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:ResourceBundlingServiceReturns 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:
resolveBundleResourceNamein 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:ResourceBundlingServiceReturns a file name representing a versioned copy of the bundle with thebundleAppendtext 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:
resolveBundleResourceNamein 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:ResourceBundlingServiceReturns 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:
resolveBundleResourcein interfaceResourceBundlingService- Parameters:
versionedBundleResourceName- the versioned bundle resource name- Returns:
- the bundle resource
-
checkForRegisteredBundleFile
Description copied from interface:ResourceBundlingServiceTells if the given versioned bundle exists- Specified by:
checkForRegisteredBundleFilein 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:ResourceBundlingServiceThrough 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:
getAdditionalBundleFilesin 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:ResourceBundlingServiceReturns names of bundles which contain the given file- Specified by:
findBundlesNameByResourceFileNamein interfaceResourceBundlingService- Parameters:
fileName- file to find in the bungle- Returns:
- first bundle name that has file, null otherwise
-
removeBundle
- Specified by:
removeBundlein interfaceResourceBundlingService
-