1 /****************************************************************************
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
6 ** This file is part of the QtXmlPatterns module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
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));