Package freemarker.template.utility
Class DeepUnwrap
java.lang.Object
freemarker.template.utility.DeepUnwrap
Utility methods for unwrapping
TemplateModel-s.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ObjectpermissiveUnwrap(TemplateModel model)Same asunwrap(TemplateModel), but it doesn't throw exception if it doesn't know how to unwrap the model, but rather returns it as-is.static ObjectpremissiveUnwrap(TemplateModel model)Deprecated.the name of this method is mistyped.static Objectunwrap(TemplateModel model)UnwrapsTemplateModel-s recursively.
-
Constructor Details
-
DeepUnwrap
public DeepUnwrap()
-
-
Method Details
-
unwrap
UnwrapsTemplateModel-s recursively. The converting of theTemplateModelobject happens with the following rules:- If the object implements
AdapterTemplateModel, then the result ofAdapterTemplateModel.getAdaptedObject(Class)forObject.classis returned. - If the object implements
WrapperTemplateModel, then the result ofWrapperTemplateModel.getWrappedObject()is returned. - If the object is identical to the null model of the current object wrapper, null is returned.
- If the object implements
TemplateScalarModel, then the result ofTemplateScalarModel.getAsString()is returned. - If the object implements
TemplateNumberModel, then the result ofTemplateNumberModel.getAsNumber()is returned. - If the object implements
TemplateDateModel, then the result ofTemplateDateModel.getAsDate()is returned. - If the object implements
TemplateBooleanModel, then the result ofTemplateBooleanModel.getAsBoolean()is returned. - If the object implements
TemplateSequenceModelorTemplateCollectionModel, then ajava.util.ArrayListis constructed from the subvariables, and each subvariable is unwrapped with the rules described here (recursive unwrapping). - If the object implements
TemplateHashModelEx, then ajava.util.HashMapis constructed from the subvariables, and each subvariable is unwrapped with the rules described here (recursive unwrapping). - Throw a
TemplateModelException, because it doesn't know how to unwrap the object.
- Throws:
TemplateModelException
- If the object implements
-
permissiveUnwrap
Same asunwrap(TemplateModel), but it doesn't throw exception if it doesn't know how to unwrap the model, but rather returns it as-is.- Throws:
TemplateModelException- Since:
- 2.3.14
-
premissiveUnwrap
@Deprecated public static Object premissiveUnwrap(TemplateModel model) throws TemplateModelExceptionDeprecated.the name of this method is mistyped. UsepermissiveUnwrap(TemplateModel)instead.- Throws:
TemplateModelException
-