freemarker.ext.misc
Class ExtendedHash

java.lang.Object
  extended by freemarker.template.SimpleHash
      extended by freemarker.ext.misc.ExtendedHash
All Implemented Interfaces:
TemplateHashModel, TemplateModel, TemplateModelRoot, TemplateObjectModel, TemplateWriteableHashModel, java.io.Serializable

public class ExtendedHash
extends SimpleHash
implements java.io.Serializable

Simple extension to the SimpleHash implementation. This class implements a number of convenience facilities in the form of template hash keys. The hash keys are:

Since:
1.7
Version:
$Id: ExtendedHash.java 1101 2013-04-01 04:17:32Z run2000 $
See Also:
ExtendedList, Serialized Form

Field Summary
 
Fields inherited from class freemarker.template.SimpleHash
hash
 
Constructor Summary
ExtendedHash()
          Creates new ExtendedHash.
ExtendedHash(java.util.Map<java.lang.String,? extends TemplateModel> hash)
          Creates new ExtendedHash given a Map of values.
 
Method Summary
 TemplateModel get(java.lang.String key)
          Gets a TemplateModel from the hash.
 
Methods inherited from class freemarker.template.SimpleHash
equals, getAsObject, hashCode, isEmpty, put, put, put, put, put, remove, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ExtendedHash

public ExtendedHash()
Creates new ExtendedHash.


ExtendedHash

public ExtendedHash(java.util.Map<java.lang.String,? extends TemplateModel> hash)
Creates new ExtendedHash given a Map of values. A defensive copy of the map is made.

Parameters:
hash - The Map of values to be copied into this ExtendedHash.
Throws:
java.lang.NullPointerException - the map value is null
Method Detail

get

public TemplateModel get(java.lang.String key)
                  throws TemplateModelException
Gets a TemplateModel from the hash. If the key matches one of the special values used in this implementation, return the special value, otherwise return the value from the underlying Map.

Specified by:
get in interface TemplateHashModel
Overrides:
get in class SimpleHash
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.
Throws:
TemplateModelException - there was a problem getting the value for the given key