MarkupTemplateEngine is the most powerful implementation class of all Groovy's template classes. As the class name suggests, Markup is the syntax for the markup class, used in XML,HTML, etc.
Unlike other templates, MarkupTemplateEngine uses a different template than the others.
Remember the writing format we learned about earlier that StreamingMarkupBuilder and JsonBuilder used? MarkupTemplateEngine uses a writing style that is almost identical.
Let's start with a simple example:
As you can see by this simple example, the output is in Markup format. In fact, the template is the Groovy DSL, all in legitimate Groovy syntax.
The MarkupTemplateEngine provides several important features.
Markup format classes are composed of tags (tag), tag properties (property) and content (text), and tags can contain sub-tags, all of which have corresponding syntax.
As can be seen, each method name is the label name, the attributes use key-value pairs, and the text is one of the parameters, and the position of the parameter does not matter and is automatically recognized; if it contains child nodes, it is enough to use closures to include them.
Commonly used functions
When studying the XML counterpart classes, you have already seen that StreamingMarkupBuilder contains methods for generating corresponding directives such as XML headers, etc. The Markup Template Engine class provides similar directive methods.
will output the given statement directly, without escaping the characters in it.
Contrary to the above, special characters will be escaped.
These HTML tagging methods generate the corresponding tags.
method will generate a standard XML document header.
method to generate HTML comments.
Generate a new row.
The implementation code is as follows.
The template file provides three forms of import instructions.
* include template: 'include.tpl'
Introduce another template file
* include unescaped: 'include.txt'
Introduce the file as is, without converting any characters
* include escaped: 'include.txt'
Conversion of introduced files according to conversion symbols
There are 3 other built-in methods that provide the same functionality.
The MarkupTemplateEngine allows the behavior of the engine to be specified using the configuration.
* declarationEncoding :
Specifies the encoding format for the output of the xmlDeclaration() method, the default is no encoding format.
Output at this time
If not set, the output is
* expandEmptyElements :
Whether to extend the empty tag, default is false, if true then the empty tag is represented by a pair of tags, e.g.
Whether to use double quotes or not, the default is false, and the attribute value is wrapped in single quotes, and true is wrapped in double quotes.
The line break, by default, uses the system property line.separator, which is
. When a custom value is set, the custom value is used.
propernewLineString = '
' time， exports
Whether to automatically escape, default is false. When set to true, incoming parameters are automatically escaped when they encounter an escape character.
Whether to indent automatically. The default is false. When set to true, indent typesetting is performed using the indent notation specified by autoIndentString, according to the node's level of containment.
Indent the string, the default is 4 spaces. Used for indenting typesetting when autoIndent is true.
Set if or not auto-wrap, default is false,when true, then auto-wrap after each tag. For example:
If false then.
This is the localized content, which by default uses the host's Local.
There is a lot more to the MarkupTemplateEngine, and the length required is continued in the next section.
>>1、Indepth analysis of KubernetesLocalPersistentVolume II2、What opportunities and challenges are presented to the insurance industry in the era of big data3、Small details of oracle parallelism r2 notes 44 days4、What is a CSS preprocessor5、JSP custom tag library taglib