Class WindowsCmdVariableSubstituter
- java.lang.Object
-
- org.clapper.util.text.AbstractVariableSubstituter
-
- org.clapper.util.text.WindowsCmdVariableSubstituter
-
- All Implemented Interfaces:
- VariableNameChecker, VariableSubstituter
public class WindowsCmdVariableSubstituter extends AbstractVariableSubstituter
The WindowsCmdVariableSubstituter class implements the VariableSubstituter interface and provides an inline variable substitution capability using a syntax that's reminiscent of the Microsoft Windows cmd.exe command interpreter. This syntax assumes that variable references are surrounded by "%" characters. For example, given the string (variables in bold):
file:%user.home%/profiles/%PLATFORM%/config.txt
and the variable values:
user.home=/home/bmc PLATFORM=freebsd
a WindowsCmdVariableSubstituter will produce the result string (substitutions noted in bold):
Notes and Caveatsfile:/home/bmc/profiles/freebsd/config.txt
- To include a literal "%" character in a string, double it.
- If a variable doesn't have a value, its reference is replaced by an empty string.
- As with all VariableSubstituter classes, an instance of the WindowsCmdVariableSubstituter class enforces its own variable syntax but defers actual variable value resolution to a separate VariableDereferencer object. One consequence of that approach is that variable names may be case-sensitive or case-insensitive, depending on how the supplied VariableDereferencer object interprets variable names.
It's also possible to configure a WindowsCmdVariableSubstituter to throw a
UndefinedVariableException, rather than substituting a blank, if a variable is undefined and a default value is not specified. See theAbstractVariableSubstituter.setAbortOnUndefinedVariable(boolean)method.- See Also:
UnixShellVariableSubstituter,VariableDereferencer,VariableSubstituter,String
-
-
Constructor Summary
Constructors Constructor and Description WindowsCmdVariableSubstituter()Default constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description 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.-
Methods inherited from class org.clapper.util.text.AbstractVariableSubstituter
getAbortOnSyntaxError, getAbortOnUndefinedVariable, legalVariableCharacter, setAbortOnSyntaxError, setAbortOnUndefinedVariable, substitute, substitute
-
-
-
-
Constructor Detail
-
WindowsCmdVariableSubstituter
public WindowsCmdVariableSubstituter()
Default constructor.
-
-
Method Detail
-
substitute
public 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 and underscores.- Specified by:
substitutein interfaceVariableSubstituter- Specified by:
substitutein classAbstractVariableSubstituter- 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:
VariableSubstitutionException- substitution errorVariableSyntaxException- syntax error, andAbstractVariableSubstituter.getAbortOnSyntaxError()returns trueUndefinedVariableException- undefined variable, andAbstractVariableSubstituter.getAbortOnUndefinedVariable()returns true- See Also:
AbstractVariableSubstituter.substitute(String,VariableDereferencer,Object),VariableDereferencer.getVariableValue(String,Object)
-
-
DMelt 3.0 © DataMelt by jWork.ORG