![JAR search and dependency download from the Maven repository](/logo.png)
freemarker.ext.dom.NodeListModel 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.ext.dom;
import java.util.ArrayList;
import java.util.List;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import freemarker.core.Environment;
import freemarker.core._UnexpectedTypeErrorExplainerTemplateModel;
import freemarker.template.ObjectWrapper;
import freemarker.template.SimpleScalar;
import freemarker.template.SimpleSequence;
import freemarker.template.TemplateBooleanModel;
import freemarker.template.TemplateDateModel;
import freemarker.template.TemplateHashModel;
import freemarker.template.TemplateModel;
import freemarker.template.TemplateModelException;
import freemarker.template.TemplateNumberModel;
import freemarker.template.TemplateScalarModel;
import freemarker.template.TemplateSequenceModel;
import freemarker.template.utility.StringUtil;
class NodeListModel extends SimpleSequence implements TemplateHashModel, _UnexpectedTypeErrorExplainerTemplateModel {
NodeModel contextNode;
XPathSupport xpathSupport;
private static ObjectWrapper nodeWrapper = new ObjectWrapper() {
public TemplateModel wrap(Object obj) {
if (obj instanceof NodeModel) {
return (NodeModel) obj;
}
return NodeModel.wrap((Node) obj);
}
};
NodeListModel(Node node) {
this(NodeModel.wrap(node));
}
NodeListModel(NodeModel contextNode) {
super(nodeWrapper);
this.contextNode = contextNode;
}
NodeListModel(NodeList nodeList, NodeModel contextNode) {
super(nodeWrapper);
for (int i=0; i0) {
xpathSupport = ((NodeModel) get(0)).getXPathSupport();
}
}
return xpathSupport;
}
public Object[] explainTypeError(Class[] expectedClasses) {
for (int i = 0; i < expectedClasses.length; i++) {
Class expectedClass = expectedClasses[i];
if (TemplateScalarModel.class.isAssignableFrom(expectedClass)
|| TemplateDateModel.class.isAssignableFrom(expectedClass)
|| TemplateNumberModel.class.isAssignableFrom(expectedClass)
|| TemplateBooleanModel.class.isAssignableFrom(expectedClass)) {
return new Object[] {
"This XML query result can't be used as string because for that it had to contain exactly "
+ "1 XML node, but it contains ", new Integer(size()), " nodes. "
+ "That is, the constructing XML query has found ",
isEmpty()
? "no matches."
: "multiple matches."
};
}
}
return null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy