public class TextTemplate extends Object
 Copy files or directories replacing parameters matching pattern '${[a-zA-Z_0-9\-\.]+}' with values from a
 CryptoProperties.
 
If the value of a variable is encrypted:
 setVariable("var", Crypto.encrypt(value.getBytes))
 
 then "${var}" will be replaced with:
 value"${var}" after a call to "setKeepEncryptedAsVar(true)}"
 ${#var}" will always be replaced with its decrypted value.
 Since 5.7.2, variables can have a default value using syntax ${parameter:=defaultValue}. The default value will be used if parameter is null or unset.
 Methods setTextParsingExtensions(String) and setFreemarkerParsingExtensions(String) allow to set
 the list of files being processed when using processDirectory(File, File), based on their extension; others
 being simply copied.
| Modifier and Type | Class and Description | 
|---|---|
protected static class  | 
TextTemplate.EscapeVariableFilter  | 
| Constructor and Description | 
|---|
TextTemplate()  | 
TextTemplate(Map<String,String> vars)
TextTemplate(Properties) provides an additional default values behavior | 
TextTemplate(Properties vars)  | 
| Modifier and Type | Method and Description | 
|---|---|
String | 
getVariable(String name)  | 
Properties | 
getVariables()  | 
void | 
initFreeMarker()
Initialize FreeMarker data model from Java properties. 
 | 
boolean | 
isTrim()  | 
Properties | 
preprocessVars(Properties unprocessedVars)  | 
List<String> | 
processDirectory(File in,
                File out)
Recursively process each file from "in" directory to "out" directory. 
 | 
void | 
processFreemarker(File in,
                 File out)  | 
protected String | 
processString(CryptoProperties props,
             String text)
That method is not recursive. 
 | 
String | 
processText(InputStream in)  | 
void | 
processText(InputStream is,
           OutputStreamWriter os)  | 
String | 
processText(String text)  | 
void | 
setFreemarkerParsingExtensions(String extensionsList)  | 
void | 
setKeepEncryptedAsVar(boolean keepEncryptedAsVar)
Whether to replace or not the variables which value is encrypted. 
 | 
void | 
setTextParsingExtensions(String extensionsList)  | 
void | 
setTrim(boolean trim)
Set to true in order to trim invisible characters (spaces) from values. 
 | 
void | 
setVariable(String name,
           String value)
If adding multiple variables, prefer use of  
setVariables(Map) | 
void | 
setVariables(Map<String,String> vars)  | 
protected Properties | 
unescape(Properties props)
unescape variables 
 | 
protected String | 
unescape(String value)  | 
public TextTemplate()
public TextTemplate(Map<String,String> vars)
TextTemplate(Properties) provides an additional default values behaviorTextTemplate(Properties)public TextTemplate(Properties vars)
vars - Properties containing keys and values for template processingpublic boolean isTrim()
public void setTrim(boolean trim)
public void setVariables(Map<String,String> vars)
public void setVariable(String name, String value)
setVariables(Map)public String getVariable(String name)
public Properties getVariables()
protected String processString(CryptoProperties props, String text)
props - CryptoProperties containing the variable valuestext - Text to processprotected Properties unescape(Properties props)
public Properties preprocessVars(Properties unprocessedVars)
public String processText(String text)
public String processText(InputStream in) throws IOException
IOExceptionpublic void processText(InputStream is, OutputStreamWriter os) throws IOException
IOExceptionpublic void initFreeMarker()
 Variables in the form "foo.bar" (String with dots) are transformed to "foo[bar]" (arrays).
 So there will be conflicts if a variable name is equal to the prefix of another variable. For instance, "
 foo.bar" and "foo.bar.qux" will conflict.
 When a conflict occurs, the conflicting variable is ignored and a warning is logged. The ignored variable will
 usually be the shortest one (without any contract on this behavior).
public void processFreemarker(File in, File out) throws IOException, freemarker.template.TemplateException
IOExceptionfreemarker.template.TemplateExceptionpublic List<String> processDirectory(File in, File out) throws FileNotFoundException, IOException, freemarker.template.TemplateException
in - Directory to read files fromout - Directory to write files toFileNotFoundExceptionIOExceptionfreemarker.template.TemplateExceptionprocessText(InputStream, OutputStreamWriter), 
processFreemarker(File, File)public void setTextParsingExtensions(String extensionsList)
extensionsList - comma-separated list of files extensions to parsepublic void setFreemarkerParsingExtensions(String extensionsList)
public void setKeepEncryptedAsVar(boolean keepEncryptedAsVar)
keepEncryptedAsVar - if true, the variables which value is encrypted won't be expandedCopyright © 2019 Nuxeo. All rights reserved.