freemarker.ext.misc
Class Perl5Substitute

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

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

Perform Perl 5 substitutions using the Jakarta ORO regular expression library. A list of regular expressions is passed in, and executed in order on a line-by-line basis. In this respect, the Perl 5 modifiers "m" and "s" make no difference here. The result of this transformation is always terminated by a newline sequence.

Usage:
From java:

 TemplateModelRoot root = new SimpleHash();

 root.put( "substitute", freemarker.ext.misc.Perl5Substitute.getInstance() );

 ...
 

From your FM-Classic template:

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

 ...
 

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

Since:
1.8
Version:
$Id: Perl5Substitute.java 1152 2013-04-15 10:34:50Z run2000 $
Author:
Nicholas Cull
See Also:
Serialized Form

Method Summary
 TemplateModel exec(java.util.List<java.lang.String> arguments)
          Creates a TemplateTransformModel with the specified arguments as regular expressions.
static Perl5Substitute getInstance()
          Return a new 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 Perl5Substitute getInstance()
Return a new instance of this class. No state is held in the method model itself. Rather, the method model creates a new instance of the transformation class itself whenever it is called. The transformation class holds all state information about the regular expressions.

Returns:
a new instance of the Perl5Substitute method model

isEmpty

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

Specified by:
isEmpty in interface TemplateModel
Returns:
true if this object is empty, otherwise false
Throws:
TemplateModelException

exec

public TemplateModel exec(java.util.List<java.lang.String> arguments)
                   throws TemplateModelException
Creates a TemplateTransformModel with the specified arguments as regular expressions. Arguments are passed as a List of String objects. Each regular expression is evaluated in order, once per line.

Specified by:
exec in interface TemplateMethodModel
Parameters:
arguments - a List of String objects containing the regular expressions to be applied
Returns:
the TemplateTransformModel produced by the method
Throws:
TemplateModelException