Package ru.proninyaroslav.template
Class Template
- java.lang.Object
-
- ru.proninyaroslav.template.Template
-
public class Template extends java.lang.ObjectRepresentation of a parsed template
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddFuncs(FuncMap funcs)voidaddParseTree(java.lang.String name, Tree tree)Adds parse tree for template with given name and associates it with template.voidexecute(java.io.OutputStream os, java.lang.Object data)Applies a parsed template to the specified data object, and writes the output to OutputStream.voidexecuteTemplate(java.io.OutputStream os, java.lang.String name, java.lang.Object data)Applies the template associated with this template that has the given name to the specified data object and writes the output to OutputStreamTemplategetTemplate(java.lang.String name)Template[]getTemplates()voidparse(java.io.InputStream input)voidparse(java.lang.String text)Named template definition ({define ...}) in text define additional templates associated with template and are removed from the definition of template itself.static Templateparse(FuncMap funcs, java.io.File... files)Create templates from the file liststatic Templateparse(FuncMap funcs, java.util.Map<java.lang.String,java.lang.String> inputs)Create templates from the map, that represent pair (Name, InputStream)TemplateparseTo(FuncMap funcs, java.io.File... files)Create templates from the file list and append to this templateTemplateparseTo(FuncMap funcs, java.util.Map<java.lang.String,java.lang.String> text)Create templates from the map, that represent pair (Name, Text) and append to this templatevoidsetDelims(java.lang.String left, java.lang.String right)
-
-
-
Constructor Detail
-
Template
public Template(java.lang.String name)
-
Template
public Template(java.lang.String name, Template parent)Allocates a new, undefined template associated with the given one and with the same delimiters. The association allows one template to invoke another with a {template} action- Parameters:
name- template nameparent- parent
-
-
Method Detail
-
parse
public static Template parse(FuncMap funcs, java.io.File... files) throws ParseException, java.io.IOException
Create templates from the file list- Parameters:
funcs- functionsfiles- template files- Returns:
- template
- Throws:
ParseException- in case of a parse errorjava.io.IOException- in case of an I/O error
-
parse
public static Template parse(FuncMap funcs, java.util.Map<java.lang.String,java.lang.String> inputs) throws ParseException
Create templates from the map, that represent pair (Name, InputStream)- Parameters:
funcs- functionsinputs- list ofInputStream- Returns:
- template
- Throws:
ParseException- in case of a parse error
-
parse
public void parse(java.lang.String text) throws InternalException, ParseExceptionNamed template definition ({define ...}) in text define additional templates associated with template and are removed from the definition of template itself. Templates can be redefined in successive calls to parse. A template definition with a body containing only white space and comments is considered empty and will not replace an existing template's body.- Parameters:
text- template text- Throws:
InternalException- in case of an internal errorParseException- in case of a parse error
-
parse
public void parse(java.io.InputStream input) throws InternalException, ParseException, java.io.IOException- Throws:
InternalExceptionParseExceptionjava.io.IOException
-
parseTo
public Template parseTo(FuncMap funcs, java.io.File... files) throws ParseException, java.io.IOException
Create templates from the file list and append to this template- Parameters:
funcs- functionsfiles- template files- Returns:
- template
- Throws:
ParseException- in case of a parse errorjava.io.IOException- in case of an I/O error
-
parseTo
public Template parseTo(FuncMap funcs, java.util.Map<java.lang.String,java.lang.String> text) throws ParseException
Create templates from the map, that represent pair (Name, Text) and append to this template- Parameters:
funcs- functionstext- pair (Name, Text)- Returns:
- template
- Throws:
ParseException- in case of a parse error
-
execute
public void execute(java.io.OutputStream os, java.lang.Object data) throws ExecExceptionApplies a parsed template to the specified data object, and writes the output to OutputStream. If an error occurs executing the template or writing its output, execution stops, but partial results may already have been written to the output writer- Parameters:
os-OutputStreamobjectdata- data- Throws:
ExecException- in case of an execute error
-
executeTemplate
public void executeTemplate(java.io.OutputStream os, java.lang.String name, java.lang.Object data) throws ExecExceptionApplies the template associated with this template that has the given name to the specified data object and writes the output to OutputStream- Parameters:
os-OutputStreamobjectname- template namedata- data- Throws:
ExecException- in case of an execute error
-
addFuncs
public void addFuncs(FuncMap funcs)
-
setDelims
public void setDelims(java.lang.String left, java.lang.String right)
-
getTemplates
public Template[] getTemplates()
-
getTemplate
public Template getTemplate(java.lang.String name)
-
addParseTree
public void addParseTree(java.lang.String name, Tree tree) throws InternalException, ParseExceptionAdds parse tree for template with given name and associates it with template. If the template does not already exist, it will create a new one. If the template does exist, it will be replaced- Parameters:
name- template nametree- parse tree- Throws:
InternalException- in case of an internal errorParseException- in case of an execute error
-
-