freemarker.ext.misc
Class Substitute

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

public final class Substitute
extends java.lang.Object
implements TemplateMethodModel, java.io.Serializable

A method model that implements the Perl 5 substitute function. This uses the Jakarta ORO library to perform the substitute.

Usage:
From java:

 TemplateModelRoot root = new SimpleHash();

 root.put( "substitute", new freemarker.ext.misc.Substitute() );

 ...
 

From your FM-Classic template:

 The following is stripped of HTML tags:
 <assign text = "<p>This paragraph has <em>all</em> tags removed.</p>">
 <assign output = substitute( "s/<[^>]*>//g", text )>

 ${output}

 ...
 

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

Constructor Summary
Substitute()
          Construct a new substitution method.
 
Method Summary
 TemplateModel exec(java.util.List<java.lang.String> arguments)
          Executes a method call.
 boolean isEmpty()
          Is the object empty?
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Substitute

public Substitute()
Construct a new substitution method.

Method Detail

isEmpty

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

Specified by:
isEmpty in interface TemplateModel
Returns:
false to indicate the method is not empty
Throws:
TemplateModelException

exec

public TemplateModel exec(java.util.List<java.lang.String> arguments)
                   throws TemplateModelException
Executes a method call. Arguments are passed as a List of String objects.

Specified by:
exec in interface TemplateMethodModel
Parameters:
arguments - a List of String objects containing the values of the arguments passed to the method.
Returns:
the TemplateModel produced by the method, or null.
Throws:
TemplateModelException