📄 xalanxpathprocessor.java
字号:
// Copyright 1997-1999 by softwarebuero m&b (SMB). All rights reserved.//// You can redistribute this software and/or modify it under the terms of// the Ozone Library License version 1 published by softwarebuero m&b (SMB).//// $Id: XalanXPathProcessor.java,v 1.7 2000/11/03 11:21:49 daniela Exp $package org.ozoneDB.xml.xpath;import java.io.IOException;import java.io.ObjectInput;import java.io.ObjectOutput;import org.w3c.dom.Document;import org.w3c.dom.Node;import org.w3c.dom.traversal.NodeFilter;import org.xml.sax.SAXException;import org.apache.xalan.xpath.XPath;import org.apache.xalan.xpath.XPathProcessorImpl;import org.apache.xalan.xpath.XPathSupport;import org.apache.xalan.xpath.xml.PrefixResolverDefault;/** * This class implements the XPathProcessor interface on top of Xalan.<p> * * This class only compiles if you have a working Xalan 1.0.1 in your classpath! * * * @version $Revision: 1.7 $ $Date: 2000/11/03 11:21:49 $ * @author <a href="http://www.softwarebuero.de">SMB</a> */public class XalanXPathProcessor extends java.lang.Object implements XPathProcessor { // Constants final static long serialVersionUID = 1; // Data protected XPathSupport xpathSupport; protected XPathProcessorImpl parser; protected XPath xpath; /** * The constructur initializes some basic but internal variables needed by * Xalans XPath implementation. */ public XalanXPathProcessor() { // Since we don't have a XML Parser involved here, install some // default support for things like namespaces, etc. // xpathSupport = new XMLParserLiaisonDefault(); xpathSupport = new NodeFilterLiaison(); // sets the DocumentTraversal for this query ((NodeFilterLiaison)xpathSupport).setDocumentTraversal( new org.apache.xerces.dom.DocumentImpl() ); // Create the XPath object. xpath = new XPath(); // Create a XPath parser. parser = new XPathProcessorImpl( xpathSupport ); } public XObject execute( XPathQuery _query, Node _rootNode ) throws SAXException { Node namespace = _query.namespace != null ? _query.namespace : _rootNode; return execute( _query.qstring, _rootNode, namespace, _query.filter ); } /** * Executes the specified query on the specified node using the specified * namespace resolver. * @param qString The XPath query string. * @param rootNode The node from which the query should start. * @param nameSpace The node that resolves namespace queries. * @param filter The node filter which is to apply while querying. * @exception SAXException If any error occurs. * @return The XObject insulating the query result. */ protected XObject execute( String qString, Node rootNode, Node nameSpace, NodeFilter filter ) throws org.xml.sax.SAXException { PrefixResolverDefault prefixResolver; if (rootNode.getNodeType() == Node.DOCUMENT_NODE) { rootNode = ((Document)rootNode).getDocumentElement(); } // Create an object to resolve namespace prefixes. // XPath namespaces are resolved from the input root node's // document element if it is a root node, or else the current root node. prefixResolver = nameSpace != null ? new PrefixResolverDefault( nameSpace ) : new PrefixResolverDefault( rootNode ); // sets the filter for this query ((NodeFilterLiaison)xpathSupport).setNodeFilter( filter == null ? new SimpleNodeFilter() : filter ); // parse the specified Query-String and build an Parse-Tree parser.initXPath( xpath, qString, prefixResolver ); // execute the XPath query on the specified root node return new XalanXObject( xpath.execute( xpathSupport, rootNode, prefixResolver ) ); } public void writeExternal( ObjectOutput out ) throws IOException { // nothing to do } public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException { xpathSupport = new NodeFilterLiaison(); ((NodeFilterLiaison)xpathSupport).setDocumentTraversal( new org.apache.xerces.dom.DocumentImpl() ); xpath = new XPath(); parser = new XPathProcessorImpl( xpathSupport ); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -