org.apache.shale.remoting.impl
Class AbstractResourceProcessor

java.lang.Object
  extended by org.apache.shale.remoting.impl.FilteringProcessor
      extended by org.apache.shale.remoting.impl.AbstractResourceProcessor
All Implemented Interfaces:
Processor
Direct Known Subclasses:
ClassResourceProcessor, WebResourceProcessor

public abstract class AbstractResourceProcessor
extends FilteringProcessor

Convenience abstract base class for Processor implementations that serve up static resources.


Field Summary
protected  Map mimeTypes
          Map of MIME types, keyed by file extension.
 
Constructor Summary
AbstractResourceProcessor()
           
 
Method Summary
protected  void copyStream(javax.faces.context.FacesContext context, InputStream inputStream, OutputStream outputStream)
          Copy the contents of the specified input stream to the specified output stream.
 int getBufferSize()
          Return the buffer size when copying.
 long getLastModified()
          Return the date/time (expressed as the number of milliseconds since the epoch) that will be generated on the Last-Modified header of all resources served by this processor.
 String getLastModifiedString()
          Return a String version of the last modified date/time, formatted as required by Section 3.3.1 of the HTTP/1.1 Specification.
protected abstract  URL getResourceURL(javax.faces.context.FacesContext context, String resourceId)
          Convert the specified resource identifier into a URL, if the resource actually exists.
protected  String httpTimestamp(Date timestamp)
          Return a textual representation of the specified date/time stamp (expressed as a java.util.Date object) in the format required by the HTTP/1.1 Specification (RFC 2616), Section 3.3.1.
protected  String httpTimestamp(long timestamp)
          Return a textual representation of the specified date/time stamp (expressed in milliseconds since the epoch, and assumed to be GMT) in the format required by the HTTP/1.1 Specification (RFC 2616), Section 3.3.1.
protected  long ifModifiedSince(javax.faces.context.FacesContext context)
          Return the value of the If-Modified-Since header included on this request, as a number of milliseconds since the epoch.
protected  InputStream inputStream(javax.faces.context.FacesContext context, URL url)
          Return an InputStream derived from the specified URL, which will point to the static resource to be served.
protected  String mimeType(javax.faces.context.FacesContext context, String resourceId)
          Return the appropriate MIME type (if known) for the specified resource path.
protected  OutputStream outputStream(javax.faces.context.FacesContext context, String contentType)
          Return an OutputStream to which our static resource is to be served.
 void process(javax.faces.context.FacesContext context, String resourceId)
          Check if the specified resource actually exists.
protected  void sendContentType(javax.faces.context.FacesContext context, String contentType)
          Set the content type on the servlet or portlet response object.
protected  void sendLastModified(javax.faces.context.FacesContext context, String timestamp)
          Set the Last-Modified header to the specified timestamp.
protected  void sendNotFound(javax.faces.context.FacesContext context, String resourceId)
          Send a "not found" HTTP response, if possible.
protected  void sendNotModified(javax.faces.context.FacesContext context, String resourceId)
          Send a "not modified" HTTP response, if possible.
protected  boolean servletRequest(javax.faces.context.FacesContext context)
          Return true if we are processing a servlet request (as opposed to a portlet request).
 void setBufferSize(int bufferSize)
          Set the buffer size when copying.
 void setLastModified(long lastModified)
          Set the date/time (expressed as the number of milliseconds since the epoch) that wll be generated on the Last-Modified header of all resources served by this processor.
 
Methods inherited from class org.apache.shale.remoting.impl.FilteringProcessor
accept, getExcludes, getIncludes, setExcludes, setIncludes
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mimeTypes

protected Map mimeTypes

Map of MIME types, keyed by file extension. This is used as a fallback if the ServletContext or PortletContext call to mimeType() does not return any result.

Constructor Detail

AbstractResourceProcessor

public AbstractResourceProcessor()
Method Detail

process

public void process(javax.faces.context.FacesContext context,
                    String resourceId)
             throws IOException

Check if the specified resource actually exists. If it does not, return an HTTP 404 status (servlet) or throw an IllegalArgumentException (portlet).

Parameters:
context - FacesContext for the current request
resourceId - Resource identifier of the resource to be served
Throws:
IllegalArgumentException - if the specified resource does not exist in a portlet environment (because we cannot return an HTTP status 404)
IOException - if an input/output error occurs

getBufferSize

public int getBufferSize()

Return the buffer size when copying.


setBufferSize

public void setBufferSize(int bufferSize)

Set the buffer size when copying.

Parameters:
bufferSize - The new buffer size

getLastModified

public long getLastModified()

Return the date/time (expressed as the number of milliseconds since the epoch) that will be generated on the Last-Modified header of all resources served by this processor. If this value has not been set upon first call to this method, it will be set to the current date and time.


setLastModified

public void setLastModified(long lastModified)

