com.revusky.niggle.templates.freemarkerimpl
Class LazyHash

java.lang.Object
  |
  +--com.revusky.niggle.templates.PresentationWrapper
        |
        +--com.revusky.niggle.templates.freemarkerimpl.FreemarkerPresentationWrapper
              |
              +--com.revusky.niggle.templates.freemarkerimpl.LazyHash
All Implemented Interfaces:
freemarker.template.TemplateHashModel, freemarker.template.TemplateModel, freemarker.template.TemplateModelRoot
Direct Known Subclasses:
RecordWrapper

public class LazyHash
extends FreemarkerPresentationWrapper
implements freemarker.template.TemplateModelRoot

A freemarker template model implementation that replaces freemarker.template.SimpleHash. This class adds the following: (i) using this, the page template syntax is case-insensitive (meshes better with HTML, which is case-insensitive) (ii) the data in a niggle record can be exposed to the page in one go. (This is a big deal!) (iii) the data model encapsulates an i18n locale. (This is a very big deal. This will be the main point at which the canonical storage strings in a data record get internationalized.) (iv) You can expose a nested List or Map in one go via put (v) This uses lazy evaluation, so should be significantly more efficient!

Author:
Jonathan Revusky

Fields inherited from class com.revusky.niggle.templates.freemarkerimpl.FreemarkerPresentationWrapper
CASE_INSENSITIVE
 
Fields inherited from class com.revusky.niggle.templates.PresentationWrapper
contentType, interaction, locale, recordWrapperClass
 
Constructor Summary
LazyHash()
           
LazyHash(ServletInteraction interaction)
           
 
Method Summary
 void clearData()
          Clears out the hash
 freemarker.template.TemplateModel get(java.lang.String key)
          Overloaded so that the template variables can be case-insensitive.
 boolean isEmpty()
           
 void put(java.lang.String key, boolean b)
          Overloaded so that the template variables can be case-insensitive.
 void put(java.lang.String key, java.lang.Object val)
          expose an arbitrary object in this hash model
 void put(java.lang.String key, Record rec)
          expose data from a record by key
 void put(java.lang.String key, freemarker.template.TemplateModel val)
           
 void remove(java.lang.String key)
          Overloaded so that the template variables can be case-insensitive.
 
Methods inherited from class com.revusky.niggle.templates.freemarkerimpl.FreemarkerPresentationWrapper
createNestedHash, createWrapper, normalizeMap, wrapString
 
Methods inherited from class com.revusky.niggle.templates.PresentationWrapper
createRecordWrapper, getLocale, inheritFrom, setContentType, setRecord, setRecordWrapperClass, setSessionContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LazyHash

public LazyHash()

LazyHash

public LazyHash(ServletInteraction interaction)
Method Detail

clearData

public void clearData()
Clears out the hash

put

public void put(java.lang.String key,
                java.lang.Object val)
expose an arbitrary object in this hash model
Parameters:
the - variable name by which to expose the records.
val - the object to wrap as a freemarker template model. expose on to a page: typically niggle records or scalars or lists or nested hashes

put

public void put(java.lang.String key,
                boolean b)
Overloaded so that the template variables can be case-insensitive.

put

public void put(java.lang.String key,
                freemarker.template.TemplateModel val)
Specified by:
put in interface freemarker.template.TemplateModelRoot

get

public freemarker.template.TemplateModel get(java.lang.String key)
                                      throws freemarker.template.TemplateModelException
Overloaded so that the template variables can be case-insensitive.
Specified by:
get in interface freemarker.template.TemplateHashModel

remove

public void remove(java.lang.String key)
Overloaded so that the template variables can be case-insensitive.
Specified by:
remove in interface freemarker.template.TemplateModelRoot

put

public void put(java.lang.String key,
                Record rec)
expose data from a record by key
Parameters:
key -  
rec - source of data.

isEmpty

public boolean isEmpty()
                throws freemarker.template.TemplateModelException
Specified by:
isEmpty in interface freemarker.template.TemplateModel