Package freemarker.core
Class BaseScope
java.lang.Object
freemarker.core.AbstractScope
freemarker.core.BaseScope
- All Implemented Interfaces:
Scope,TemplateHashModel,TemplateHashModelEx,TemplateModel
- Direct Known Subclasses:
BlockScope,TemplateNamespace
A basic scope that stores variables locally in a hash map.
-
Nested Class Summary
Nested classes/interfaces inherited from interface freemarker.template.TemplateModel
TemplateModel.InvalidExpressionModel, TemplateModel.JavaNull -
Field Summary
Fields inherited from interface freemarker.template.TemplateModel
INVALID_EXPRESSION, JAVA_NULL, NOTHING -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()booleandefinesVariable(String key) Gets a TemplateModel from the hash.Returns the names of variables directly managed by this scope (i.e.booleanisEmpty()keys()voidput(String key, TemplateModel value) Set a variable in this scope.Removes a variable in this scope.intsize()values()Methods inherited from class freemarker.core.AbstractScope
getEnclosingScope, getEnvironment, getTemplate, resolveVariable
-
Method Details
-
put
Description copied from interface:ScopeSet a variable in this scope. This will typically only be used internally by the FreeMarker engine. -
remove
Description copied from interface:ScopeRemoves a variable in this scope. This will typically only be used by FreeMarker engine internals -
get
Description copied from interface:TemplateHashModelGets a TemplateModel from the hash.- Parameters:
key- the name by which the TemplateModel is identified in the template.- Returns:
- the TemplateModel referred to by the key, or null if not found.
-
definesVariable
- Returns:
- whether the variable is defined in this specific scope. (It could be defined in a fallback scope and this method will return false.)
-
isEmpty
public boolean isEmpty()- Specified by:
isEmptyin interfaceTemplateHashModel- Overrides:
isEmptyin classAbstractScope
-
keys
- Returns:
- a collection containing the keys in the hash. Every element of
the returned collection must implement the
TemplateScalarModel(as the keys of hashes are always strings). - Throws:
TemplateModelException
-
values
- Returns:
- a collection containing the values in the hash.
- Throws:
TemplateModelException
-
size
- Returns:
- the number of key/value mappings in the hash.
- Throws:
TemplateModelException
-
clear
public void clear() -
getDirectVariableNames
Description copied from interface:ScopeReturns the names of variables directly managed by this scope (i.e. it does not traverse the chain of enclosing scopes, but limits itself to this scope only).- Returns:
- a collection of known variable names for this scope, without enclosing scopes. The returned collection should be either immutable, or it should be disconnected from the scope, so any modifications to the collection don't affect the scope.
-