public class StringTemplate extends Object implements Serializable
toString(Properties)
with the current values (this simulates JavaEE EL). System properties can be accessed using the props. prefix,
and environment properties can be accessed using the env. prefix.
Automatically provides environment properties, system properties and user specified properties.
Default values are separated by semicolon (e.g. ${property:defaultValue}). The property name must contain only letters, numbers and underscores
(this is not strictly checked but may lead to undefined behaviour).
Backslash works as a general escape character and escapes any letter behind it (e.g. \\ is replaced by \, \@ is replaced by @ etc.).
Examples: ${propertyA} ${non_existing:default} ${env.JAVA_HOME} ${props['java.runtime.name']}
Notice: The first call to the constructor and calls to the static method parseTemplate(String, Properties)
might take more time than a simple RegExp
match but this is payed back for the subsequent calls to toString()
.Constructor and Description |
---|
StringTemplate(String template)
Creates a template using the provided string interpretation.
|
StringTemplate(String template,
Properties properties)
Creates a template using the provided string interpretation using the additional properties.
|
Modifier and Type | Method and Description |
---|---|
boolean |
hasDynamicPlaceholders()
Were there any placeholders that need to be replaced each time when rendered?
|
boolean |
hasPlaceholders()
Were there any placeholders in the template?
|
static String |
parseTemplate(String template,
Properties properties)
Gets the rendered template of the provided string interpretation and properties.
|
String |
toString()
Renders the template.
|
String |
toString(Properties localProperties)
Renders the template using the additionally provided properties.
|
public StringTemplate(String template)
template
- The string interpretation of the pattern.public StringTemplate(String template, Properties properties)
template
- The string interpretation of the pattern.properties
- Properties to be immediately replaced in the template.public boolean hasPlaceholders()
public boolean hasDynamicPlaceholders()
public String toString()
public String toString(Properties localProperties)
localProperties
- The additional properties to be replaced in the template.public static String parseTemplate(String template, Properties properties)
template
- The string representation of the template.properties
- The properties to be replaced in the template.Copyright © 2010–2017 PerfCake Community. All rights reserved.