Package freemarker.template
Class WrappingTemplateModel
java.lang.Object
freemarker.template.WrappingTemplateModel
- Direct Known Subclasses:
SimpleCollection,SimpleHash,SimpleSequence
A base class for containers that wrap arbitrary Java objects into
TemplateModel instances.-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedProtected constructor that creates a new wrapping template model using the default object wrapper.protectedWrappingTemplateModel(ObjectWrapper objectWrapper) Protected constructor that creates a new wrapping template model using the specified object wrapper. -
Method Summary
Modifier and TypeMethodDescriptionstatic ObjectWrapperReturns the default object wrapper that is used when a wrapping template model is constructed without being passed an explicit object wrapper.Returns the object wrapper instance used by this wrapping template model.static voidsetDefaultObjectWrapper(ObjectWrapper objectWrapper) Sets the default object wrapper that is used when a wrapping template model is constructed without being passed an explicit object wrapper.voidsetObjectWrapper(ObjectWrapper objectWrapper) protected final TemplateModelWraps the passed object into a template model using this object's object wrapper, except that null is not wrapped but simply returned.
-
Constructor Details
-
WrappingTemplateModel
protected WrappingTemplateModel()Protected constructor that creates a new wrapping template model using the default object wrapper. -
WrappingTemplateModel
Protected constructor that creates a new wrapping template model using the specified object wrapper.- Parameters:
objectWrapper- the wrapper to use. If null is passed, the default object wrapper is used.
-
-
Method Details
-
setDefaultObjectWrapper
Sets the default object wrapper that is used when a wrapping template model is constructed without being passed an explicit object wrapper. The default value isObjectWrapper.SIMPLE_WRAPPER. Note thatConfiguration.setSharedVariable(String, Object)andTemplate.process(Object, java.io.Writer)don't use this setting, they rather use whatever object wrapper theirConfigurable.getObjectWrapper()method returns. -
getDefaultObjectWrapper
Returns the default object wrapper that is used when a wrapping template model is constructed without being passed an explicit object wrapper. Note thatConfiguration.setSharedVariable(String, Object)andTemplate.process(Object, java.io.Writer)don't use this setting, they rather use whatever object wrapper theirConfigurable.getObjectWrapper()method returns. -
getObjectWrapper
Returns the object wrapper instance used by this wrapping template model. -
setObjectWrapper
-
wrap
Wraps the passed object into a template model using this object's object wrapper, except that null is not wrapped but simply returned.- Parameters:
obj- the object to wrap- Returns:
- the template model that wraps the object
- Throws:
TemplateModelException- if the wrapper does not know how to wrap the passed object.
-