public class PropertiesSubstitutor
extends java.lang.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 java.util.regex.Pattern |
EXPR_PTR
Expression pattern, e.g.
|
static java.util.regex.Pattern |
PROP_PTR
Simple property patterns, e.g.
|
Constructor and Description |
---|
PropertiesSubstitutor()
Creates a properties substitutor.
|
PropertiesSubstitutor(java.util.Map<java.lang.String,?> map)
Creates a properties substitutor based on specified properties map.
|
PropertiesSubstitutor(ParametersCallback parameters)
Creates a properties substitutor.
|
Modifier and Type | Method and Description |
---|---|
java.lang.String |
getNullString()
Returns string literal representing null value.
|
ParametersCallback |
getParameters() |
static boolean |
hasProperties(java.lang.String string)
Tests if the given string contains properties/expressions.
|
void |
setNullString(java.lang.String nullString)
Sets string literal representing null.
|
void |
setParameters(ParametersCallback parameters)
Sets parameters callback used for substitution.
|
java.lang.String |
substitute(java.io.Reader reader)
Reads content from reader and expands properties.
|
void |
substitute(java.io.Reader reader,
java.io.Writer writer)
Copies content from reader to writer and expands properties.
|
java.lang.String |
substitute(java.lang.String s)
Substitutes properties/expressions in s and returns the result string.
|
protected java.lang.String |
toString(java.lang.Object o)
Converts specified object to string.
|
public static final java.util.regex.Pattern PROP_PTR
public static final java.util.regex.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 PropertiesSubstitutor(java.util.Map<java.lang.String,?> map)
map
- parameters to substitute.public java.lang.String substitute(java.lang.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(java.io.Reader reader, java.io.Writer writer) throws java.io.IOException
reader
- reader to process.writer
- writer to output substituted content to.java.io.IOException
- if I/O error occurs.public java.lang.String substitute(java.io.Reader reader) throws java.io.IOException
Note: For performance reasons use
substitute(java.io.Reader,java.io.Writer)
if possible.
reader
- reader to process.java.io.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 java.lang.String getNullString()
Used when converting objects toString(Object)
.
public void setNullString(java.lang.String nullString)
Used when converting objects toString(Object)
.
nullString
- string literal representing nullprotected java.lang.String toString(java.lang.Object o)
getNullString()
represents null values.
Subclasses may provide custom conversion strategy here.
o
- object to convert to String.public static boolean hasProperties(java.lang.String string)
string
- string to check.Copyright © Copyright 2006-2019 The Scriptella Project Team.