public class TextTemplate extends Object
${...}
variables. This class uses
VariablesWriter
for actual variables injection.
Using this class is trivial: create template instance, wrapping a given template string with variables, and uses
put(String, Object)
to replace variables with values. When complete uses toString()
to get string
with variables replaced.
TextTemplate parameters = new TextTemplate(template); parameters.put("fax-number", faxNumber); parameters.put("email-address", emailAddress); ... // do something with parameters.toString()
Modifier and Type | Field and Description |
---|---|
private static Log |
log
Class logger.
|
private String |
template
Source template string with variables.
|
private Map<String,String> |
variables
Variables map.
|
Constructor and Description |
---|
TextTemplate(String template)
Construct text template instance for given string with
${...} variable place holders. |
Modifier and Type | Method and Description |
---|---|
void |
put(String name,
Object value)
Set variables value.
|
String |
toString()
Inject variables into template and return resulting string.
|
private static final Log log
private String template
public TextTemplate(String template)
${...}
variable place holders.template
- string with variable place holders.public void put(String name, Object value)
This method uses Converter
to convert variable value to string. If there is no converter able to handle given
variable value type this method rise exception.
name
- variable name,value
- variable value.IllegalArgumentException
- if variable name is null or empty or value is null.ConverterException
- if there is no converter able to handle given value type.Copyright © 2018. All rights reserved.