org.mentawai.core
Class StreamConsequence

java.lang.Object
  extended by org.mentawai.core.StreamConsequence
All Implemented Interfaces:
Consequence

public class StreamConsequence
extends java.lang.Object
implements Consequence

A web-based consequence that gets a ready-to-use input stream from the output of the action, get the contents from that input stream and flush them to the servlet output stream. Very useful for loading images from a database, downloads and other resources that the programmer may want to protect from direct access from the client. This class is thread-safe.

Author:
Rubem Azenha

Field Summary
static java.lang.String CONTENT_DISPOSITION_KEY
          The default key ("contentDisposition") to look for in the action output.
static java.lang.String CONTENT_LENGTH_KEY
          The default key ("contentLength") to look for in the action output.
static java.lang.String CONTENT_TYPE_KEY
          The default key ("contentType") to look for in the action output.
static java.lang.String FILENAME_KEY
           
static java.lang.String STREAM_KEY
          The default key ("stream") to look for in the action output.
 
Constructor Summary
StreamConsequence()
          Creates a new instance of the StreamConsequence class.
StreamConsequence(java.lang.String contentType)
          Creates a new instance of the StreamConsequence class, with the given content-type
StreamConsequence(java.lang.String contentType, java.lang.String stream_key)
          Creates a new instance of the StreamConsequence class, with the given content-type and key.
StreamConsequence(java.lang.String contentType, java.lang.String stream_key, java.lang.String content_disposition_key)
          Creates a new instance of the StreamConsequence class, with the given content-type and key.
StreamConsequence(java.lang.String contentType, java.lang.String stream_key, java.lang.String content_disposition_key, java.lang.String content_length_key)
          Creates a new instance of the StreamConsequence class, with the given content-type and key.
 
Method Summary
protected  void defineHeader(javax.servlet.http.HttpServletResponse res, Output output)
           
 void execute(Action a, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
          Executes the action, reading from the input stream the data that has to be flushed into the servlet output stream.
 void setContentTypeKey(java.lang.String key)
           
 void setFileNameKey(java.lang.String filename_key)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STREAM_KEY

public static final java.lang.String STREAM_KEY
The default key ("stream") to look for in the action output.

See Also:
Constant Field Values

CONTENT_DISPOSITION_KEY

public static final java.lang.String CONTENT_DISPOSITION_KEY
The default key ("contentDisposition") to look for in the action output.

See Also:
Constant Field Values

CONTENT_LENGTH_KEY

public static final java.lang.String CONTENT_LENGTH_KEY
The default key ("contentLength") to look for in the action output.

See Also:
Constant Field Values

CONTENT_TYPE_KEY

public static final java.lang.String CONTENT_TYPE_KEY
The default key ("contentType") to look for in the action output.

See Also:
Constant Field Values

FILENAME_KEY

public static final java.lang.String FILENAME_KEY
See Also:
Constant Field Values
Constructor Detail

StreamConsequence

public StreamConsequence()
Creates a new instance of the StreamConsequence class. The content type and everything else will be dynamic, in other words, defined by the action at runtime.


StreamConsequence

public StreamConsequence(java.lang.String contentType)
Creates a new instance of the StreamConsequence class, with the given content-type

Parameters:
contentType - The content type to set in the servlet response.

StreamConsequence

public StreamConsequence(java.lang.String contentType,
                         java.lang.String stream_key)
Creates a new instance of the StreamConsequence class, with the given content-type and key.

Parameters:
contentType - The content type to set in the servlet response.
stream_key - The key with which to get the stream from the output.

StreamConsequence

public StreamConsequence(java.lang.String contentType,
                         java.lang.String stream_key,
                         java.lang.String content_disposition_key)
Creates a new instance of the StreamConsequence class, with the given content-type and key.

Parameters:
contentType - The content type to set in the servlet response.
stream_key - The key with which to get the stream from the output.
content_disposition_key - The key with which to get the content disposition from the output.

StreamConsequence

public StreamConsequence(java.lang.String contentType,
                         java.lang.String stream_key,
                         java.lang.String content_disposition_key,
                         java.lang.String content_length_key)
Creates a new instance of the StreamConsequence class, with the given content-type and key.

Parameters:
contentType - The content type to set in the servlet response.
stream_key - The key with which to get the stream from the output.
content_disposition_key - The key with which to get the content disposition from the output.
content_length_key - The key with which to get the content length from the output.
Method Detail

setFileNameKey

public void setFileNameKey(java.lang.String filename_key)

setContentTypeKey

public void setContentTypeKey(java.lang.String key)

execute

public void execute(Action a,
                    javax.servlet.http.HttpServletRequest req,
                    javax.servlet.http.HttpServletResponse res)
             throws ConsequenceException
Executes the action, reading from the input stream the data that has to be flushed into the servlet output stream.

Specified by:
execute in interface Consequence
Parameters:
a - The action that generated this consequence.
req - The servlet request of the action.
res - The servlet response of the action.
Throws:
ConsequenceException

defineHeader

protected void defineHeader(javax.servlet.http.HttpServletResponse res,
                            Output output)
                     throws ConsequenceException
Throws:
ConsequenceException


Copyright © 2005 Mentawai Team. All Rights Reserved.