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
public class BaseScope extends AbstractScope
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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()booleandefinesVariable(String key)TemplateModelget(String key)Gets a TemplateModel from the hash.Collection<String>getDirectVariableNames()Returns the names of variables directly managed by this scope (i.e.booleanisEmpty()TemplateCollectionModelkeys()voidput(String key, TemplateModel value)Set a variable in this scope.TemplateModelremove(String key)Removes a variable in this scope.intsize()TemplateCollectionModelvalues()-
Methods inherited from class freemarker.core.AbstractScope
getEnclosingScope, getEnvironment, getTemplate, resolveVariable
-
-
-
-
Method Detail
-
put
public void put(String key, TemplateModel value)
Description copied from interface:ScopeSet a variable in this scope. This will typically only be used internally by the FreeMarker engine.
-
remove
public TemplateModel remove(String key)
Description copied from interface:ScopeRemoves a variable in this scope. This will typically only be used by FreeMarker engine internals
-
get
public TemplateModel get(String key)
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
public boolean definesVariable(String key)
- 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
public TemplateCollectionModel keys() throws TemplateModelException
- 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
public TemplateCollectionModel values() throws TemplateModelException
- Returns:
- a collection containing the values in the hash.
- Throws:
TemplateModelException
-
size
public int size() throws TemplateModelException- Returns:
- the number of key/value mappings in the hash.
- Throws:
TemplateModelException
-
clear
public void clear()
-
getDirectVariableNames
public Collection<String> 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.
-
-