Class PropertiesSubstitutor
$ symbol indicate property or expression to evaluate and substitute.
The following properties/expression syntax is used:
Property reference
References named property.Examples:
$foo
Expression
. Expression is wrapped by braces and evaluated byExpression engine.
Examples:
${name+' '+surname} etc.
This class is not thread safe
- Version:
- 1.0
- Author:
- Fyodor Kupolov
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreates a properties substitutor.PropertiesSubstitutor(Map<String, ?> map) Creates a properties substitutor based on specified properties map.PropertiesSubstitutor(ParametersCallback parameters) Creates a properties substitutor. -
Method Summary
Modifier and TypeMethodDescriptionReturns string literal representing null value.static booleanhasProperties(String string) Tests if the given string contains properties/expressions.voidsetNullString(String nullString) Sets string literal representing null.voidsetParameters(ParametersCallback parameters) Sets parameters callback used for substitution.substitute(Reader reader) Reads content from reader and expands properties.voidsubstitute(Reader reader, Writer writer) Copies content from reader to writer and expands properties.substitute(String s) Substitutes properties/expressions in s and returns the result string.protected StringConverts specified object to string.
-
Field Details
-
PROP_PTR
Simple property patterns, e.g. $property -
EXPR_PTR
Expression pattern, e.g. ${property} etc.
-
-
Constructor Details
-
PropertiesSubstitutor
public PropertiesSubstitutor()Creates a properties substitutor.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 beforesubstitute(String). -
PropertiesSubstitutor
Creates a properties substitutor.- Parameters:
parameters- parameters callback to use for substitution.
-
PropertiesSubstitutor
Creates a properties substitutor based on specified properties map.- Parameters:
map- parameters to substitute.
-
-
Method Details
-
substitute
Substitutes properties/expressions in s and returns the result string.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.
- Parameters:
s- string to substitute. Null strings allowed.- Returns:
- substituted string.
-
substitute
Copies content from reader to writer and expands properties.- Parameters:
reader- reader to process.writer- writer to output substituted content to.- Throws:
IOException- if I/O error occurs.
-
substitute
Reads content from reader and expands properties.Note: For performance reasons use
substitute(java.io.Reader,java.io.Writer)if possible.- Parameters:
reader- reader to process.- Returns:
- reader's content with properties expanded.
- Throws:
IOException- if I/O error occurs.- See Also:
-
getParameters
- Returns:
- parameter callback used for substitution.
-
setParameters
Sets parameters callback used for substitution.- Parameters:
parameters- not null parameters callback.
-
getNullString
Returns string literal representing null value.Used when converting objects
toString(Object).- Returns:
- string representing null value.
-
setNullString
Sets string literal representing null.Used when converting objects
toString(Object).- Parameters:
nullString- string literal representing null
-
toString
Converts specified object to string.getNullString()represents null values.Subclasses may provide custom conversion strategy here.
- Parameters:
o- object to convert to String.- Returns:
- string representation of object.
-
hasProperties
Tests if the given string contains properties/expressions.- Parameters:
string- string to check.- Returns:
- true if a given string contains properties/expressions.
-