• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

KHTML

  • sources
  • kde-4.12
  • kdelibs
  • khtml
  • xpath
parsedstatement.cpp
Go to the documentation of this file.
1 /*
2  * parsedstatement.cc - Copyright 2005 Frerich Raabe <raabe@kde.org>
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25 #include "parsedstatement.h"
26 #include "path.h"
27 
28 #include "xml/dom_nodeimpl.h"
29 #include "xml/dom_nodelistimpl.h"
30 #include "xml/dom3_xpathimpl.h"
31 
32 using namespace DOM;
33 
34 namespace khtml {
35 namespace XPath {
36 
37 Expression *khtmlParseXPathStatement( const DOMString &statement, int& ec );
38 
39 ParsedStatement::ParsedStatement( const DOMString &statement, khtml::XPathNSResolverImpl* res )
40  : m_res( res ), m_expr( 0 ), m_ec( 0 )
41 {
42  parse( statement );
43 }
44 
45 ParsedStatement::~ParsedStatement()
46 {
47  delete m_expr;
48 }
49 
50 void ParsedStatement::parse( const DOMString &statement )
51 {
52  kDebug(6011) << "parsing:" << statement.string();
53  m_ec = 0;
54  delete m_expr;
55  Expression::evaluationContext().reset( 0, m_res.get() );
56 
57  m_expr = khtmlParseXPathStatement( statement, m_ec );
58 
59  kDebug(6011) << "AST:" << (m_expr ? m_expr->dump() : QString::fromLatin1("*** parse error ***"));
60 }
61 
62 void ParsedStatement::optimize()
63 {
64  if ( !m_expr ) {
65  return;
66  }
67  m_expr->optimize();
68 }
69 
70 Value ParsedStatement::evaluate(NodeImpl* context, int& ec) const
71 {
72  Expression::evaluationContext().reset(context, m_res.get());
73  Value res = m_expr->evaluate();
74  ec = Expression::evaluationContext().exceptionCode;
75 
76  // If the result is a nodeset, we need to put it in document order
77  // and remove duplicates.
78  if ( res.isNodeset() )
79  res.toNodeset()->normalizeUpto(StaticNodeListImpl::DocumentOrder);
80  return res;
81 }
82 
83 QString ParsedStatement::dump() const
84 {
85  return m_expr->dump();
86 }
87 
88 } // namespace XPath
89 } // namespace khtml
90 
91 // kate: indent-width 4; replace-tabs off; tab-width 4; space-indent off;
khtml::XPath::Value::isNodeset
bool isNodeset() const
Definition: expression.cpp:86
parsedstatement.h
khtmlParseXPathStatement
Expression * khtmlParseXPathStatement(const DOM::DOMString &statement, int &ec)
Definition: parser.cpp:2170
khtml::XPath::EvaluationContext::exceptionCode
int exceptionCode
Definition: expression.h:67
DOM::DOMString::string
QString string() const
Definition: dom_string.cpp:236
QString
khtml::XPath::EvaluationContext::reset
void reset(DOM::NodeImpl *ctx, XPathNSResolverImpl *res)
Definition: expression.h:51
kDebug
static QDebug kDebug(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
khtml::XPath::Value
Definition: expression.h:75
khtml::XPath::Expression::dump
virtual QString dump() const =0
khtml::XPath::Expression::evaluationContext
static EvaluationContext & evaluationContext()
Definition: expression.cpp:212
DOM::DOMString
This class implements the basic string we use in the DOM.
Definition: dom_string.h:43
khtml::XPath::ParsedStatement::dump
QString dump() const
Definition: parsedstatement.cpp:83
khtml::XPath::ParsedStatement::optimize
void optimize()
Definition: parsedstatement.cpp:62
khtml::XPath::ParsedStatement::evaluate
Value evaluate(DOM::NodeImpl *context, int &ec) const
Definition: parsedstatement.cpp:70
path.h
khtml::XPath::Expression::evaluate
virtual Value evaluate() const
Definition: expression.cpp:229
khtml::XPath::ParsedStatement::~ParsedStatement
~ParsedStatement()
Definition: parsedstatement.cpp:45
khtml::XPath::khtmlParseXPathStatement
Expression * khtmlParseXPathStatement(const DOMString &statement, int &ec)
Definition: parser.cpp:2170
khtml::XPath::Value::toNodeset
DomNodeList & toNodeset()
Definition: expression.cpp:106
khtml::XPath::Expression::optimize
void optimize()
Definition: expression.cpp:242
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:51:22 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KHTML

Skip menu "KHTML"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal