Qt 4.8
qxmlschema_p.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 
43 #include "qxmlschema.h"
44 #include "qxmlschema_p.h"
45 
46 #include <QtCore/QBuffer>
47 #include <QtCore/QIODevice>
48 #include <QtCore/QUrl>
49 
51 
53  : m_namePool(namePool)
55  , m_uriResolver(0)
57  , m_schemaContext(new QPatternist::XsdSchemaContext(m_namePool.d))
58  , m_schemaParserContext(new QPatternist::XsdSchemaParserContext(m_namePool.d, m_schemaContext))
59  , m_schemaIsValid(false)
60 {
63 }
64 
66  : m_namePool(QXmlNamePool(schemaContext->namePool().data()))
68  , m_uriResolver(0)
70  , m_schemaContext(schemaContext)
71  , m_schemaParserContext(new QPatternist::XsdSchemaParserContext(m_namePool.d, m_schemaContext))
72  , m_schemaIsValid(false)
73 {
76 }
77 
79  : QSharedData(other)
80 {
81  m_namePool = other.m_namePool;
87 
92 }
93 
94 void QXmlSchemaPrivate::load(const QUrl &source, const QString &targetNamespace)
95 {
97 
98  m_schemaContext->setMessageHandler(messageHandler());
99  m_schemaContext->setUriResolver(uriResolver());
100  m_schemaContext->setNetworkAccessManager(networkAccessManager());
101 
104  if (reply)
105  load(reply.data(), source, targetNamespace);
106 }
107 
108 void QXmlSchemaPrivate::load(const QByteArray &data, const QUrl &documentUri, const QString &targetNamespace)
109 {
110  QByteArray localData(data);
111 
112  QBuffer buffer(&localData);
113  buffer.open(QIODevice::ReadOnly);
114 
115  load(&buffer, documentUri, targetNamespace);
116 }
117 
118 void QXmlSchemaPrivate::load(QIODevice *source, const QUrl &documentUri, const QString &targetNamespace)
119 {
121  m_schemaIsValid = false;
122 
123  if (!source) {
124  qWarning("A null QIODevice pointer cannot be passed.");
125  return;
126  }
127 
128  if (!source->isReadable()) {
129  qWarning("The device must be readable.");
130  return;
131  }
132 
134  m_schemaContext->setMessageHandler(messageHandler());
135  m_schemaContext->setUriResolver(uriResolver());
136  m_schemaContext->setNetworkAccessManager(networkAccessManager());
137 
139  parser.setDocumentURI(documentUri);
140  parser.setTargetNamespace(targetNamespace);
141 
142  try {
143  parser.parse();
144  m_schemaParserContext->resolver()->resolve();
145 
146  m_schemaIsValid = true;
147  } catch (QPatternist::Exception exception) {
148  Q_UNUSED(exception);
149  m_schemaIsValid = false;
150  }
151 }
152 
154 {
155  return m_schemaIsValid;
156 }
157 
159 {
160  return m_namePool;
161 }
162 
164 {
165  return m_documentUri;
166 }
167 
169 {
171 }
172 
174 {
176  return m_userMessageHandler;
177 
178  return m_messageHandler.data()->value;
179 }
180 
182 {
183  m_uriResolver = resolver;
184 }
185 
187 {
188  return m_uriResolver;
189 }
190 
192 {
193  m_userNetworkAccessManager = networkmanager;
194 }
195 
197 {
200 
201  return m_networkAccessManager.data()->value;
202 }
203 
QPatternist::ReferenceCountedValue< QAbstractMessageHandler >::Ptr m_messageHandler
Definition: qxmlschema_p.h:96
double d
Definition: qnumeric_p.h:62
QXmlNamePool namePool() const
QAbstractMessageHandler * messageHandler() const
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
bool isReadable() const
Returns true if data can be read from the device; otherwise returns false.
Definition: qiodevice.cpp:544
QAbstractMessageHandler * m_userMessageHandler
QPatternist::XsdSchemaContext::Ptr m_schemaContext
Definition: qxmlschema_p.h:99
bool open(OpenMode openMode)
Reimplemented Function
Definition: qbuffer.cpp:338
A smart pointer very similar to std::auto_ptr.
Definition: qautoptr_p.h:73
QNetworkAccessManager * m_userNetworkAccessManager
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QPatternist::XsdSchemaParserContext::Ptr m_schemaParserContext
Definition: qxmlschema_p.h:100
QNetworkAccessManager * networkAccessManager() const
The QBuffer class provides a QIODevice interface for a QByteArray.
Definition: qbuffer.h:57
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:61
The QString class provides a Unicode character string.
Definition: qstring.h:83
QExplicitlySharedDataPointer< XsdSchemaParserContext > Ptr
The QXmlNamePool class is a table of shared strings referenced by instances of QXmlName.
Definition: qxmlnamepool.h:69
T * data() const
Definition: qautoptr_p.h:149
const QAbstractUriResolver * m_uriResolver
Definition: qxmlschema_p.h:94
The QAbstractUriResolver class is a callback interface for resolving Uniform Resource Identifiers...
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QXmlSchemaPrivate(const QXmlNamePool &namePool)
QUrl documentUri() const
The resource loader will report no error and return an empty QNetworkReply.
The namespace for the internal API of QtXmlPatterns.
Q_CORE_EXPORT void qWarning(const char *,...)
QXmlNamePool m_namePool
Definition: qxmlschema_p.h:92
static const char * data(const QByteArray &arr)
QExplicitlySharedDataPointer< QPatternist::NamePool > d
Definition: qxmlnamepool.h:88
void setDocumentURI(const QUrl &uri)
The QNetworkAccessManager class allows the application to send network requests and receive replies...
static QNetworkReply * load(const QUrl &uri, QNetworkAccessManager *const networkManager, const ReportContext::Ptr &context, ErrorHandling handling=FailOnError)
Helper function that do NetworkAccessDelegator::get(), but does it blocked.
void load(const QUrl &source, const QString &targetNamespace)
QPatternist::ReferenceCountedValue< QNetworkAccessManager >::Ptr m_networkAccessManager
Definition: qxmlschema_p.h:97
QAbstractMessageHandler * m_userMessageHandler
Definition: qxmlschema_p.h:93
The QAbstractMessageHandler class provides a callback interface for handling messages.
The QSharedData class is a base class for shared data objects.
Definition: qshareddata.h:56
QNetworkAccessManager * m_userNetworkAccessManager
Definition: qxmlschema_p.h:95
bool isValid() const
Implements the parsing of XML schema file.
void setMessageHandler(QAbstractMessageHandler *handler)
const QAbstractUriResolver * m_uriResolver
bool parse(ParserType parserType=TopLevelParser)
void setUriResolver(const QAbstractUriResolver *resolver)
QImageIOHandler * handler
The QIODevice class is the base interface class of all I/O devices in Qt.
Definition: qiodevice.h:66
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
static QUrl normalizeQueryURI(const QUrl &uri)
void setNetworkAccessManager(QNetworkAccessManager *networkmanager)
const QAbstractUriResolver * uriResolver() const
void setTargetNamespace(const QString &targetNamespace)