org.apache.velocity.tools.view.context
Class ChainedContext

java.lang.Object
  extended by VelocityContext
      extended by org.apache.velocity.tools.view.context.ChainedContext
All Implemented Interfaces:
ViewContext

public class ChainedContext
extends VelocityContext
implements ViewContext

Velocity context implementation specific to the Servlet environment.

It provides the following special features:

The internalGet(String key) method implements the following search order for objects:

  1. toolbox
  2. servlet request, servlet response, servlet session, servlet context
  3. local hashtable of objects (traditional use)
  4. servlet request attribues, servlet session attribute, servlet context attributes

The purpose of this class is to make it easy for web designer to work with Java servlet based web applications. They do not need to be concerned with the concepts of request, session or application attributes and the lifetime of objects in these scopes.

Note that the put() method always puts objects into the local hashtable.

Version:
$Id: ChainedContext.java 514723 2007-03-05 16:39:32Z nbubna $
Author:
Geir Magnusson Jr., Gabe Sidler

Field Summary
private  ServletContext application
           
private  HttpServletRequest request
           
private  HttpServletResponse response
           
private  HttpSession session
           
private  java.util.Map toolbox
           
private  VelocityEngine velocity
           
 
Fields inherited from interface org.apache.velocity.tools.view.context.ViewContext
APPLICATION, REQUEST, RESPONSE, SESSION, XHTML
 
Constructor Summary
ChainedContext(Context ctx, VelocityEngine velocity, HttpServletRequest request, HttpServletResponse response, ServletContext application)
           
ChainedContext(VelocityEngine velocity, HttpServletRequest request, HttpServletResponse response, ServletContext application)
           
 
Method Summary
 java.lang.Object getAttribute(java.lang.String key)
          Searches for the named attribute in request, session (if valid), and application scope(s) in order and returns the value associated or null.
 HttpServletRequest getRequest()
          Returns the current servlet request.
 HttpServletResponse getResponse()
          Returns the current servlet response.
 ServletContext getServletContext()
          Returns the servlet context.
 java.util.Map getToolbox()
          Returns a read-only view of the toolbox Map for this context.
 Context getVelocityContext()
          Returns a reference to the Velocity context (this object).
 VelocityEngine getVelocityEngine()
          Returns a reference to the VelocityEngine.
 java.lang.Object internalGet(java.lang.String key)
          Looks up and returns the object with the specified key.
 void setToolbox(java.util.Map box)
          Sets the toolbox of view tools.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

toolbox

private java.util.Map toolbox

request

private HttpServletRequest request

response

private HttpServletResponse response

session

private HttpSession session

application

private ServletContext application

velocity

private VelocityEngine velocity
Constructor Detail

ChainedContext

public ChainedContext(VelocityEngine velocity,
                      HttpServletRequest request,
                      HttpServletResponse response,
                      ServletContext application)

ChainedContext

public ChainedContext(Context ctx,
                      VelocityEngine velocity,
                      HttpServletRequest request,
                      HttpServletResponse response,
                      ServletContext application)
Method Detail

setToolbox

public void setToolbox(java.util.Map box)

Sets the toolbox of view tools.

Parameters:
box - toolbox of view tools

getToolbox

public java.util.Map getToolbox()

Returns a read-only view of the toolbox Map for this context.

Returns:
an unmodifiable version of the toolbox for this request or null if there is none
Since:
VelocityTools 1.3

internalGet

public java.lang.Object internalGet(java.lang.String key)

Looks up and returns the object with the specified key.

See the class documentation for more details.

Parameters:
key - the key of the object requested
Returns:
the requested object or null if not found

getAttribute

public java.lang.Object getAttribute(java.lang.String key)

Searches for the named attribute in request, session (if valid), and application scope(s) in order and returns the value associated or null.

Specified by:
getAttribute in interface ViewContext
Since:
VelocityTools 1.1

getRequest

public HttpServletRequest getRequest()

Returns the current servlet request.

Specified by:
getRequest in interface ViewContext

getResponse

public HttpServletResponse getResponse()

Returns the current servlet response.

Specified by:
getResponse in interface ViewContext

getServletContext

public ServletContext getServletContext()

Returns the servlet context.

Specified by:
getServletContext in interface ViewContext

getVelocityContext

public Context getVelocityContext()

Returns a reference to the Velocity context (this object).

Specified by:
getVelocityContext in interface ViewContext

getVelocityEngine

public VelocityEngine getVelocityEngine()

Returns a reference to the VelocityEngine.

Specified by:
getVelocityEngine in interface ViewContext


Copyright (c) 2003-2007 Apache Software Foundation