com.ibm.portal.resourceaggregator.combiner
Interface ResourceCombinerService


public interface ResourceCombinerService

The resource combiner service is a helper that provides the ability to combine an arbitrary number of resources of type CSS, JS or Markup. It generates a URI/URL which can be invoked to retrieve the combined content. It is the responsibility of the caller to write the URI/URL into the page markup so that the browser resolves the link and actually retrieve the combine resources.

In order to generate the URI/URL the service provides input methods to add multiple ResourceURIVariationss. A variation object in itself represents multiple URIs to the same resource with different characteristics, such as a compressed and uncompressed JavaScript file, or different files for different device classes.

The service selects one flavor of the given URIs from a ResourceURIVariations based on the current runtime context and generates a URI/URL that combines all of those once invoked.

For performance reasons it is recommended to not create the ResourceList object with every request but cache this in an instance variable and simply retrieve the URI/URL list on every request.

A usage example of the service follows:
Use the following code to create the list once and store this in an instance variable. This allows the system to cache the url generation process and saves performance.

     ...
     ResourceCombinerService resourceCombinerService = home.getResourceCombinerService(corContext);
     
     ResourceList list = home.createResourceList(ResourceType.CSS);
     
     ResourceURIVariations resourceVariations = home.createResourceVariations();
     resourceVariations.add("res:/mycontextroot/mypath/file.min.css");
     resourceVariations.add("res:/mycontextroot/mypath/file.css", URIType.DEBUG);
     resourceVariations.add("res:/mycontextroot/mypath/file.rtl.min.css", URIType.RTL);
     resourceVariations.add("res:/mycontextroot/mypath/file.rtl.css", URIType.DEBUG, URIType.RTL);
     resourceVariations.add("res:/mycontextroot/mypath/file.mobile.min.css", "smartphone/tablet");
     resourceVariations.add("res:/mycontextroot/mypath/file.mobile.css", "smartphone/tablet", URIType.DEBUG);
     resourceVariations.add("res:/mycontextroot/mypath/file.mobile.rtl.min.css", "smartphone/tablet", URIType.RTL);
     resourceVariations.add("res:/mycontextroot/mypath/file.mobile.rtl.css", "smartphone/tablet", URIType.DEBUG, URIType.RTL);
     list.add(resourceVariations);
     
     resourceVariations = home.createResourceVariations();
     resourceVariations.add("res:/mycontextroot/mypath/red.min.css");
     resourceVariations.add("res:/mycontextroot/mypath/red.css", URIType.DEBUG);
     resourceVariations.add("res:/mycontextroot/mypath/red.rtl.min.css", URIType.RTL);
     resourceVariations.add("res:/mycontextroot/mypath/red.rtl.css", URIType.DEBUG, URIType.RTL);
     resourceVariations.add("res:/mycontextroot/mypath/red.mobile.min.css", "smartphone/tablet");
     resourceVariations.add("res:/mycontextroot/mypath/red.mobile.css", "smartphone/tablet", URIType.DEBUG);
     resourceVariations.add("res:/mycontextroot/mypath/red.mobile.rtl.min.css", "smartphone/tablet", URIType.RTL);
     resourceVariations.add("res:/mycontextroot/mypath/red.mobile.rtl.css", "smartphone/tablet", URIType.DEBUG, URIType.RTL);
     list.add(resourceVariations);
 

Retrieve the URIs/URLs with every request based on the resource list object like shown below:

     ...
     ResourceCombinerService resourceCombinerService = home.getResourceCombinerService(corContext);
     
     List combinedCSSURI = resourceCombinerService.getCombinedURI(list);
     
     ...
 

Since:
8.5.0.3

Nested Class Summary
static class ResourceCombinerService.ResourceType
          Defines the Resource type
 
Method Summary
 java.util.List<Addressable> getCombinedURI(ResourceList list)
          Returns a number of combiner URIs that deliver a combined response of all resources passed into this function.
 

Method Detail

getCombinedURI

java.util.List<Addressable> getCombinedURI(ResourceList list)
                                           throws java.lang.Exception
Returns a number of combiner URIs that deliver a combined response of all resources passed into this function. In most cases the returned list only contains one URI, but in a few cases, for instance with CSS size limits on IE, it may return multiple URIs.

Parameters:
list - a ResourceList object. Must not be null.
Returns:
returns a list of combiner URIs. Never null.
Throws:
java.lang.Exception