public abstract class AbstractVariableSubstituter extends java.lang.Object implements VariableSubstituter, VariableNameChecker
VariableSubstituter
classes, containing
various useful utility methods.Modifier | Constructor and Description |
---|---|
protected |
AbstractVariableSubstituter()
Creates a new instance of AbstractVariableSubstituter
|
Modifier and Type | Method and Description |
---|---|
boolean |
getAbortOnSyntaxError()
Get the value of the flag that controls whether the
substitute() methods will abort when they encounter a
syntax error.
|
boolean |
getAbortOnUndefinedVariable()
Get the value of the flag that controls whether the
substitute() methods will abort when they encounter an
undefined variable.
|
boolean |
legalVariableCharacter(char c)
Determine whether a character is a legal variable identifier character.
|
void |
setAbortOnSyntaxError(boolean enable)
Set or clear the flag that controls whether the
substitute() methods will abort when they encounter a
syntax error.
|
void |
setAbortOnUndefinedVariable(boolean enable)
Set or clear the flag that controls whether the substitute()
methods will abort when they encounter an undefined variable.
|
java.lang.String |
substitute(java.lang.String s,
VariableDereferencer deref)
Substitute all variable references in the supplied string, using
a Unix Bourne Shell-style variable syntax.
|
java.lang.String |
substitute(java.lang.String s,
VariableDereferencer deref,
java.lang.Object context)
Substitute all variable references in the supplied string, using
a Unix Bourne Shell-style variable syntax.
|
abstract java.lang.String |
substitute(java.lang.String s,
VariableDereferencer deref,
VariableNameChecker nameChecker,
java.lang.Object context)
Substitute all variable references in the supplied string, using
a Unix Bourne Shell-style variable syntax.
|
protected AbstractVariableSubstituter()
public boolean legalVariableCharacter(char c)
legalVariableCharacter
in interface VariableNameChecker
c
- The characterVariableSubstituter.substitute(java.lang.String, org.clapper.util.text.VariableDereferencer, java.lang.Object)
public java.lang.String substitute(java.lang.String s, VariableDereferencer deref) throws VariableSyntaxException, UndefinedVariableException, VariableSubstitutionException
Substitute all variable references in the supplied string, using a Unix Bourne Shell-style variable syntax. This method uses a supplied VariableDereferencer object to resolve variable values. Note that this method throws no exceptions. Syntax errors in the variable references are silently ignored. Variables that have no value are substituted as the empty string. This method assumes that variable names may consist solely of alphanumeric characters, underscores and periods. This syntax is sufficient to substitute variables from System.properties, for instance. If you want more control over the legal characters, use the one of the other substitute methods.
Calling this method is equivalent to:
substitute(s, deref, null)
s
- the string containing possible variable referencesderef
- the VariableDereferencer object
to use to resolve the variables' values.UndefinedVariableException
- undefined variable, and
getAbortOnUndefinedVariable()
returns trueVariableSyntaxException
- syntax error, and
getAbortOnSyntaxError()
returns trueVariableSubstitutionException
- substitution errorsubstitute(String,VariableDereferencer,VariableNameChecker,Object)
,
VariableDereferencer.getVariableValue(String,Object)
public java.lang.String substitute(java.lang.String s, VariableDereferencer deref, java.lang.Object context) throws VariableSyntaxException, UndefinedVariableException, VariableSubstitutionException
Substitute all variable references in the supplied string, using a Unix Bourne Shell-style variable syntax. This method uses a supplied VariableDereferencer object to resolve variable values. Note that this method throws no exceptions. Syntax errors in the variable references are silently ignored. Variables that have no value are substituted as the empty string. This method assumes that variable names may consist solely of alphanumeric characters, underscores and periods. This syntax is sufficient to substitute variables from System.properties, for instance. If you want more control over the legal characters, use the one of the other substitute methods.
substitute
in interface VariableSubstituter
s
- the string containing possible variable referencesderef
- the VariableDereferencer object
to use to resolve the variables' values.context
- an optional context object, passed through unmodified
to the deref object's
VariableDereferencer.getVariableValue(java.lang.String, java.lang.Object)
method.
This object can be anything at all (and, in fact, may
be null if you don't care.) It's primarily useful
for passing context information from the caller to
the (custom) VariableDereferencer.UndefinedVariableException
- undefined variable, and
getAbortOnUndefinedVariable()
returns trueVariableSyntaxException
- syntax error, and
getAbortOnSyntaxError()
returns trueVariableSubstitutionException
- substitution errorsubstitute(String,VariableDereferencer,VariableNameChecker,Object)
,
VariableDereferencer.getVariableValue(String,Object)
public abstract java.lang.String substitute(java.lang.String s, VariableDereferencer deref, VariableNameChecker nameChecker, java.lang.Object context) throws VariableSyntaxException, UndefinedVariableException, VariableSubstitutionException
Substitute all variable references in the supplied string, using
a Unix Bourne Shell-style variable syntax. This method uses a
supplied VariableDereferencer object to resolve variable
values. Note that this method throws no exceptions. Syntax errors in
the variable references are silently ignored. Variables that have no
value are substituted as the empty string. If the
nameChecker parameter is not null, this method calls its
VariableNameChecker.legalVariableCharacter(char)
method to
determine whether a given character is a legal part of a variable
name. If nameChecker is null, then this method assumes that
variable names may consist solely of alphanumeric characters,
underscores and periods. This syntax is sufficient to substitute
variables from System.properties, for instance.
substitute
in interface VariableSubstituter
s
- the string containing possible variable referencesderef
- the VariableDereferencer object
to use to resolve the variables' values.nameChecker
- the VariableNameChecker object to be
used to check for legal variable name characters,
or nullcontext
- an optional context object, passed through
unmodified to the deref object's
VariableDereferencer.getVariableValue(java.lang.String, java.lang.Object)
method. This object can be anything at all (and,
in fact, may be null if you don't care.) It's
primarily useful for passing context information
from the caller to the
VariableDereferencer.UndefinedVariableException
- undefined variable, and
getAbortOnUndefinedVariable()
returns trueVariableSyntaxException
- syntax error, and
getAbortOnSyntaxError()
returns trueVariableSubstitutionException
- substitution errorsubstitute(String,VariableDereferencer,Object)
,
VariableDereferencer.getVariableValue(String,Object)
public boolean getAbortOnSyntaxError()
VariableSyntaxException
.getAbortOnSyntaxError
in interface VariableSubstituter
setAbortOnUndefinedVariable(boolean)
public boolean getAbortOnUndefinedVariable()
UndefinedVariableException
.getAbortOnUndefinedVariable
in interface VariableSubstituter
setAbortOnUndefinedVariable(boolean)
public void setAbortOnSyntaxError(boolean enable)
VariableSyntaxException
. The flag defaults to false.setAbortOnSyntaxError
in interface VariableSubstituter
enable
- true to enable the "abort on syntax error"
flag, false to disable it.getAbortOnUndefinedVariable()
public void setAbortOnUndefinedVariable(boolean enable)
UndefinedVariableException
. The flag defaults to false.setAbortOnUndefinedVariable
in interface VariableSubstituter
enable
- true to enable the "abort on undefined variable"
flag, false to disable it.getAbortOnUndefinedVariable()