1 package org.xmldb.common.xml.queries.xalan2; 2 54 import org.w3c.dom.Node ; 55 import org.w3c.dom.Document ; 56 import org.w3c.dom.traversal.NodeFilter; 57 import org.apache.xml.utils.PrefixResolver; 58 import org.apache.xml.utils.PrefixResolverDefault; 59 import org.apache.xpath.XPathAPI; 60 import org.xmldb.common.xml.queries.XPathQuery; 61 import org.xmldb.common.xml.queries.XObject; 62 63 67 public final class XPathQueryImpl implements XPathQuery { 68 69 73 private String qstring; 74 private Node rootNode; 75 private Node namespace; 76 private NodeFilter filter; 77 private PrefixResolver prefixResolver; 78 79 public XPathQueryImpl() { 80 } 81 82 public void setQString( String qstring ) throws Exception { 83 this.qstring = qstring; 84 } 85 86 public void setNamespace( Node namespace ) throws Exception { 87 this.namespace = namespace; 88 } 89 90 public void setNodeFilter( NodeFilter filter ) throws Exception { 91 this.filter = filter; 92 } 93 94 100 public XObject execute( Node rootNode ) throws Exception { 101 if (rootNode.getNodeType() == Node.DOCUMENT_NODE) { 102 rootNode = ((Document )rootNode).getDocumentElement (); 103 } 104 this.rootNode = rootNode; 105 prefixResolver = namespace != null ? new PrefixResolverDefault (namespace): 106 new PrefixResolverDefault (rootNode); 107 108 org.apache.xpath.objects.XObject xobj = 110 XPathAPI.eval (rootNode, qstring, prefixResolver); 111 112 117 return new XObjectImpl (xobj); 118 } 119 } 120 121 | Popular Tags |