File indexing completed on 2024-04-28 11:39:29
0001 /* 0002 * dom3_xpathimpl.h - Copyright 2005 Frerich Raabe <raabe@kde.org> 0003 * Copyright 2010 Maksim Orlovich <maksim@kde.org> 0004 * 0005 * Redistribution and use in source and binary forms, with or without 0006 * modification, are permitted provided that the following conditions 0007 * are met: 0008 * 0009 * 1. Redistributions of source code must retain the above copyright 0010 * notice, this list of conditions and the following disclaimer. 0011 * 2. Redistributions in binary form must reproduce the above copyright 0012 * notice, this list of conditions and the following disclaimer in the 0013 * documentation and/or other materials provided with the distribution. 0014 * 0015 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 0016 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 0017 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 0018 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 0019 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 0020 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 0021 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 0022 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 0023 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 0024 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 0025 */ 0026 #ifndef XPATHRESULTIMPL_H 0027 #define XPATHRESULTIMPL_H 0028 0029 #include "misc/shared.h" 0030 #include "xpath/expression.h" 0031 #include "xpath/parsedstatement.h" 0032 0033 namespace DOM 0034 { 0035 class DOMStringImpl; 0036 class NodeImpl; 0037 } 0038 0039 namespace khtml 0040 { 0041 0042 class XPathNSResolverImpl; 0043 0044 class XPathResultImpl : public Shared<XPathResultImpl> 0045 { 0046 public: 0047 XPathResultImpl(); 0048 XPathResultImpl(const XPath::Value &value); 0049 0050 void convertTo(unsigned short type, int &exceptioncode); 0051 0052 unsigned short resultType() const; 0053 0054 double numberValue(int &exceptioncode) const; 0055 DOM::DOMString stringValue(int &exceptioncode) const; 0056 bool booleanValue(int &exceptioncode) const; 0057 DOM::NodeImpl *singleNodeValue(int &exceptioncode) const; 0058 0059 bool invalidIteratorState() const; 0060 unsigned long snapshotLength(int &exceptioncode) const; 0061 DOM::NodeImpl *iterateNext(int &exceptioncode); 0062 DOM::NodeImpl *snapshotItem(unsigned long index, int &exceptioncode); 0063 0064 private: 0065 XPath::Value m_value; 0066 unsigned long m_nodeIterator; 0067 unsigned short m_resultType; 0068 }; 0069 0070 class XPathExpressionImpl : public Shared<XPathExpressionImpl> 0071 { 0072 public: 0073 XPathExpressionImpl(const DOM::DOMString &expression, 0074 XPathNSResolverImpl *resolver); 0075 0076 // expression we got while parsing, or 0 0077 int parseExceptionCode(); 0078 0079 XPathResultImpl *evaluate(DOM::NodeImpl *contextNode, 0080 unsigned short type, 0081 XPathResultImpl *result, 0082 int &exceptioncode); 0083 0084 private: 0085 XPath::ParsedStatement m_statement; 0086 }; 0087 0088 // This is the base class for resolver interfaces 0089 class XPathNSResolverImpl : public khtml::Shared<XPathNSResolverImpl> 0090 { 0091 public: 0092 enum Type { 0093 Default, 0094 JS, 0095 CPP 0096 }; 0097 0098 virtual DOM::DOMString lookupNamespaceURI(const DOM::DOMString &prefix) = 0; 0099 virtual Type type() = 0; 0100 virtual ~XPathNSResolverImpl() {} 0101 }; 0102 0103 // This is the default implementation, used by createNSResolver 0104 class DefaultXPathNSResolverImpl : public XPathNSResolverImpl 0105 { 0106 public: 0107 DefaultXPathNSResolverImpl(DOM::NodeImpl *node); 0108 0109 DOM::DOMString lookupNamespaceURI(const DOM::DOMString &prefix) override; 0110 Type type() override 0111 { 0112 return Default; 0113 } 0114 0115 private: 0116 SharedPtr<DOM::NodeImpl> m_node; 0117 }; 0118 0119 } // namespace khtml 0120 0121 #endif // XPATHRESULTIMPL_H 0122