org.apache.cocoon.reading
Class ResourceReader

java.lang.Object
  extended byorg.apache.cocoon.util.AbstractLogEnabled
      extended byorg.apache.cocoon.reading.AbstractReader
          extended byorg.apache.cocoon.reading.ResourceReader
All Implemented Interfaces:
org.apache.cocoon.caching.CacheableProcessingComponent, Configurable, Poolable, org.apache.cocoon.reading.Reader, Recyclable, org.apache.cocoon.sitemap.SitemapModelComponent, org.apache.cocoon.sitemap.SitemapOutputComponent
Direct Known Subclasses:
ImageReader

public class ResourceReader
extends org.apache.cocoon.reading.AbstractReader
implements org.apache.cocoon.caching.CacheableProcessingComponent, Configurable

The ResourceReader component is used to serve binary data in a sitemap pipeline. It makes use of HTTP Headers to determine if the requested resource should be written to the OutputStream or if it can signal that it hasn't changed.

Configuration:

<expires>
This parameter is optional. When specified it determines how long in miliseconds the resources can be cached by any proxy or browser between Cocoon and the requesting visitor. Defaults to -1.
<quick-modified-test>
This parameter is optional. This boolean parameter controls the last modified test. If set to true (default is false), only the last modified of the current source is tested, but not if the same source is used as last time (see http://marc.theaimsgroup.com/?l=xml-cocoon-dev&m=102921894301915 )
<byte-ranges>
This parameter is optional. This boolean parameter controls whether Cocoon should support byterange requests (to allow clients to resume broken/interrupted downloads). Defaults to true.

Default configuration:

   <expires>-1</expires>
   <quick-modified-test>false</quick-modified-test>
   <byte-ranges>true</byte-ranges>
 

In addition to reader configuration, above parameters can be passed to the reader at the time when it is used.

Version:
$Id: ResourceReader.html 1304280 2012-03-23 11:18:01Z ilgrosso $

Field Summary
protected  int bufferSize
           
protected  boolean byteRanges
           
protected  int configuredBufferSize
           
protected  boolean configuredByteRanges
           
protected  long configuredExpires
           
protected  boolean configuredQuickTest
           
protected  long expires
           
protected  Source inputSource
           
protected  boolean quickTest
           
protected  org.apache.cocoon.environment.Request request
           
protected  org.apache.cocoon.environment.Response response
           
 
Fields inherited from class org.apache.cocoon.reading.AbstractReader
objectModel, out, parameters, resolver, source
 
Fields inherited from interface org.apache.cocoon.reading.Reader
ROLE
 
Constructor Summary
ResourceReader()
           
 
Method Summary
 void configure(Configuration configuration)
          Deprecated. use property injection instead
 void generate()
          Generates the requested resource.
 Serializable getKey()
          Generate the unique key.
 long getLastModified()
           
 String getMimeType()
          Returns the mime-type of the resource in process.
 SourceValidity getValidity()
          Generate the validity object.
protected  boolean hasRanges()
           
protected  void processStream(InputStream inputStream)
           
 void recycle()
          Recyclable
 void setBufferSize(int bufferSize)
           
 void setByteRanges(boolean byteRanges)
          This parameter is optional.
 void setExpires(long expires)
          This parameter is optional.
 void setQuickTest(boolean quickTest)
          This parameter is optional.
 void setup(org.apache.cocoon.environment.SourceResolver resolver, Map objectModel, String src, Parameters par)
          Setup the reader.
protected  void setupHeaders()
          Setup the response headers: Accept-Ranges, Expires, Last-Modified
 
Methods inherited from class org.apache.cocoon.reading.AbstractReader
setOutputStream, shouldSetContentLength
 
Methods inherited from class org.apache.cocoon.util.AbstractLogEnabled
getLogger, setLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

configuredExpires

protected long configuredExpires

configuredQuickTest

protected boolean configuredQuickTest

configuredBufferSize

protected int configuredBufferSize

configuredByteRanges

protected boolean configuredByteRanges

expires

protected long expires

quickTest

protected boolean quickTest

bufferSize

protected int bufferSize

byteRanges

protected boolean byteRanges

response

protected org.apache.cocoon.environment.Response response

request

protected org.apache.cocoon.environment.Request request

inputSource

protected Source inputSource
Constructor Detail

ResourceReader

public ResourceReader()
Method Detail

setBufferSize

public void setBufferSize(int bufferSize)
Parameters:
bufferSize -

setByteRanges

public void setByteRanges(boolean byteRanges)
This parameter is optional. This boolean parameter controls whether Cocoon should support byterange requests (to allow clients to resume broken/interrupted downloads). Defaults to true.

Parameters:
byteRanges -

setExpires

public void setExpires(long expires)
This parameter is optional. When specified it determines how long in miliseconds the resources can be cached by any proxy or browser between Cocoon and the requesting visitor. Defaults to -1.

Parameters:
expires -

setQuickTest

public void setQuickTest(boolean quickTest)
This parameter is optional. This boolean parameter controls the last modified test. If set to true (default is false), only the last modified of the current source is tested, but not if the same source is used as last time (see http://marc.theaimsgroup.com/?l=xml-cocoon-dev&m=102921894301915 )

Parameters:
quickTest -

configure

public void configure(Configuration configuration)
               throws ConfigurationException
Deprecated. use property injection instead

Read reader configuration

Specified by:
configure in interface Configurable
Throws:
ConfigurationException

setup

public void setup(org.apache.cocoon.environment.SourceResolver resolver,
                  Map objectModel,
                  String src,
                  Parameters par)
           throws org.apache.cocoon.ProcessingException,
                  SAXException,
                  IOException
Setup the reader. The resource is opened to get an InputStream, the length and the last modification date

Specified by:
setup in interface org.apache.cocoon.sitemap.SitemapModelComponent
Throws:
org.apache.cocoon.ProcessingException
SAXException
IOException

setupHeaders

protected void setupHeaders()
Setup the response headers: Accept-Ranges, Expires, Last-Modified


recycle

public void recycle()
Recyclable

Specified by:
recycle in interface Recyclable

hasRanges

protected boolean hasRanges()
Returns:
True if byte ranges support is enabled and request has range header.

getKey

public Serializable getKey()
Generate the unique key. This key must be unique inside the space of this component.

Specified by:
getKey in interface org.apache.cocoon.caching.CacheableProcessingComponent
Returns:
The generated key hashes the src

getValidity

public SourceValidity getValidity()
Generate the validity object.

Specified by:
getValidity in interface org.apache.cocoon.caching.CacheableProcessingComponent
Returns:
The generated validity object or null if the component is currently not cacheable.

getLastModified

public long getLastModified()
Specified by:
getLastModified in interface org.apache.cocoon.reading.Reader
Returns:
the time the read source was last modified or 0 if it is not possible to detect

processStream

protected void processStream(InputStream inputStream)
                      throws IOException,
                             org.apache.cocoon.ProcessingException
Throws:
IOException
org.apache.cocoon.ProcessingException

generate

public void generate()
              throws IOException,
                     org.apache.cocoon.ProcessingException
Generates the requested resource.

Specified by:
generate in interface org.apache.cocoon.reading.Reader
Throws:
IOException
org.apache.cocoon.ProcessingException

getMimeType

public String getMimeType()
Returns the mime-type of the resource in process.

Specified by:
getMimeType in interface org.apache.cocoon.sitemap.SitemapOutputComponent


Copyright 1999-2008 The Apache Software Foundation. All Rights Reserved.