public class VariableSubstitutor extends Object implements Serializable
Modifier and Type | Field and Description |
---|---|
protected boolean |
bracesRequired
Whether braces are required for substitution.
|
private static long |
serialVersionUID |
protected static int |
TYPE_AT
A constant for file type.
|
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 Map |
typeNameToConstantMap
A mapping of file type names to corresponding integer constants.
|
protected Properties |
variables
The variable value mappings
|
Constructor and Description |
---|
VariableSubstitutor(Properties variables)
Constructs a new substitutor using the specified variable value mappings.
|
Modifier and Type | Method and Description |
---|---|
boolean |
areBracesRequired()
Get whether this substitutor requires braces.
|
protected String |
escapeSpecialChars(String str,
int type)
Escapes the special characters in the specified string using file type specific rules.
|
protected int |
getTypeConstant(String type)
Returns the internal constant for the specified file type.
|
void |
setBracesRequired(boolean braces)
Specify whether this substitutor requires braces.
|
int |
substitute(InputStream in,
OutputStream out,
String type,
String encoding)
Substitutes the variables found in the specified input stream.
|
int |
substitute(Reader reader,
Writer writer,
String type)
Substitutes the variables found in the data read from the specified reader.
|
String |
substitute(String str,
String type)
Substitutes the variables found in the specified string.
|
private static final long serialVersionUID
protected transient Properties variables
protected boolean bracesRequired
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 final int TYPE_AT
protected static final Map typeNameToConstantMap
public VariableSubstitutor(Properties variables)
variables
- the map with variable value mappingspublic boolean areBracesRequired()
public void setBracesRequired(boolean braces)
public String substitute(String str, String type) throws IllegalArgumentException
str
- the string to check for variablestype
- the escaping type or null for plainIllegalArgumentException
- if unknown escaping type specifiedpublic int substitute(InputStream in, OutputStream out, String type, String encoding) throws IllegalArgumentException, UnsupportedEncodingException, 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 defaultIllegalArgumentException
- if unknown file type specifiedUnsupportedEncodingException
- if encoding not supportedIOException
- if an I/O error occurspublic int substitute(Reader reader, Writer writer, String type) throws IllegalArgumentException, IOException
reader
- the reader to readwriter
- the writer used to write data outtype
- the file type or null for plainIllegalArgumentException
- if unknown file type specifiedIOException
- if an I/O error occursprotected int getTypeConstant(String type)
type
- the type name or null for plainprotected String escapeSpecialChars(String str, int type)
str
- the string to check for special characterstype
- the target file type (one of TYPE_xxx)WebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses