org.apache.cocoon.environment.http
Class HttpResponse

java.lang.Object
  extended by org.apache.cocoon.environment.http.HttpResponse
All Implemented Interfaces:
Response

public final class HttpResponse
extends Object
implements Response

Implements the Response interface to provide response functionality in the HTTP servlets environment.

Version:
CVS $Id: HttpResponse.html 1304258 2012-03-23 10:09:27Z ilgrosso $
Author:
Apache Cocoon Team

Constructor Summary
protected HttpResponse(HttpServletResponse res)
          Creates a HttpServletResponse based on a real HttpServletResponse object
 
Method Summary
 void addCookie(Cookie cookie)
          Adds the specified cookie to the response.
 void addDateHeader(String name, long date)
          Adds a response header with the given name and date-value.
 void addHeader(String name, String value)
          Adds a response header with the given name and value.
 void addIntHeader(String name, int value)
          Adds a response header with the given name and int value.
 boolean containsHeader(String name)
          Returns a boolean indicating whether the named response header has already been set.
 Cookie createCookie(String name, String value)
          Create a new cookie which is not added to the response
 String encodeRedirectUrl(String url)
          Deprecated. As of version 2.1, use encodeRedirectURL(String url) instead
 String encodeRedirectURL(String url)
           
 String encodeUrl(String url)
          Deprecated. As of version 2.1, use encodeURL(String url) instead
 String encodeURL(String url)
          Encodes the specified URL by including the session ID in it, or, if encoding is not needed, returns the URL unchanged.
 void flushBuffer()
           
 int getBufferSize()
           
 String getCharacterEncoding()
          Returns the name of the charset used for the MIME body sent in this response.
 Locale getLocale()
          Returns the locale assigned to the response.
 ServletOutputStream getOutputStream()
           
 PrintWriter getWriter()
           
 boolean isCommitted()
           
 void reset()
           
 void sendError(int sc)
           
 void sendError(int sc, String msg)
           
 void sendPermanentRedirect(String location)
           
 void sendRedirect(String location)
           
 void setBufferSize(int size)
           
 void setContentLength(int len)
           
 void setContentType(String type)
           
 void setDateHeader(String name, long date)
          Sets a response header with the given name and date-value.
 void setHeader(String name, String value)
          Sets a response header with the given name and value.
 void setIntHeader(String name, int value)
          Sets a response header with the given name and int value.
 void setLocale(Locale loc)
          Sets the locale of the response, setting the headers (including the Content-Type's charset) as appropriate.
 void setStatus(int sc)
           
 void setStatus(int sc, String sm)
          Deprecated. As of version 2.1, due to ambiguous meaning of the message parameter. To set a status code use setStatus(int), to send an error with a description use sendError(int, String).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HttpResponse

protected HttpResponse(HttpServletResponse res)
Creates a HttpServletResponse based on a real HttpServletResponse object

Method Detail

createCookie

public Cookie createCookie(String name,
                           String value)
Create a new cookie which is not added to the response

Specified by:
createCookie in interface Response
Parameters:
name - a String specifying the name of the cookie
value - a String specifying the value of the cookie

addCookie

public void addCookie(Cookie cookie)
Description copied from interface: Response
Adds the specified cookie to the response. This method can be called multiple times to set more than one cookie.

Specified by:
addCookie in interface Response
Parameters:
cookie - the Cookie to return to the client

containsHeader

public boolean containsHeader(String name)
Description copied from interface: Response
Returns a boolean indicating whether the named response header has already been set.

Specified by:
containsHeader in interface Response
Parameters:
name - the header name
Returns:
true if the named response header has already been set; false otherwise

encodeURL

public String encodeURL(String url)
Description copied from interface: Response
Encodes the specified URL by including the session ID in it, or, if encoding is not needed, returns the URL unchanged. The implementation of this method includes the logic to determine whether the session ID needs to be encoded in the URL. For example, if the browser supports cookies, or session tracking is turned off, URL encoding is unnecessary.

For robust session tracking, all URLs emitted by a servlet should be run through this method. Otherwise, URL rewriting cannot be used with browsers which do not support cookies.

Specified by:
encodeURL in interface Response
Parameters:
url - the url to be encoded.
Returns:
the encoded URL if encoding is needed; the unchanged URL otherwise.

encodeRedirectURL

public String encodeRedirectURL(String url)

sendError

public void sendError(int sc,
                      String msg)
               throws IOException
Throws:
IOException

sendError

public void sendError(int sc)
               throws IOException
Throws:
IOException

sendRedirect

public void sendRedirect(String location)
                  throws IOException
Throws:
IOException

sendPermanentRedirect

public void sendPermanentRedirect(String location)
                           throws IOException
Throws:
IOException

setDateHeader

public void setDateHeader(String name,
                          long date)
Description copied from interface: Response
Sets a response header with the given name and date-value. The date is specified in terms of milliseconds since the epoch. If the header had already been set, the new value overwrites the previous one. The containsHeader method can be used to test for the presence of a header before setting its value.

Specified by:
setDateHeader in interface Response
Parameters:
name - the name of the header to set
date - the assigned date value
See Also:
Response.containsHeader(String), Response.addDateHeader(String, long)

addDateHeader

public void addDateHeader(String name,
                          long date)
Description copied from interface: Response
Adds a response header with the given name and date-value. The date is specified in terms of milliseconds since the epoch. This method allows response headers to have multiple values.

Specified by:
addDateHeader in interface Response
Parameters:
name - the name of the header to set
date - the additional date value
See Also:
Response.setDateHeader(String, long)

setHeader

public void setHeader(String name,
                      String value)
Description copied from interface: Response
Sets a response header with the given name and value. If the header had already been set, the new value overwrites the previous one. The containsHeader method can be used to test for the presence of a header before setting its value.

Specified by:
setHeader in interface Response
Parameters:
name - the name of the header
value - the header value
See Also:
Response.containsHeader(String), Response.addHeader(String, String)

addHeader

public void addHeader(String name,
                      String value)
Description copied from interface: Response
Adds a response header with the given name and value. This method allows response headers to have multiple values.

Specified by:
addHeader in interface Response
Parameters:
name - the name of the header
value - the additional header value
See Also:
Response.setHeader(String, String)

setIntHeader

public void setIntHeader(String name,
                         int value)
Description copied from interface: Response
Sets a response header with the given name and int value. If the header had already been set, the new value overwrites the previous one. The containsHeader method can be used to test for the presence of a header before setting its value.

Specified by:
setIntHeader in interface Response
Parameters:
name - the name of the header to set
value - the assigned int value
See Also:
Response.containsHeader(String), Response.addIntHeader(String, int)

addIntHeader

public void addIntHeader(String name,
                         int value)
Description copied from interface: Response
Adds a response header with the given name and int value. This method allows response headers to have multiple values.

Specified by:
addIntHeader in interface Response
Parameters:
name - the name of the header to set
value - the additional int value
See Also:
Response.setIntHeader(String, int)

setStatus

public void setStatus(int sc)

encodeUrl

public String encodeUrl(String url)
Deprecated. As of version 2.1, use encodeURL(String url) instead


encodeRedirectUrl

public String encodeRedirectUrl(String url)
Deprecated. As of version 2.1, use encodeRedirectURL(String url) instead


setStatus

public void setStatus(int sc,
                      String sm)
Deprecated. As of version 2.1, due to ambiguous meaning of the message parameter. To set a status code use setStatus(int), to send an error with a description use sendError(int, String).


getCharacterEncoding

public String getCharacterEncoding()
Description copied from interface: Response
Returns the name of the charset used for the MIME body sent in this response.

If no charset has been assigned, it is implicitly set to ISO-8859-1 (Latin-1).

See RFC 2047 (http://ds.internic.net/rfc/rfc2045.txt) for more information about character encoding and MIME.

Specified by:
getCharacterEncoding in interface Response
Returns:
a String specifying the name of the charset, for example, ISO-8859-1

getOutputStream

public ServletOutputStream getOutputStream()
                                    throws IOException
Throws:
IOException

getWriter

public PrintWriter getWriter()
                      throws IOException
Throws:
IOException

setContentLength

public void setContentLength(int len)

setContentType

public void setContentType(String type)

setBufferSize

public void setBufferSize(int size)

getBufferSize

public int getBufferSize()

flushBuffer

public void flushBuffer()
                 throws IOException
Throws:
IOException

isCommitted

public boolean isCommitted()

reset

public void reset()

setLocale

public void setLocale(Locale loc)
Description copied from interface: Response
Sets the locale of the response, setting the headers (including the Content-Type's charset) as appropriate. By default, the response locale is the default locale for the server.

Specified by:
setLocale in interface Response
Parameters:
loc - the locale of the response
See Also:
Response.getLocale()

getLocale

public Locale getLocale()
Description copied from interface: Response
Returns the locale assigned to the response.

Specified by:
getLocale in interface Response
See Also:
Response.setLocale(Locale)


Copyright © 1999-2010 The Apache Software Foundation. All Rights Reserved.