freemarker.engine
Class FMModel

java.lang.Object
  extended by freemarker.engine.FMModel

public class FMModel
extends java.lang.Object

General purpose class for passing object models to a FM-Classic template. These can be passed in as objects or classes using the putObject(String, Object) and putClass(String, Class) methods.

For occasions where a custom TemplateModel is required, these can be added using the putModel(String, freemarker.template.TemplateModel) method.

Once the model is complete, it can be applied using one of the FMEngine.apply() methods.

Since:
1.9
Version:
$Id: FMModel.java 1149 2013-04-15 09:57:11Z run2000 $
Author:
Nicholas Cull

Field Summary
protected  TemplateHashModel m_cInnerModel
           
protected  java.util.HashMap<java.lang.String,TemplateModel> m_cModel
           
 
Constructor Summary
FMModel()
          Create a new empty FMModel.
FMModel(FMModel innerModel)
          Create a new FMModel that wraps the given inner model.
FMModel(TemplateHashModel innerModel)
          Create a new FMModel that wraps the given inner model.
 
Method Summary
 FMModel putClass(java.lang.String name, java.lang.Class clz)
          Puts the given class into this FMModel, with the given name.
 FMModel putClass(java.lang.String name, java.lang.String className)
          Puts the named class into this FMModel, with the given name.
 FMModel putModel(java.lang.String name, TemplateModel model)
          Puts the given template model into this FMModel, with the given name.
 FMModel putObject(java.lang.String name, java.lang.Object obj)
          Puts the given object into this FMModel, with the given name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_cInnerModel

protected final TemplateHashModel m_cInnerModel

m_cModel

protected final java.util.HashMap<java.lang.String,TemplateModel> m_cModel
Constructor Detail

FMModel

public FMModel()
Create a new empty FMModel. The model can be applied against a template using the FMEngine object.


FMModel

public FMModel(TemplateHashModel innerModel)
Create a new FMModel that wraps the given inner model. The inner model can be read, but not altered from this model.

Parameters:
innerModel - the inner model to be wrapped

FMModel

public FMModel(FMModel innerModel)
Create a new FMModel that wraps the given inner model. The inner model can be read, but not altered from this model.

Parameters:
innerModel - the inner model to be wrapped
Method Detail

putModel

public final FMModel putModel(java.lang.String name,
                              TemplateModel model)
Puts the given template model into this FMModel, with the given name.

Parameters:
name - the name of the object to be added
model - the template model to be added

putObject

public final FMModel putObject(java.lang.String name,
                               java.lang.Object obj)
Puts the given object into this FMModel, with the given name.

Parameters:
name - the name of the object to be added
obj - the object to be added

putClass

public final FMModel putClass(java.lang.String name,
                              java.lang.Class clz)
Puts the given class into this FMModel, with the given name.

Parameters:
name - the name of the object to be added
clz - the class to be added

putClass

public final FMModel putClass(java.lang.String name,
                              java.lang.String className)
                       throws java.lang.ClassNotFoundException
Puts the named class into this FMModel, with the given name.

Parameters:
name - the name of the object to be added
className - the name of the class to be added
Throws:
java.lang.ClassNotFoundException