org.apache.wicket.util.string.interpolator
Class VariableInterpolator

java.lang.Object
  extended by org.apache.wicket.util.string.interpolator.VariableInterpolator
Direct Known Subclasses:
MapVariableInterpolator, PropertyVariableInterpolator

public abstract class VariableInterpolator
extends java.lang.Object

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").

Since:
1.2.6
Author:
Jonathan Locke

Field Summary
protected  java.lang.String string
          The String to interpolate into
 
Constructor Summary
VariableInterpolator(java.lang.String string)
          Constructor.
VariableInterpolator(java.lang.String string, boolean exceptionOnNullVarValue)
          Constructor.
 
Method Summary
protected abstract  java.lang.String getValue(java.lang.String variableName)
          Retrieves a value for a variable name during interpolation.
 java.lang.String toString()
          Interpolates using variables.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

string

protected final java.lang.String string
The String to interpolate into

Constructor Detail

VariableInterpolator

public VariableInterpolator(java.lang.String string)
Constructor.

Parameters:
string - a String to interpolate with variable values

VariableInterpolator

public VariableInterpolator(java.lang.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 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:
toString in class java.lang.Object
Returns:
the interpolated String


Copyright © 2004-2010 Apache Software Foundation. All Rights Reserved.