|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.clapper.util.text.MapVariableDereferencer
public class MapVariableDereferencer
The MapVariableDereferencer class implements the VariableDereferencer interface and resolves variable references by looking them up in a supplied Map object. By using a Map object, this class can support variable lookups from a variety of existing data structures, including:
The keys and values in the supplied Map object must be String objects.
Perhaps the simplest example is one that uses the environment variables of the running Java VM. (Recall that java.lang.System.getenv() is no longer deprecated as of the 1.5 JDK.) The following sample program reads strings from the command line and substitutes Unix-style environment variable references.
import org.clapper.util.text.MapVariableDereferencer;
import org.clapper.util.text.VariableDereferencer;
import org.clapper.util.text.VariableSubstituter;
import org.clapper.util.text.UnixShellVariableSubstituter;
public class Test
{
public static void main (String[] args) throws Throwable
{
VariableDereference vars = new MapVariableDereferencer (System.getenv());
VariableSubstituter sub = new UnixShellVariableSubstituter();
for (int i = 0; i < args.length; i++)
{
System.out.println ("BEFORE: \"" + args[i] + "\"");
System.out.println ("AFTER: \"" + sub.substitute (args[i], vars, null));
}
}
}
VariableDereferencer,
VariableSubstituter| Constructor Summary | |
|---|---|
MapVariableDereferencer(java.util.Map<java.lang.String,java.lang.String> map)
Create a new MapVariableDereferencer object that resolves its variable references from the specified Map object. |
|
MapVariableDereferencer(java.util.Properties properties)
Create a new MapVariableDereferencer object that resolves its variable references from the specified Properties object. |
|
| Method Summary | |
|---|---|
java.lang.String |
getVariableValue(java.lang.String varName,
java.lang.Object context)
Get the value associated with a given variable. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public MapVariableDereferencer(java.util.Map<java.lang.String,java.lang.String> map)
map - The Map object from which to resolve
variable references.public MapVariableDereferencer(java.util.Properties properties)
properties - The Properties object from which to resolve
variable references.| Method Detail |
|---|
public java.lang.String getVariableValue(java.lang.String varName,
java.lang.Object context)
getVariableValue in interface VariableDereferencervarName - The name of the variable for which the value is
desired.context - a context object, passed through from the caller
to the dereferencer, or null if there isn't one.
Ignored here.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||