Set the date/time (expressed as the number of milliseconds since the epoch) that wll be generated on the Last-Modified header of all resources served by this processor.

Parameters:
lastModified - The new last modified value

getLastModifiedString

public String getLastModifiedString()

Return a String version of the last modified date/time, formatted as required by Section 3.3.1 of the HTTP/1.1 Specification. If the lastModified property has not been set upon first call to this method, it will be set to the current date and time.


getResourceURL

protected abstract URL getResourceURL(javax.faces.context.FacesContext context,
                                      String resourceId)

Convert the specified resource identifier into a URL, if the resource actually exists. Otherwise, return null.

Parameters:
context - FacesContext for the current request
resourceId - Resource identifier to translate

copyStream

protected void copyStream(javax.faces.context.FacesContext context,
                          InputStream inputStream,
                          OutputStream outputStream)
                   throws IOException

Copy the contents of the specified input stream to the specified output stream.

Parameters:
context - FacesContext for the current request
inputStream - InputStream to be copied from
outputStream - OutputStream to be copied to
Throws:
IOException - if an input/output error occurs

httpTimestamp

protected String httpTimestamp(Date timestamp)

Return a textual representation of the specified date/time stamp (expressed as a java.util.Date object) in the format required by the HTTP/1.1 Specification (RFC 2616), Section 3.3.1. An example of this format is:

Sun, 06 Nov 1994 08:49:37 GMT

Parameters:
timestamp - The date/time to be formatted, expressed as a java.util.Date

httpTimestamp

protected String httpTimestamp(long timestamp)

Return a textual representation of the specified date/time stamp (expressed in milliseconds since the epoch, and assumed to be GMT) in the format required by the HTTP/1.1 Specification (RFC 2616), Section 3.3.1. An example of this format is:

Sun, 06 Nov 1994 08:49:37 GMT

Parameters:
timestamp - The date/time to be formatted, expressed as the number of milliseconds since the epoch

ifModifiedSince

protected long ifModifiedSince(javax.faces.context.FacesContext context)

Return the value of the If-Modified-Since header included on this request, as a number of milliseconds since the epoch. If this header was not included (or we cannot tell if it was included), return -1 instead.

Parameters:
context - FacesContext for the current request

inputStream

protected InputStream inputStream(javax.faces.context.FacesContext context,
                                  URL url)
                           throws IOException

Return an InputStream derived from the specified URL, which will point to the static resource to be served.

Parameters:
context - FacesContext for the current request
url - URL from which to derive an input stream
Throws:
IOException - if an input/output error occurs

mimeType

protected String mimeType(javax.faces.context.FacesContext context,
                          String resourceId)

Return the appropriate MIME type (if known) for the specified resource path. This method is portable across servlet and portlet environments. If no MIME type is known, fall back to a configured list, based on the extension of the requested resource. If no result can be found in the fallback list, return null.

Parameters:
context - FacesContext for the current request
resourceId - Resource identifier of the resource to categorize

outputStream

protected OutputStream outputStream(javax.faces.context.FacesContext context,
                                    String contentType)
                             throws IOException

Return an OutputStream to which our static resource is to be served.

Parameters:
context - FacesContext for the current request
contentType - Content type for this response
Throws:
IOException - if an input/output error occurs

servletRequest

protected boolean servletRequest(javax.faces.context.FacesContext context)

Return true if we are processing a servlet request (as opposed to a portlet request).

Parameters:
context - FacesContext for the current request

sendContentType

protected void sendContentType(javax.faces.context.FacesContext context,
                               String contentType)

Set the content type on the servlet or portlet response object.

Parameters:
context - FacesContext for the current request
contentType - The content type to be set

sendLastModified

protected void sendLastModified(javax.faces.context.FacesContext context,
                                String timestamp)

Set the Last-Modified header to the specified timestamp.

Parameters:
context - FacesContext for this request
timestamp - String version of the last modified timestamp

sendNotFound

protected void sendNotFound(javax.faces.context.FacesContext context,
                            String resourceId)
                     throws IOException

Send a "not found" HTTP response, if possible. Otherwise, throw an IllegalArgumentException that will ripple out.

Parameters:
context - FacesContext for the current request
resourceId - Resource identifier of the resource that was not found
Throws:
IllegalArgumentException - if we cannot send an HTTP response
IOException - if an input/output error occurs

sendNotModified

protected void sendNotModified(javax.faces.context.FacesContext context,
                               String resourceId)
                        throws IOException

Send a "not modified" HTTP response, if possible. Otherwise, throw an IllegalArgumentException that will ripple out.

Parameters:
context - FacesContext for the current request
resourceId - Resource identifier of the resource that was not modified
Throws:
IllegalArgumentException - if we cannot send an HTTP response
IOException - if an input/output error occurs


Copyright © 2004-2007 Apache Software Foundation. All Rights Reserved.