org.niggle.templates.freemarkerimpl
Class FreemarkerPage

java.lang.Object
  |
  +--org.niggle.templates.freemarkerimpl.FreemarkerPage
All Implemented Interfaces:
freemarker.template.ObjectWrapper, Page

public class FreemarkerPage
extends java.lang.Object
implements Page, freemarker.template.ObjectWrapper

An implementation of the org.niggle.templates.Page interface that uses the freemarker template library.

Author:
Jonathan Revusky

Field Summary
protected  freemarker.template.SimpleHash model
           
protected static java.lang.Class recordWrapperClass
           
 
Constructor Summary
FreemarkerPage(freemarker.template.Template pageTemplate, java.util.Map root, java.lang.String contentType)
          Creates a new FreemarkerPage.
 
Method Summary
protected  RecordWrapper createRecordWrapper(Record rec)
          create a wrapper of the appropriate class to wrap the given record, reusing the context info.
 void expose(java.lang.String key, boolean b)
          Convenience method really, since all Freemarker scalar variables are strings.
 void expose(java.lang.String key, java.lang.Object item)
          expose internal data, publishing it to make it available to a Freemarker Template.
 void exposeResourceBundle(java.lang.String lookupName)
          expose an instance of java.util.ResourceBundle as a template hash variable
protected  java.util.Locale getLocale()
           
static java.lang.Class getRecordWrapperClass()
           
 void outputPage(javax.servlet.http.HttpServletResponse response)
          Prepare the cooked HTML, filling in the parameters with data values, and send it to the end user via the servlet's response stream.
 void setHeader(java.lang.String param, java.lang.String value)
          Set a header in the servlet response.
static void setRecordWrapperClass(java.lang.Class cl)
           
 void setStatic(boolean isStatic)
          sets a technical hint as to whether the page should be cached.
 java.lang.String toString()
           
 freemarker.template.TemplateModel wrap(java.lang.Object val)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

model

protected freemarker.template.SimpleHash model

recordWrapperClass

protected static java.lang.Class recordWrapperClass
Constructor Detail

FreemarkerPage

public FreemarkerPage(freemarker.template.Template pageTemplate,
                      java.util.Map root,
                      java.lang.String contentType)
               throws java.io.IOException
Creates a new FreemarkerPage.

Parameters:
pageTemplate - the template to use.
Method Detail

outputPage

public void outputPage(javax.servlet.http.HttpServletResponse response)
                throws java.io.IOException
Prepare the cooked HTML, filling in the parameters with data values, and send it to the end user via the servlet's response stream.

Specified by:
outputPage in interface Page
Parameters:
response - handle to where the output should go.
Throws:
java.io.IOException

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
Returns:
the processed HTML as a String

expose

public void expose(java.lang.String key,
                   java.lang.Object item)
expose internal data, publishing it to make it available to a Freemarker Template.

Specified by:
expose in interface Page
Parameters:
key - name of the field in the template
item - source of the data to populate the template

expose

public void expose(java.lang.String key,
                   boolean b)
Convenience method really, since all Freemarker scalar variables are strings. Exposes the boolean value as "true" or "". (Note that the empty string in freemarker is essentially false

Specified by:
expose in interface Page
Parameters:
key - name of the field in the template
b - sets to boolean value according to: b ? "true" : ""

exposeResourceBundle

public void exposeResourceBundle(java.lang.String lookupName)
Description copied from interface: Page
expose an instance of java.util.ResourceBundle as a template hash variable

Specified by:
exposeResourceBundle in interface Page

getRecordWrapperClass

public static java.lang.Class getRecordWrapperClass()

setRecordWrapperClass

public static void setRecordWrapperClass(java.lang.Class cl)

createRecordWrapper

protected RecordWrapper createRecordWrapper(Record rec)
create a wrapper of the appropriate class to wrap the given record, reusing the context info.


wrap

public freemarker.template.TemplateModel wrap(java.lang.Object val)
Specified by:
wrap in interface freemarker.template.ObjectWrapper

setStatic

public void setStatic(boolean isStatic)
Description copied from interface: Page
sets a technical hint as to whether the page should be cached. (By default this is false.)

Specified by:
setStatic in interface Page

setHeader

public void setHeader(java.lang.String param,
                      java.lang.String value)
Description copied from interface: Page
Set a header in the servlet response.

Specified by:
setHeader in interface Page

getLocale

protected java.util.Locale getLocale()