Qt 4.8
qabstractxmlreceiver.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtXmlPatterns module of the Qt Toolkit.
7 **
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.
16 **
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.
24 **
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.
28 **
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.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include <QString>
43 
44 #include "qitem_p.h"
45 
46 #include "qabstractxmlreceiver_p.h"
47 #include "qabstractxmlreceiver.h"
48 
50 
195 template<const QXmlNodeModelIndex::Axis axis>
197 {
198  Q_ASSERT(!node.isNull());
199  const QXmlNodeModelIndex::Iterator::Ptr it(node.iterate(axis));
200  QXmlNodeModelIndex next(it->next());
201 
202  while(!next.isNull())
203  {
204  sendAsNode(next);
205  next = it->next();
206  }
207 }
208 
213  : d_ptr(d)
214 {
215 }
216 
221 {
222 }
223 
228 {
229 }
230 
242 /*
243 ### Qt 5:
244 
245 Consider how source locations should be communicated. Maybe every signature
246 should be extended by adding "qint64 line = -1, qint64 column = -1".
247  */
248 
305 /*
306 ### Qt 5:
307 
308 Change
309  virtual void startDocument() = 0;
310 
311 To:
312  virtual void startDocument(const QUrl &uri) = 0;
313 
314 Such that it allows the document URI to be communicated. The contract would
315 allow null QUrls.
316 */
317 
398 {
399  Q_ASSERT(outputItem);
400  Q_ASSERT(outputItem.isNode());
401  const QXmlNodeModelIndex asNode = outputItem.asNode();
402 
403  switch(asNode.kind())
404  {
406  {
407  const QString &v = outputItem.stringValue();
408  attribute(asNode.name(), QStringRef(&v));
409  return;
410  }
412  {
413  startElement(asNode.name());
414 
415  /* First the namespaces, then attributes, then the children. */
416  asNode.sendNamespaces(this);
417  sendFromAxis<QXmlNodeModelIndex::AxisAttribute>(asNode);
418  sendFromAxis<QXmlNodeModelIndex::AxisChild>(asNode);
419 
420  endElement();
421 
422  return;
423  }
425  {
426  const QString &v = asNode.stringValue();
427  characters(QStringRef(&v));
428  return;
429  }
431  {
432  processingInstruction(asNode.name(), outputItem.stringValue());
433  return;
434  }
436  {
437  comment(outputItem.stringValue());
438  return;
439  }
441  {
442  startDocument();
443  sendFromAxis<QXmlNodeModelIndex::AxisChild>(asNode);
444  endDocument();
445  return;
446  }
448  Q_ASSERT_X(false, Q_FUNC_INFO, "Not implemented");
449  }
450 
451  Q_ASSERT_X(false, Q_FUNC_INFO,
452  QString::fromLatin1("Unknown node type: %1").arg(asNode.kind()).toUtf8().constData());
453 }
454 
478 {
480  "The caller must guarantee only whitespace is passed. Use characters() in other cases.");
481  const QString &v = value.toString();
482  characters(QStringRef(&v));
483 }
484 
489 {
490  if(item.isNode())
491  return sendAsNode(item);
492  else
494 }
495 
511 
double d
Definition: qnumeric_p.h:62
QString toString() const
Returns a copy of the string reference as a QString object.
Definition: qstring.cpp:8653
QScopedPointer< QAbstractXmlReceiverPrivate > d_ptr
The QXmlNodeModelIndex class identifies a node in an XML node model subclassed from QAbstractXmlNodeM...
virtual void characters(const QStringRef &value)=0
This callback is called when a text node appears in the XQuery Sequence.
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QAbstractXmlReceiver()
Constructs an abstract xml receiver.
bool isNull() const
Returns true if this QXmlNodeModelIndex is a default constructed value, otherwise false...
static QVariant toQt(const AtomicValue *const value)
virtual void attribute(const QXmlName &name, const QStringRef &value)=0
This callback is called when an attribute node appears in the XQuery Sequence.
#define it(className, varName)
Due to strong interdependencies, this file contains the definitions for the classes Item...
virtual void startElement(const QXmlName &name)=0
This callback is called when a new element node appears in the XQuery Sequence.
virtual void processingInstruction(const QXmlName &target, const QString &value)=0
This callback is called when a processing instruction appears in the XQuery Sequence.
The QExplicitlySharedDataPointer class represents a pointer to an explicitly shared object...
Definition: qshareddata.h:136
virtual ~QAbstractXmlReceiver()
Destroys the xml receiver.
const AtomicValue * asAtomicValue() const
Definition: qitem_p.h:373
The QString class provides a Unicode character string.
Definition: qstring.h:83
bool isNode() const
Determines whether this item is an atomic value, or a node.
Definition: qitem_p.h:349
virtual void comment(const QString &value)=0
This callback is called when a comment node appears in the XQuery Sequence.
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
void sendAsNode(const QPatternist::Item &outputItem)
Treats outputItem as a node and calls the appropriate function, e.
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QString trimmed() const Q_REQUIRED_RESULT
Returns a string that has whitespace removed from the start and the end.
Definition: qstring.cpp:4506
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
virtual void endDocument()=0
This callback is called when the end of a document node appears in the XQuery Sequence.
QString stringValue() const
Returns the string value of this Item.
Definition: qitem_p.h:302
virtual void atomicValue(const QVariant &value)=0
This callback is called when an atomic value appears in the XQuery Sequence.
The QStringRef class provides a thin wrapper around QString substrings.
Definition: qstring.h:1099
virtual void startDocument()=0
This callback is called when a document node appears in the XQuery Sequence.
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
const QXmlNodeModelIndex & asNode() const
Definition: qitem_p.h:379
Represents an item in the XPath 2.0 Data Model.
Definition: qitem_p.h:182
virtual void item(const QPatternist::Item &item)
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
QExplicitlySharedDataPointer< QAbstractXmlForwardIterator< QXmlNodeModelIndex > > iterate(const Axis axis) const
Definition: qitem_p.h:456
virtual void whitespaceOnly(const QStringRef &value)
This function may be called instead of characters() if, and only if, value consists only of whitespac...
const QChar * constData() const
Returns a pointer to the data stored in the QString.
Definition: qstring.h:712
void sendFromAxis(const QXmlNodeModelIndex &node)
virtual void endElement()=0
This callback is called when the end of an element node appears in the XQuery Sequence.
#define Q_FUNC_INFO
Definition: qglobal.h:1871