XPathSupport getXPathSupport() throws TemplateModelException { if (xpathSupport == null) { if (contextNode != null) { xpathSupport = contextNode.getXPathSupport(); } else if (size() > 0) { xpathSupport = ((NodeModel) get(0)).getXPathSupport(); } } return xpathSupport; }
boolean matchesName(String name, Environment env) { return DomStringUtil.matchesName(name, getNodeName(), getNodeNamespace(), env); } }
/** * Same as {@link #parse(InputSource, boolean, boolean) parse(source, true, true)}, but loads from a {@link File}; * don't miss the security warnings documented there. */ static public NodeModel parse(File f) throws SAXException, IOException, ParserConfigurationException { return parse(f, true, true); }
@Override public TemplateModel get(String key) throws TemplateModelException { if (key.equals("*")) { return getRootElement(); } else if (key.equals("**")) { NodeList nl = ((Document) node).getElementsByTagName("*"); return new NodeListModel(nl, this); } else if (DomStringUtil.isXMLNameLike(key)) { ElementModel em = (ElementModel) NodeModel.wrap(((Document) node).getDocumentElement()); if (em.matchesName(key, Environment.getCurrentEnvironment())) { return em; } else { return new NodeListModel(this); } } return super.get(key); }
static public NodeModel wrap(Node node) { if (node == null) { return null; } NodeModel result = null; switch (node.getNodeType()) { case Node.DOCUMENT_NODE : result = new DocumentModel((Document) node); break; case Node.ELEMENT_NODE : result = new ElementModel((Element) node); break; case Node.ATTRIBUTE_NODE : result = new AttributeNodeModel((Attr) node); break; case Node.CDATA_SECTION_NODE : case Node.COMMENT_NODE : case Node.TEXT_NODE : result = new CharacterDataNodeModel((org.w3c.dom.CharacterData) node); break; case Node.PROCESSING_INSTRUCTION_NODE : result = new PINodeModel((ProcessingInstruction) node); break; case Node.DOCUMENT_TYPE_NODE : result = new DocumentTypeModel((DocumentType) node); break; } return result; }
public TemplateModel wrap(Object obj) { if (obj instanceof NodeModel) { return (NodeModel) obj; } return NodeModel.wrap((Node) obj); } };
public TemplateModel exec(List args) throws TemplateModelException { if (args.size() != 1) { throw new TemplateModelException("Expecting exactly one arguments"); } String query = (String) args.get(0); // Now, we try to behave as if this is an XPath expression XPathSupport xps = getXPathSupport(); if (xps == null) { throw new TemplateModelException("No XPath support available"); } return xps.executeQuery(node, query); }
public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { ++callCount; return createInputSource(publicId, getTemplate(systemId)); }
public String getNamespaceForPrefix(String prefix, Node node) { return getNamespaceForPrefix(prefix); }
public boolean isEmpty() { return size() == 0; }
String getQualifiedName() throws TemplateModelException { return getNodeName(); }
public String getNamespaceForPrefix(String prefix, Node node) { return getNamespaceForPrefix(prefix); }
static boolean isXMLNameLike(String name) { return isXMLNameLike(name, 0); }
/** * @return whether the qname matches the combination of nodeName, nsURI, and environment prefix settings. */ static public boolean matchesName(String qname, String nodeName, String nsURI, Environment env) { return _ExtDomApi.matchesName(qname, nodeName, nsURI, env); }
static public boolean matchesName(String qname, String nodeName, String nsURI, Environment env) { return DomStringUtil.matchesName(qname, nodeName, nsURI, env); }
NodeListModel(Node contextNode) { this(NodeModel.wrap(contextNode)); }
/** * Same as {@link #parse(InputSource, boolean, boolean) parse(is, true, true)}; don't miss the security warnings * documented there. */ static public NodeModel parse(InputSource is) throws SAXException, IOException, ParserConfigurationException { return parse(is, true, true); }
static public boolean isXMLNameLike(String name) { return DomStringUtil.isXMLNameLike(name); }
public TemplateModel wrapDomNode(Object obj) { return NodeModel.wrap((Node) obj); }