freemarker.ext.misc
Class Methods

java.lang.Object
  extended by freemarker.ext.misc.Methods
All Implemented Interfaces:
TemplateHashModel, TemplateModel, java.io.Serializable

public final class Methods
extends java.lang.Object
implements TemplateHashModel, java.io.Serializable

A simple hash model that provides access to all the non-deprecated method models in this package.

The keys are as follows:

Usage:
From java:

 TemplateModelRoot root = new SimpleHash();

 root.put( "methods", freemarker.ext.misc.Methods.getInstance() );

 ...
 

From your FM-Classic template:

 <assign var1 = "5">
 <assign var2 = "3">
 <assign var3 = methods.asNumber( var1 ) + methods.asNumber( var2 )>
 <p>The sum of ${var1} and ${var2} is: ${var3}</p>

 ...
 

Note:
Methods is a singleton instance. Use the getInstance() method to retrieve instances of this model.

Since:
1.8.1
Version:
$Id: Methods.java 1101 2013-04-01 04:17:32Z run2000 $
Author:
Nicholas Cull
See Also:
Serialized Form

Method Summary
 TemplateModel get(java.lang.String key)
          Gets a TemplateModel from the hash.
static Methods getInstance()
          Retrieve a singleton instance of this class.
 boolean isEmpty()
          Is the object empty?
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static Methods getInstance()
Retrieve a singleton instance of this class. Since there is no state information held between calls, there is only a need for one instance.

Returns:
an instance of this Methods class

isEmpty

public boolean isEmpty()
                throws TemplateModelException
Is the object empty?

Specified by:
isEmpty in interface TemplateModel
Returns:
false to indicate that this model is non-empty
Throws:
TemplateModelException

get

public TemplateModel get(java.lang.String key)
                  throws TemplateModelException
Gets a TemplateModel from the hash.

Specified by:
get in interface TemplateHashModel
Parameters:
key - the name by which the TemplateModel is identified in the template.
Returns:
the TemplateModel referred to by the key, or null if not found.
Throws:
TemplateModelException - there was a problem getting the value for the given key