freemarker.template.utility
Class DeepUnwrap

java.lang.Object
  extended by freemarker.template.utility.DeepUnwrap

public class DeepUnwrap
extends java.lang.Object

Utility methods for unwrapping TemplateModel-s.

Version:
$Id: DeepUnwrap.java,v 1.6 2005/06/16 18:13:58 ddekany Exp $
Author:
Attila Szegedi

Constructor Summary
DeepUnwrap()
           
 
Method Summary
static java.lang.Object permissiveUnwrap(TemplateModel model)
          Same as unwrap(TemplateModel), but it doesn't throw exception if it doesn't know how to unwrap the model, but rather returns it as-is.
static java.lang.Object premissiveUnwrap(TemplateModel model)
          Deprecated. the name of this method is mistyped. Use permissiveUnwrap(TemplateModel) instead.
static java.lang.Object unwrap(TemplateModel model)
          Unwraps TemplateModel-s recursively.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DeepUnwrap

public DeepUnwrap()
Method Detail

unwrap

public static java.lang.Object unwrap(TemplateModel model)
                               throws TemplateModelException
Unwraps TemplateModel-s recursively. The converting of the TemplateModel object happens with the following rules:
  1. If the object implements AdapterTemplateModel, then the result of AdapterTemplateModel.getAdaptedObject(Class) for Object.class is returned.
  2. If the object implements WrapperTemplateModel, then the result of WrapperTemplateModel.getWrappedObject() is returned.
  3. If the object is identical to the null model of the current object wrapper, null is returned.
  4. If the object implements TemplateScalarModel, then the result of TemplateScalarModel.getAsString() is returned.
  5. If the object implements TemplateNumberModel, then the result of TemplateNumberModel.getAsNumber() is returned.
  6. If the object implements TemplateDateModel, then the result of TemplateDateModel.getAsDate() is returned.
  7. If the object implements TemplateBooleanModel, then the result of TemplateBooleanModel.getAsBoolean() is returned.
  8. If the object implements TemplateSequenceModel or TemplateCollectionModel, then a java.util.ArrayList is constructed from the subvariables, and each subvariable is unwrapped with the rules described here (recursive unwrapping).
  9. If the object implements TemplateHashModelEx, then a java.util.HashMap is constructed from the subvariables, and each subvariable is unwrapped with the rules described here (recursive unwrapping).
  10. Throw a TemplateModelException, because it doesn't know how to unwrap the object.

Throws:
TemplateModelException

permissiveUnwrap

public static java.lang.Object permissiveUnwrap(TemplateModel model)
                                         throws TemplateModelException
Same as unwrap(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

public static java.lang.Object premissiveUnwrap(TemplateModel model)
                                         throws TemplateModelException
Deprecated. the name of this method is mistyped. Use permissiveUnwrap(TemplateModel) instead.

Throws:
TemplateModelException