1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2015 The Qt Company Ltd. 4 ** Contact: http://www.qt.io/licensing/ 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 The Qt Company. For licensing terms 14 ** and conditions see http://www.qt.io/terms-conditions. For further 15 ** information use the contact form at http://www.qt.io/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 or version 3 as published by the Free 20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and 21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the 22 ** following information to ensure the GNU Lesser General Public License 23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and 24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 25 ** 26 ** As a special exception, The Qt Company gives you certain additional 27 ** rights. These rights are described in The Qt Company LGPL Exception 28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 29 ** 30 ** GNU General Public License Usage 31 ** Alternatively, this file may be used under the terms of the GNU 32 ** General Public License version 3.0 as published by the Free Software 33 ** Foundation and appearing in the file LICENSE.GPL included in the 34 ** packaging of this file. Please review the following information to 35 ** ensure the GNU General Public License version 3.0 requirements will be 36 ** met: http://www.gnu.org/copyleft/gpl.html. 37 ** 38 ** $QT_END_LICENSE$ 39 ** 40 ****************************************************************************/ 41 42 // 43 // W A R N I N G 44 // ------------- 45 // 46 // This file is not part of the Qt API. It exists purely as an 47 // implementation detail. This header file may change from version to 48 // version without notice, or even be removed. 49 // 50 // We mean it. 51 52 #ifndef Patternist_XsdTypeChecker_H 53 #define Patternist_XsdTypeChecker_H 54 55 #include <QtXmlPatterns/QSourceLocation> 56 57 #include "qschematype_p.h" 58 #include "qsourcelocationreflection_p.h" 59 #include "qxsdschemacontext_p.h" 60 61 QT_BEGIN_HEADER 62 63 QT_BEGIN_NAMESPACE 64 65 class QXmlQuery; 66 67 namespace QPatternist 68 { 69 /** 70 * @short An implementation of SourceLocationReflection that takes a QSourceLocation. 71 * 72 * This is a convenience class which provides a QSourceLocation with a SourceLocationReflection 73 * interface. 74 */ 75 class XsdSchemaSourceLocationReflection : public SourceLocationReflection 76 { 77 public: 78 XsdSchemaSourceLocationReflection(const QSourceLocation &location); 79 80 virtual const SourceLocationReflection *actualReflection() const; 81 virtual QSourceLocation sourceLocation() const; 82 83 private: 84 const QSourceLocation m_sourceLocation; 85 }; 86 87 /** 88 * @short The class that provides methods for checking a string against a type. 89 * 90 * The class provides functionality for type-aware string handling. 91 */ 92 class XsdTypeChecker 93 { 94 public: 95 /** 96 * Creates a new type checker. 97 * 98 * @param context The schema context that is used for error reporting. 99 * @param namespaceBindings The namespace bindings that shall be used to check against xs:QName based types. 100 * @param location The source location that is used for error reporting. 101 */ 102 XsdTypeChecker(const XsdSchemaContext::Ptr &context, const QVector<QXmlName> &namespaceBindings, const QSourceLocation &location); 103 104 /** 105 * Destroys the type checker. 106 */ 107 ~XsdTypeChecker(); 108 109 /** 110 * Returns all facets for the given @p type. 111 * 112 * The list of facets is created by following the type hierarchy from xs:anyType down to the given type 113 * and merging the facets in each step. 114 */ 115 static XsdFacet::Hash mergedFacetsForType(const SchemaType::Ptr &type, const XsdSchemaContext::Ptr &context); 116 117 /** 118 * Returns the normalized value for the given @p value. 119 * 120 * The normalized value is the original value with all the white space facets 121 * applied on it. 122 * 123 * @param value The original value. 124 * @param facets The hash of all facets of the values type. 125 */ 126 static QString normalizedValue(const QString &value, const XsdFacet::Hash &facets); 127 128 /** 129 * Checks whether the @p normalizedString is valid according the given @p type. 130 * 131 * @param normalizedString The string in normalized form (whitespace facets applied). 132 * @param type The type the string shall be tested against. 133 * @param errorMsg Contains the error message if the normalizedString does not match the type. 134 * @param boundType The type the data was bound to during validation. 135 * 136 * @note The @p boundType only differs from @p type if the type is derived from an based union value. 137 */ 138 bool isValidString(const QString &normalizedString, const AnySimpleType::Ptr &type, QString &errorMsg, AnySimpleType::Ptr *boundType = 0) const; 139 140 /** 141 * Returns whether the given @p value and @p otherValue are of @p type and are equal. 142 */ 143 bool valuesAreEqual(const QString &value, const QString &otherValue, const AnySimpleType::Ptr &type) const; 144 145 private: 146 Q_DISABLE_COPY(XsdTypeChecker) 147 148 /** 149 * Checks the given value against the facets of @p type. 150 */ 151 bool checkConstrainingFacets(const AtomicValue::Ptr &value, const QString &lexicalValue, const AnySimpleType::Ptr &type, QString &errorMsg) const; 152 bool checkConstrainingFacetsString(const QString &value, const XsdFacet::Hash &facets, const AnySimpleType::Ptr &type, QString &errorMsg) const; 153 bool checkConstrainingFacetsSignedInteger(long long value, const QString &lexicalValue, const XsdFacet::Hash &facets, QString &errorMsg) const; 154 bool checkConstrainingFacetsUnsignedInteger(unsigned long long value, const QString &lexicalValue, const XsdFacet::Hash &facets, QString &errorMsg) const; 155 bool checkConstrainingFacetsDouble(double value, const QString &lexicalValue, const XsdFacet::Hash &facets, QString &errorMsg) const; 156 bool checkConstrainingFacetsDecimal(const AtomicValue::Ptr &value, const QString &lexicalValue, const XsdFacet::Hash &facets, QString &errorMsg) const; 157 bool checkConstrainingFacetsDateTime(const QDateTime &value, const QString &lexicalValue, const XsdFacet::Hash &facets, const AnySimpleType::Ptr &type, QString &errorMsg) const; 158 bool checkConstrainingFacetsDuration(const AtomicValue::Ptr &value, const QString &lexicalValue, const XsdFacet::Hash &facets, QString &errorMsg) const; 159 bool checkConstrainingFacetsBoolean(bool value, const QString &lexicalValue, const XsdFacet::Hash &facets, QString &errorMsg) const; 160 bool checkConstrainingFacetsBinary(const QByteArray &value, const XsdFacet::Hash &facets, const AnySimpleType::Ptr &type, QString &errorMsg) const; 161 bool checkConstrainingFacetsQName(const QXmlName&, const QString &lexicalValue, const XsdFacet::Hash &facets, QString &errorMsg) const; 162 bool checkConstrainingFacetsNotation(const QXmlName &value, const XsdFacet::Hash &facets, QString &errorMsg) const; 163 bool checkConstrainingFacetsList(const QStringList &values, const QString &lexicalValue, const AnySimpleType::Ptr &itemType, const XsdFacet::Hash &facets, QString &errorMsg) const; 164 bool checkConstrainingFacetsUnion(const QString &value, const QString &lexicalValue, const XsdSimpleType::Ptr &simpleType, const XsdFacet::Hash &facets, QString &errorMsg) const; 165 166 /** 167 * Creates an atomic value of @p type from the given string @p value. 168 */ 169 AtomicValue::Ptr fromLexical(const QString &value, const SchemaType::Ptr &type, const ReportContext::Ptr &context, const SourceLocationReflection *const reflection) const; 170 171 /** 172 * Converts a qualified name into a QXmlName according to the namespace 173 * mappings of the current node. 174 */ 175 QXmlName convertToQName(const QString &name) const; 176 177 XsdSchemaContext::Ptr m_context; 178 XsdSchema::Ptr m_schema; 179 const NamePool::Ptr m_namePool; 180 QVector<QXmlName> m_namespaceBindings; 181 SourceLocationReflection* m_reflection; 182 }; 183 } 184 185 QT_END_NAMESPACE 186 187 QT_END_HEADER 188 189 #endif 190