fnug.resource
Class DefaultResourceCollection

java.lang.Object
  extended by fnug.resource.AbstractResource
      extended by fnug.resource.AbstractAggregatedResource
          extended by fnug.resource.DefaultResourceCollection
All Implemented Interfaces:
AggregatedResource, HasBundle, HasLastModifiedBytes, Resource, ResourceCollection

public class DefaultResourceCollection
extends AbstractAggregatedResource
implements ResourceCollection, HasBundle

Default implementation of ResourceCollection.

Author:
Martin Algesten

Nested Class Summary
 
Nested classes/interfaces inherited from class fnug.resource.AbstractResource
AbstractResource.Entry
 
Field Summary
 
Fields inherited from class fnug.resource.AbstractResource
CONTENT_TYPE_TEXT_CSS, CONTENT_TYPE_TEXT_JAVASCRIPT
 
Constructor Summary
DefaultResourceCollection(Bundle owner, Bundle bundle, Resource[] aggregates, Resource[] dependencies)
          Constructs setting all necessary bits.
 
Method Summary
protected  byte[] buildAggregate()
          Builds two sets of aggregated bytes.
 boolean checkModified()
          Calls Resource.checkModified() on all the underlying resources in AggregatedResource.getAggregates() and AggregatedResource.getDependencies().
 Resource[] getAggregates()
          Aggregates are the resources that actually make up the aggregated resource - that are used to produce the Resource.getBytes().
 Bundle getBundle()
          Returns the associated bundle.
 Resource getCompressedCss()
          Returns a resource that is the compressed version of the ResourceCollection.getCss().
 Resource getCompressedJs()
          Returns a resource that is the compressed version of the ResourceCollection.getJs() .
 byte[] getCss()
          Returns the dependent css files, concatenated in dependency order.
 Resource[] getDependencies()
          Dependencies are resources that are just dependent on for Resource.getLastModified() (along with AggregatedResource.getAggregates()) but are not part of making the bytes of the aggregate.
 List<Resource> getExistingCssAggregates()
          Returns the discovered dependent css files that actually exists (doesn't return -1 for Resource.getLastModified()).
 List<Resource> getExistingJsAggregates()
          Returns the discovered dependent javascript files that actually exists (doesn't return -1 for Resource.getLastModified()).
 byte[] getJs()
          Returns the dependent javascript files, concatenated in dependency order.
 String getPath()
          The path of a resource collection is an md5 hash sum as hexadecimal of all the aggregates file names and last modified dates prepended with the bundle name.
 
Methods inherited from class fnug.resource.AbstractAggregatedResource
findRequiresTags, readEntry, readLastModified
 
Methods inherited from class fnug.resource.AbstractResource
contentTypeForPath, ensureReadEntry, getBasePath, getBytes, getContentType, getFullPath, getLastModified, isCss, isJs, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface fnug.resource.AggregatedResource
getBasePath
 
Methods inherited from interface fnug.resource.Resource
findRequiresTags, getBytes, getContentType, getFullPath, getLastModified, isCss, isJs
 

Constructor Detail

DefaultResourceCollection

public DefaultResourceCollection(Bundle owner,
                                 Bundle bundle,
                                 Resource[] aggregates,
                                 Resource[] dependencies)
Constructs setting all necessary bits.

Parameters:
owner - The bundle that generated this collection.
bundle - The bundle to which the resources in this collection belongs.
aggregates - Resources that comprises the aggregates. This is a mix of javascript, css and other dependent resources.
dependencies - Resources that are just dependencies, not used for building aggregated bytes, but for AbstractResource.getLastModified().
Method Detail

getPath

public String getPath()
The path of a resource collection is an md5 hash sum as hexadecimal of all the aggregates file names and last modified dates prepended with the bundle name. I.e. "bundle-ab39283bcd09237576"

Specified by:
getPath in interface Resource
Overrides:
getPath in class AbstractResource
Returns:
Path part of a resource full path.

getAggregates

public Resource[] getAggregates()
Aggregates are the resources that actually make up the aggregated resource - that are used to produce the Resource.getBytes().

Specified by:
getAggregates in interface AggregatedResource
Returns:
the resources that are part of producing the aggregated resource bytes.

getDependencies

public Resource[] getDependencies()
Dependencies are resources that are just dependent on for Resource.getLastModified() (along with AggregatedResource.getAggregates()) but are not part of making the bytes of the aggregate.

Specified by:
getDependencies in interface AggregatedResource
Returns:
the dependencies used only for last modified date, not bytes.

getBundle

public Bundle getBundle()
Returns the associated bundle.

Specified by:
getBundle in interface HasBundle
Returns:
the associated bundle.

buildAggregate

protected byte[] buildAggregate()
Builds two sets of aggregated bytes. One which is getJs() and the other getCss(). Loops over all getAggregates() and picks out Resource.isJs() and Resource.isCss().

Specified by:
buildAggregate in class AbstractAggregatedResource
Returns:
the aggregated bytes, built from AggregatedResource.getAggregates().

getJs

public byte[] getJs()
Returns the dependent javascript files, concatenated in dependency order. This is the same as calling Resource.getBytes() on the resource.

Specified by:
getJs in interface ResourceCollection
Returns:
the uncompressed bytes of all the javascript resources.

getCss

public byte[] getCss()
Returns the dependent css files, concatenated in dependency order.

Specified by:
getCss in interface ResourceCollection
Returns:
the uncompressed bytes of all the css resources.

getCompressedJs

public Resource getCompressedJs()
Returns a resource that is the compressed version of the ResourceCollection.getJs() .

Specified by:
getCompressedJs in interface ResourceCollection
Returns:
compressed resource.

getCompressedCss

public Resource getCompressedCss()
Returns a resource that is the compressed version of the ResourceCollection.getCss().

Specified by:
getCompressedCss in interface ResourceCollection
Returns:
compressed resource.

checkModified

public boolean checkModified()
Calls Resource.checkModified() on all the underlying resources in AggregatedResource.getAggregates() and AggregatedResource.getDependencies(). After that calls super class checkModified() which may trigger a rebuild of the aggregate (via AbstractAggregatedResource.readEntry(), AbstractAggregatedResource.buildAggregate()) If any resource is changed, will dropped the compressed javascript and css.

Specified by:
checkModified in interface Resource
Overrides:
checkModified in class AbstractAggregatedResource
Returns:
true if any of the resources were found to be newer.

getExistingJsAggregates

public List<Resource> getExistingJsAggregates()
Returns the discovered dependent javascript files that actually exists (doesn't return -1 for Resource.getLastModified()).

Specified by:
getExistingJsAggregates in interface ResourceCollection
Returns:
existing dependent javascript files.

getExistingCssAggregates

public List<Resource> getExistingCssAggregates()
Returns the discovered dependent css files that actually exists (doesn't return -1 for Resource.getLastModified()).

Specified by:
getExistingCssAggregates in interface ResourceCollection
Returns:
existing dependent css files.


Copyright © 2012. All Rights Reserved.