summaryrefslogtreecommitdiff
path: root/src/xmlpatterns/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/xmlpatterns/api')
-rw-r--r--src/xmlpatterns/api/api.pri11
-rw-r--r--src/xmlpatterns/api/qabstractxmlforwarditerator_p.h15
-rw-r--r--src/xmlpatterns/api/qabstractxmlnodemodel.cpp20
-rw-r--r--src/xmlpatterns/api/qabstractxmlnodemodel.h8
-rw-r--r--src/xmlpatterns/api/qabstractxmlnodemodel_p.h10
-rw-r--r--src/xmlpatterns/api/qabstractxmlpullprovider.cpp177
-rw-r--r--src/xmlpatterns/api/qabstractxmlpullprovider_p.h113
-rw-r--r--src/xmlpatterns/api/qabstractxmlreceiver.cpp1
-rw-r--r--src/xmlpatterns/api/qabstractxmlreceiver.h3
-rw-r--r--src/xmlpatterns/api/qpullbridge.cpp232
-rw-r--r--src/xmlpatterns/api/qpullbridge_p.h103
-rw-r--r--src/xmlpatterns/api/qresourcedelegator.cpp8
-rw-r--r--src/xmlpatterns/api/qsourcelocation.cpp2
-rw-r--r--src/xmlpatterns/api/qxmlnamepool.cpp4
-rw-r--r--src/xmlpatterns/api/qxmlnamepool.h7
-rw-r--r--src/xmlpatterns/api/qxmlquery.cpp41
-rw-r--r--src/xmlpatterns/api/qxmlquery.h12
-rw-r--r--src/xmlpatterns/api/qxmlquery_p.h37
-rw-r--r--src/xmlpatterns/api/qxmlresultitems.cpp1
-rw-r--r--src/xmlpatterns/api/qxmlresultitems.h3
-rw-r--r--src/xmlpatterns/api/qxmlschema.cpp299
-rw-r--r--src/xmlpatterns/api/qxmlschema.h97
-rw-r--r--src/xmlpatterns/api/qxmlschema_p.cpp203
-rw-r--r--src/xmlpatterns/api/qxmlschema_p.h109
-rw-r--r--src/xmlpatterns/api/qxmlschemavalidator.cpp344
-rw-r--r--src/xmlpatterns/api/qxmlschemavalidator.h97
-rw-r--r--src/xmlpatterns/api/qxmlschemavalidator_p.h131
27 files changed, 2044 insertions, 44 deletions
diff --git a/src/xmlpatterns/api/api.pri b/src/xmlpatterns/api/api.pri
index a0298f25fb..9fcc2f53e6 100644
--- a/src/xmlpatterns/api/api.pri
+++ b/src/xmlpatterns/api/api.pri
@@ -3,11 +3,13 @@ HEADERS += $$PWD/qabstractxmlforwarditerator_p.h \
$$PWD/qabstracturiresolver.h \
$$PWD/qabstractxmlnodemodel.h \
$$PWD/qabstractxmlnodemodel_p.h \
+ $$PWD/qabstractxmlpullprovider_p.h \
$$PWD/qabstractxmlreceiver.h \
$$PWD/qabstractxmlreceiver_p.h \
$$PWD/qdeviceresourceloader_p.h \
$$PWD/qiodevicedelegate_p.h \
$$PWD/qnetworkaccessdelegator_p.h \
+ $$PWD/qpullbridge_p.h \
$$PWD/qresourcedelegator_p.h \
$$PWD/qsimplexmlnodemodel.h \
$$PWD/qsourcelocation.h \
@@ -20,6 +22,10 @@ HEADERS += $$PWD/qabstractxmlforwarditerator_p.h \
$$PWD/qxmlquery_p.h \
$$PWD/qxmlresultitems.h \
$$PWD/qxmlresultitems_p.h \
+ $$PWD/qxmlschema.h \
+ $$PWD/qxmlschema_p.h \
+ $$PWD/qxmlschemavalidator.h \
+ $$PWD/qxmlschemavalidator_p.h \
$$PWD/qxmlserializer.h \
$$PWD/qxmlserializer_p.h \
$$PWD/../../../tools/xmlpatterns/qcoloringmessagehandler_p.h \
@@ -29,9 +35,11 @@ SOURCES += $$PWD/qvariableloader.cpp \
$$PWD/qabstractmessagehandler.cpp \
$$PWD/qabstracturiresolver.cpp \
$$PWD/qabstractxmlnodemodel.cpp \
+ $$PWD/qabstractxmlpullprovider.cpp \
$$PWD/qabstractxmlreceiver.cpp \
$$PWD/qiodevicedelegate.cpp \
$$PWD/qnetworkaccessdelegator.cpp \
+ $$PWD/qpullbridge.cpp \
$$PWD/qresourcedelegator.cpp \
$$PWD/qsimplexmlnodemodel.cpp \
$$PWD/qsourcelocation.cpp \
@@ -41,6 +49,9 @@ SOURCES += $$PWD/qvariableloader.cpp \
$$PWD/qxmlnamepool.cpp \
$$PWD/qxmlquery.cpp \
$$PWD/qxmlresultitems.cpp \
+ $$PWD/qxmlschema.cpp \
+ $$PWD/qxmlschema_p.cpp \
+ $$PWD/qxmlschemavalidator.cpp \
$$PWD/qxmlserializer.cpp \
$$PWD/../../../tools/xmlpatterns/qcoloringmessagehandler.cpp \
$$PWD/../../../tools/xmlpatterns/qcoloroutput.cpp
diff --git a/src/xmlpatterns/api/qabstractxmlforwarditerator_p.h b/src/xmlpatterns/api/qabstractxmlforwarditerator_p.h
index fde5634ad3..cbc8f59c2e 100644
--- a/src/xmlpatterns/api/qabstractxmlforwarditerator_p.h
+++ b/src/xmlpatterns/api/qabstractxmlforwarditerator_p.h
@@ -55,7 +55,7 @@
#include <QtCore/QList>
#include <QtCore/QVector>
#include <QtCore/QSharedData>
-
+#include <QtCore/QString>
QT_BEGIN_HEADER
@@ -74,6 +74,19 @@ inline bool qIsForwardIteratorEnd(const T &unit)
return !unit;
}
+/**
+ * @short Helper class for StringSplitter
+ *
+ * Needed by the QAbstractXmlForwardIterator sub-class.
+ *
+ * @relates StringSplitter
+ */
+template<>
+inline bool qIsForwardIteratorEnd(const QString &unit)
+{
+ return unit.isNull();
+}
+
template<typename T> class QAbstractXmlForwardIterator;
class QAbstractXmlForwardIteratorPrivate;
diff --git a/src/xmlpatterns/api/qabstractxmlnodemodel.cpp b/src/xmlpatterns/api/qabstractxmlnodemodel.cpp
index 8f0f80a3f1..fda7cb4254 100644
--- a/src/xmlpatterns/api/qabstractxmlnodemodel.cpp
+++ b/src/xmlpatterns/api/qabstractxmlnodemodel.cpp
@@ -190,8 +190,7 @@ bool QAbstractXmlNodeModel::isIgnorableInDeepEqual(const QXmlNodeModelIndex &n)
Because the node model can be accessed concurrently by threads in
the QtXmlPatterns module, subclasses of QAbstractXmlNodeModel must
- be written to be \l{Thread Support in Qt#Reentrancy and Thread-Safety}
- {thread-safe}.
+ be written to be \l{Reentrancy and Thread-Safety}{thread-safe}.
Classes that simplify implementing thread-safety include QReadLocker
and QWriteLocker.
@@ -302,7 +301,6 @@ QAbstractXmlNodeModel::QAbstractXmlNodeModel(QAbstractXmlNodeModelPrivate *d) :
*/
QAbstractXmlNodeModel::~QAbstractXmlNodeModel()
{
- delete d_ptr;
}
/*!
@@ -1666,4 +1664,20 @@ void QAbstractXmlNodeModel::copyNodeTo(const QXmlNodeModelIndex &node,
"This function is not expected to be called.");
}
+/*!
+ Returns the source location for the object with the given \a index
+ or a default constructed QSourceLocation in case no location
+ information is available.
+
+ \since 4.6
+*/
+QSourceLocation QAbstractXmlNodeModel::sourceLocation(const QXmlNodeModelIndex &index) const
+{
+ // TODO: make this method virtual in Qt5 to allow source location support in custom models
+ if (d_ptr)
+ return d_ptr->sourceLocation(index);
+ else
+ return QSourceLocation();
+}
+
QT_END_NAMESPACE
diff --git a/src/xmlpatterns/api/qabstractxmlnodemodel.h b/src/xmlpatterns/api/qabstractxmlnodemodel.h
index 0ee4ac5e56..f02f1ea733 100644
--- a/src/xmlpatterns/api/qabstractxmlnodemodel.h
+++ b/src/xmlpatterns/api/qabstractxmlnodemodel.h
@@ -44,6 +44,7 @@
#include <QtXmlPatterns/QXmlName>
#include <QtCore/QSharedData>
+#include <QtCore/QScopedPointer>
QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
@@ -56,6 +57,7 @@ QT_MODULE(XmlPatterns)
class QAbstractXmlNodeModel;
class QAbstractXmlNodeModelPrivate;
class QAbstractXmlReceiver;
+class QSourceLocation;
class QUrl;
class QXmlName;
class QXmlNodeModelIndex;
@@ -69,6 +71,7 @@ namespace QPatternist
class DynamicContext;
class Item;
class ItemType;
+ class XsdValidatedXmlNodeModel;
template<typename TResult, typename TSource, typename TMapper, typename Context> class ItemMappingIterator;
template<typename TResult, typename TSource, typename TMapper> class SequenceMappingIterator;
typedef QExplicitlySharedDataPointer<ItemType> ItemTypePtr;
@@ -315,6 +318,8 @@ public:
QAbstractXmlReceiver *const receiver,
const NodeCopySettings &) const;
+ QSourceLocation sourceLocation(const QXmlNodeModelIndex &index) const;
+
protected:
virtual QXmlNodeModelIndex nextFromSimpleAxis(SimpleAxis axis, const QXmlNodeModelIndex &origin) const = 0;
@@ -339,10 +344,11 @@ protected:
return QXmlNodeModelIndex::create(data, this, additionalData);
}
- QAbstractXmlNodeModelPrivate *d_ptr;
+ QScopedPointer<QAbstractXmlNodeModelPrivate> d_ptr;
private:
friend class QPatternist::ItemMappingIterator<QXmlNodeModelIndex, QXmlNodeModelIndex, const QAbstractXmlNodeModel *, QExplicitlySharedDataPointer<QPatternist::DynamicContext> >;
friend class QPatternist::SequenceMappingIterator<QXmlNodeModelIndex, QXmlNodeModelIndex, const QAbstractXmlNodeModel *>;
+ friend class QPatternist::XsdValidatedXmlNodeModel;
inline QExplicitlySharedDataPointer<QAbstractXmlForwardIterator<QXmlNodeModelIndex> > mapToSequence(const QXmlNodeModelIndex &ni,
const QExplicitlySharedDataPointer<QPatternist::DynamicContext> &) const;
diff --git a/src/xmlpatterns/api/qabstractxmlnodemodel_p.h b/src/xmlpatterns/api/qabstractxmlnodemodel_p.h
index 11e16923e5..4640781cf3 100644
--- a/src/xmlpatterns/api/qabstractxmlnodemodel_p.h
+++ b/src/xmlpatterns/api/qabstractxmlnodemodel_p.h
@@ -52,6 +52,9 @@
#ifndef QABSTRACTXMLNODEMODEL_P_H
#define QABSTRACTXMLNODEMODEL_P_H
+#include "qabstractxmlnodemodel.h"
+#include "qsourcelocation.h"
+
QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
@@ -62,6 +65,13 @@ public:
virtual ~QAbstractXmlNodeModelPrivate()
{
}
+
+ virtual QSourceLocation sourceLocation(const QXmlNodeModelIndex &index) const
+ {
+ Q_UNUSED(index);
+
+ return QSourceLocation();
+ }
};
QT_END_NAMESPACE
diff --git a/src/xmlpatterns/api/qabstractxmlpullprovider.cpp b/src/xmlpatterns/api/qabstractxmlpullprovider.cpp
new file mode 100644
index 0000000000..87716f9791
--- /dev/null
+++ b/src/xmlpatterns/api/qabstractxmlpullprovider.cpp
@@ -0,0 +1,177 @@
+/****************************************************************************
+**
+** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://qt.nokia.com/contact.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QHash>
+
+#include "qxmlname.h"
+#include "qnamepool_p.h"
+#include "qabstractxmlpullprovider_p.h"
+
+QT_BEGIN_NAMESPACE
+
+using namespace QPatternist;
+
+// TODO have example where query selects, and the events for the result are indented
+
+/*!
+ \internal
+ \class AbstractXmlPullProvider
+ \brief The AbstractXmlPullProvider class provides a pull-based stream interface for the XPath Data Model.
+ \reentrant
+ \ingroup xml-tools
+
+ AbstractXmlPullProvider allows a stream of items from the XPath Data Model -- essentially XML --
+ to be iterated over. The subclass of AbstractXmlPullProvider provides the events, and the
+ user calling next() and so on, consumes them. AbstractXmlPullProvider can be considered
+ a forward-only, non-reversible iterator.
+
+ Note that the content the events describes, are not necessarily a well-formed XML document, but
+ rather an instance of the XPath Data model, to be specific. For instance, maybe a pull provider
+ returns two atomic values, followed by an element tree, and at the end two document nodes.
+
+ If you are subclassing AbstractXmlPullProvider, be careful to correctly implement
+ the behaviors, as described for the individual members and events.
+
+ \sa AbstractXmlPullProvider::Event
+ */
+
+/*!
+ \enum AbstractXmlPullProvider::Event
+ \value StartOfInput The value AbstractXmlPullProvider::current() returns before the first call to next().
+ \value AtomicValue an atomic value such as an \c xs:integer, \c xs:hexBinary, or \c xs:dateTime. Atomic values
+ can only be top level items.
+ \value StartDocument Signals the start of a document node. Note that a AbstractXmlPullProvider can provide
+ a sequence of document nodes.
+ \value EndDocument Signals the end of a document node. StartDocument and EndDocument are always balanced
+ and always top-level events. For instance, StartDocument can never appear after any StartElement
+ events that hasn't been balanced by the corresponding amount of EndElement events.
+ \value StartElement Signals an element start tag.
+ \value EndElement Signals the end of an element. StartElement and EndElement events are always balanced.
+ \value Text Signals a text node. Adjacent text nodes cannot occur.
+ \value ProcessingInstruction A processing instruction. Its name is returned from name(), and its value in stringValue().
+ \value Comment a comment node. Its value can be retrieved with stingValue().
+ \value Attribute Signals an attribute node. Attribute events can only appear after Namespace events, or
+ if no such are sent, after the StartElement. In addition they must appear sequentially,
+ and each name must be unique. The ordering of attribute events is undefined and insignificant.
+ \value Namespace Signals a namespace binding. They occur very infrequently and are not needed for attributes
+ and elements. Namespace events can only appear after the StartElement event. The
+ ordering of namespace events is undefined and insignificant.
+ \value EndOfInput When next() is called after the last event, EndOfInput is returned.
+
+ \sa AbstractXmlPullProvider::current()
+ */
+
+/*!
+ Constucts a AbstractXmlPullProvider instance.
+ */
+AbstractXmlPullProvider::AbstractXmlPullProvider()
+{
+}
+
+/*!
+ Destructs this AbstractXmlPullProvider.
+ */
+AbstractXmlPullProvider::~AbstractXmlPullProvider()
+{
+}
+
+/*!
+ \fn Event AbstractXmlPullProvider::next() = 0;
+ Advances this AbstractXmlPullProvider, and returns the new event.
+
+ \sa current()
+ */
+
+/*!
+ \fn Event AbstractXmlPullProvider::current() const = 0;
+ Returns the event that next() returned the last time it was called. It doesn't
+ alter this AbstractXmlPullProvider.
+
+ current() may not modify this AbstractXmlPullProvider's state. Subsequent calls to current()
+ must return the same value.
+
+ \sa AbstractXmlPullProvider::Event
+ */
+
+/*!
+ \fn QName AbstractXmlPullProvider::name() const = 0;
+ If the current event is StartElement,
+ EndElement, ProcessingInstruction, Attribute, or Namespace, the node's name is returned.
+
+ If the current event is ProcessingInstruction,
+ the processing instruction target is in in the local name.
+
+ If the current event is Namespace, the name's namespace URI is the namespace, and
+ the local name is the prefix the name is binding to.
+
+ In all other cases, an invalid QName is returned.
+ */
+
+/*!
+ \fn QVariant AbstractXmlPullProvider::atomicValue() const = 0;
+
+ If current() event is AtomicValue, the atomic value is returned as a QVariant.
+ In all other cases, this function returns a null QVariant.
+ */
+
+/*!
+ \fn QString AbstractXmlPullProvider::stringValue() const = 0;
+
+ If current() is Text, the text node's value is returned.
+
+ If the current() event is Comment, its value is returned. The subclasser guarantees
+ it does not contain the string "-->".
+
+ If the current() event is ProcessingInstruction, its data is returned. The subclasser
+ guarantees the data does not contain the string "?>".
+
+ In other cases, it returns a default constructed string.
+ */
+
+/*!
+ \fn QHash<QXmlName, QString> AbstractXmlPullProvider::attributes() = 0;
+
+ If the current() is Element, the attributes of the element are returned,
+ an empty list of attributes otherwise.
+ */
+
+QT_END_NAMESPACE
+
diff --git a/src/xmlpatterns/api/qabstractxmlpullprovider_p.h b/src/xmlpatterns/api/qabstractxmlpullprovider_p.h
new file mode 100644
index 0000000000..f752483853
--- /dev/null
+++ b/src/xmlpatterns/api/qabstractxmlpullprovider_p.h
@@ -0,0 +1,113 @@
+/****************************************************************************
+**
+** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://qt.nokia.com/contact.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+
+#ifndef QABSTRACTXMLPULLPROVIDER_H
+#define QABSTRACTXMLPULLPROVIDER_H
+
+#include <QtCore/QtGlobal>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+class QXmlItem;
+class QXmlName;
+class QString;
+class QVariant;
+template<typename Key, typename Value> class QHash;
+
+namespace QPatternist
+{
+ class AbstractXmlPullProviderPrivate;
+
+ class AbstractXmlPullProvider
+ {
+ public:
+ AbstractXmlPullProvider();
+ virtual ~AbstractXmlPullProvider();
+
+ enum Event
+ {
+ StartOfInput = 1,
+ AtomicValue = 1 << 1,
+ StartDocument = 1 << 2,
+ EndDocument = 1 << 3,
+ StartElement = 1 << 4,
+ EndElement = 1 << 5,
+ Text = 1 << 6,
+ ProcessingInstruction = 1 << 7,
+ Comment = 1 << 8,
+ Attribute = 1 << 9,
+ Namespace = 1 << 10,
+ EndOfInput = 1 << 11
+ };
+
+ virtual Event next() = 0;
+ virtual Event current() const = 0;
+ virtual QXmlName name() const = 0;
+ virtual QVariant atomicValue() const = 0;
+ virtual QString stringValue() const = 0;
+
+ virtual QHash<QXmlName, QString> attributes() = 0;
+ virtual QHash<QXmlName, QXmlItem> attributeItems() = 0;
+
+ /* *** The functions below are internal. */
+ private:
+ Q_DISABLE_COPY(AbstractXmlPullProvider)
+ AbstractXmlPullProviderPrivate *d;
+ };
+}
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
diff --git a/src/xmlpatterns/api/qabstractxmlreceiver.cpp b/src/xmlpatterns/api/qabstractxmlreceiver.cpp
index 742a080a39..5ffc01ce77 100644
--- a/src/xmlpatterns/api/qabstractxmlreceiver.cpp
+++ b/src/xmlpatterns/api/qabstractxmlreceiver.cpp
@@ -224,7 +224,6 @@ QAbstractXmlReceiver::QAbstractXmlReceiver() : d_ptr(0)
*/
QAbstractXmlReceiver::~QAbstractXmlReceiver()
{
- delete d_ptr;
}
/*!
diff --git a/src/xmlpatterns/api/qabstractxmlreceiver.h b/src/xmlpatterns/api/qabstractxmlreceiver.h
index 95781bd5e3..a1ead34e3b 100644
--- a/src/xmlpatterns/api/qabstractxmlreceiver.h
+++ b/src/xmlpatterns/api/qabstractxmlreceiver.h
@@ -43,6 +43,7 @@
#define QABSTRACTXMLRECEIVER_H
#include <QtCore/QVariant>
+#include <QtCore/QScopedPointer>
#include <QtXmlPatterns/QXmlNodeModelIndex>
QT_BEGIN_HEADER
@@ -90,7 +91,7 @@ public:
protected:
QAbstractXmlReceiver(QAbstractXmlReceiverPrivate *d);
- QAbstractXmlReceiverPrivate *d_ptr;
+ QScopedPointer<QAbstractXmlReceiverPrivate> d_ptr;
void sendAsNode(const QPatternist::Item &outputItem);
private:
diff --git a/src/xmlpatterns/api/qpullbridge.cpp b/src/xmlpatterns/api/qpullbridge.cpp
new file mode 100644
index 0000000000..80973bbd1b
--- /dev/null
+++ b/src/xmlpatterns/api/qpullbridge.cpp
@@ -0,0 +1,232 @@
+/****************************************************************************
+**
+** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://qt.nokia.com/contact.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QVariant>
+
+#include "qabstractxmlnodemodel_p.h"
+#include "qitemmappingiterator_p.h"
+#include "qitem_p.h"
+#include "qxmlname.h"
+#include "qxmlquery_p.h"
+
+#include "qpullbridge_p.h"
+
+QT_BEGIN_NAMESPACE
+
+using namespace QPatternist;
+
+/*!
+ \brief Bridges a QPatternist::SequenceIterator to QAbstractXmlPullProvider.
+ \class QPatternist::PullBridge
+ \internal
+ \reentrant
+ \ingroup xml-tools
+
+ The approach of this class is rather straight forward since QPatternist::SequenceIterator
+ and QAbstractXmlPullProvider are conceptually similar. While QPatternist::SequenceIterator only
+ delivers top level items(since it's not an event stream, it's a list of items), PullBridge
+ needs to recursively iterate the children of nodes too, which is achieved through the
+ stack m_iterators.
+ */
+
+AbstractXmlPullProvider::Event PullBridge::next()
+{
+ m_index = m_iterators.top().second->next();
+
+ if(!m_index.isNull())
+ {
+ Item item(m_index);
+
+ if(item && item.isAtomicValue())
+ m_current = AtomicValue;
+ else
+ {
+ Q_ASSERT(item.isNode());
+
+ switch(m_index.kind())
+ {
+ case QXmlNodeModelIndex::Attribute:
+ {
+ m_current = Attribute;
+ break;
+ }
+ case QXmlNodeModelIndex::Comment:
+ {
+ m_current = Comment;
+ break;
+ }
+ case QXmlNodeModelIndex::Element:
+ {
+ m_iterators.push(qMakePair(StartElement, m_index.iterate(QXmlNodeModelIndex::AxisChild)));
+ m_current = StartElement;
+ break;
+ }
+ case QXmlNodeModelIndex::Document:
+ {
+ m_iterators.push(qMakePair(StartDocument, m_index.iterate(QXmlNodeModelIndex::AxisChild)));
+ m_current = StartDocument;
+ break;
+ }
+ case QXmlNodeModelIndex::Namespace:
+ {
+ m_current = Namespace;
+ break;
+ }
+ case QXmlNodeModelIndex::ProcessingInstruction:
+ {
+ m_current = ProcessingInstruction;
+ break;
+ }
+ case QXmlNodeModelIndex::Text:
+ {
+ m_current = Text;
+ break;
+ }
+ }
+ }
+ }
+ else
+ {
+ if(m_iterators.isEmpty())
+ m_current = EndOfInput;
+ else
+ {
+ switch(m_iterators.top().first)
+ {
+ case StartOfInput:
+ {
+ m_current = EndOfInput;
+ break;
+ }
+ case StartElement:
+ {
+ m_current = EndElement;
+ m_iterators.pop();
+ break;
+ }
+ case StartDocument:
+ {
+ m_current = EndDocument;
+ m_iterators.pop();
+ break;
+ }
+ default:
+ {
+ Q_ASSERT_X(false, Q_FUNC_INFO,
+ "Invalid value.");
+ m_current = EndOfInput;
+ }
+ }
+ }
+
+ }
+
+ return m_current;
+}
+
+AbstractXmlPullProvider::Event PullBridge::current() const
+{
+ return m_current;
+}
+
+QXmlNodeModelIndex PullBridge::index() const
+{
+ return m_index;
+}
+
+QSourceLocation PullBridge::sourceLocation() const
+{
+ return m_index.model()->sourceLocation(m_index);
+}
+
+QXmlName PullBridge::name() const
+{
+ return m_index.name();
+}
+
+QVariant PullBridge::atomicValue() const
+{
+ return QVariant();
+}
+
+QString PullBridge::stringValue() const
+{
+ return QString();
+}
+
+QHash<QXmlName, QString> PullBridge::attributes()
+{
+ Q_ASSERT(m_current == StartElement);
+
+ QHash<QXmlName, QString> attributes;
+
+ QXmlNodeModelIndex::Iterator::Ptr it = m_index.iterate(QXmlNodeModelIndex::AxisAttribute);
+ QXmlNodeModelIndex index = it->next();
+ while (!index.isNull()) {
+ const Item attribute(index);
+ attributes.insert(index.name(), index.stringValue());
+
+ index = it->next();
+ }
+
+ return attributes;
+}
+
+QHash<QXmlName, QXmlItem> PullBridge::attributeItems()
+{
+ Q_ASSERT(m_current == StartElement);
+
+ QHash<QXmlName, QXmlItem> attributes;
+
+ QXmlNodeModelIndex::Iterator::Ptr it = m_index.iterate(QXmlNodeModelIndex::AxisAttribute);
+ QXmlNodeModelIndex index = it->next();
+ while (!index.isNull()) {
+ const Item attribute(index);
+ attributes.insert(index.name(), QXmlItem(index));
+
+ index = it->next();
+ }
+
+ return attributes;
+}
+
+QT_END_NAMESPACE
+
diff --git a/src/xmlpatterns/api/qpullbridge_p.h b/src/xmlpatterns/api/qpullbridge_p.h
new file mode 100644
index 0000000000..2243f3beea
--- /dev/null
+++ b/src/xmlpatterns/api/qpullbridge_p.h
@@ -0,0 +1,103 @@
+/****************************************************************************
+**
+** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://qt.nokia.com/contact.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+
+#ifndef PATTERNIST_PULLBRIDGE_P_H
+#define PATTERNIST_PULLBRIDGE_P_H
+
+#include <QtCore/QPair>
+#include <QtCore/QStack>
+
+#include "qabstractxmlforwarditerator_p.h"
+#include "qabstractxmlpullprovider_p.h"
+#include "qitem_p.h"
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+namespace QPatternist
+{
+ class PullBridge : public AbstractXmlPullProvider
+ {
+ public:
+ inline PullBridge(const QXmlNodeModelIndex::Iterator::Ptr &it) : m_current(StartOfInput)
+ {
+ Q_ASSERT(it);
+ m_iterators.push(qMakePair(StartOfInput, it));
+ }
+
+ virtual Event next();
+ virtual Event current() const;
+ virtual QXmlName name() const;
+ /**
+ * Returns always an empty QVariant.
+ */
+ virtual QVariant atomicValue() const;
+ virtual QString stringValue() const;
+ virtual QHash<QXmlName, QString> attributes();
+ virtual QHash<QXmlName, QXmlItem> attributeItems();
+
+ QXmlNodeModelIndex index() const;
+ QSourceLocation sourceLocation() const;
+
+ private:
+ typedef QStack<QPair<Event, QXmlNodeModelIndex::Iterator::Ptr> > IteratorStack;
+ IteratorStack m_iterators;
+ QXmlNodeModelIndex m_index;
+ Event m_current;
+ };
+}
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
diff --git a/src/xmlpatterns/api/qresourcedelegator.cpp b/src/xmlpatterns/api/qresourcedelegator.cpp
index 8f269fd27f..36d9c21b43 100644
--- a/src/xmlpatterns/api/qresourcedelegator.cpp
+++ b/src/xmlpatterns/api/qresourcedelegator.cpp
@@ -45,14 +45,6 @@ QT_BEGIN_NAMESPACE
using namespace QPatternist;
-/**
- * Duplicated in qacceltreeresourceloader.cpp.
- */
-static inline uint qHash(const QUrl &uri)
-{
- return qHash(uri.toString());
-}
-
bool ResourceDelegator::isUnparsedTextAvailable(const QUrl &uri,
const QString &encoding)
{
diff --git a/src/xmlpatterns/api/qsourcelocation.cpp b/src/xmlpatterns/api/qsourcelocation.cpp
index 137f886f59..ba3872620a 100644
--- a/src/xmlpatterns/api/qsourcelocation.cpp
+++ b/src/xmlpatterns/api/qsourcelocation.cpp
@@ -206,7 +206,7 @@ QDebug operator<<(QDebug debug, const QSourceLocation &sourceLocation)
<< sourceLocation.line()
<< ", column:"
<< sourceLocation.column()
- << ")";
+ << ')';
return debug;
}
#endif
diff --git a/src/xmlpatterns/api/qxmlnamepool.cpp b/src/xmlpatterns/api/qxmlnamepool.cpp
index 510f74aeac..0c099c114e 100644
--- a/src/xmlpatterns/api/qxmlnamepool.cpp
+++ b/src/xmlpatterns/api/qxmlnamepool.cpp
@@ -96,6 +96,10 @@ QXmlNamePool::~QXmlNamePool()
{
}
+QXmlNamePool::QXmlNamePool(QPatternist::NamePool *namePool) : d(QExplicitlySharedDataPointer<QPatternist::NamePool>(namePool))
+{
+}
+
/*!
Assigns the \a other name pool to this one.
*/
diff --git a/src/xmlpatterns/api/qxmlnamepool.h b/src/xmlpatterns/api/qxmlnamepool.h
index ca9d218e64..08481c88b6 100644
--- a/src/xmlpatterns/api/qxmlnamepool.h
+++ b/src/xmlpatterns/api/qxmlnamepool.h
@@ -54,6 +54,8 @@ QT_MODULE(XmlPatterns)
namespace QPatternist
{
class NamePool;
+ class XsdSchemaParser;
+ class XsdValidatingInstanceReader;
}
namespace QPatternistSDK
@@ -73,10 +75,15 @@ public:
QXmlNamePool &operator=(const QXmlNamePool &other);
private:
+ QXmlNamePool(QPatternist::NamePool *namePool);
friend class QXmlQueryPrivate;
friend class QXmlQuery;
+ friend class QXmlSchemaPrivate;
+ friend class QXmlSchemaValidatorPrivate;
friend class QXmlSerializerPrivate;
friend class QXmlName;
+ friend class QPatternist::XsdSchemaParser;
+ friend class QPatternist::XsdValidatingInstanceReader;
friend class QPatternistSDK::Global;
QExplicitlySharedDataPointer<QPatternist::NamePool> d;
};
diff --git a/src/xmlpatterns/api/qxmlquery.cpp b/src/xmlpatterns/api/qxmlquery.cpp
index cfd6070bcf..9f9b136656 100644
--- a/src/xmlpatterns/api/qxmlquery.cpp
+++ b/src/xmlpatterns/api/qxmlquery.cpp
@@ -151,7 +151,7 @@ QT_BEGIN_NAMESPACE
\endcode
\note For the current release, XSLT support should be considered
- experimental. See section \l{QtXmlPatterns Module#XSLT
+ experimental. See section \l{Using XML technologies#XSLT
2.0}{XSLT conformance} for details.
Stylesheet parameters are bound using bindVariable().
@@ -231,6 +231,18 @@ QT_BEGIN_NAMESPACE
\value XQuery10 XQuery 1.0.
\value XSLT20 XSLT 2.0
+ \omitvalue XmlSchema11IdentityConstraintSelector The selector, the restricted
+ XPath pattern found in W3C XML Schema 1.1 for uniqueness
+ contraints. Apart from restricting the syntax, the type check stage
+ for the expression assumes a sequence of nodes to be the focus.
+ \omitvalue XmlSchema11IdentityConstraintField The field, the restricted
+ XPath pattern found in W3C XML Schema 1.1 for uniqueness
+ contraints. Apart from restricting the syntax, the type check stage
+ for the expression assumes a sequence of nodes to be the focus.
+ \omitvalue XPath20 Signifies XPath 2.0. Has no effect in the public API, it's
+ used internally. As With XmlSchema11IdentityConstraintSelector and
+ XmlSchema11IdentityConstraintField, the type check stage
+ for the expression assumes a sequence of nodes to be the focus.
\sa setQuery()
*/
@@ -279,7 +291,7 @@ QXmlQuery::QXmlQuery(const QXmlNamePool &np) : d(new QXmlQueryPrivate(np))
create instances of QXmlQuery for running XQueries.
\note The XSL-T support in this release is considered experimental.
- See the \l{QtXmlPatterns Module#XSLT 2.0}{XSLT conformance} for
+ See the \l{Using XML technologies#XSLT 2.0}{XSLT conformance} for
details.
\since 4.5
@@ -415,7 +427,7 @@ void QXmlQuery::setQuery(QIODevice *sourceCode, const QUrl &documentURI)
return;
}
- d->queryURI = QXmlQueryPrivate::normalizeQueryURI(documentURI);
+ d->queryURI = QPatternist::XPathHelper::normalizeQueryURI(documentURI);
d->expression(sourceCode);
}
@@ -463,12 +475,12 @@ void QXmlQuery::setQuery(const QUrl &queryURI, const QUrl &baseURI)
{
Q_ASSERT_X(queryURI.isValid(), Q_FUNC_INFO, "The passed URI must be valid.");
- const QUrl canonicalURI(QXmlQueryPrivate::normalizeQueryURI(queryURI));
+ const QUrl canonicalURI(QPatternist::XPathHelper::normalizeQueryURI(queryURI));
Q_ASSERT(canonicalURI.isValid());
Q_ASSERT(!canonicalURI.isRelative());
Q_ASSERT(baseURI.isValid() || baseURI.isEmpty());
- d->queryURI = QXmlQueryPrivate::normalizeQueryURI(baseURI.isEmpty() ? queryURI : baseURI);
+ d->queryURI = QPatternist::XPathHelper::normalizeQueryURI(baseURI.isEmpty() ? queryURI : baseURI);
QPatternist::AutoPtr<QIODevice> result;
@@ -1039,6 +1051,25 @@ bool QXmlQuery::setFocus(QIODevice *document)
}
/*!
+ This function behaves identically to calling the setFocus() overload with a
+ QIODevice whose content is \a focus encoded as UTF-8. That is, \a focus is
+ treated as if it contained an XML document.
+
+ Returns the same result as the overload.
+
+ \overload
+ \since 4.6
+ */
+bool QXmlQuery::setFocus(const QString &focus)
+{
+ QBuffer device;
+ device.setData(focus.toUtf8());
+ device.open(QIODevice::ReadOnly);
+
+ return setFocusHelper(this, &device);
+}
+
+/*!
Returns a value indicating what this QXmlQuery is being used for.
The default is QXmlQuery::XQuery10, which means the QXmlQuery is
being used for running XQuery and XPath queries. QXmlQuery::XSLT20
diff --git a/src/xmlpatterns/api/qxmlquery.h b/src/xmlpatterns/api/qxmlquery.h
index 4491effb7d..c4f1eca8b3 100644
--- a/src/xmlpatterns/api/qxmlquery.h
+++ b/src/xmlpatterns/api/qxmlquery.h
@@ -71,6 +71,8 @@ namespace QPatternistSDK
namespace QPatternist
{
+ class XsdSchemaParser;
+ class XsdValidatingInstanceReader;
class VariableLoader;
};
@@ -79,8 +81,11 @@ class Q_XMLPATTERNS_EXPORT QXmlQuery
public:
enum QueryLanguage
{
- XQuery10 = 1,
- XSLT20 = 2
+ XQuery10 = 1,
+ XSLT20 = 2,
+ XmlSchema11IdentityConstraintSelector = 1024,
+ XmlSchema11IdentityConstraintField = 2048,
+ XPath20 = 4096
};
QXmlQuery();
@@ -122,6 +127,7 @@ public:
void setFocus(const QXmlItem &item);
bool setFocus(const QUrl &documentURI);
bool setFocus(QIODevice *document);
+ bool setFocus(const QString &focus);
void setInitialTemplateName(const QXmlName &name);
void setInitialTemplateName(const QString &name);
@@ -135,6 +141,8 @@ private:
friend class QXmlName;
friend class QXmlSerializer;
friend class QPatternistSDK::TestCase;
+ friend class QPatternist::XsdSchemaParser;
+ friend class QPatternist::XsdValidatingInstanceReader;
friend class QPatternist::VariableLoader;
template<typename TInputType> friend bool setFocusHelper(QXmlQuery *const queryInstance,
const TInputType &focusValue);
diff --git a/src/xmlpatterns/api/qxmlquery_p.h b/src/xmlpatterns/api/qxmlquery_p.h
index f39b9e3f58..b8a759400d 100644
--- a/src/xmlpatterns/api/qxmlquery_p.h
+++ b/src/xmlpatterns/api/qxmlquery_p.h
@@ -142,13 +142,10 @@ public:
if(!m_functionFactory)
{
- if(queryLanguage == QXmlQuery::XQuery10)
- m_functionFactory = QPatternist::FunctionFactoryCollection::xpath20Factory(namePool.d);
- else
- {
- Q_ASSERT(queryLanguage == QXmlQuery::XSLT20);
+ if(queryLanguage == QXmlQuery::XSLT20)
m_functionFactory = QPatternist::FunctionFactoryCollection::xslt20Factory(namePool.d);
- }
+ else
+ m_functionFactory = QPatternist::FunctionFactoryCollection::xpath20Factory(namePool.d);
}
const QPatternist::GenericStaticContext::Ptr genericStaticContext(new QPatternist::GenericStaticContext(namePool.d,
@@ -164,6 +161,14 @@ public:
if(!contextItem.isNull())
m_staticContext = QPatternist::StaticContext::Ptr(new QPatternist::StaticFocusContext(QPatternist::AtomicValue::qtToXDMType(contextItem), m_staticContext));
+ else if( queryLanguage == QXmlQuery::XmlSchema11IdentityConstraintField
+ || queryLanguage == QXmlQuery::XmlSchema11IdentityConstraintSelector
+ || queryLanguage == QXmlQuery::XPath20)
+ m_staticContext = QPatternist::StaticContext::Ptr(new QPatternist::StaticFocusContext(QPatternist::BuiltinTypes::node, m_staticContext));
+
+ for (int i = 0; i < m_additionalNamespaceBindings.count(); ++i) {
+ m_staticContext->namespaceBindings()->addBinding(m_additionalNamespaceBindings.at(i));
+ }
return m_staticContext;
}
@@ -207,19 +212,6 @@ public:
return m_resourceLoader;
}
-
- static inline QUrl normalizeQueryURI(const QUrl &uri)
- {
- Q_ASSERT_X(uri.isEmpty() || uri.isValid(), Q_FUNC_INFO,
- "The URI passed to QXmlQuery::setQuery() must be valid or empty.");
- if(uri.isEmpty())
- return QUrl::fromLocalFile(QCoreApplication::applicationFilePath());
- else if(uri.isRelative())
- return QUrl::fromLocalFile(QCoreApplication::applicationFilePath()).resolved(uri);
- else
- return uri;
- }
-
void setRequiredType(const QPatternist::SequenceType::Ptr &seqType)
{
Q_ASSERT(seqType);
@@ -278,6 +270,11 @@ public:
return m_expr;
}
+ inline void addAdditionalNamespaceBinding(const QXmlName &binding)
+ {
+ m_additionalNamespaceBindings.append(binding);
+ }
+
QXmlNamePool namePool;
QPointer<QAbstractMessageHandler> messageHandler;
/**
@@ -321,6 +318,8 @@ public:
QPatternist::SequenceType::Ptr m_requiredType;
QPatternist::FunctionFactory::Ptr m_functionFactory;
QPatternist::NetworkAccessDelegator::Ptr m_networkAccessDelegator;
+
+ QList<QXmlName> m_additionalNamespaceBindings;
};
QT_END_NAMESPACE
diff --git a/src/xmlpatterns/api/qxmlresultitems.cpp b/src/xmlpatterns/api/qxmlresultitems.cpp
index 71d3724261..f6d2f5f23b 100644
--- a/src/xmlpatterns/api/qxmlresultitems.cpp
+++ b/src/xmlpatterns/api/qxmlresultitems.cpp
@@ -85,7 +85,6 @@ QXmlResultItems::QXmlResultItems() : d_ptr(new QXmlResultItemsPrivate())
*/
QXmlResultItems::~QXmlResultItems()
{
- delete d_ptr;
}
/*!
diff --git a/src/xmlpatterns/api/qxmlresultitems.h b/src/xmlpatterns/api/qxmlresultitems.h
index cd4c5a4907..7f1e4c053a 100644
--- a/src/xmlpatterns/api/qxmlresultitems.h
+++ b/src/xmlpatterns/api/qxmlresultitems.h
@@ -43,6 +43,7 @@
#define QXMLRESULTITEMS
#include <QtCore/QString>
+#include <QtCore/QScopedPointer>
QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
@@ -66,7 +67,7 @@ public:
private:
friend class QXmlQuery;
Q_DECLARE_PRIVATE(QXmlResultItems)
- QXmlResultItemsPrivate *d_ptr;
+ QScopedPointer<QXmlResultItemsPrivate> d_ptr;
Q_DISABLE_COPY(QXmlResultItems)
};
diff --git a/src/xmlpatterns/api/qxmlschema.cpp b/src/xmlpatterns/api/qxmlschema.cpp
new file mode 100644
index 0000000000..91d8f3a99d
--- /dev/null
+++ b/src/xmlpatterns/api/qxmlschema.cpp
@@ -0,0 +1,299 @@
+/****************************************************************************
+**
+** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://qt.nokia.com/contact.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qxmlschema.h"
+#include "qxmlschema_p.h"
+
+#include <QtCore/QIODevice>
+#include <QtCore/QUrl>
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \class QXmlSchema
+
+ \brief The QXmlSchema class provides loading and validation of a W3C XML Schema.
+
+ \reentrant
+ \since 4.6
+ \ingroup xml-tools
+
+ The QXmlSchema class loads, compiles and validates W3C XML Schema files
+ that can be used further for validation of XML instance documents via
+ \l{QXmlSchemaValidator}.
+
+ The following example shows how to load a XML Schema file from the network
+ and test whether it is a valid schema document:
+
+ \snippet doc/src/snippets/qxmlschema/main.cpp 0
+
+ \sa QXmlSchemaValidator, {xmlpatterns/schema}{XML Schema Validation Example}
+*/
+
+/*!
+ Constructs an invalid, empty schema that cannot be used until
+ load() is called.
+ */
+QXmlSchema::QXmlSchema()
+ : d(new QXmlSchemaPrivate(QXmlNamePool()))
+{
+}
+
+/*!
+ Constructs a QXmlSchema that is a copy of \a other. The new
+ instance will share resources with the existing schema
+ to the extent possible.
+ */
+QXmlSchema::QXmlSchema(const QXmlSchema &other)
+ : d(other.d)
+{
+}
+
+/*!
+ Destroys this QXmlSchema.
+ */
+QXmlSchema::~QXmlSchema()
+{
+}
+
+/*!
+ Sets this QXmlSchema to a schema loaded from the \a source
+ URI.
+
+ If the schema \l {isValid()} {is invalid}, \c{false} is returned
+ and the behavior is undefined.
+
+ Example:
+
+ \snippet doc/src/snippets/qxmlschema/main.cpp 0
+
+ \sa isValid()
+ */
+bool QXmlSchema::load(const QUrl &source)
+{
+ d->load(source, QString());
+ return d->isValid();
+}
+
+/*!
+ Sets this QXmlSchema to a schema read from the \a source
+ device. The device must have been opened with at least
+ QIODevice::ReadOnly.
+
+ \a documentUri represents the schema obtained from the \a source
+ device. It is the base URI of the schema, that is used
+ internally to resolve relative URIs that appear in the schema, and
+ for message reporting.
+
+ If \a source is \c null or not readable, or if \a documentUri is not
+ a valid URI, behavior is undefined.
+
+ If the schema \l {isValid()} {is invalid}, \c{false} is returned
+ and the behavior is undefined.
+
+ Example:
+
+ \snippet doc/src/snippets/qxmlschema/main.cpp 1
+
+ \sa isValid()
+ */
+bool QXmlSchema::load(QIODevice *source, const QUrl &documentUri)
+{
+ d->load(source, documentUri, QString());
+ return d->isValid();
+}
+
+/*!
+ Sets this QXmlSchema to a schema read from the \a data
+
+ \a documentUri represents the schema obtained from the \a data.
+ It is the base URI of the schema, that is used internally to
+ resolve relative URIs that appear in the schema, and
+ for message reporting.
+
+ If \a documentUri is not a valid URI, behavior is undefined.
+ \sa isValid()
+
+ If the schema \l {isValid()} {is invalid}, \c{false} is returned
+ and the behavior is undefined.
+
+ Example:
+
+ \snippet doc/src/snippets/qxmlschema/main.cpp 2
+
+ \sa isValid()
+ */
+bool QXmlSchema::load(const QByteArray &data, const QUrl &documentUri)
+{
+ d->load(data, documentUri, QString());
+ return d->isValid();
+}
+
+/*!
+ Returns true if this schema is valid. Examples of invalid schemas
+ are ones that contain syntax errors or that do not conform the
+ W3C XML Schema specification.
+ */
+bool QXmlSchema::isValid() const
+{
+ return d->isValid();
+}
+
+/*!
+ Returns the name pool used by this QXmlSchema for constructing \l
+ {QXmlName} {names}. There is no setter for the name pool, because
+ mixing name pools causes errors due to name confusion.
+ */
+QXmlNamePool QXmlSchema::namePool() const
+{
+ return d->namePool();
+}
+
+/*!
+ Returns the document URI of the schema or an empty URI if no
+ schema has been set.
+ */
+QUrl QXmlSchema::documentUri() const
+{
+ return d->documentUri();
+}
+
+/*!
+ Changes the \l {QAbstractMessageHandler}{message handler} for this
+ QXmlSchema to \a handler. The schema sends all compile and
+ validation messages to this message handler. QXmlSchema does not take
+ ownership of \a handler.
+
+ Normally, the default message handler is sufficient. It writes
+ compile and validation messages to \e stderr. The default message
+ handler includes color codes if \e stderr can render colors.
+
+ When QXmlSchema calls QAbstractMessageHandler::message(),
+ the arguments are as follows:
+
+ \table
+ \header
+ \o message() argument
+ \o Semantics
+ \row
+ \o QtMsgType type
+ \o Only QtWarningMsg and QtFatalMsg are used. The former
+ identifies a warning, while the latter identifies an error.
+ \row
+ \o const QString & description
+ \o An XHTML document which is the actual message. It is translated
+ into the current language.
+ \row
+ \o const QUrl &identifier
+ \o Identifies the error with a URI, where the fragment is
+ the error code, and the rest of the URI is the error namespace.
+ \row
+ \o const QSourceLocation & sourceLocation
+ \o Identifies where the error occurred.
+ \endtable
+
+ */
+void QXmlSchema::setMessageHandler(QAbstractMessageHandler *handler)
+{
+ d->setMessageHandler(handler);
+}
+
+/*!
+ Returns the message handler that handles compile and validation
+ messages for this QXmlSchema.
+ */
+QAbstractMessageHandler *QXmlSchema::messageHandler() const
+{
+ return d->messageHandler();
+}
+
+/*!
+ Sets the URI resolver to \a resolver. QXmlSchema does not take
+ ownership of \a resolver.
+
+ \sa uriResolver()
+ */
+void QXmlSchema::setUriResolver(const QAbstractUriResolver *resolver)
+{
+ d->setUriResolver(resolver);
+}
+
+/*!
+ Returns the schema's URI resolver. If no URI resolver has been set,
+ QtXmlPatterns will use the URIs in schemas as they are.
+
+ The URI resolver provides a level of abstraction, or \e{polymorphic
+ URIs}. A resolver can rewrite \e{logical} URIs to physical ones, or
+ it can translate obsolete or invalid URIs to valid ones.
+
+ When QtXmlPatterns calls QAbstractUriResolver::resolve() the
+ absolute URI is the URI mandated by the schema specification, and the
+ relative URI is the URI specified by the user.
+
+ \sa setUriResolver()
+ */
+const QAbstractUriResolver *QXmlSchema::uriResolver() const
+{
+ return d->uriResolver();
+}
+
+/*!
+ Sets the network manager to \a manager.
+ QXmlSchema does not take ownership of \a manager.
+
+ \sa networkAccessManager()
+ */
+void QXmlSchema::setNetworkAccessManager(QNetworkAccessManager *manager)
+{
+ d->setNetworkAccessManager(manager);
+}
+
+/*!
+ Returns the network manager, or 0 if it has not been set.
+
+ \sa setNetworkAccessManager()
+ */
+QNetworkAccessManager *QXmlSchema::networkAccessManager() const
+{
+ return d->networkAccessManager();
+}
+
+QT_END_NAMESPACE
diff --git a/src/xmlpatterns/api/qxmlschema.h b/src/xmlpatterns/api/qxmlschema.h
new file mode 100644
index 0000000000..5ae151b8db
--- /dev/null
+++ b/src/xmlpatterns/api/qxmlschema.h
@@ -0,0 +1,97 @@
+/****************************************************************************
+**
+** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://qt.nokia.com/contact.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QXMLSCHEMA_H
+#define QXMLSCHEMA_H
+
+#include <QtCore/QSharedDataPointer>
+#include <QtCore/QUrl>
+#include <QtXmlPatterns/QXmlNamePool>
+
+QT_BEGIN_HEADER
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(XmlPatterns)
+
+class QAbstractMessageHandler;
+class QAbstractUriResolver;
+class QIODevice;
+class QNetworkAccessManager;
+class QUrl;
+class QXmlNamePool;
+class QXmlSchemaPrivate;
+
+class Q_XMLPATTERNS_EXPORT QXmlSchema
+{
+ friend class QXmlSchemaValidatorPrivate;
+
+ public:
+ QXmlSchema();
+ QXmlSchema(const QXmlSchema &other);
+ ~QXmlSchema();
+
+ bool load(const QUrl &source);
+ bool load(QIODevice *source, const QUrl &documentUri = QUrl());
+ bool load(const QByteArray &data, const QUrl &documentUri = QUrl());
+
+ bool isValid() const;
+
+ QXmlNamePool namePool() const;
+ QUrl documentUri() const;
+
+ void setMessageHandler(QAbstractMessageHandler *handler);
+ QAbstractMessageHandler *messageHandler() const;
+
+ void setUriResolver(const QAbstractUriResolver *resolver);
+ const QAbstractUriResolver *uriResolver() const;
+
+ void setNetworkAccessManager(QNetworkAccessManager *networkmanager);
+ QNetworkAccessManager *networkAccessManager() const;
+
+ private:
+ QSharedDataPointer<QXmlSchemaPrivate> d;
+};
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
diff --git a/src/xmlpatterns/api/qxmlschema_p.cpp b/src/xmlpatterns/api/qxmlschema_p.cpp
new file mode 100644
index 0000000000..eefd781157
--- /dev/null
+++ b/src/xmlpatterns/api/qxmlschema_p.cpp
@@ -0,0 +1,203 @@
+/****************************************************************************
+**
+** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://qt.nokia.com/contact.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qacceltreeresourceloader_p.h"
+#include "qxmlschema.h"
+#include "qxmlschema_p.h"
+
+#include <QtCore/QBuffer>
+#include <QtCore/QIODevice>
+#include <QtCore/QUrl>
+
+QT_BEGIN_NAMESPACE
+
+QXmlSchemaPrivate::QXmlSchemaPrivate(const QXmlNamePool &namePool)
+ : m_namePool(namePool)
+ , m_userMessageHandler(0)
+ , m_uriResolver(0)
+ , m_userNetworkAccessManager(0)
+ , m_schemaContext(new QPatternist::XsdSchemaContext(m_namePool.d))
+ , m_schemaParserContext(new QPatternist::XsdSchemaParserContext(m_namePool.d, m_schemaContext))
+ , m_schemaIsValid(false)
+{
+ m_networkAccessManager = new QPatternist::ReferenceCountedValue<QNetworkAccessManager>(new QNetworkAccessManager());
+ m_messageHandler = new QPatternist::ReferenceCountedValue<QAbstractMessageHandler>(new QPatternist::ColoringMessageHandler());
+}
+
+QXmlSchemaPrivate::QXmlSchemaPrivate(const QPatternist::XsdSchemaContext::Ptr &schemaContext)
+ : m_namePool(QXmlNamePool(schemaContext->namePool().data()))
+ , m_userMessageHandler(0)
+ , m_uriResolver(0)
+ , m_userNetworkAccessManager(0)
+ , m_schemaContext(schemaContext)
+ , m_schemaParserContext(new QPatternist::XsdSchemaParserContext(m_namePool.d, m_schemaContext))
+ , m_schemaIsValid(false)
+{
+ m_networkAccessManager = new QPatternist::ReferenceCountedValue<QNetworkAccessManager>(new QNetworkAccessManager());
+ m_messageHandler = new QPatternist::ReferenceCountedValue<QAbstractMessageHandler>(new QPatternist::ColoringMessageHandler());
+}
+
+QXmlSchemaPrivate::QXmlSchemaPrivate(const QXmlSchemaPrivate &other)
+ : QSharedData(other)
+{
+ m_namePool = other.m_namePool;
+ m_userMessageHandler = other.m_userMessageHandler;
+ m_uriResolver = other.m_uriResolver;
+ m_userNetworkAccessManager = other.m_userNetworkAccessManager;
+ m_messageHandler = other.m_messageHandler;
+ m_networkAccessManager = other.m_networkAccessManager;
+
+ m_schemaContext = other.m_schemaContext;
+ m_schemaParserContext = other.m_schemaParserContext;
+ m_schemaIsValid = other.m_schemaIsValid;
+ m_documentUri = other.m_documentUri;
+}
+
+void QXmlSchemaPrivate::load(const QUrl &source, const QString &targetNamespace)
+{
+ m_documentUri = QPatternist::XPathHelper::normalizeQueryURI(source);
+
+ m_schemaContext->setMessageHandler(messageHandler());
+ m_schemaContext->setUriResolver(uriResolver());
+ m_schemaContext->setNetworkAccessManager(networkAccessManager());
+
+ const QPatternist::AutoPtr<QNetworkReply> reply(QPatternist::AccelTreeResourceLoader::load(source, m_schemaContext->networkAccessManager(),
+ m_schemaContext, QPatternist::AccelTreeResourceLoader::ContinueOnError));
+ if (reply)
+ load(reply.data(), source, targetNamespace);
+}
+
+void QXmlSchemaPrivate::load(const QByteArray &data, const QUrl &documentUri, const QString &targetNamespace)
+{
+ QByteArray localData(data);
+
+ QBuffer buffer(&localData);
+ buffer.open(QIODevice::ReadOnly);
+
+ load(&buffer, documentUri, targetNamespace);
+}
+
+void QXmlSchemaPrivate::load(QIODevice *source, const QUrl &documentUri, const QString &targetNamespace)
+{
+ m_schemaParserContext = QPatternist::XsdSchemaParserContext::Ptr(new QPatternist::XsdSchemaParserContext(m_namePool.d, m_schemaContext));
+ m_schemaIsValid = false;
+
+ if (!source) {
+ qWarning("A null QIODevice pointer cannot be passed.");
+ return;
+ }
+
+ if (!source->isReadable()) {
+ qWarning("The device must be readable.");
+ return;
+ }
+
+ m_documentUri = QPatternist::XPathHelper::normalizeQueryURI(documentUri);
+ m_schemaContext->setMessageHandler(messageHandler());
+ m_schemaContext->setUriResolver(uriResolver());
+ m_schemaContext->setNetworkAccessManager(networkAccessManager());
+
+ QPatternist::XsdSchemaParser parser(m_schemaContext, m_schemaParserContext, source);
+ parser.setDocumentURI(documentUri);
+ parser.setTargetNamespace(targetNamespace);
+
+ try {
+ parser.parse();
+ m_schemaParserContext->resolver()->resolve();
+
+ m_schemaIsValid = true;
+ } catch (QPatternist::Exception exception) {
+ m_schemaIsValid = false;
+ }
+}
+
+bool QXmlSchemaPrivate::isValid() const
+{
+ return m_schemaIsValid;
+}
+
+QXmlNamePool QXmlSchemaPrivate::namePool() const
+{
+ return m_namePool;
+}
+
+QUrl QXmlSchemaPrivate::documentUri() const
+{
+ return m_documentUri;
+}
+
+void QXmlSchemaPrivate::setMessageHandler(QAbstractMessageHandler *handler)
+{
+ m_userMessageHandler = handler;
+}
+
+QAbstractMessageHandler *QXmlSchemaPrivate::messageHandler() const
+{
+ if (m_userMessageHandler)
+ return m_userMessageHandler;
+
+ return m_messageHandler.data()->value;
+}
+
+void QXmlSchemaPrivate::setUriResolver(const QAbstractUriResolver *resolver)
+{
+ m_uriResolver = resolver;
+}
+
+const QAbstractUriResolver *QXmlSchemaPrivate::uriResolver() const
+{
+ return m_uriResolver;
+}
+
+void QXmlSchemaPrivate::setNetworkAccessManager(QNetworkAccessManager *networkmanager)
+{
+ m_userNetworkAccessManager = networkmanager;
+}
+
+QNetworkAccessManager *QXmlSchemaPrivate::networkAccessManager() const
+{
+ if (m_userNetworkAccessManager)
+ return m_userNetworkAccessManager;
+
+ return m_networkAccessManager.data()->value;
+}
+
+QT_END_NAMESPACE
diff --git a/src/xmlpatterns/api/qxmlschema_p.h b/src/xmlpatterns/api/qxmlschema_p.h
new file mode 100644
index 0000000000..a34be08a4e
--- /dev/null
+++ b/src/xmlpatterns/api/qxmlschema_p.h
@@ -0,0 +1,109 @@
+/****************************************************************************
+**
+** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://qt.nokia.com/contact.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+
+#ifndef QXMLSCHEMA_P_H
+#define QXMLSCHEMA_P_H
+
+#include "qabstractmessagehandler.h"
+#include "qabstracturiresolver.h"
+#include "qautoptr_p.h"
+#include "qcoloringmessagehandler_p.h"
+#include "qreferencecountedvalue_p.h"
+
+#include "qxsdschemacontext_p.h"
+#include "qxsdschemaparser_p.h"
+#include "qxsdschemaparsercontext_p.h"
+
+#include <QtCore/QSharedData>
+#include <QtNetwork/QNetworkAccessManager>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+class QXmlSchemaPrivate : public QSharedData
+{
+ public:
+ QXmlSchemaPrivate(const QXmlNamePool &namePool);
+ QXmlSchemaPrivate(const QPatternist::XsdSchemaContext::Ptr &schemaContext);
+ QXmlSchemaPrivate(const QXmlSchemaPrivate &other);
+
+ void load(const QUrl &source, const QString &targetNamespace);
+ void load(QIODevice *source, const QUrl &documentUri, const QString &targetNamespace);
+ void load(const QByteArray &data, const QUrl &documentUri, const QString &targetNamespace);
+ bool isValid() const;
+ QXmlNamePool namePool() const;
+ QUrl documentUri() const;
+ void setMessageHandler(QAbstractMessageHandler *handler);
+ QAbstractMessageHandler *messageHandler() const;
+ void setUriResolver(const QAbstractUriResolver *resolver);
+ const QAbstractUriResolver *uriResolver() const;
+ void setNetworkAccessManager(QNetworkAccessManager *networkmanager);
+ QNetworkAccessManager *networkAccessManager() const;
+
+ QXmlNamePool m_namePool;
+ QAbstractMessageHandler* m_userMessageHandler;
+ const QAbstractUriResolver* m_uriResolver;
+ QNetworkAccessManager* m_userNetworkAccessManager;
+ QPatternist::ReferenceCountedValue<QAbstractMessageHandler>::Ptr m_messageHandler;
+ QPatternist::ReferenceCountedValue<QNetworkAccessManager>::Ptr m_networkAccessManager;
+
+ QPatternist::XsdSchemaContext::Ptr m_schemaContext;
+ QPatternist::XsdSchemaParserContext::Ptr m_schemaParserContext;
+ bool m_schemaIsValid;
+ QUrl m_documentUri;
+};
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
diff --git a/src/xmlpatterns/api/qxmlschemavalidator.cpp b/src/xmlpatterns/api/qxmlschemavalidator.cpp
new file mode 100644
index 0000000000..26809d97b4
--- /dev/null
+++ b/src/xmlpatterns/api/qxmlschemavalidator.cpp
@@ -0,0 +1,344 @@
+/****************************************************************************
+**
+** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://qt.nokia.com/contact.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qxmlschemavalidator.h"
+#include "qxmlschemavalidator_p.h"
+
+#include "qacceltreeresourceloader_p.h"
+#include "qxmlschema.h"
+#include "qxmlschema_p.h"
+#include "qxsdvalidatinginstancereader_p.h"
+
+#include <QtCore/QBuffer>
+#include <QtCore/QIODevice>
+#include <QtCore/QUrl>
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \class QXmlSchemaValidator
+
+ \brief The QXmlSchemaValidator class validates XML instance documents against a W3C XML Schema.
+
+ \reentrant
+ \since 4.6
+ \ingroup xml-tools
+
+ The QXmlSchemaValidator class loads, parses an XML instance document and validates it
+ against a W3C XML Schema that has been compiled with \l{QXmlSchema}.
+
+ The following example shows how to load a XML Schema from a local
+ file, check whether it is a valid schema document and use it for validation
+ of an XML instance document:
+
+ \snippet doc/src/snippets/qxmlschemavalidator/main.cpp 3
+
+ \sa QXmlSchema, {xmlpatterns/schema}{XML Schema Validation Example}
+*/
+
+/*!
+ Constructs a schema validator.
+ The schema used for validation must be referenced in the XML instance document
+ via the \c xsi:schemaLocation or \c xsi:noNamespaceSchemaLocation attribute.
+ */
+QXmlSchemaValidator::QXmlSchemaValidator()
+ : d(new QXmlSchemaValidatorPrivate(QXmlSchema()))
+{
+}
+
+/*!
+ Constructs a schema validator that will use \a schema for validation.
+ If an empty \l {QXmlSchema} schema is passed to the validator, the schema used
+ for validation must be referenced in the XML instance document
+ via the \c xsi:schemaLocation or \c xsi:noNamespaceSchemaLocation attribute.
+ */
+QXmlSchemaValidator::QXmlSchemaValidator(const QXmlSchema &schema)
+ : d(new QXmlSchemaValidatorPrivate(schema))
+{
+}
+
+/*!
+ Destroys this QXmlSchemaValidator.
+ */
+QXmlSchemaValidator::~QXmlSchemaValidator()
+{
+ delete d;
+}
+
+/*!
+ Sets the \a schema that shall be used for further validation.
+ If the schema is empty, the schema used for validation must be referenced
+ in the XML instance document via the \c xsi:schemaLocation or
+ \c xsi:noNamespaceSchemaLocation attribute.
+ */
+void QXmlSchemaValidator::setSchema(const QXmlSchema &schema)
+{
+ d->setSchema(schema);
+}
+
+/*!
+ Validates the XML instance document read from \a data with the
+ given \a documentUri against the schema.
+
+ Returns \c true if the XML instance document is valid according to the
+ schema, \c false otherwise.
+
+ Example:
+
+ \snippet doc/src/snippets/qxmlschemavalidator/main.cpp 2
+ */
+bool QXmlSchemaValidator::validate(const QByteArray &data, const QUrl &documentUri) const
+{
+ QByteArray localData(data);
+
+ QBuffer buffer(&localData);
+ buffer.open(QIODevice::ReadOnly);
+
+ return validate(&buffer, documentUri);
+}
+
+/*!
+ Validates the XML instance document read from \a source against the schema.
+
+ Returns \c true if the XML instance document is valid according to the
+ schema, \c false otherwise.
+
+ Example:
+
+ \snippet doc/src/snippets/qxmlschemavalidator/main.cpp 0
+ */
+bool QXmlSchemaValidator::validate(const QUrl &source) const
+{
+ d->m_context->setMessageHandler(messageHandler());
+ d->m_context->setUriResolver(uriResolver());
+ d->m_context->setNetworkAccessManager(networkAccessManager());
+
+ const QPatternist::AutoPtr<QNetworkReply> reply(QPatternist::AccelTreeResourceLoader::load(source, d->m_context->networkAccessManager(),
+ d->m_context, QPatternist::AccelTreeResourceLoader::ContinueOnError));
+ if (reply)
+ return validate(reply.data(), source);
+ else
+ return false;
+}
+
+/*!
+ Validates the XML instance document read from \a source with the
+ given \a documentUri against the schema.
+
+ Returns \c true if the XML instance document is valid according to the
+ schema, \c false otherwise.
+
+ Example:
+
+ \snippet doc/src/snippets/qxmlschemavalidator/main.cpp 1
+ */
+bool QXmlSchemaValidator::validate(QIODevice *source, const QUrl &documentUri) const
+{
+ if (!source) {
+ qWarning("A null QIODevice pointer cannot be passed.");
+ return false;
+ }
+
+ if (!source->isReadable()) {
+ qWarning("The device must be readable.");
+ return false;
+ }
+
+ const QUrl normalizedUri = QPatternist::XPathHelper::normalizeQueryURI(documentUri);
+
+ d->m_context->setMessageHandler(messageHandler());
+ d->m_context->setUriResolver(uriResolver());
+ d->m_context->setNetworkAccessManager(networkAccessManager());
+
+ QPatternist::NetworkAccessDelegator::Ptr delegator(new QPatternist::NetworkAccessDelegator(d->m_context->networkAccessManager(),
+ d->m_context->networkAccessManager()));
+
+ QPatternist::AccelTreeResourceLoader loader(d->m_context->namePool(), delegator, QPatternist::AccelTreeBuilder<true>::SourceLocationsFeature);
+
+ QPatternist::Item item;
+ try {
+ item = loader.openDocument(source, normalizedUri, d->m_context);
+ } catch (QPatternist::Exception exception) {
+ return false;
+ }
+
+ QXmlNodeModelIndex index = item.asNode();
+ const QAbstractXmlNodeModel *model = item.asNode().model();
+
+ QPatternist::XsdValidatedXmlNodeModel *validatedModel = new QPatternist::XsdValidatedXmlNodeModel(model);
+
+ QPatternist::XsdValidatingInstanceReader reader(validatedModel, normalizedUri, d->m_context);
+ if (d->m_schema)
+ reader.addSchema(d->m_schema, d->m_schemaDocumentUri);
+ try {
+ reader.read();
+ } catch (QPatternist::Exception exception) {
+ return false;
+ }
+
+ return true;
+}
+
+/*!
+ Returns the name pool used by this QXmlSchemaValidator for constructing \l
+ {QXmlName} {names}. There is no setter for the name pool, because
+ mixing name pools causes errors due to name confusion.
+ */
+QXmlNamePool QXmlSchemaValidator::namePool() const
+{
+ return d->m_namePool;
+}
+
+/*!
+ Returns the schema that is used for validation.
+ */
+QXmlSchema QXmlSchemaValidator::schema() const
+{
+ return d->m_originalSchema;
+}
+
+/*!
+ Changes the \l {QAbstractMessageHandler}{message handler} for this
+ QXmlSchemaValidator to \a handler. The schema validator sends all parsing and
+ validation messages to this message handler. QXmlSchemaValidator does not take
+ ownership of \a handler.
+
+ Normally, the default message handler is sufficient. It writes
+ compile and validation messages to \e stderr. The default message
+ handler includes color codes if \e stderr can render colors.
+
+ When QXmlSchemaValidator calls QAbstractMessageHandler::message(),
+ the arguments are as follows:
+
+ \table
+ \header
+ \o message() argument
+ \o Semantics
+ \row
+ \o QtMsgType type
+ \o Only QtWarningMsg and QtFatalMsg are used. The former
+ identifies a warning, while the latter identifies an error.
+ \row
+ \o const QString & description
+ \o An XHTML document which is the actual message. It is translated
+ into the current language.
+ \row
+ \o const QUrl &identifier
+ \o Identifies the error with a URI, where the fragment is
+ the error code, and the rest of the URI is the error namespace.
+ \row
+ \o const QSourceLocation & sourceLocation
+ \o Identifies where the error occurred.
+ \endtable
+
+ */
+void QXmlSchemaValidator::setMessageHandler(QAbstractMessageHandler *handler)
+{
+ d->m_userMessageHandler = handler;
+}
+
+/*!
+ Returns the message handler that handles parsing and validation
+ messages for this QXmlSchemaValidator.
+ */
+QAbstractMessageHandler *QXmlSchemaValidator::messageHandler() const
+{
+ if (d->m_userMessageHandler)
+ return d->m_userMessageHandler;
+
+ return d->m_messageHandler.data()->value;
+}
+
+/*!
+ Sets the URI resolver to \a resolver. QXmlSchemaValidator does not take
+ ownership of \a resolver.
+
+ \sa uriResolver()
+ */
+void QXmlSchemaValidator::setUriResolver(const QAbstractUriResolver *resolver)
+{
+ d->m_uriResolver = resolver;
+}
+
+/*!
+ Returns the schema's URI resolver. If no URI resolver has been set,
+ QtXmlPatterns will use the URIs in instance documents as they are.
+
+ The URI resolver provides a level of abstraction, or \e{polymorphic
+ URIs}. A resolver can rewrite \e{logical} URIs to physical ones, or
+ it can translate obsolete or invalid URIs to valid ones.
+
+ When QtXmlPatterns calls QAbstractUriResolver::resolve() the
+ absolute URI is the URI mandated by the schema specification, and the
+ relative URI is the URI specified by the user.
+
+ \sa setUriResolver()
+ */
+const QAbstractUriResolver *QXmlSchemaValidator::uriResolver() const
+{
+ return d->m_uriResolver;
+}
+
+/*!
+ Sets the network manager to \a manager.
+ QXmlSchemaValidator does not take ownership of \a manager.
+
+ \sa networkAccessManager()
+ */
+void QXmlSchemaValidator::setNetworkAccessManager(QNetworkAccessManager *manager)
+{
+ d->m_userNetworkAccessManager = manager;
+}
+
+/*!
+ Returns the network manager, or 0 if it has not been set.
+
+ \sa setNetworkAccessManager()
+ */
+QNetworkAccessManager *QXmlSchemaValidator::networkAccessManager() const
+{
+ if (d->m_userNetworkAccessManager)
+ return d->m_userNetworkAccessManager;
+
+ return d->m_networkAccessManager.data()->value;
+}
+
+QT_END_NAMESPACE
diff --git a/src/xmlpatterns/api/qxmlschemavalidator.h b/src/xmlpatterns/api/qxmlschemavalidator.h
new file mode 100644
index 0000000000..afe55a4b49
--- /dev/null
+++ b/src/xmlpatterns/api/qxmlschemavalidator.h
@@ -0,0 +1,97 @@
+/****************************************************************************
+**
+** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://qt.nokia.com/contact.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QXMLSCHEMAVALIDATOR_H
+#define QXMLSCHEMAVALIDATOR_H
+
+#include <QtCore/QUrl>
+#include <QtXmlPatterns/QXmlNamePool>
+
+QT_BEGIN_HEADER
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(XmlPatterns)
+
+class QAbstractMessageHandler;
+class QAbstractUriResolver;
+class QIODevice;
+class QNetworkAccessManager;
+class QUrl;
+class QXmlNamePool;
+class QXmlSchema;
+class QXmlSchemaValidatorPrivate;
+
+class Q_XMLPATTERNS_EXPORT QXmlSchemaValidator
+{
+ public:
+ QXmlSchemaValidator();
+ QXmlSchemaValidator(const QXmlSchema &schema);
+ ~QXmlSchemaValidator();
+
+ void setSchema(const QXmlSchema &schema);
+
+ bool validate(const QUrl &source) const;
+ bool validate(QIODevice *source, const QUrl &documentUri = QUrl()) const;
+ bool validate(const QByteArray &data, const QUrl &documentUri = QUrl()) const;
+
+ QXmlNamePool namePool() const;
+ QXmlSchema schema() const;
+
+ void setMessageHandler(QAbstractMessageHandler *handler);
+ QAbstractMessageHandler *messageHandler() const;
+
+ void setUriResolver(const QAbstractUriResolver *resolver);
+ const QAbstractUriResolver *uriResolver() const;
+
+ void setNetworkAccessManager(QNetworkAccessManager *networkmanager);
+ QNetworkAccessManager *networkAccessManager() const;
+
+ private:
+ QXmlSchemaValidatorPrivate* const d;
+
+ Q_DISABLE_COPY(QXmlSchemaValidator)
+};
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
diff --git a/src/xmlpatterns/api/qxmlschemavalidator_p.h b/src/xmlpatterns/api/qxmlschemavalidator_p.h
new file mode 100644
index 0000000000..3e98aa6647
--- /dev/null
+++ b/src/xmlpatterns/api/qxmlschemavalidator_p.h
@@ -0,0 +1,131 @@
+/****************************************************************************
+**
+** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtXmlPatterns of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://qt.nokia.com/contact.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+
+#ifndef QXMLSCHEMAVALIDATOR_P_H
+#define QXMLSCHEMAVALIDATOR_P_H
+
+#include "qabstractmessagehandler.h"
+#include "qabstracturiresolver.h"
+#include "qautoptr_p.h"
+#include "qcoloringmessagehandler_p.h"
+#include "qxmlschema.h"
+#include "qxmlschema_p.h"
+
+#include "qxsdschemacontext_p.h"
+#include "qxsdschema_p.h"
+
+#include <QtNetwork/QNetworkAccessManager>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+class QXmlSchemaValidatorPrivate
+{
+public:
+ QXmlSchemaValidatorPrivate(const QXmlSchema &schema)
+ : m_namePool(schema.namePool())
+ , m_userMessageHandler(0)
+ , m_uriResolver(0)
+ , m_userNetworkAccessManager(0)
+ {
+ setSchema(schema);
+
+ const QXmlSchemaPrivate *p = schema.d;
+
+ // initialize the environment properties with the ones from the schema
+
+ if (p->m_userNetworkAccessManager) // schema has user defined network access manager
+ m_userNetworkAccessManager = p->m_userNetworkAccessManager;
+ else
+ m_networkAccessManager = p->m_networkAccessManager;
+
+ if (p->m_userMessageHandler) // schema has user defined message handler
+ m_userMessageHandler = p->m_userMessageHandler;
+ else
+ m_messageHandler = p->m_messageHandler;
+
+ m_uriResolver = p->m_uriResolver;
+ }
+
+ void setSchema(const QXmlSchema &schema)
+ {
+ // use same name pool as the schema
+ m_namePool = schema.namePool();
+ m_schema = schema.d->m_schemaParserContext->schema();
+ m_schemaDocumentUri = schema.documentUri();
+
+ // create a new schema context
+ m_context = QPatternist::XsdSchemaContext::Ptr(new QPatternist::XsdSchemaContext(m_namePool.d));
+ m_context->m_schemaTypeFactory = schema.d->m_schemaContext->m_schemaTypeFactory;
+ m_context->m_builtinTypesFacetList = schema.d->m_schemaContext->m_builtinTypesFacetList;
+
+ m_originalSchema = schema;
+ }
+
+ QXmlNamePool m_namePool;
+ QAbstractMessageHandler* m_userMessageHandler;
+ const QAbstractUriResolver* m_uriResolver;
+ QNetworkAccessManager* m_userNetworkAccessManager;
+ QPatternist::ReferenceCountedValue<QAbstractMessageHandler>::Ptr m_messageHandler;
+ QPatternist::ReferenceCountedValue<QNetworkAccessManager>::Ptr m_networkAccessManager;
+
+ QXmlSchema m_originalSchema;
+ QPatternist::XsdSchemaContext::Ptr m_context;
+ QPatternist::XsdSchema::Ptr m_schema;
+ QUrl m_schemaDocumentUri;
+};
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif