Class AbstractVariableSubstituter
- java.lang.Object
-
- org.clapper.util.text.AbstractVariableSubstituter
-
- All Implemented Interfaces:
- VariableNameChecker, VariableSubstituter
- Direct Known Subclasses:
- UnixShellVariableSubstituter, WindowsCmdVariableSubstituter
public abstract class AbstractVariableSubstituter extends java.lang.Object implements VariableSubstituter, VariableNameChecker
Abstract base class forVariableSubstituterclasses, containing various useful utility methods.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method and Description booleangetAbortOnSyntaxError()Get the value of the flag that controls whether the substitute() methods will abort when they encounter a syntax error.booleangetAbortOnUndefinedVariable()Get the value of the flag that controls whether the substitute() methods will abort when they encounter an undefined variable.booleanlegalVariableCharacter(char c)Determine whether a character is a legal variable identifier character.voidsetAbortOnSyntaxError(boolean enable)Set or clear the flag that controls whether the substitute() methods will abort when they encounter a syntax error.voidsetAbortOnUndefinedVariable(boolean enable)Set or clear the flag that controls whether the substitute() methods will abort when they encounter an undefined variable.java.lang.Stringsubstitute(java.lang.String s, VariableDereferencer deref)Substitute all variable references in the supplied string, using a Unix Bourne Shell-style variable syntax.java.lang.Stringsubstitute(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.Stringsubstitute(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.
-
-
-
Method Detail
-
legalVariableCharacter
public boolean legalVariableCharacter(char c)
Determine whether a character is a legal variable identifier character. This default implementation permits alphanumerics, underscores and periods ("."). Subclasses can override this method.- Specified by:
legalVariableCharacterin interfaceVariableNameChecker- Parameters:
c- The character- Returns:
- true if the character is legal, false otherwise.
- See Also:
VariableSubstituter.substitute(java.lang.String, org.clapper.util.text.VariableDereferencer, java.lang.Object)
-
substitute
public java.lang.String substitute(java.lang.String s, VariableDereferencer deref) throws VariableSyntaxException, UndefinedVariableException, VariableSubstitutionExceptionSubstitute 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)
- Parameters:
s- the string containing possible variable referencesderef- the VariableDereferencer object to use to resolve the variables' values.- Returns:
- The (possibly) expanded string.
- Throws:
UndefinedVariableException- undefined variable, andgetAbortOnUndefinedVariable()returns trueVariableSyntaxException- syntax error, andgetAbortOnSyntaxError()returns trueVariableSubstitutionException- substitution error- See Also:
substitute(String,VariableDereferencer,VariableNameChecker,Object),VariableDereferencer.getVariableValue(String,Object)
-
substitute
public java.lang.String substitute(java.lang.String s, VariableDereferencer deref, java.lang.Object context) throws VariableSyntaxException, UndefinedVariableException, VariableSubstitutionExceptionSubstitute 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.
- Specified by:
substitutein interfaceVariableSubstituter- Parameters:
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'sVariableDereferencer.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.- Returns:
- The (possibly) expanded string.
- Throws:
UndefinedVariableException- undefined variable, andgetAbortOnUndefinedVariable()returns trueVariableSyntaxException- syntax error, andgetAbortOnSyntaxError()returns trueVariableSubstitutionException- substitution error- See Also:
substitute(String,VariableDereferencer,VariableNameChecker,Object),VariableDereferencer.getVariableValue(String,Object)
-
substitute
public abstract java.lang.String substitute(java.lang.String s, VariableDereferencer deref, VariableNameChecker nameChecker, java.lang.Object context) throws VariableSyntaxException, UndefinedVariableException, VariableSubstitutionExceptionSubstitute 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.- Specified by:
substitutein interfaceVariableSubstituter- Parameters:
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'sVariableDereferencer.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.- Returns:
- The (possibly) expanded string.
- Throws:
UndefinedVariableException- undefined variable, andgetAbortOnUndefinedVariable()returns trueVariableSyntaxException- syntax error, andgetAbortOnSyntaxError()returns trueVariableSubstitutionException- substitution error- See Also:
substitute(String,VariableDereferencer,Object),VariableDereferencer.getVariableValue(String,Object)
-
getAbortOnSyntaxError
public boolean getAbortOnSyntaxError()
Get the value of the flag that controls whether the substitute() methods will abort when they encounter a syntax error. If this flag is clear, then this object will recover from a syntax error (usually by leaving the syntactically bad variable reference untouched in the resulting string). If this flag is set, then a syntax error results in aVariableSyntaxException.- Specified by:
getAbortOnSyntaxErrorin interfaceVariableSubstituter- Returns:
- true if the "abort on syntax error" capability is enabled, false if it is disabled.
- See Also:
setAbortOnUndefinedVariable(boolean)
-
getAbortOnUndefinedVariable
public boolean getAbortOnUndefinedVariable()
Get the value of the flag that controls whether the substitute() methods will abort when they encounter an undefined variable. If this flag is clear, then an undefined variable is expanded to an empty string. If this flag is set, then an undefined value results in anUndefinedVariableException.- Specified by:
getAbortOnUndefinedVariablein interfaceVariableSubstituter- Returns:
- true if the "abort on undefined variable" capability is enabled, false if it is disabled.
- See Also:
setAbortOnUndefinedVariable(boolean)
-
setAbortOnSyntaxError
public void setAbortOnSyntaxError(boolean enable)
Set or clear the flag that controls whether the substitute() methods will abort when they encounter a syntax error. If this flag is clear, then this object will recover from a syntax error (usually by leaving the syntactically bad variable reference untouched in the resulting string). If this flag is set, then a syntax error results in aVariableSyntaxException. The flag defaults to false.- Specified by:
setAbortOnSyntaxErrorin interfaceVariableSubstituter- Parameters:
enable- true to enable the "abort on syntax error" flag, false to disable it.- See Also:
getAbortOnUndefinedVariable()
-
setAbortOnUndefinedVariable
public void setAbortOnUndefinedVariable(boolean enable)
Set or clear the flag that controls whether the substitute() methods will abort when they encounter an undefined variable. If this flag is clear, then an undefined variable is expanded to an empty string. If this flag is set, then an undefined value results in anUndefinedVariableException. The flag defaults to false.- Specified by:
setAbortOnUndefinedVariablein interfaceVariableSubstituter- Parameters:
enable- true to enable the "abort on undefined variable" flag, false to disable it.- See Also:
getAbortOnUndefinedVariable()
-
-
DMelt 3.0 © DataMelt by jWork.ORG