org.schmant.support.text
Class PropertyValueTextStrategy

java.lang.Object
  extended by org.schmant.support.text.PropertyValueTextStrategy
All Implemented Interfaces:
ReplacementTextStrategy

public class PropertyValueTextStrategy
extends Object
implements ReplacementTextStrategy

This ReplacementTextStrategy takes the text captured by the n:th capturing group and uses it as a key for looking up a property value in a supplied Properties object. The replacement text is that property value.

By default, if a property does not exist, this object throws an SchmantException. It can be configured to return an empty string instead by using the PropertyValueTextStrategy(Properties, int, boolean) constructor.

The task factory reference contains an example of how this strategy can be used.

Since:
0.8
Author:
Karl Gustafsson

Constructor Summary
PropertyValueTextStrategy(Properties props)
          Create a new property value text strategy that uses the value of the first capturing group as the property key.
PropertyValueTextStrategy(Properties props, int capturingGroupNo, boolean ignoreMissingProperties)
          Create a new property value text strategy that uses the value of the supplied capturing group number as the property key.
 
Method Summary
 String getReplace(String text, Matcher m)
          Get the replacement text for the supplied text.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PropertyValueTextStrategy

public PropertyValueTextStrategy(Properties props)
Create a new property value text strategy that uses the value of the first capturing group as the property key.

Parameters:
props - The property object that this object uses.

PropertyValueTextStrategy

public PropertyValueTextStrategy(Properties props,
                                 int capturingGroupNo,
                                 boolean ignoreMissingProperties)
Create a new property value text strategy that uses the value of the supplied capturing group number as the property key.

Parameters:
props - The property object.
capturingGroupNo - The number of the capturing group that this strategy uses as the property key when looking up values. The first capturing group is number one. The zeroth capturing group contains the entire matched pattern.
ignoreMissingProperties - If this is set to true, this object returns an empty string instead of throwing an exception if a property is missing. Use with care!
Method Detail

getReplace

public String getReplace(String text,
                         Matcher m)
                  throws SchmantException
Description copied from interface: ReplacementTextStrategy
Get the replacement text for the supplied text.

Specified by:
getReplace in interface ReplacementTextStrategy
Parameters:
text - The text.
m - The Matcher that matches the current text. This object can only be read from. Its state must not be updated.
Returns:
The replacement text.
Throws:
SchmantException