Package net.emustudio.edigen.misc
Class Template
- java.lang.Object
-
- net.emustudio.edigen.misc.Template
-
public class Template extends java.lang.ObjectA simple templating system.The user supplies a template as a text and a set of variables with their values. In the template, a variable is identified by a percent sign followed by its name. The template system replaces the variables by their values. Each variable can be either block or inline.
A line contains a block variable if it consists only of whitespace characters and the variable itself. During the replacement, each line of the block variable value is prepended with the whitespace string same as that located before the variable name. This allows inserting the source code with the proper indentation.
All other variables are inline. An inline variable is replaced by its value as-is.
Unset variables found in the template are left unmodified.
-
-
Constructor Summary
Constructors Constructor Description Template(java.io.BufferedReader template, java.io.BufferedWriter output)Constructs a template system.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidsetVariable(java.lang.String name, java.lang.String value)Sets a value of a variable.voidwrite()Writes the whole resulting output.
-
-
-
Method Detail
-
setVariable
public void setVariable(java.lang.String name, java.lang.String value)Sets a value of a variable.- Parameters:
name- the variable name; must start with a letter or an underscore and continue with letters, numbers and underscoresvalue- the variable value- Throws:
java.lang.IllegalArgumentException- if the variable name is invalid
-
write
public void write() throws java.io.IOExceptionWrites the whole resulting output.- Throws:
java.io.IOException- if an exception occurs during writing
-
-