org.apache.tapestry.web
Interface WebResponse

All Known Implementing Classes:
PortletWebResponse, RenderWebResponse, ServletWebResponse

public interface WebResponse

Controls the response to the client, and specifically allows for creating the output stream (or print writer) to which content is sent. This is essentially a generic version of HttpServletResponse. Some operations may be unsupported in some implementations (for example, the portlet implementation can't handle any of the setHeader methods).

Since:
4.0
Author:
Howard M. Lewis Ship

Method Summary
 String encodeURL(String url)
          Encodes a URL, which adds information to the URL needed to ensure that the request triggered by the URL will be associated with the current session (if any).
 String getNamespace()
          Returns a value to be prefixed or suffixed with any client-side JavaScript elements (variables and function names) to ensure that they are unique with the context of the entire page.
 OutputStream getOutputStream(ContentType contentType)
          Returns a output stream to which output should be sent.
 PrintWriter getPrintWriter(ContentType contentType)
          Returns a PrintWriter to which output should be sent.
 void reset()
          Resets any buffered content.
 void sendError(int statusCode, String message)
          Sends an error response.
 void setContentLength(int contentLength)
          Sets the response content length header.
 void setDateHeader(String name, long date)
          Sets a response header as a date.
 void setHeader(String name, String value)
          Sets a response header as a string.
 void setIntHeader(String name, int value)
          Sets a response header with the given name and integer value.
 void setStatus(int status)
          Sets the status code for this response.
 

Method Detail

getOutputStream

OutputStream getOutputStream(ContentType contentType)
                             throws IOException
Returns a output stream to which output should be sent. This method should only be invoked once on a response.

Parameters:
contentType - The encoding type that this outputstream will write content as.
Returns:
the output stream, configured for the given type.
Throws:
IOException - On io error.

getPrintWriter

PrintWriter getPrintWriter(ContentType contentType)
                           throws IOException
Returns a PrintWriter to which output should be sent. This method should be invoked once on a response. A second call is expected to be so that an exception page can be rendered, and the underlying request data is reset.

Parameters:
contentType - The type of content encoding the writer is for.
Returns:
A new PrintWriter instance.
Throws:
IOException - On io error.

encodeURL

String encodeURL(String url)
Encodes a URL, which adds information to the URL needed to ensure that the request triggered by the URL will be associated with the current session (if any). In most cases, the string is returned unchanged.

Parameters:
url - The URL to encode.
Returns:
The url encoded.

reset

void reset()
Resets any buffered content. This may be used after an error to radically change what the output will be.


setContentLength

void setContentLength(int contentLength)
Sets the response content length header.

Parameters:
contentLength - The total content length this response will write.

getNamespace

String getNamespace()
Returns a value to be prefixed or suffixed with any client-side JavaScript elements (variables and function names) to ensure that they are unique with the context of the entire page. For servlets, this is the empty string.

Returns:
The namespace that this requests resources should be pre-pended with.

setDateHeader

void setDateHeader(String name,
                   long date)
Sets a response header as a date.

Parameters:
name - the name of the header to set
date - the date value to set, in milliseconds since the epoch

setHeader

void setHeader(String name,
               String value)
Sets a response header as a string.

Parameters:
name - the name of the header to set
value - the value for the named header

setIntHeader

void setIntHeader(String name,
                  int value)
Sets a response header with the given name and integer value.

Parameters:
name - the name of the header to set
value - the value for the named header

setStatus

void setStatus(int status)
Sets the status code for this response.

Parameters:
status - The HTTP status code to set on the return header.

sendError

void sendError(int statusCode,
               String message)
               throws IOException
Sends an error response.

Parameters:
statusCode - The error status code to set on the header.
message - The message to give as the reason for error.
Throws:
IOException - on io error.


Copyright © 2006-2008 Apache Software Foundation. All Rights Reserved.