1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtXmlPatterns module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
44 #include "qabstractxmlnodemodel_p.h"
45 #include "qitemmappingiterator_p.h"
48 #include "qxmlquery_p.h"
50 #include "qpullbridge_p.h"
54 using namespace QPatternist;
57 \brief Bridges a QPatternist::SequenceIterator to QAbstractXmlPullProvider.
58 \class QPatternist::PullBridge
63 The approach of this class is rather straight forward since QPatternist::SequenceIterator
64 and QAbstractXmlPullProvider are conceptually similar. While QPatternist::SequenceIterator only
65 delivers top level items(since it's not an event stream, it's a list of items), PullBridge
66 needs to recursively iterate the children of nodes too, which is achieved through the
70 AbstractXmlPullProvider::Event PullBridge::next()
72 m_index = m_iterators.top().second->next();
78 if(item && item.isAtomicValue())
79 m_current = AtomicValue;
82 Q_ASSERT(item.isNode());
84 switch(m_index.kind())
86 case QXmlNodeModelIndex::Attribute:
88 m_current = Attribute;
91 case QXmlNodeModelIndex::Comment:
96 case QXmlNodeModelIndex::Element:
98 m_iterators.push(qMakePair(StartElement, m_index.iterate(QXmlNodeModelIndex::AxisChild)));
99 m_current = StartElement;
102 case QXmlNodeModelIndex::Document:
104 m_iterators.push(qMakePair(StartDocument, m_index.iterate(QXmlNodeModelIndex::AxisChild)));
105 m_current = StartDocument;
108 case QXmlNodeModelIndex::Namespace:
110 m_current = Namespace;
113 case QXmlNodeModelIndex::ProcessingInstruction:
115 m_current = ProcessingInstruction;
118 case QXmlNodeModelIndex::Text:
128 if(m_iterators.isEmpty())
129 m_current = EndOfInput;
132 switch(m_iterators.top().first)
136 m_current = EndOfInput;
141 m_current = EndElement;
147 m_current = EndDocument;
153 Q_ASSERT_X(false, Q_FUNC_INFO,
155 m_current = EndOfInput;
165 AbstractXmlPullProvider::Event PullBridge::current() const
170 QXmlNodeModelIndex PullBridge::index() const
175 QSourceLocation PullBridge::sourceLocation() const
177 return m_index.model()->sourceLocation(m_index);
180 QXmlName PullBridge::name() const
182 return m_index.name();
185 QVariant PullBridge::atomicValue() const
190 QString PullBridge::stringValue() const
195 QHash<QXmlName, QString> PullBridge::attributes()
197 Q_ASSERT(m_current == StartElement);
199 QHash<QXmlName, QString> attributes;
201 QXmlNodeModelIndex::Iterator::Ptr it = m_index.iterate(QXmlNodeModelIndex::AxisAttribute);
202 QXmlNodeModelIndex index = it->next();
203 while (!index.isNull()) {
204 const Item attribute(index);
205 attributes.insert(index.name(), index.stringValue());
213 QHash<QXmlName, QXmlItem> PullBridge::attributeItems()
215 Q_ASSERT(m_current == StartElement);
217 QHash<QXmlName, QXmlItem> attributes;
219 QXmlNodeModelIndex::Iterator::Ptr it = m_index.iterate(QXmlNodeModelIndex::AxisAttribute);
220 QXmlNodeModelIndex index = it->next();
221 while (!index.isNull()) {
222 const Item attribute(index);
223 attributes.insert(index.name(), QXmlItem(index));