1 16 19 package com.sun.org.apache.xpath.internal; 20 21 import javax.xml.transform.TransformerException ; 22 23 import com.sun.org.apache.xml.internal.utils.PrefixResolver; 24 import com.sun.org.apache.xml.internal.utils.PrefixResolverDefault; 25 import com.sun.org.apache.xpath.internal.objects.XObject; 26 27 import org.w3c.dom.Document ; 28 import org.w3c.dom.Node ; 29 import org.w3c.dom.NodeList ; 30 import org.w3c.dom.traversal.NodeIterator; 31 32 55 public class CachedXPathAPI 56 { 57 60 protected XPathContext xpathSupport; 61 62 65 public CachedXPathAPI() 66 { 67 xpathSupport = new XPathContext(); 68 } 69 70 80 public CachedXPathAPI(CachedXPathAPI priorXPathAPI) 81 { 82 xpathSupport = priorXPathAPI.xpathSupport; 83 } 84 85 86 91 public XPathContext getXPathContext() 92 { 93 return this.xpathSupport; 94 } 95 96 97 108 public Node selectSingleNode(Node contextNode, String str) 109 throws TransformerException 110 { 111 return selectSingleNode(contextNode, str, contextNode); 112 } 113 114 125 public Node selectSingleNode( 126 Node contextNode, String str, Node namespaceNode) 127 throws TransformerException 128 { 129 130 NodeIterator nl = selectNodeIterator(contextNode, str, namespaceNode); 132 133 return nl.nextNode(); 135 } 136 137 147 public NodeIterator selectNodeIterator(Node contextNode, String str) 148 throws TransformerException 149 { 150 return selectNodeIterator(contextNode, str, contextNode); 151 } 152 153 164 public NodeIterator selectNodeIterator( 165 Node contextNode, String str, Node namespaceNode) 166 throws TransformerException 167 { 168 169 XObject list = eval(contextNode, str, namespaceNode); 171 172 return list.nodeset(); 174 } 175 176 186 public NodeList selectNodeList(Node contextNode, String str) 187 throws TransformerException 188 { 189 return selectNodeList(contextNode, str, contextNode); 190 } 191 192 203 public NodeList selectNodeList( 204 Node contextNode, String str, Node namespaceNode) 205 throws TransformerException 206 { 207 208 XObject list = eval(contextNode, str, namespaceNode); 210 211 return list.nodelist(); 213 } 214 215 231 public XObject eval(Node contextNode, String str) 232 throws TransformerException 233 { 234 return eval(contextNode, str, contextNode); 235 } 236 237 257 public XObject eval(Node contextNode, String str, Node namespaceNode) 258 throws TransformerException 259 { 260 261 267 PrefixResolverDefault prefixResolver = new PrefixResolverDefault( 272 (namespaceNode.getNodeType() == Node.DOCUMENT_NODE) 273 ? ((Document ) namespaceNode).getDocumentElement() : namespaceNode); 274 275 XPath xpath = new XPath(str, null, prefixResolver, XPath.SELECT, null); 277 278 int ctxtNode = xpathSupport.getDTMHandleFromNode(contextNode); 281 282 return xpath.execute(xpathSupport, ctxtNode, prefixResolver); 283 } 284 285 307 public XObject eval( 308 Node contextNode, String str, PrefixResolver prefixResolver) 309 throws TransformerException 310 { 311 312 XPath xpath = new XPath(str, null, prefixResolver, XPath.SELECT, null); 319 320 XPathContext xpathSupport = new XPathContext(); 322 int ctxtNode = xpathSupport.getDTMHandleFromNode(contextNode); 323 324 return xpath.execute(xpathSupport, ctxtNode, prefixResolver); 325 } 326 } 327 | Popular Tags |