001 /*
002 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
003 *
004 * This code is free software; you can redistribute it and/or modify it
005 * under the terms of the GNU General Public License version 2 only, as
006 * published by the Free Software Foundation. Sun designates this
007 * particular file as subject to the "Classpath" exception as provided
008 * by Sun in the LICENSE file that accompanied this code.
009 *
010 * This code is distributed in the hope that it will be useful, but WITHOUT
011 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
012 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
013 * version 2 for more details (a copy is included in the LICENSE file that
014 * accompanied this code).
015 *
016 * You should have received a copy of the GNU General Public License version
017 * 2 along with this work; if not, write to the Free Software Foundation,
018 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
019 *
020 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
021 * CA 95054 USA or visit www.sun.com if you need additional information or
022 * have any questions.
023 */
024
025 /*
026 * This file is available under and governed by the GNU General Public
027 * License version 2 only, as published by the Free Software Foundation.
028 * However, the following notice accompanied the original version of this
029 * file and, per its terms, should not be removed:
030 *
031 * Copyright (c) 2002 World Wide Web Consortium,
032 * (Massachusetts Institute of Technology, Institut National de
033 * Recherche en Informatique et en Automatique, Keio University). All
034 * Rights Reserved. This program is distributed under the W3C's Software
035 * Intellectual Property License. This program is distributed in the
036 * hope that it will be useful, but WITHOUT ANY WARRANTY; without even
037 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
038 * PURPOSE.
039 * See W3C License http://www.w3.org/Consortium/Legal/ for more details.
040 */
041
042 package org.w3c.dom.xpath;
043
044 import org.w3c.dom.Node;
045 import org.w3c.dom.DOMException;
046
047 /**
048 * The evaluation of XPath expressions is provided by
049 * <code>XPathEvaluator</code>. In a DOM implementation which supports the
050 * XPath 3.0 feature, as described above, the <code>XPathEvaluator</code>
051 * interface will be implemented on the same object which implements the
052 * <code>Document</code> interface permitting it to be obtained by the usual
053 * binding-specific method such as casting or by using the DOM Level 3
054 * getInterface method. In this case the implementation obtained from the
055 * Document supports the XPath DOM module and is compatible with the XPath
056 * 1.0 specification.
057 * <p>Evaluation of expressions with specialized extension functions or
058 * variables may not work in all implementations and is, therefore, not
059 * portable. <code>XPathEvaluator</code> implementations may be available
060 * from other sources that could provide specific support for specialized
061 * extension functions or variables as would be defined by other
062 * specifications.
063 * <p>See also the <a href='http://www.w3.org/2002/08/WD-DOM-Level-3-XPath-20020820'>Document Object Model (DOM) Level 3 XPath Specification</a>.
064 */
065 public interface XPathEvaluator {
066 /**
067 * Creates a parsed XPath expression with resolved namespaces. This is
068 * useful when an expression will be reused in an application since it
069 * makes it possible to compile the expression string into a more
070 * efficient internal form and preresolve all namespace prefixes which
071 * occur within the expression.
072 * @param expression The XPath expression string to be parsed.
073 * @param resolver The <code>resolver</code> permits translation of
074 * prefixes within the XPath expression into appropriate namespace URIs
075 * . If this is specified as <code>null</code>, any namespace prefix
076 * within the expression will result in <code>DOMException</code>
077 * being thrown with the code <code>NAMESPACE_ERR</code>.
078 * @return The compiled form of the XPath expression.
079 * @exception XPathException
080 * INVALID_EXPRESSION_ERR: Raised if the expression is not legal
081 * according to the rules of the <code>XPathEvaluator</code>i
082 * @exception DOMException
083 * NAMESPACE_ERR: Raised if the expression contains namespace prefixes
084 * which cannot be resolved by the specified
085 * <code>XPathNSResolver</code>.
086 */
087 public XPathExpression createExpression(String expression,
088 XPathNSResolver resolver) throws XPathException,
089 DOMException;
090
091 /**
092 * Adapts any DOM node to resolve namespaces so that an XPath expression
093 * can be easily evaluated relative to the context of the node where it
094 * appeared within the document. This adapter works like the DOM Level 3
095 * method <code>lookupNamespaceURI</code> on nodes in resolving the
096 * namespaceURI from a given prefix using the current information
097 * available in the node's hierarchy at the time lookupNamespaceURI is
098 * called. also correctly resolving the implicit xml prefix.
099 * @param nodeResolver The node to be used as a context for namespace
100 * resolution.
101 * @return <code>XPathNSResolver</code> which resolves namespaces with
102 * respect to the definitions in scope for a specified node.
103 */
104 public XPathNSResolver createNSResolver(Node nodeResolver);
105
106 /**
107 * Evaluates an XPath expression string and returns a result of the
108 * specified type if possible.
109 * @param expression The XPath expression string to be parsed and
110 * evaluated.
111 * @param contextNode The <code>context</code> is context node for the
112 * evaluation of this XPath expression. If the XPathEvaluator was
113 * obtained by casting the <code>Document</code> then this must be
114 * owned by the same document and must be a <code>Document</code>,
115 * <code>Element</code>, <code>Attribute</code>, <code>Text</code>,
116 * <code>CDATASection</code>, <code>Comment</code>,
117 * <code>ProcessingInstruction</code>, or <code>XPathNamespace</code>
118 * node. If the context node is a <code>Text</code> or a
119 * <code>CDATASection</code>, then the context is interpreted as the
120 * whole logical text node as seen by XPath, unless the node is empty
121 * in which case it may not serve as the XPath context.
122 * @param resolver The <code>resolver</code> permits translation of
123 * prefixes within the XPath expression into appropriate namespace URIs
124 * . If this is specified as <code>null</code>, any namespace prefix
125 * within the expression will result in <code>DOMException</code>
126 * being thrown with the code <code>NAMESPACE_ERR</code>.
127 * @param type If a specific <code>type</code> is specified, then the
128 * result will be returned as the corresponding type.For XPath 1.0
129 * results, this must be one of the codes of the
130 * <code>XPathResult</code> interface.
131 * @param result The <code>result</code> specifies a specific result
132 * object which may be reused and returned by this method. If this is
133 * specified as <code>null</code>or the implementation does not reuse
134 * the specified result, a new result object will be constructed and
135 * returned.For XPath 1.0 results, this object will be of type
136 * <code>XPathResult</code>.
137 * @return The result of the evaluation of the XPath expression.For XPath
138 * 1.0 results, this object will be of type <code>XPathResult</code>.
139 * @exception XPathException
140 * INVALID_EXPRESSION_ERR: Raised if the expression is not legal
141 * according to the rules of the <code>XPathEvaluator</code>i
142 * <br>TYPE_ERR: Raised if the result cannot be converted to return the
143 * specified type.
144 * @exception DOMException
145 * NAMESPACE_ERR: Raised if the expression contains namespace prefixes
146 * which cannot be resolved by the specified
147 * <code>XPathNSResolver</code>.
148 * <br>WRONG_DOCUMENT_ERR: The Node is from a document that is not
149 * supported by this <code>XPathEvaluator</code>.
150 * <br>NOT_SUPPORTED_ERR: The Node is not a type permitted as an XPath
151 * context node or the request type is not permitted by this
152 * <code>XPathEvaluator</code>.
153 */
154 public Object evaluate(String expression, Node contextNode,
155 XPathNSResolver resolver, short type, Object result)
156 throws XPathException, DOMException;
157
158 }
|