Class ParameterExpander
Parameter References
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.
Command Line Intrinsics
When this class is run as a command line application, the following intrinsic parameters expand to pre-defined values:
NOW
- ISO-8601 representation of the time when processing has started.
INPUTS
- A space-separated list of all input file arguments.
SUBST
- A space-separated list of
name
=
value pairs of the defined parameters.
ParameterExpander_main
which takes multiple substitution
from a text file input and can process multiple input files to multiple outputs in one
single run.
Conditional Sections
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
name- Marks the beginning of a section
that is only included if parameter name has a specified value that
is not the empty string. The section extends until a matching
ELSE
orENDIF
reference, or until the end of input. ELSE
- Ends the current conditional section and starts a section that is only included in the opposite case, that is if the named parameter has no specified value or is set to the empty string. If there is no current conditional section, then an excluded section is started.
ENDIF
- Ends the current conditional section. Enclosing conditional sections remain in effect. If there is no current conditional section, then nothing happens.
Conditional sections may be nested. Text is included if and only if there is no enclosing section that is being excluded.
Command Line Syntax
FIXME DOKU WEITERMACHEN ?? SONAR-BT-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Represents one transformation of one particular word appearing marked in the input by some text in the output.(package private) class
One application run of the enclosing ParameterExpander. -
Field Summary
Modifier and TypeFieldDescriptionstatic final String
static final char
static final String
The applied encoding when no system propertyENCODING_PROPERTY_NAME
is set when running the command line tool.static final String
The applied escape character when no system propertyESCAPE_PROPERTY_NAME
is set when running the command line tool.static final String
Argument toSystem.getProperty(java.lang.String)
for the applied character encding when running the command line tool.static final String
Argument toSystem.getProperty(java.lang.String)
for the applied escape character when running the command line tool.static final ParameterExpander.Parameter
evidentstatic final ParameterExpander.Parameter
evidentstatic final char
static final ParameterExpander.Parameter
evident -
Constructor Summary
ConstructorDescriptionParameterExpander
(String escape, Consumer<String> receiveWarnings) Only constructor, sets the escape string to be applied when running this instance. -
Method Summary
Modifier and TypeMethodDescriptionstatic String
getInputsValue
(Collection<String> inputs) Build a string representation of file names in the given collection.static String
Return the current date in ISO format.Build a string representation of all map entries insubstitution
.static void
Run an instance of this class as a command line tool.static void
parseArgument
(String arg, List<String> inputs, Consumer<String> receiveWarnings, Map<ParameterExpander.Parameter, String> substitution) Analyses one command line argument and puts it to the given substituion map or the list of inputs, depending on an appearing'='
.void
evidentvoid
setPredefinedParameters
(Collection<String> inputs) Stores tosubstitution
the values of the predfined system parameters for this run.Return the map from parameter instances to their substitution text.protected static @Opt ParameterExpander.Parameter
systemParameter
(String name) Constructs a new parameter object if the given name is a valid system (= predefined) parameter name.void
Apply the substitution as defined by this ParameterExpander to the replacement text assigend to all parameters.static @Opt ParameterExpander.Parameter
userParameter
(String name) Constructs a new parameter object if the given name is a valid user parameter name.
-
Field Details
-
ESCAPE_PROPERTY_NAME
Argument toSystem.getProperty(java.lang.String)
for the applied escape character when running the command line tool.- See Also:
-
ENCODING_PROPERTY_NAME
Argument toSystem.getProperty(java.lang.String)
for the applied character encding when running the command line tool.- See Also:
-
DEFAULT_ESCAPE
The applied escape character when no system propertyESCAPE_PROPERTY_NAME
is set when running the command line tool.- See Also:
-
DEFAULT_ENCODING
The applied encoding when no system propertyENCODING_PROPERTY_NAME
is set when running the command line tool.- See Also:
-
OPEN_BRACE
public static final char OPEN_BRACE- See Also:
-
CLOSE_BRACE
public static final char CLOSE_BRACE- See Also:
-
ASSIGN
- See Also:
-
NOW
evident -
INPUTS
evident -
SUBST
evident
-
-
Constructor Details
-
ParameterExpander
Only constructor, sets the escape string to be applied when running this instance.
-
-
Method Details
-
userParameter
Constructs a new parameter object if the given name is a valid user parameter name. This includes non-emptiness, lower case start, only valid Java id characters, etc. see class documentation.- Returns:
- null if not a valid user parameter name
-
systemParameter
Constructs a new parameter object if the given name is a valid system (= predefined) parameter name. This includes non-emptiness, upper case start, only valid Java id characters, etc. see class documentation.- Returns:
- null if not a valid user parameter name
-
substitution
Return the map from parameter instances to their substitution text. The delivered refernce is directly to the mutable map, applied when running. -
process
evident- Throws:
IOException
-
main
Run an instance of this class as a command line tool.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
The behavior can be configured via system properties:'='
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 fromSystem.in
. Output is always written toSystem.out
.eu.bandm.tools.util.ParameterExpander.encoding
- The name of the encoding to use for input and output stream (default:
"UTF-8"
). eu.bandm.tools.util.ParameterExpander.escape
- The
nonempty escape prefix (default:
"$"
).
- Throws:
IOException
-
setPredefinedParameters
Stores tosubstitution
the values of the predfined system parameters for this run. -
parseArgument
public static void parseArgument(String arg, List<String> inputs, Consumer<String> receiveWarnings, Map<ParameterExpander.Parameter, String> substitution) Analyses one command line argument and puts it to the given substituion map or the list of inputs, depending on an appearing'='
. -
getSubstValue
Build a string representation of all map entries insubstitution
. -
getNowValue
Return the current date in ISO format. -
getInputsValue
Build a string representation of file names in the given collection. -
unfoldRecursiveSubstitutions
public void unfoldRecursiveSubstitutions()Apply the substitution as defined by this ParameterExpander to the replacement text assigend to all parameters. The number of repeated substitution runs is limited, and cyclic dependencies will thus not hang the execution, but will not be resolved. This is signalled by a warning text printed to System.err.
-