org.mentawai.core
Class StreamConsequence

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

public class StreamConsequence
extends 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, Sergio Oliveira Jr.

Field Summary
static String APPLICATION_OGG
          Ogg, a multimedia bitstream container format.
static String APPLICATION_PDF
          Portable Document Format.
static String APPLICATION_SOAP
          SOAP.
static String AUDIO_MPEG
          MP3 or other MPEG audio.
static String AUDIO_OGG
          Ogg Vorbis, Speex, Flac and other audio.
static String CONTENT_DISPOSITION
          The default key ("contentDisposition") to look for in the action output.
static String CONTENT_LENGTH
          The default key ("contentLength") to look for in the action output.
static String CONTENT_TYPE
          The default key ("contentType") to look for in the action output.
static String EXCEL
           
static String FILENAME
           
static String IMAGE_GIF
          GIF image.
static String IMAGE_JPEG
          JPEG JFIF image.
static String IMAGE_PNG
          Portable Network Graphics.
static String STREAM
          The default key ("stream") to look for in the action output.
 
Constructor Summary
StreamConsequence()
          Creates a new instance of the StreamConsequence class.
StreamConsequence(String contentType)
          Creates a new instance of the StreamConsequence class, with the given content-type
 
Method Summary
protected  void defineHeader(javax.servlet.http.HttpServletResponse res, Output output)
           
 void execute(Action a, String result, 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.
 StreamConsequence keyForContentDisposition(String key)
           
 StreamConsequence keyForContentLength(String key)
           
 StreamConsequence keyForContentType(String key)
           
 StreamConsequence keyForFilename(String key)
           
 StreamConsequence keyForStream(String key)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STREAM

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

See Also:
Constant Field Values

CONTENT_DISPOSITION

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

See Also:
Constant Field Values

CONTENT_LENGTH

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

See Also:
Constant Field Values

CONTENT_TYPE

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

See Also:
Constant Field Values

APPLICATION_OGG

public static final String APPLICATION_OGG
Ogg, a multimedia bitstream container format. Defined in RFC 5334.

See Also:
Constant Field Values

APPLICATION_PDF

public static final String APPLICATION_PDF
Portable Document Format. Defined in RFC 3778 5334.

See Also:
Constant Field Values

APPLICATION_SOAP

public static final String APPLICATION_SOAP
SOAP. Defined by RFC 3902.

See Also:
Constant Field Values

AUDIO_MPEG

public static final String AUDIO_MPEG
MP3 or other MPEG audio. Defined in RFC 3003.

See Also:
Constant Field Values

AUDIO_OGG

public static final String AUDIO_OGG
Ogg Vorbis, Speex, Flac and other audio. Defined in RFC 5334.

See Also:
Constant Field Values

IMAGE_GIF

public static final String IMAGE_GIF
GIF image. Defined in RFC 2045 and RFC 2046.

See Also:
Constant Field Values

IMAGE_JPEG

public static final String IMAGE_JPEG
JPEG JFIF image. Defined in RFC 2045 and RFC 2046.

See Also:
Constant Field Values

IMAGE_PNG

public static final String IMAGE_PNG
Portable Network Graphics. Defined in RFC 2083.

See Also:
Constant Field Values

EXCEL

public static final String EXCEL
See Also:
Constant Field Values

FILENAME

public static final String FILENAME
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(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.
Method Detail

keyForFilename

public StreamConsequence keyForFilename(String key)

keyForContentType

public StreamConsequence keyForContentType(String key)

keyForContentDisposition

public StreamConsequence keyForContentDisposition(String key)

keyForContentLength

public StreamConsequence keyForContentLength(String key)

keyForStream

public StreamConsequence keyForStream(String key)

execute

public void execute(Action a,
                    String result,
                    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.
result - The result generated by the action.
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 © 2013. All Rights Reserved.