magoffin.matt.ma2.web.util
Class WebMediaResponse

java.lang.Object
  extended by magoffin.matt.ma2.web.util.WebMediaResponse
All Implemented Interfaces:
MediaResponse

public class WebMediaResponse
extends java.lang.Object
implements MediaResponse

Web implementation of MediaResponse.

Version:
$Revision: 43 $ $Date: 2007-10-21 11:10:01 +1300 (Sun, 21 Oct 2007) $
Author:
matt.magoffin

Constructor Summary
WebMediaResponse()
          Default constructor.
WebMediaResponse(javax.servlet.http.HttpServletResponse webResponse, boolean download)
          Construct from an HttpServletResponse.
WebMediaResponse(javax.servlet.http.HttpServletResponse webResponse, java.lang.String filename)
          Construct from an HttpServletResponse.
 
Method Summary
 java.io.OutputStream getOutputStream()
          Get the output stream.
 void setItem(MediaItem item)
          Set the media item used in the response.
 void setMediaLength(long length)
          Set the length of the media of the response.
 void setMimeType(java.lang.String mime)
          Set the MIME type of a response.
 void setModifiedDate(long date)
          Set the modification date of the response.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WebMediaResponse

public WebMediaResponse()
Default constructor.


WebMediaResponse

public WebMediaResponse(javax.servlet.http.HttpServletResponse webResponse,
                        java.lang.String filename)
Construct from an HttpServletResponse.

Parameters:
webResponse - the HttpServletResponse to respond with
filename - a filename to set on the response via a HTTP Content-Disposition header

WebMediaResponse

public WebMediaResponse(javax.servlet.http.HttpServletResponse webResponse,
                        boolean download)
Construct from an HttpServletResponse.

Parameters:
webResponse - the HttpServletResponse to respond with
download - true if should generate a download HTTP Content-Disposition header
Method Detail

setMimeType

public void setMimeType(java.lang.String mime)
Description copied from interface: MediaResponse
Set the MIME type of a response.

The MIME type of the response might be different from the MIME type of the MediaItem in the request. For example a request for an MP3 resource might actually return a JPG image extracted from the metadata of that MP3 file.

Specified by:
setMimeType in interface MediaResponse
Parameters:
mime - the MIME type of the response

setMediaLength

public void setMediaLength(long length)
Description copied from interface: MediaResponse
Set the length of the media of the response.

This should be the lenght, in bytes, if the data representing the result of the media request processing.

Specified by:
setMediaLength in interface MediaResponse
Parameters:
length - the length of the content

setItem

public void setItem(MediaItem item)
Description copied from interface: MediaResponse
Set the media item used in the response.

The MediaRequest object only contains the ID of the MediaItem to process. This method should be called with the actual MediaItem for that ID.

Specified by:
setItem in interface MediaResponse
Parameters:
item - the media item

getOutputStream

public java.io.OutputStream getOutputStream()
Description copied from interface: MediaResponse
Get the output stream.

This is the OutputStream that the result of processing the request should be written to. During request processing, the MediaHandler doing the processing should write the resulting media item data to this stream.

Specified by:
getOutputStream in interface MediaResponse
Returns:
output stream to write the result to

setModifiedDate

public void setModifiedDate(long date)
Description copied from interface: MediaResponse
Set the modification date of the response.

If possible, this method should be called and set with the last modification date of the result of processing this media request. This is to aid client caching, for clients that request media items with a "if modified since" directive, such as HTTP clients.

Specified by:
setModifiedDate in interface MediaResponse
Parameters:
date - the modification date