public class PropertiesSubstitutor extends Object
$ symbol indicate property or expression to evaluate and substitute.
The following properties/expression syntax is used:
$foo
Expression engine.
Examples:
${name+' '+surname} etc.
This class is not thread safe
| Modifier and Type | Field and Description |
|---|---|
static Pattern |
EXPR_PTR
Expression pattern, e.g.
|
static Pattern |
PROP_PTR
Simple property patterns, e.g.
|
| Constructor and Description |
|---|
PropertiesSubstitutor()
Creates a properties substitutor.
|
PropertiesSubstitutor(Map<String,?> map)
Creates a properties substitutor based on specified properties map.
|
PropertiesSubstitutor(ParametersCallback parameters)
Creates a properties substitutor.
|
| Modifier and Type | Method and Description |
|---|---|
String |
getNullString()
Returns string literal representing null value.
|
ParametersCallback |
getParameters() |
static boolean |
hasProperties(String string)
Tests if the given string contains properties/expressions.
|
void |
setNullString(String nullString)
Sets string literal representing null.
|
void |
setParameters(ParametersCallback parameters)
Sets parameters callback used for substitution.
|
String |
substitute(Reader reader)
Reads content from reader and expands properties.
|
void |
substitute(Reader reader,
Writer writer)
Copies content from reader to writer and expands properties.
|
String |
substitute(String s)
Substitutes properties/expressions in s and returns the result string.
|
protected String |
toString(Object o)
Converts specified object to string.
|
public static final Pattern PROP_PTR
public static final Pattern EXPR_PTR
public PropertiesSubstitutor()
This constructor is used for performance critical places where multiple instantiation
via PropertiesSubstitutor(scriptella.spi.ParametersCallback) is expensive.
Note: setParameters(scriptella.spi.ParametersCallback) must be called before
substitute(String).
public PropertiesSubstitutor(ParametersCallback parameters)
parameters - parameters callback to use for substitution.public String substitute(String s)
If result of evaluation is null or the property being substitued doesn't have value in callback - the whole expressions is copied into result string as is.
s - string to substitute. Null strings allowed.public void substitute(Reader reader, Writer writer) throws IOException
reader - reader to process.writer - writer to output substituted content to.IOException - if I/O error occurs.public String substitute(Reader reader) throws IOException
Note: For performance reasons use
substitute(java.io.Reader,java.io.Writer) if possible.
reader - reader to process.IOException - if I/O error occurs.substitute(java.io.Reader,java.io.Writer)public ParametersCallback getParameters()
public void setParameters(ParametersCallback parameters)
parameters - not null parameters callback.public String getNullString()
Used when converting objects toString(Object).
public void setNullString(String nullString)
Used when converting objects toString(Object).
nullString - string literal representing nullprotected String toString(Object o)
getNullString() represents null values.
Subclasses may provide custom conversion strategy here.
o - object to convert to String.public static boolean hasProperties(String string)
string - string to check.Copyright © 2006-2012. All Rights Reserved.