Package org.apache.velocity.context
Class AbstractContext
java.lang.Object
org.apache.velocity.context.AbstractContext
- All Implemented Interfaces:
Context
,InternalEventContext
- Direct Known Subclasses:
DBContext
,TreeMapContext
,VelocityContext
This class is the abstract base class for all conventional
Velocity Context implementations. Simply extend this class
and implement the abstract routines that access your preferred
storage method.
Takes care of context chaining.
Also handles / enforces policy on null keys and values :
- Null keys and values are accepted and basically dropped.
- If you place an object into the context with a null key, it will be ignored and logged.
- If you try to place a null into the context with any key, it will be dropped and logged.
- Version:
- $Id$
- Author:
- Geir Magnusson Jr., Fedor Karpelevitch, Jason van Zyl
-
Constructor Summary
ConstructorDescriptiondefault CTORAbstractContext
(Context inner) Chaining constructor accepts a Context argument. -
Method Summary
Modifier and TypeMethodDescriptionboolean
containsKey
(String key) Indicates whether the specified key is in the context.Gets the value corresponding to the provided key from the context.returns innerContext if one is chainedint
get the current macro call depthget the current macro nameget the current template nameString[]
getKeys()
Get all the keys for the values in the contextString[]
get the current macro name stackString[]
get the current template name stackreturns 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 keyabstract boolean
Implement to determine if a key is in the storage.abstract Object
internalGet
(String key) Implement to return a value from the context storage.abstract String[]
Implement to return an object array of key strings from your storage.abstract Object
internalPut
(String key, Object value) Implement to put a value into the context storage.abstract Object
internalRemove
(String key) Implement to remove an item from your storage.void
remove the current macro name from stackvoid
remove the current template name from stackvoid
set the current macro name on top of stackvoid
set the current template name on top of stackAdds a name/value pair to the context.Removes the value associated with the specified key from the context.void
void
setMacroLibraries
(List<Template> macroLibraries)
-
Constructor Details
-
AbstractContext
public AbstractContext()default CTOR -
AbstractContext
Chaining constructor accepts a Context argument. It will relay get() operations into this Context in the even the 'local' get() returns null.- Parameters:
inner
- context to be chained
-
-
Method Details
-
internalGet
Implement to return a value from the context storage.
The implementation of this method is required for proper operation of a Context implementation in general Velocity use.- Parameters:
key
- key whose associated value is to be returned- Returns:
- object stored in the context
-
internalPut
Implement to put a value into the context storage.
The implementation of this method is required for proper operation of a Context implementation in general Velocity use.- Parameters:
key
- key with which to associate the valuevalue
- value to be associated with the key- Returns:
- previously stored value if exists, or null
-
internalContainsKey
Implement to determine if a key is in the storage.
Currently, this method is not used internally by the Velocity engine.- Parameters:
key
- key to test for existence- Returns:
- true if found, false if not
-
internalGetKeys
Implement to return an object array of key strings from your storage.
Currently, this method is not used internally by the Velocity engine.- Returns:
- array of keys
-
internalRemove
Implement to remove an item from your storage.
Currently, this method is not used internally by the Velocity engine.- Parameters:
key
- key to remove- Returns:
- object removed if exists, else null
-
put
Adds a name/value pair to the context. -
get
Gets the value corresponding to the provided key from the context. Supports the chaining context mechanism. If the 'local' context doesn't have the value, we try to get it from the chained context. -
containsKey
Indicates whether the specified key is in the context. Provided for debugging purposes.- Specified by:
containsKey
in interfaceContext
- Parameters:
key
- The key to look for.- Returns:
- true if the key is in the context, false if not.
-
getKeys
Get all the keys for the values in the context -
remove
Removes the value associated with the specified key from the context. -
getChainedContext
returns innerContext if one is chained- Returns:
- Context if chained,
null
if not
-
pushCurrentTemplateName
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
get the current template name- Returns:
- String current template name
-
getTemplateNameStack
get the current template name stack- Returns:
- String[] with the template name stack contents.
-
pushCurrentMacroName
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
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
get the current macro name stack- Returns:
- String[] with the macro name stack contents.
-
icacheGet
returns an IntrospectionCache Data (@see IntrospectionCacheData) object if exists for the key- Parameters:
key
- key to find in cache- Returns:
- cache object
-
icachePut
places an IntrospectionCache Data (@see IntrospectionCacheData) element in the cache for specified key- Parameters:
key
- keyo
- IntrospectionCacheData object to place in cache
-
setCurrentResource
- See Also:
-
getCurrentResource
- See Also:
-
setMacroLibraries
- See Also:
-
getMacroLibraries
- See Also:
-
attachEventCartridge
- Specified by:
attachEventCartridge
in interfaceInternalEventContext
- Parameters:
ec
-- Returns:
- The old EventCartridge.
- See Also:
-
getEventCartridge
- Specified by:
getEventCartridge
in interfaceInternalEventContext
- Returns:
- The current EventCartridge.
- See Also:
-