Class VariableInterpolator

java.lang.Object
org.apache.wicket.util.string.interpolator.VariableInterpolator
All Implemented Interfaces:
Serializable, IClusterable
Direct Known Subclasses:
MapVariableInterpolator, PropertyVariableInterpolator

public abstract class VariableInterpolator extends Object implements IClusterable
Base class for variable interpolators. An interpolator substitutes values into a String. So, a variable interpolator substitutes the values of one or more variables into a String.

The String to interpolate (substitute into) is passed to the VariableInterpolator's constructor. Variables are denoted in this string by the syntax ${variableName}. A subclass provides an implementation for the abstract method getValue(String variableName). The toString() method then performs an interpolation by replacing each variable of the form ${variableName} with the value returned by getValue("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:
  • Field Details

    • string

      protected final String string
      The String to interpolate into
  • Constructor Details

    • VariableInterpolator

      public VariableInterpolator(String string)
      Constructor.
      Parameters:
      string - a String to interpolate with variable values
    • VariableInterpolator

      public VariableInterpolator(String string, boolean exceptionOnNullVarValue)
      Constructor.
      Parameters:
      string - a String to interpolate with variable values
      exceptionOnNullVarValue - if true an IllegalStateException will be thrown if getValue(String) returns null, otherwise the ${varname} string will be left in the String so that multiple interpolators can be chained
  • Method Details

    • getValue

      protected abstract String getValue(String variableName)
      Retrieves a value for a variable name during interpolation.
      Parameters:
      variableName - a variable name
      Returns:
      the value
    • toString

      public String toString()
      Interpolates using variables.
      Overrides:
      toString in class Object
      Returns:
      the interpolated String