WARNING: USE THIS SOFTWARE AT YOUR OWN RISK! THIS IS EXPERIMENTAL SOFTWARE NOT INTENDED FOR PRODUCTION USE! Zuble is currently an early stage prototype. As such Zuble is minimally tested and inherently unstable. It is provided for experimental, development, and demonstration purposes only. Zuble QML Types   |  Zuble C++ Classes   |  Zuble Overview
Zuble  0.1
Zuble Framework C++/QML extension API
ZSchemaValidator.cpp
Go to the documentation of this file.
1 /*
2  * Zuble - A run-time system for QML/Javascript applications
3  * Copyright (C) 2013, 2014 Bob Dinitto
4  *
5  * Filename: ZSchemaValidator.cpp
6  * Created on: 11/9/2014
7  * Author: Bob Dinitto
8  *
9  * Zuble is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  *
23  */
24 
25 #include "ZSchemaValidator.h"
26 #include <QXmlSchemaValidator>
27 #include <QtQml>
28 
29 namespace Zbl
30 {
31 
33 
35  QObject(parent), m_status(true), m_msgHandler(this)
36 {
37  m_schema.setMessageHandler(&m_msgHandler);
38 }
39 
40 void ZSchemaValidator::zMessage(QVariant message)
41 {
42  emit statusMessage(message);
43 }
44 
46 {
48 
49  return qmlRegisterType<ZSchemaValidator>(
50  "org.zuble.qml",
51  1,
52  0,
53  "ZSchemaValidator");
54 }
55 
56 
58 {
59  return m_schemaUrl.url();
60 }
61 
63 {
64  m_schemaUrl.setUrl(schemaUrl);
65 
66  m_status = m_schema.load(m_schemaUrl); // TBD: slow here!
67 }
68 
69 
71 {
72  QXmlSchemaValidator v(m_schema);
73 
74 #if 0
75  QAbstractMessageHandler* msgHandler =
76  dynamic_cast<QAbstractMessageHandler*>(m_msgHandler);
77 
78  if(!msgHandler)
79  {
80  zDebug() << "I hate you! I hate you! I really really hate you!";
81  }
82  else
83  {
84  zDebug() << "I luv you! I luv you! I really really luv you!";
85  }
86 #endif
87 
88  v.setMessageHandler(&m_msgHandler);
89 
90  m_status = v.validate(m_XmlDocUrl);
91 
92  return m_status;
93 
94 }
95 
97 {
98  return m_XmlDocUrl.url();
99 }
100 
101 void ZSchemaValidator::setXmlDocUrl(const QString& xmlDoc)
102 {
103  m_XmlDocUrl.setUrl(xmlDoc);
104 }
105 
107 {
108  return m_status;
109 }
110 
111 
112 
113 
114 
115 } // Zbl
116 
QXmlSchema m_schema
The encapsulated QXmlSchema object.
QString getSchemaUrl()
Obtain the schema URI.
virtual ZBL_DECLARE_LOGGED_OBJECT void zMessage(QVariant message)
#define ZBL_REGISTER_LOGGED_OBJECT
Definition: zglobal.h:104
bool m_status
Most recent status. true = OK, false = failed.
Q_INVOKABLE bool isOk()
Determines the status of the most recent operation.
QString getXmlDocUrl()
Obtain the XML instance document URI.
Definition: ZAndGate.cpp:6
QUrl m_XmlDocUrl
The URI to the XML instance document that will be valudated against an XML schema.
#define ZBL_DEFINE_LOGGED_OBJECT(class_name)
Definition: zglobal.h:99
void setSchemaUrl(const QString &schemaUrl)
Sets the URI of the XML schema to use for validating XML documents and loads the schema into memory...
static int registerType()
Registers this object with the QML type system.
QUrl m_schemaUrl
The URI to the schema against which the instance document will be validated.
bool validate()
Validates the current XML document against the currently loaded XML schema.
#define zDebug()
Definition: zglobal.h:113
void statusMessage(QVariant message)
ZxMessageHandler m_msgHandler
QXmlQuery.
This class wraps the QXmlSchemaValidator and QXmlSchema classes.
void setXmlDocUrl(const QString &xmlDocUrl)
Sets the URI of the XML instance Document to be validated against the XML schema. ...