Class VariableInterpolator
- java.lang.Object
-
- org.apache.wicket.util.string.interpolator.VariableInterpolator
-
- All Implemented Interfaces:
java.io.Serializable,IClusterable
- Direct Known Subclasses:
MapVariableInterpolator
public abstract class VariableInterpolator extends java.lang.Object implements IClusterable
Base class for variable interpolators. An interpolator substitutes values into aString. So, a variable interpolator substitutes the values of one or more variables into aString.The
Stringto interpolate (substitute into) is passed to theVariableInterpolator's constructor. Variables are denoted in this string by the syntax${variableName}. A subclass provides an implementation for the abstract methodgetValue(String variableName). ThetoString()method then performs an interpolation by replacing each variable of the form${variableName}with the value returned bygetValue("variableName")."$" is the escape char. Thus "$${text}" can be used to escape it (ignore interpretation). If '$3.24' is needed then '$$${amount}' should be used. The first $ sign escapes the second, and the third is used to interpolate the variable.
- Since:
- 1.2.6
- Author:
- Jonathan Locke
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.StringstringTheStringto interpolate into
-
Constructor Summary
Constructors Constructor Description VariableInterpolator(java.lang.String string)Constructor.VariableInterpolator(java.lang.String string, boolean exceptionOnNullVarValue)Constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract java.lang.StringgetValue(java.lang.String variableName)Retrieves a value for a variable name during interpolation.java.lang.StringtoString()Interpolates using variables.
-
-
-
Constructor Detail
-
VariableInterpolator
public VariableInterpolator(java.lang.String string)
Constructor.- Parameters:
string- aStringto interpolate with variable values
-
VariableInterpolator
public VariableInterpolator(java.lang.String string, boolean exceptionOnNullVarValue)Constructor.- Parameters:
string- aStringto interpolate with variable valuesexceptionOnNullVarValue- iftrueanIllegalStateExceptionwill be thrown ifgetValue(String)returnsnull, otherwise the${varname}string will be left in theStringso that multiple interpolators can be chained
-
-
Method Detail
-
getValue
protected abstract java.lang.String getValue(java.lang.String variableName)
Retrieves a value for a variable name during interpolation.- Parameters:
variableName- a variable name- Returns:
- the value
-
toString
public java.lang.String toString()
Interpolates using variables.- Overrides:
toStringin classjava.lang.Object- Returns:
- the interpolated
String
-
-