org.apache.cocoon.reading
Class ResourceReader

java.lang.Object
  extended by org.apache.avalon.framework.logger.AbstractLogEnabled
      extended by org.apache.cocoon.reading.AbstractReader
          extended by org.apache.cocoon.reading.ResourceReader
All Implemented Interfaces:
Poolable, Recyclable, Component, Configurable, LogEnabled, CacheableProcessingComponent, Reader, SitemapModelComponent, SitemapOutputComponent
Direct Known Subclasses:
EventAwareReader, ImageOpReader, ImageReader

public class ResourceReader
extends AbstractReader
implements 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:
CVS $Id: ResourceReader.html 1304258 2012-03-23 10:09:27Z ilgrosso $
Author:
Giacomo Pati, Torsten Curdt, Carsten Ziegeler

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  Request request
           
protected  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)
          Read reader configuration
 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()
           
 void parameterize(Parameters parameters)
           
protected  void processStream(InputStream inputStream)
           
 void recycle()
          Recyclable
 void setup(SourceResolver resolver, Map objectModel, String src, Parameters par)
          Setup the reader.
protected  void setupHeaders()
          Setup the response headers: Accept-Ranges, Expires
 
Methods inherited from class org.apache.cocoon.reading.AbstractReader
setOutputStream, shouldSetContentLength
 
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
 
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 Response response

request

protected Request request

inputSource

protected Source inputSource
Constructor Detail

ResourceReader

public ResourceReader()
Method Detail

configure

public void configure(Configuration configuration)
               throws ConfigurationException
Read reader configuration

Specified by:
configure in interface Configurable
Throws:
ConfigurationException

parameterize

public void parameterize(Parameters parameters)
                  throws ParameterException
Throws:
ParameterException

setup

public void setup(SourceResolver resolver,
                  Map objectModel,
                  String src,
                  Parameters par)
           throws 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 SitemapModelComponent
Overrides:
setup in class AbstractReader
Throws:
ProcessingException
SAXException
IOException

setupHeaders

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


recycle

public void recycle()
Recyclable

Specified by:
recycle in interface Recyclable
Overrides:
recycle in class AbstractReader

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 CacheableProcessingComponent
Returns:
The generated key hashes the src

getValidity

public SourceValidity getValidity()
Generate the validity object.

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

getLastModified

public long getLastModified()
Specified by:
getLastModified in interface Reader
Overrides:
getLastModified in class AbstractReader
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,
                             ProcessingException
Throws:
IOException
ProcessingException

generate

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

Specified by:
generate in interface Reader
Throws:
IOException
ProcessingException

getMimeType

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

Specified by:
getMimeType in interface SitemapOutputComponent
Overrides:
getMimeType in class AbstractReader
See Also:
AbstractProcessingPipeline.setMimeTypeForSerializer(org.apache.cocoon.environment.Environment), AbstractProcessingPipeline.setMimeTypeForReader(org.apache.cocoon.environment.Environment)


Copyright © 1999-2010 The Apache Software Foundation. All Rights Reserved.