|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.izforge.izpack.installer.VariableSubstitutor
Substitutes variables occurring in an input stream or a string. This implementation supports a generic variable value mapping and escapes the possible special characters occurring in the substituted values. The file types specifically supported are plain text files (no escaping), Java properties files, and XML files. A valid variable name matches the regular expression [a-zA-Z][a-zA-Z0-9_]* and names are case sensitive. Variables are referenced either by $NAME or ${NAME} (the latter syntax being useful in situations like ${NAME}NOTPARTOFNAME). If a referenced variable is undefined then it is not substituted but the corresponding part of the stream is copied as is.
Field Summary | |
protected java.util.Map |
environment
The variable value mappings |
protected static int |
TYPE_JAVA_PROPERTIES
A constant for file type. |
protected static int |
TYPE_PLAIN
A constant for file type. |
protected static int |
TYPE_SHELL
A constant for file type. |
protected static int |
TYPE_XML
A constant for file type. |
protected static java.util.Map |
typeNameToConstantMap
A mapping of file type names to corresponding integer constants. |
Constructor Summary | |
VariableSubstitutor(java.util.Map environment)
Constructs a new substitutor using the specified variable value mappings. |
Method Summary | |
protected java.lang.String |
escapeSpecialChars(java.lang.String str,
int type)
Escapes the special characters in the specified string using file type specific rules. |
protected int |
getTypeConstant(java.lang.String type)
Returns the internal constant for the specified file type. |
void |
substitute(java.io.InputStream in,
java.io.OutputStream out,
java.lang.String type,
java.lang.String encoding)
Substitutes the variables found in the specified input stream. |
void |
substitute(java.io.Reader reader,
java.io.Writer writer,
java.lang.String type)
Substitutes the variables found in the data read from the specified reader. |
java.lang.String |
substitute(java.lang.String str,
java.lang.String type)
Substitutes the variables found in the specified string. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected java.util.Map environment
protected static final int TYPE_PLAIN
protected static final int TYPE_JAVA_PROPERTIES
protected static final int TYPE_XML
protected static final int TYPE_SHELL
protected static java.util.Map typeNameToConstantMap
Constructor Detail |
public VariableSubstitutor(java.util.Map environment)
environment
- the environment with variable value mappingsMethod Detail |
public java.lang.String substitute(java.lang.String str, java.lang.String type) throws java.lang.IllegalArgumentException
str
- the string to check for variablestype
- the escaping type or null for plain
java.lang.IllegalArgumentException
- if unknown escaping type specifiedpublic void substitute(java.io.InputStream in, java.io.OutputStream out, java.lang.String type, java.lang.String encoding) throws java.lang.IllegalArgumentException, java.io.UnsupportedEncodingException, java.io.IOException
in
- the input stream to readout
- the output stream to writetype
- the file type or null for plainencoding
- the character encoding or null
for default
java.lang.IllegalArgumentException
- if unknown file type specified
java.io.UnsupportedEncodingException
- if encoding not supported
java.io.IOException
- if an I/O error occurspublic void substitute(java.io.Reader reader, java.io.Writer writer, java.lang.String type) throws java.lang.IllegalArgumentException, java.io.IOException
reader
- the reader to readwriter
- the writer used to write data outtype
- the file type or null for plain
java.lang.IllegalArgumentException
- if unknown file type specified
java.io.IOException
- if an I/O error occursprotected int getTypeConstant(java.lang.String type)
type
- the type name or null for plain
protected java.lang.String escapeSpecialChars(java.lang.String str, int type)
str
- the string to check for special characterstype
- the target file type (one of TYPE_xxx)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |