![JAR search and dependency download from the Maven repository](/logo.png)
freemarker.template.utility.DOMNodeModel Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of freemarker-gae Show documentation
Show all versions of freemarker-gae Show documentation
Google App Engine compliant variation of FreeMarker.
FreeMarker is a "template engine"; a generic tool to generate text output based on templates.
/*
* Copyright 2014 Attila Szegedi, Daniel Dekany, Jonathan Revusky
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package freemarker.template.utility;
import java.util.HashMap;
import java.util.List;
import org.w3c.dom.Attr;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.Text;
import freemarker.template.SimpleHash;
import freemarker.template.SimpleScalar;
import freemarker.template.TemplateBooleanModel;
import freemarker.template.TemplateHashModel;
import freemarker.template.TemplateMethodModel;
import freemarker.template.TemplateModel;
import freemarker.template.TemplateModelException;
import freemarker.template.TemplateSequenceModel;
/**
* A convenient wrapper class for wrapping a Node in the W3C DOM API.
*/
public class DOMNodeModel implements TemplateHashModel {
static private HashMap equivalenceTable = new HashMap();
static {
equivalenceTable.put("*", "children");
equivalenceTable.put("@*", "attributes");
}
private Node node;
private HashMap cache = new HashMap();
public DOMNodeModel(Node node) {
this.node = node;
}
public TemplateModel get(String key) throws TemplateModelException {
TemplateModel result = null;
if (equivalenceTable.containsKey(key)) {
key = (String) equivalenceTable.get(key);
}
if (cache.containsKey(key)) {
result = (TemplateModel) cache.get(key);
}
if (result == null) {
if ("attributes".equals(key)) {
NamedNodeMap attributes = node.getAttributes();
if (attributes != null) {
SimpleHash hash = new SimpleHash();
for (int i = 0; i
© 2015 - 2025 Weber Informatics LLC | Privacy Policy