The TemplateBuilder class from the package com.lambdazen.htmlsplicer includes methods to load HTMLTemplate objects from DOM Document objects. The complete API documentation for Template builder is at https://sourceforge.net/projects/htmlsplicer/files/apidocs.zip
The following code instantiates a HTMLTemplate object fooTemplate from a DOM document object, fooDoc.
HTMLTemplate fooTemplate = new TemplateBuilder().newTemplate(fooDoc);
When generating variable bindings dynamically at the server, it may be more convenient to instantiate a HTML template using a Map from String variable names to DOM Nodes. This method has the following signature:
public HTMLTemplate fromMapOfBindingNodes(Map<String, Node> nodeMap) throws HTMLSplicerException;
Finally, in cases where the variable binding is to a simple text node, you can use the following method that takes a Map from String variable names to the String value of the text node.
public HTMLTemplate fromMapOfBindingStrings(Map<String, String> stringMap) throws HTMLSplicerException;
Note that this method automatically encodes HTML special characters such as < and > and can not be used to bind anything other than a text node.
A TemplateBuilder can also be instantiated with some global bindings. This ensures that every HTMLTemplate created by that object, using newTemplate, fromMapOfBindingNodes, or fromMapOfBindingStrings, will automatically be substituted with the global bindings when possible. Global bindings are useful for substitutions for error messages, internationalized strings, branding messages, etc. which must be replaced on every document generated by the server.