Package org.apache.velocity
Class VelocityContext
- java.lang.Object
-
- org.apache.velocity.context.AbstractContext
-
- org.apache.velocity.VelocityContext
-
- All Implemented Interfaces:
Serializable
,Cloneable
,Context
,InternalEventContext
public class VelocityContext extends AbstractContext implements Cloneable, Serializable
General purpose implementation of the application Context interface for general application use. This class should be used in place of the original Context class. This implementation uses a HashMap (@see java.util.HashMap ) for data storage. This context implementation cannot be shared between threads without those threads synchronizing access between them, as the HashMap is not synchronized, nor are some of the fundamentals of AbstractContext. If you need to share a Context between threads with simultaneous access for some reason, please create your own and extend the interface Context- Version:
- $Id$
- Author:
- Geir Magnusson Jr., Jason van Zyl, Fedor Karpelevitch, Daniel Rall
- See Also:
Context
, Serialized Form
-
-
Constructor Summary
Constructors Constructor Description VelocityContext()
Creates a new instance (with no inner context).VelocityContext(Map<String,Object> context)
Creates a new instance with the provided storage (and no inner context).VelocityContext(Map<String,Object> context, Context innerContext)
Initializes internal storage (never tonull
), and inner context.VelocityContext(Context innerContext)
Chaining constructor, used when you want to wrap a context in another.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description EventCartridge
attachEventCartridge(EventCartridge ec)
Object
clone()
Clones this context object.int
getCurrentMacroCallDepth()
get the current macro call depthString
getCurrentMacroName()
get the current macro nameResource
getCurrentResource()
String
getCurrentTemplateName()
get the current template nameEventCartridge
getEventCartridge()
List<Template>
getMacroLibraries()
String[]
getMacroNameStack()
get the current macro name stackString[]
getTemplateNameStack()
get the current template name stackIntrospectionCacheData
icacheGet(Object key)
returns an IntrospectionCache Data (@see IntrospectionCacheData) object if exists for the keyvoid
icachePut(Object key, IntrospectionCacheData o)
places an IntrospectionCache Data (@see IntrospectionCacheData) element in the cache for specified keyboolean
internalContainsKey(String key)
determines if there is a value for the given keyObject
internalGet(String key)
retrieves value for key from internal storageString[]
internalGetKeys()
returns array of keysObject
internalPut(String key, Object value)
stores the value for key to internal storageObject
internalRemove(String key)
remove a key/value pair from the internal storagevoid
popCurrentMacroName()
remove the current macro name from stackvoid
popCurrentTemplateName()
remove the current template name from stackvoid
pushCurrentMacroName(String s)
set the current macro name on top of stackvoid
pushCurrentTemplateName(String s)
set the current template name on top of stackvoid
setCurrentResource(Resource r)
void
setMacroLibraries(List<Template> macroLibraries)
-
Methods inherited from class org.apache.velocity.context.AbstractContext
containsKey, get, getChainedContext, getKeys, put, remove
-
-
-
-
Constructor Detail
-
VelocityContext
public VelocityContext()
Creates a new instance (with no inner context).
-
VelocityContext
public VelocityContext(Map<String,Object> context)
Creates a new instance with the provided storage (and no inner context).- Parameters:
context
-
-
VelocityContext
public VelocityContext(Context innerContext)
Chaining constructor, used when you want to wrap a context in another. The inner context will be 'read only' - put() calls to the wrapping context will only effect the outermost context- Parameters:
innerContext
- TheContext
implementation to wrap.
-
-
Method Detail
-
internalGet
public Object internalGet(String key)
retrieves value for key from internal storage- Specified by:
internalGet
in classAbstractContext
- Parameters:
key
- name of value to get- Returns:
- value as object
-
internalPut
public Object internalPut(String key, Object value)
stores the value for key to internal storage- Specified by:
internalPut
in classAbstractContext
- Parameters:
key
- name of value to storevalue
- value to store- Returns:
- previous value of key as Object
-
internalContainsKey
public boolean internalContainsKey(String key)
determines if there is a value for the given key- Specified by:
internalContainsKey
in classAbstractContext
- Parameters:
key
- name of value to check- Returns:
- true if non-null value in store
-
internalGetKeys
public String[] internalGetKeys()
returns array of keys- Specified by:
internalGetKeys
in classAbstractContext
- Returns:
- keys as []
-
internalRemove
public Object internalRemove(String key)
remove a key/value pair from the internal storage- Specified by:
internalRemove
in classAbstractContext
- Parameters:
key
- name of value to remove- Returns:
- value removed
-
clone
public Object clone()
Clones this context object.
-
pushCurrentTemplateName
public void pushCurrentTemplateName(String s)
set the current template name on top of stack- Parameters:
s
- current template name
-
popCurrentTemplateName
public void popCurrentTemplateName()
remove the current template name from stack
-
getCurrentTemplateName
public String getCurrentTemplateName()
get the current template name- Returns:
- String current template name
-
getTemplateNameStack
public String[] getTemplateNameStack()
get the current template name stack- Returns:
- String[] with the template name stack contents.
-
pushCurrentMacroName
public void pushCurrentMacroName(String s)
set the current macro name on top of stack- Parameters:
s
- current macro name
-
popCurrentMacroName
public void popCurrentMacroName()
remove the current macro name from stack
-
getCurrentMacroName
public String getCurrentMacroName()
get the current macro name- Returns:
- String current macro name
-
getCurrentMacroCallDepth
public int getCurrentMacroCallDepth()
get the current macro call depth- Returns:
- int current macro call depth
-
getMacroNameStack
public String[] getMacroNameStack()
get the current macro name stack- Returns:
- String[] with the macro name stack contents.
-
icacheGet
public IntrospectionCacheData icacheGet(Object key)
returns an IntrospectionCache Data (@see IntrospectionCacheData) object if exists for the key- Parameters:
key
- key to find in cache- Returns:
- cache object
-
icachePut
public void icachePut(Object key, IntrospectionCacheData o)
places an IntrospectionCache Data (@see IntrospectionCacheData) element in the cache for specified key- Parameters:
key
- keyo
- IntrospectionCacheData object to place in cache
-
setCurrentResource
public void setCurrentResource(Resource r)
- See Also:
InternalHousekeepingContext.setCurrentResource(org.apache.velocity.runtime.resource.Resource)
-
getCurrentResource
public Resource getCurrentResource()
- See Also:
InternalHousekeepingContext.getCurrentResource()
-
setMacroLibraries
public void setMacroLibraries(List<Template> macroLibraries)
- See Also:
InternalHousekeepingContext.setMacroLibraries(List)
-
getMacroLibraries
public List<Template> getMacroLibraries()
- See Also:
InternalHousekeepingContext.getMacroLibraries()
-
attachEventCartridge
public EventCartridge attachEventCartridge(EventCartridge ec)
- Specified by:
attachEventCartridge
in interfaceInternalEventContext
- Returns:
- The old EventCartridge.
- See Also:
InternalEventContext.attachEventCartridge(org.apache.velocity.app.event.EventCartridge)
-
getEventCartridge
public EventCartridge getEventCartridge()
- Specified by:
getEventCartridge
in interfaceInternalEventContext
- Returns:
- The current EventCartridge.
- See Also:
InternalEventContext.getEventCartridge()
-
-