com.primix.tapestry
Class RequestContext

java.lang.Object
  |
  +--com.primix.tapestry.RequestContext
All Implemented Interfaces:
IRender

public class RequestContext
extends java.lang.Object
implements IRender

This class encapsulates all the relevant data for one request cycle of an ApplicationServlet, that is:

It also provides methods for:

This class is not a component, but does implement IRender. When asked to render (perhaps as the delegate of a Delegator component} it simply invokes write(IResponseWriter) to display all debugging output.

This class is derived from the original class com.primix.servlet.RequestContext, part of the ServletUtils framework available from The Giant Java Tree.

Version:
$Id: RequestContext.java,v 1.17 2001/09/21 12:35:09 hship Exp $
Author:
Howard Ship

Constructor Summary
RequestContext(ApplicationServlet servlet, HttpServletRequest request, HttpServletResponse response)
          Creates a RequestContext from its components.
 
Method Summary
 void addCookie(Cookie cookie)
          Adds a Cookie to the response.
 void addCookie(java.lang.String name, java.lang.String value)
          Adds a simple Cookie.
 HttpSession createSession()
          Like getSession(), but forces the creation of the HttpSession, if necessary.
static java.lang.String encodeColor(java.awt.Color color)
          Encodes a java.awt.Color in the standard HTML format: a pound sign ('#'), followed by six hex digits for specifying the red, green and blue components of the color.
 void forward(java.lang.String path)
          Forwards the request to a new resource, typically a JSP.
 java.lang.String getAbsoluteURL(java.lang.String URI)
          Builds an absolute URL from the given URI, using the HttpServletRequest as the source for scheme, server name and port.
 java.lang.String getAbsoluteURL(java.lang.String URI, java.lang.String scheme, java.lang.String server, int port)
          Does some easy checks to turn a path (or URI) into an absolute URL.
 Cookie getCookie(java.lang.String name)
          Gets a named Cookie.
 java.lang.String getCookieValue(java.lang.String name)
          Reads the named Cookie and returns its value (if it exists), or null if it does not exist.
 java.lang.String getParameter(java.lang.String name)
          Returns the named parameter from the HttpServletRequest.
 java.lang.String[] getParameterValues(java.lang.String name)
          For parameters that are, or are possibly, multi-valued, this method returns all the values as an array of Strings.
 java.lang.String getPathInfo(int index)
          Returns the pathInfo string at the given index.
 int getPathInfoCount()
          Returns the number of items in the pathInfo.
 HttpServletRequest getRequest()
           
 HttpServletResponse getResponse()
           
 ApplicationServlet getServlet()
           
 HttpSession getSession()
          Returns the HttpSession, if necessary, invoking HttpServletRequest.getSession(boolean).
 void redirect(java.lang.String path)
          Invokes HttpResponse.sendRedirect(), but massages path, supplying missing elements to make it a full URL (i.e., specifying scheme, server, port, etc.).
 void render(IResponseWriter writer, IRequestCycle cycle)
          Invokes write(IResponseWriter), which is used for debugging.
 void write(IResponseWriter writer)
          Writes the state of the context to the writer, typically for inclusion in a HTML page returned to the user.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RequestContext

public RequestContext(ApplicationServlet servlet,
                      HttpServletRequest request,
                      HttpServletResponse response)
Creates a RequestContext from its components.
Method Detail

addCookie

public void addCookie(java.lang.String name,
                      java.lang.String value)
Adds a simple Cookie. To set a Cookie with attributes, use addCookie(Cookie).

addCookie

public void addCookie(Cookie cookie)
Adds a Cookie to the response. Once added, the Cookie will also be available to getCookie(String) method.

Cookies should only be added before invoking ServletResponse.getWriter()..


encodeColor

public static java.lang.String encodeColor(java.awt.Color color)
Encodes a java.awt.Color in the standard HTML format: a pound sign ('#'), followed by six hex digits for specifying the red, green and blue components of the color.

forward

public void forward(java.lang.String path)
             throws ServletException,
                    java.io.IOException
Forwards the request to a new resource, typically a JSP.

getAbsoluteURL

public java.lang.String getAbsoluteURL(java.lang.String URI)
Builds an absolute URL from the given URI, using the HttpServletRequest as the source for scheme, server name and port.
See Also:
getAbsoluteURL(String, String, String, int)

getAbsoluteURL

public java.lang.String getAbsoluteURL(java.lang.String URI,
                                       java.lang.String scheme,
                                       java.lang.String server,
                                       int port)
Does some easy checks to turn a path (or URI) into an absolute URL. We assume

getCookie

public Cookie getCookie(java.lang.String name)
Gets a named Cookie.
Parameters:
name - The name of the Cookie.
Returns:
The Cookie, or null if no Cookie with that name exists.

getCookieValue

public java.lang.String getCookieValue(java.lang.String name)
Reads the named Cookie and returns its value (if it exists), or null if it does not exist.

getParameter

public java.lang.String getParameter(java.lang.String name)
Returns the named parameter from the HttpServletRequest.

Use getParameterValues(String) for parameters that may invlude multiple values.


getParameterValues

public java.lang.String[] getParameterValues(java.lang.String name)
For parameters that are, or are possibly, multi-valued, this method returns all the values as an array of Strings.

getPathInfo

public java.lang.String getPathInfo(int index)
Returns the pathInfo string at the given index. If the index is out of range, this returns null.

getPathInfoCount

public int getPathInfoCount()
Returns the number of items in the pathInfo.

getRequest

public HttpServletRequest getRequest()

getResponse

public HttpServletResponse getResponse()

getServlet

public ApplicationServlet getServlet()

getSession

public HttpSession getSession()
Returns the HttpSession, if necessary, invoking HttpServletRequest.getSession(boolean). However, this method will not create a session.

createSession

public HttpSession createSession()
Like getSession(), but forces the creation of the HttpSession, if necessary.

redirect

public void redirect(java.lang.String path)
              throws java.io.IOException
Invokes HttpResponse.sendRedirect(), but massages path, supplying missing elements to make it a full URL (i.e., specifying scheme, server, port, etc.).

The 2.2 Servlet API will do this automatically, and a little more, according to the early documentation.


write

public void write(IResponseWriter writer)
Writes the state of the context to the writer, typically for inclusion in a HTML page returned to the user. This is useful when debugging.

render

public void render(IResponseWriter writer,
                   IRequestCycle cycle)
            throws RequestCycleException
Invokes write(IResponseWriter), which is used for debugging.
Specified by:
render in interface IRender