public class ParameterExpander extends Object
Parameters references are of the form ESC+'{'+
name+'}'
, where ESC is a configurable
nonempty constant prefix string, and name is a valid Java identifier
starting with a lower-case letter. Compounds may be structured by internal
capitalization (camel case). The default prefix is "$"
.
Examples: ${param}
, ${anotherParam}
.
If a parameter reference is recognized, and a value has been specified
(via substitution
or the command line), then the reference is
removed from the character stream, and replaced by the value. References to
unknown parameters and syntactic fragments that do not constitute a
well-formed reference are left untouched.
Java identifiers that start with an upper case letter are reserved for intrinsic operations. The names of these are otherwise case-insensitive; for interoperability a form that uses only upper case is recommended.
Java identifiers that do not start with a letter are reserved for future use.
When this class is run as a command line application, the following intrinsic parameters expand to pre-defined values:
NOW
INPUTS
SUBST
=
value pairs of the defined
parameters.Arbitrary sections of input text may be included from or excluded in the output, depending on whether a parameter has a specified non-empty value.
IF
nameELSE
or ENDIF
reference, or until the end of
input.ELSE
ENDIF
Conditional sections may be nested. Text is included if and only if there is no enclosing section that is being excluded.
Modifier and Type | Class and Description |
---|---|
static class |
ParameterExpander.Parameter |
Modifier and Type | Field and Description |
---|---|
static String |
ASSIGN |
static char |
CLOSE_BRACE |
static String |
DEFAULT_ENCODING |
static String |
DEFAULT_ESCAPE |
static String |
ENCODING_PROPERTY_NAME |
static String |
ESCAPE_PROPERTY_NAME |
static ParameterExpander.Parameter |
INPUTS |
static int |
MAX_VALUE_LENGTH |
static ParameterExpander.Parameter |
NOW |
static char |
OPEN_BRACE |
static ParameterExpander.Parameter |
SUBST |
Constructor and Description |
---|
ParameterExpander(String escape) |
Modifier and Type | Method and Description |
---|---|
static String |
getInputsValue(Collection<String> inputs) |
static String |
getNowValue() |
String |
getSubstValue() |
static void |
main(String[] args)
Run an instance of this class as a command line tool.
|
static void |
parseArgument(String arg,
List<String> inputs,
Map<ParameterExpander.Parameter,String> substitution) |
void |
process(Reader in,
Writer out) |
void |
setPredefinedParameters(Collection<String> inputs) |
Map<ParameterExpander.Parameter,String> |
substitution() |
protected static ParameterExpander.Parameter |
systemParameter(String name) |
void |
unfoldRecursiveSubstitutions() |
static ParameterExpander.Parameter |
userParameter(String name) |
public static final String ESCAPE_PROPERTY_NAME
public static final String ENCODING_PROPERTY_NAME
public static final String DEFAULT_ESCAPE
public static final String DEFAULT_ENCODING
public static final char OPEN_BRACE
public static final char CLOSE_BRACE
public static final String ASSIGN
public static final int MAX_VALUE_LENGTH
public static final ParameterExpander.Parameter NOW
public static final ParameterExpander.Parameter INPUTS
public static final ParameterExpander.Parameter SUBST
public ParameterExpander(String escape)
public static ParameterExpander.Parameter userParameter(String name)
protected static ParameterExpander.Parameter systemParameter(String name)
public Map<ParameterExpander.Parameter,String> substitution()
public void process(Reader in, Writer out) throws IOException
IOException
public static void main(String[] args) throws IOException
Every command line argument that contains the character '='
is assumed to be a parameter specifier of the form
name+'='+
value.
Command line arguments that do not contain the character
'='
are assumed to be names of input files. All named files
are processed in order, and the output is concatenated. If there is no
named input file, then input is read from System.in
. Output is
always written to System.out
.
eu.bandm.tools.util.ParameterExpander.encoding
"UTF-8"
).eu.bandm.tools.util.ParameterExpander.escape
"$"
).IOException
public void setPredefinedParameters(Collection<String> inputs)
public static void parseArgument(String arg, List<String> inputs, Map<ParameterExpander.Parameter,String> substitution)
public String getSubstValue()
public static String getNowValue()
public static String getInputsValue(Collection<String> inputs)
public void unfoldRecursiveSubstitutions()
see also the complete user documentation .