public interface ObjectWrapper
TemplateModel
interfaces). Thus this is what decides what parts of the Java objects will be accessible in the templates and how.
For example, with a BeansWrapper
both the items of Map
and the JavaBean properties (the getters)
of an object are accessible in template uniformly with the myObject.foo
syntax, where "foo" is the map key or
the property name. This is because both kind of object is wrapped by BeansWrapper
into a
TemplateHashModel
implementation that will call Map.get(Object)
or the getter method, transparently
to the template language.
Modifier and Type | Field and Description |
---|---|
static ObjectWrapper |
BEANS_WRAPPER
An
ObjectWrapper that exposes the object methods and JavaBeans properties as hash elements, and has
custom handling for Java Map -s, ResourceBundle -s, etc. |
static ObjectWrapper |
DEFAULT_WRAPPER
The default object wrapper implementation, focusing on backward compatibility and out-of-the box extra features.
|
static ObjectWrapper |
SIMPLE_WRAPPER
Object wrapper that uses
SimpleXXX wrappers only. |
Modifier and Type | Method and Description |
---|---|
TemplateModel |
wrap(java.lang.Object obj)
Makes a
TemplateModel out of a non-TemplateModel object, usually by "wrapping" it into a
TemplateModel implementation that delegates to the original object. |
static final ObjectWrapper BEANS_WRAPPER
ObjectWrapper
that exposes the object methods and JavaBeans properties as hash elements, and has
custom handling for Java Map
-s, ResourceBundle
-s, etc. It doesn't treat
Node
-s and Jython objects specially, however.static final ObjectWrapper DEFAULT_WRAPPER
BeansWrapper
with the special handling of Node
-s (for XML processing) and
Jython objects. However, for backward compatibility, it also somewhat downgrades BeansWrapper
by using
SimpleHash
for Map
-s, SimpleSequence
for List
-s and collections/arrays.
Furthermore it uses SimpleScalar
, SimpleNumber
to wrap String
-s and Number
-s,
although this is not considered to be harmful.static final ObjectWrapper SIMPLE_WRAPPER
SimpleXXX
wrappers only.
It behaves like the DEFAULT_WRAPPER
, but for objects
that it does not know how to wrap as a SimpleXXX
it
throws an exception. It makes no use of reflection-based
exposure of anything, which may makes it a good candidate for security-restricted applications.TemplateModel wrap(java.lang.Object obj) throws TemplateModelException
TemplateModel
out of a non-TemplateModel
object, usually by "wrapping" it into a
TemplateModel
implementation that delegates to the original object.obj
- The object to wrap into a TemplateModel
. If the it already implements TemplateModel
,
it should just return the object as is.TemplateModel
wrapper of the object passed in. To support un-wrapping, you may consider the
return value to implement WrapperTemplateModel
and AdapterTemplateModel
.TemplateModelException