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

java.lang.Object
  extended by org.apache.velocity.context.AbstractContext
      extended by org.apache.velocity.VelocityContext
          extended by org.apache.velocity.tools.view.context.ChainedContext
All Implemented Interfaces:
java.lang.Cloneable, org.apache.velocity.context.Context, org.apache.velocity.context.InternalEventContext, ViewContext

public class ChainedContext
extends org.apache.velocity.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  javax.servlet.ServletContext application
           
private  javax.servlet.http.HttpServletRequest request
           
private  javax.servlet.http.HttpServletResponse response
           
private  javax.servlet.http.HttpSession session
           
private  java.util.Map toolbox
           
private  org.apache.velocity.app.VelocityEngine velocity
           
 
Fields inherited from interface org.apache.velocity.tools.view.context.ViewContext
APPLICATION, REQUEST, RESPONSE, SESSION, XHTML
 
Constructor Summary
ChainedContext(org.apache.velocity.context.Context ctx, org.apache.velocity.app.VelocityEngine velocity, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.ServletContext application)
           
ChainedContext(org.apache.velocity.app.VelocityEngine velocity, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.ServletContext application)
           
 
Method Summary
 org.apache.velocity.app.event.EventCartridge attachEventCartridge(org.apache.velocity.app.event.EventCartridge arg0)
           
 boolean getAllowRendering()
           
 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.
 org.apache.velocity.runtime.resource.Resource getCurrentResource()
           
 java.lang.String getCurrentTemplateName()
           
 org.apache.velocity.app.event.EventCartridge getEventCartridge()
           
 javax.servlet.http.HttpServletRequest getRequest()
          Returns the current servlet request.
 javax.servlet.http.HttpServletResponse getResponse()
          Returns the current servlet response.
 javax.servlet.ServletContext getServletContext()
          Returns the servlet context.
 java.lang.Object[] getTemplateNameStack()
           
 java.util.Map getToolbox()
          Returns a read-only view of the toolbox Map for this context.
 org.apache.velocity.context.Context getVelocityContext()
          Returns a reference to the Velocity context (this object).
 org.apache.velocity.app.VelocityEngine getVelocityEngine()
          Returns a reference to the VelocityEngine.
 org.apache.velocity.util.introspection.IntrospectionCacheData icacheGet(java.lang.Object arg0)
           
 void icachePut(java.lang.Object arg0, org.apache.velocity.util.introspection.IntrospectionCacheData arg1)
           
 java.lang.Object internalGet(java.lang.String key)
          Looks up and returns the object with the specified key.
 void popCurrentTemplateName()
           
 void pushCurrentTemplateName(java.lang.String arg0)
           
 void setAllowRendering(boolean arg0)
           
 void setCurrentResource(org.apache.velocity.runtime.resource.Resource arg0)
           
 void setToolbox(java.util.Map box)
          Sets the toolbox of view tools.
 
Methods inherited from class org.apache.velocity.VelocityContext
clone, internalContainsKey, internalGetKeys, internalPut, internalRemove
 
Methods inherited from class org.apache.velocity.context.AbstractContext
containsKey, get, getChainedContext, getKeys, put, remove
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

toolbox

private java.util.Map toolbox

request

private javax.servlet.http.HttpServletRequest request

response

private javax.servlet.http.HttpServletResponse response

session

private javax.servlet.http.HttpSession session

application

private javax.servlet.ServletContext application

velocity

private org.apache.velocity.app.VelocityEngine velocity
Constructor Detail

ChainedContext

public ChainedContext(org.apache.velocity.app.VelocityEngine velocity,
                      javax.servlet.http.HttpServletRequest request,
                      javax.servlet.http.HttpServletResponse response,
                      javax.servlet.ServletContext application)

ChainedContext

public ChainedContext(org.apache.velocity.context.Context ctx,
                      org.apache.velocity.app.VelocityEngine velocity,
                      javax.servlet.http.HttpServletRequest request,
                      javax.servlet.http.HttpServletResponse response,
                      javax.servlet.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.

Overrides:
internalGet in class org.apache.velocity.VelocityContext
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 javax.servlet.http.HttpServletRequest getRequest()

Returns the current servlet request.

Specified by:
getRequest in interface ViewContext

getResponse

public javax.servlet.http.HttpServletResponse getResponse()

Returns the current servlet response.

Specified by:
getResponse in interface ViewContext

getServletContext

public javax.servlet.ServletContext getServletContext()

Returns the servlet context.

Specified by:
getServletContext in interface ViewContext

getVelocityContext

public org.apache.velocity.context.Context getVelocityContext()

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

Specified by:
getVelocityContext in interface ViewContext

getVelocityEngine

public org.apache.velocity.app.VelocityEngine getVelocityEngine()

Returns a reference to the VelocityEngine.

Specified by:
getVelocityEngine in interface ViewContext

pushCurrentTemplateName

public void pushCurrentTemplateName(java.lang.String arg0)

popCurrentTemplateName

public void popCurrentTemplateName()

getCurrentTemplateName

public java.lang.String getCurrentTemplateName()

getTemplateNameStack

public java.lang.Object[] getTemplateNameStack()

icacheGet

public org.apache.velocity.util.introspection.IntrospectionCacheData icacheGet(java.lang.Object arg0)

icachePut

public void icachePut(java.lang.Object arg0,
                      org.apache.velocity.util.introspection.IntrospectionCacheData arg1)

setCurrentResource

public void setCurrentResource(org.apache.velocity.runtime.resource.Resource arg0)

getCurrentResource

public org.apache.velocity.runtime.resource.Resource getCurrentResource()

getAllowRendering

public boolean getAllowRendering()

setAllowRendering

public void setAllowRendering(boolean arg0)

attachEventCartridge

public org.apache.velocity.app.event.EventCartridge attachEventCartridge(org.apache.velocity.app.event.EventCartridge arg0)
Specified by:
attachEventCartridge in interface org.apache.velocity.context.InternalEventContext

getEventCartridge

public org.apache.velocity.app.event.EventCartridge getEventCartridge()
Specified by:
getEventCartridge in interface org.apache.velocity.context.InternalEventContext


Copyright (c) 2003-2007 Apache Software Foundation