fnug.resource
Class DefaultCompressedResource

java.lang.Object
  extended by fnug.resource.AbstractResource
      extended by fnug.resource.DefaultCompressedResource
All Implemented Interfaces:
HasBundle, HasLastModifiedBytes, Resource

public class DefaultCompressedResource
extends AbstractResource
implements HasBundle

Special resource that only postpones compression of bytes to the call of getBytes(). Returned by ResourceCollection.getCompressedJs() and ResourceCollection.getCompressedCss(). When a resource change, this instance is dropped instead of reused since the change may make the aggregation be comprised of other resources.

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
DefaultCompressedResource(Bundle bundle, String basePath, String path, byte[] bytes, long lastModified, Compressor compressor)
          Constructs setting all necessary fields.
 
Method Summary
 List<String> findRequiresTags()
          Always throws UnsupportedOperationException.
 Bundle getBundle()
          Returns the associated bundle.
 byte[] getBytes()
          Retrieves the bytes via the superclass AbstractResource.getBytes() (which ultimately leads to readEntry()).
protected  AbstractResource.Entry readEntry()
          Returns readLastModified() and the bytes given in the constructor.
protected  long readLastModified()
          Returns the last modified passed into constructor.
 
Methods inherited from class fnug.resource.AbstractResource
checkModified, ensureReadEntry, getBasePath, getContentType, getFullPath, getLastModified, getPath, isCss, isJs, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DefaultCompressedResource

public DefaultCompressedResource(Bundle bundle,
                                 String basePath,
                                 String path,
                                 byte[] bytes,
                                 long lastModified,
                                 Compressor compressor)
Constructs setting all necessary fields.

Parameters:
bundle - The associated bundle.
basePath - Base path of the compressed resource. This is not always the same as the associated bundle's since a resource collection may be for another bundle.
path - Path of the compressed resource. This is set to an md5 sum of all the aggregated paths and modified dates.
bytes - the bytes to compress.
lastModified - The last modified date of the bytes.
compressor - The compressor to use when compressing.
Method Detail

getBundle

public Bundle getBundle()
Returns the associated bundle.

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

readEntry

protected AbstractResource.Entry readEntry()
Returns readLastModified() and the bytes given in the constructor.

Specified by:
readEntry in class AbstractResource
Returns:
the bytes and last modified date.

getBytes

public byte[] getBytes()
Retrieves the bytes via the superclass AbstractResource.getBytes() (which ultimately leads to readEntry()). After that the compressed bytes are reused, never recompressed since the whole instance is dropped if any underlying resource changes.

Specified by:
getBytes in interface HasLastModifiedBytes
Specified by:
getBytes in interface Resource
Overrides:
getBytes in class AbstractResource
Returns:
the timestamped bytes.

readLastModified

protected long readLastModified()
Returns the last modified passed into constructor.

Specified by:
readLastModified in class AbstractResource
Returns:
the last modified date of the underlying data source, such as a file.

findRequiresTags

public List<String> findRequiresTags()
Always throws UnsupportedOperationException.

Specified by:
findRequiresTags in interface Resource
Returns:
The list of parsed resources found in the file.


Copyright © 2012. All Rights Reserved.