org.weborganic.bastille.web
Class GetWebBundles

java.lang.Object
  extended by org.weborganic.bastille.web.GetWebBundles
All Implemented Interfaces:
Cacheable, ContentGenerator

public final class GetWebBundles
extends Object
implements ContentGenerator, Cacheable

This generator returns the list of timestamped scripts and styles for a given service.

It will assemble and minimize the scripts and styles together as much as possible and return the list of bundles. Because the name each bundle includes unique stamp, they can be cached for a long periods. When files included in a bundle are modified, this generator will automatically produce a new bundle with a new stamp so that it results in a different URL.

Bundling

Scripts are simply concatenated. Styles are concatenated and import rules will automatically include the imported styles into the main file.

Minimization

Both styles and scripts can be minimised after the bundling. Minimized bundles will be saved using the following extensions .min.js and .min.css. If files to be bundled already use the *.min.* extension, it will be considered to be already minimised and won't be minimised again.

File naming

Bundled files are automatically named as:

[bundlename]-[date]-[etag].[ext]

The bundle name is specified in the configuration; the date is the creation date of the bundle; the etag is the 4-character alphanumerical stamp; and the extension depends on the MIME type and minimization options.

Configuration

This generator is highly configurable and the configuration properties are specific (but similar) for styles and scripts.

Properties pertaining to scripts and styles are prefixed by respectively bastille.jsbundler and bastille.cssbundler.

The minimize property can be used to control minimization of the code.

The location property can be used to define where the bundled files should be stored.

A bundle config defines the list of bundles to create. The "default" config is made of three bundles 'global', 'group', and 'service'.

Each bundle is specified using the bundles property each bundle name is mapped to the list of files to bundle, the {GROUP} and {SERVICE} values are automatically replaced by the Berlioz service/group name in use.

Default configuration

The default configuration is the equivalent of:

<bastille>
   <cssbundler minimize="true" location="/style/_/">
     <configs default="global,group,service"/>
     <bundles global="/style/global.css"
               group="/style/{GROUP}.css"
             service="/style/{GROUP}/{SERVICE}.css"/>
     <datauris threshold="4096"/>
   </cssbundler>
   <jsbundler minimize="true" location="/script/_/">
     <configs default="global,group,service"/>
     <bundles global="/style/global.js"
               group="/script/{GROUP}.js"
             service="/script/{GROUP}/{SERVICE}.js"/>
   </jsbundler>
 </bastille>
 

Parameters

No parameters are required for this generator, but the bundling can be disabled by setting the berlioz-bundle parameter to true

Returned XML

The XML returns the scripts and styles in the order in which they are defined.

<script src="[jslocation]/[bundle].js" bundled="[true|false]" minimized="[true|false]" />
 ...
 <style  src="[csslocation]/[bundle].css" bundled="[true|false]" minimized="[true|false]" />
 ...
 

Error handling

Usage

ETag

Since:
0.6.0

Constructor Summary
GetWebBundles()
           
 
Method Summary
 String getETag(ContentRequest req)
           
 void process(ContentRequest req, XMLWriter xml)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GetWebBundles

public GetWebBundles()
Method Detail

getETag

public String getETag(ContentRequest req)
Specified by:
getETag in interface Cacheable

process

public void process(ContentRequest req,
                    XMLWriter xml)
             throws BerliozException,
                    IOException
Specified by:
process in interface ContentGenerator
Throws:
BerliozException
IOException