1 <?xml version="1.0" encoding="UTF-8" ?>
3 /****************************************************************************
5 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
6 ** Contact: http://www.qt-project.org/
8 ** This file is part of the Patternist project on Qt Labs.
10 ** $QT_BEGIN_LICENSE:LGPL$
11 ** GNU Lesser General Public License Usage
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this
15 ** file. Please review the following information to ensure the GNU Lesser
16 ** General Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
23 ** GNU General Public License Usage
24 ** Alternatively, this file may be used under the terms of the GNU General
25 ** Public License version 3.0 as published by the Free Software Foundation
26 ** and appearing in the file LICENSE.GPL included in the packaging of this
27 ** file. Please review the following information to ensure the GNU General
28 ** Public License version 3.0 requirements will be met:
29 ** http://www.gnu.org/copyleft/gpl.html.
32 ** Alternatively, this file may be used in accordance with the terms and
33 ** conditions contained in a signed written agreement between you and Nokia.
42 ***************************************************************************
47 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
48 xmlns:h="http://www.w3.org/1999/xhtml"
51 <xsl:output omit-xml-declaration="yes"/>
54 This code open the following specifications:
56 - XQuery 1.0 and XPath 2.0 Functions and Operators
57 - XML Path Language (XPath) 2.0
58 - XSL Transformations (XSLT) Version 2.0
59 - XQuery 1.0: An XML Query Language
61 and extracts the error codes as well as their documentation and exports
62 them as enum values into a C++ enumerator called ErrorCode.
64 NOTE: Be aware of binary compatibility when using this stylesheet.
68 <xsl:variable name="xslt20" select="document('xslt20.html')"/>
70 <xsl:variable name="xslt20" select="document('http://www.w3.org/TR/xslt20')"/>
73 <xsl:variable name="xqfo" select="document('xqfo.html')"/>
75 <xsl:variable name="xqfo" select="document('http://www.w3.org/TR/xpath-functions/')"/>
78 <xsl:variable name="xq" select="document('xq.html')"/>
80 <xsl:variable name="xq" select="document('http://www.w3.org/TR/xquery/')"/>
83 <xsl:variable name="ser" select="document('ser.html')"/>
85 <xsl:variable name="ser" select="document('http://www.w3.org/TR/xslt-xquery-serialization/')"/>
88 *********************************************
89 *********************************************
91 <xsl:template match="/"><xsl:text disable-output-escaping="yes"
92 ><![CDATA[/****************************************************************************
94 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
95 ** Contact: http://www.qt-project.org/
97 ** This file is part of the QtXmlPatterns module of the Qt Toolkit.
99 ** $QT_BEGIN_LICENSE:LGPL$
100 ** GNU Lesser General Public License Usage
101 ** This file may be used under the terms of the GNU Lesser General Public
102 ** License version 2.1 as published by the Free Software Foundation and
103 ** appearing in the file LICENSE.LGPL included in the packaging of this
104 ** file. Please review the following information to ensure the GNU Lesser
105 ** General Public License version 2.1 requirements will be met:
106 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
108 ** In addition, as a special exception, Nokia gives you certain additional
109 ** rights. These rights are described in the Nokia Qt LGPL Exception
110 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
112 ** GNU General Public License Usage
113 ** Alternatively, this file may be used under the terms of the GNU General
114 ** Public License version 3.0 as published by the Free Software Foundation
115 ** and appearing in the file LICENSE.GPL included in the packaging of this
116 ** file. Please review the following information to ensure the GNU General
117 ** Public License version 3.0 requirements will be met:
118 ** http://www.gnu.org/copyleft/gpl.html.
121 ** Alternatively, this file may be used in accordance with the terms and
122 ** conditions contained in a signed written agreement between you and Nokia.
131 ****************************************************************************/
137 // This file is not part of the Qt API. It exists purely as an
138 // implementation detail. This header file may change from version to
139 // version without notice, or even be removed.
143 #ifndef Patternist_ReportContext_H
144 #define Patternist_ReportContext_H
146 #include <QSharedData>
147 #include <QAbstractUriResolver>
148 #include <QSourceLocation>
150 #include "qnamepool_p.h"
151 #include "qxmlname.h"
157 class QAbstractMessageHandler;
158 class QSourceLocation;
161 namespace QPatternist
163 class SourceLocationReflection;
166 * @short A callback for reporting errors.
168 * ReportContext receives messages of various severity and type via its
169 * functions warning() and error(). In turn, ReportContext create Message instances
170 * and submit them to the QAbstractMessageHandler instance returned by messageHandler().
172 * The Message attributes are set as follows:
174 * - Message::description() - A translated, human-readable description
175 * - Message::type() - Message::Error if a static, dynamic or type error was encountered
176 * that halted compilation or evaluation, or Message::Warning in case of a warning
177 * - Message::identifier() - This is a URI consisting of the error namespace with the
178 * error code as fragment. For example, a Message representing a syntax error
179 * would return the type "http://www.w3.org/2005/xqt-errors#XPST0003". The convenience
180 * function codeFromURI() can be used to extract the error code. The error namespace
181 * is typically the namespace for XPath and XQuery errors(as in the previous example), but
182 * can also be user defined.
184 * @see <a href="http://www.w3.org/TR/xpath20/#id-identifying-errors">XML Path Language
185 * (XPath) 2.0, 2.3.2 Identifying and Reporting Errors</a>
186 * @see <a href="http://www.w3.org/TR/xpath-functions/#func-error">XQuery 1.0 and
187 * XPath 2.0 Functions and Operators, 3 The Error Function</a>
188 * @author Frans Englich <frans.englich@nokia.com>
189 * @warning This file is auto-generated from extractErrorCodes.xsl. Any
190 * modifications done to this file are lost.
192 class Q_AUTOTEST_EXPORT ReportContext : public QSharedData
195 typedef QHash<const SourceLocationReflection *, QSourceLocation> LocationHash;
198 * A smart pointer wrapping ReportContext instances.
200 typedef QExplicitlySharedDataPointer<ReportContext> Ptr;
203 * @short Default constructors.
205 * For some reason GCC fails to synthesize it, so we provide an empty
208 inline ReportContext() {}
210 virtual ~ReportContext();
213 * Error codes that corresponds to the error codes defined in the
214 * relevant specifications. They are used throughout the API for
215 * identifying error conditions.
217 * While strings could have been used for identifying errors, enums
218 * reduces bugs by providing type safety.
220 * @see <a href="http://www.w3.org/TR/xpath20/#errors">XML
221 * Path Language (XPath) 2.0, 2.3 Error Handling</a>
222 * @see <a href="http://www.w3.org/TR/xpath-functions/#d1e10985">XQuery 1.0
223 * and XPath 2.0 Functions and Operators, C Error Summary</a>
224 * @see <a href="http://www.w3.org/TR/xslt20/#error-summary">XSL Transformations
225 * (XSLT) Version 2.0, E Summary of Error Conditions (Non-Normative)</a>
226 * @note The enumerator values' Doxygen documentation is copied from the
228 * <a href="http://www.w3.org/TR/xpath-functions">XQuery 1.0 and XPath
229 * 2.0 Functions and Operators</a>,
230 * <a href="http://www.w3.org/TR/xpath20">XML Path Language (XPath) 2.0</a>, and
231 * <a href="http://www.w3.org/TR/xslt20/">XSL Transformations (XSLT)
232 * Version 2.0</a>, respectively. The doxygen documentation is therefore covered
233 * by the following legal notice:
234 * "Copyright @ 2005 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C
235 * <a href="http://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer">liability</a>,
236 * <a href="http://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks">trademark</a> and
237 * <a href="http://www.w3.org/Consortium/Legal/copyright-documents">document
238 * use</a> rules apply."
239 * @warning This enumerator is auto-generated from the relevant specifications
240 * by the XSL-T stylesheet extractErrorCodes.xsl. Hence, any modifications
241 * done to this file, in contrary to the stylesheet, are therefore lost.
246 * XML Schema error code.
250 <!-- The order of the calls is significant. The templates takes into account
251 to avoid the last comma(extractXSLT20 does this). -->
252 <xsl:call-template name="extractXQuery10"/>
253 <xsl:call-template name="extractXQueryFO"/>
254 <xsl:call-template name="extractSerialization"/>
255 <xsl:call-template name="extractXSLT20"/>
257 <xsl:text disable-output-escaping="yes"><![CDATA[
259 * Issues a warning, should not be used excessively. This can
260 * be used to communicate that a certain implementation defined
261 * feature is unsupported or that a certain expression most likely
262 * doesn't do what the users wants, to name a few examples.
264 * @see <a href="http://www.w3.org/TR/xpath20/#errors">XML Path Language (XPath) 2.0,
265 * 2.3 Error Handling</a>
266 * @param message the message to be read by the user.
267 * @param sourceLocation the location of where the warning originates from.
269 void warning(const QString &message, const QSourceLocation &sourceLocation = QSourceLocation());
272 * Issues an error. May be used at the static analysis phase or
273 * the dynamic evaluation phase.
275 * For SourceLocationReflection instances, the overload taking an SouourceLocationReflection should be used.
277 * @see <a href="http://www.w3.org/TR/xpath20/#errors">XML Path Language (XPath) 2.0,
278 * 2.3 Error Handling</a>
279 * @param message the message to be read by the user.
280 * @param errorCode identifies the error condition, as described
281 * @param sourceLocation the location of where the error originates from
282 * in "XML Path Language (XPath) 2.0" section "G Error Conditions"
284 void error(const QString &message,
285 const ReportContext::ErrorCode errorCode,
286 const QSourceLocation &sourceLocation);
291 * Same as the above, but passes the SourceLocationReflection as reference for error reporting.
293 void error(const QString &message,
294 const ReportContext::ErrorCode errorCode,
295 const SourceLocationReflection *reflection);
298 * Issues an error which is not identified in the XPath specifications. This function
299 * is among other things used for implementing the <tt>fn:error()</tt> function.
301 void error(const QString &message,
302 const QXmlName qName,
303 const SourceLocationReflection *const r);
306 * @return the QAbstractMessageHandler which functions such as warning() and
307 * error() should submit messages to. This function
308 * may never return @c null; a valid QAbstractMessageHandler pointer must always be returned.
310 virtual QAbstractMessageHandler *messageHandler() const = 0;
312 virtual NamePool::Ptr namePool() const = 0;
315 * Returns a string representation of the error code @p code.
317 * @see ReportContext::ErrorCode
318 * @param errorCode identifies the error condition, as described
319 * in <a href="http://www.w3.org/TR/xpath20/#id-errors">XML Path
320 * Language (XPath) 2.0, G Error Conditions</a>
322 static QString codeToString(const ReportContext::ErrorCode errorCode);
325 * @returns the error code part of @p typeURI and sets @p uri to the error namespace. Note
326 * that the error namespace not necessarily is the namespace for XPath and
327 * XQuery errors, http://www.w3.org/2005/xqt-errors, but can be user defined.
329 static QString codeFromURI(const QString &typeURI,
333 * @short Returns the source location applying for @p reflection.
335 virtual QSourceLocation locationFor(const SourceLocationReflection *const reflection) const = 0;
338 * Resolves @p relative against @p baseURI, possibly using a URI resolver.
340 QUrl resolveURI(const QUrl &relative,
341 const QUrl &baseURI) const;
344 * @short The URI resolver in use.
346 * If no URI resolver is in use, a @c null pointer is returned.
348 * @note You should probably use resolveURI(), which handles the case of
349 * when uriResolver() is @c null.
351 virtual QAbstractUriResolver *uriResolver() const = 0;
354 void createError(const QString &description,
355 const QtMsgType type,
357 const QSourceLocation &sourceLocation) const;
358 static inline QString finalizeDescription(const QString &desc);
359 QSourceLocation lookupSourceLocation(const SourceLocationReflection *const ref) const;
361 Q_DISABLE_COPY(ReportContext)
365 * @short This is the class type that is being thrown when a query error occur.
367 * @relates ReportContext
369 typedef bool Exception;
379 *********************************************
380 *********************************************
387 *********************************************
388 XQuery 1.0 and XPath 2.0 Functions and Operators
389 *********************************************
391 <xsl:template name="extractXQueryFO">
392 <xsl:apply-templates mode="xqfo" select="$xqfo/h:html/h:body/h:div[@class = 'back']//
393 h:div[h:h2/h:a/@id = 'error-summary']/h:dl/h:dt"/>
396 <xsl:template mode="xqfo" match="h:dt">
397 /**<xsl:call-template name="formatDocs">
398 <xsl:with-param name="content" select="substring(., 15)"/>
401 <xsl:value-of select="substring(h:a/@name, 4)"/>,
404 *********************************************
405 *********************************************
412 *********************************************
413 XQuery 1.0: An XML Query Language
414 *********************************************
416 <xsl:template name="extractXQuery10">
417 <xsl:apply-templates mode="xquery10" select="$xq/h:html/h:body/h:div[@class = 'back']//
418 h:div[h:h2/h:a/@id = 'id-errors']/h:dl/h:dt"/>
421 <xsl:template mode="xquery10" match="h:dt">
422 /**<xsl:call-template name="formatDocs">
423 <xsl:with-param name="content" select="following-sibling::h:dd/h:p"/>
426 <xsl:value-of select="substring(., 5)"/>,
429 *********************************************
430 *********************************************
436 *********************************************
437 XSL Transformations (XSLT) Version 2.0
438 *********************************************
440 <xsl:template name="extractXSLT20">
441 <xsl:apply-templates mode="xslt20" select="$xslt20/h:html/h:body/h:div[@class = 'back']//
442 h:div[@class = 'div1' and h:h2/h:a/@id = 'error-summary']/h:dl/h:dt"/>
445 <xsl:template mode="xslt20" match="h:dt">
446 /**<xsl:call-template name="formatDocs">
447 <xsl:with-param name="content" select="following-sibling::h:dd/h:p"/>
450 <xsl:value-of select="normalize-space(substring(h:a/h:span, 4))"/>
452 <xsl:if test="position() != last()">,</xsl:if>
453 <xsl:text>
</xsl:text>
456 *********************************************
457 *********************************************
463 *********************************************
464 XSLT 2.0 and XQuery 1.0 Serialization
465 *********************************************
467 <xsl:template name="extractSerialization">
468 <xsl:apply-templates mode="ser" select="$ser/h:html/h:body/h:div[@class = 'back']//
469 h:div[@class = 'div1' and h:h2/h:a/@id = 'id-errors']/h:dl/h:dt"/>
472 <xsl:template mode="ser" match="h:dt">
473 /**<xsl:call-template name="formatDocs">
474 <xsl:with-param name="content" select="following-sibling::h:dd/h:p"/>
477 <xsl:value-of select="substring(., 5)"/>,
480 *********************************************
481 *********************************************
487 <!-- Random stuff -->
488 <xsl:template name="formatDocs">
489 <xsl:param name="content"/>
491 <xsl:call-template name="internalFormatDocs">
492 <xsl:with-param name="content">
493 <!-- Escape # in order to keep Doxygen happy. -->
494 <xsl:call-template name="replace-string">
495 <xsl:with-param name="text" select="translate(normalize-space($content), ' ', '')"/>
496 <xsl:with-param name="from" select="' #'"/>
497 <xsl:with-param name="to" select="' \#'"/>
504 <xsl:template name="internalFormatDocs">
505 <xsl:param name="content"/>
507 <xsl:variable name="nextText" select="substring($content, 61)"/>
508 <xsl:variable name="afterSpace" select="substring-after($nextText, ' ')"/>
509 * <xsl:value-of select="substring($content, 1, 60)"/>
510 <xsl:value-of select="substring-before($nextText, ' ')"/>
512 <xsl:when test="string-length($afterSpace) = 0"><xsl:value-of select="$nextText"/>
514 <xsl:when test="string-length($afterSpace) < 60">
515 * <xsl:value-of select="$afterSpace"/>
517 <xsl:when test="string-length($nextText)">
518 <xsl:call-template name="formatDocs">
519 <xsl:with-param name="content"
520 select="$afterSpace"/>
527 reusable replace-string function
528 http://aspn.activestate.com/ASPN/Cookbook/XSLT/Recipe/65426
530 <xsl:template name="replace-string">
531 <xsl:param name="text"/>
532 <xsl:param name="from"/>
533 <xsl:param name="to"/>
536 <xsl:when test="contains($text, $from)">
538 <xsl:variable name="before" select="substring-before($text, $from)"/>
539 <xsl:variable name="after" select="substring-after($text, $from)"/>
541 <xsl:value-of select="$before"/>
542 <xsl:value-of select="$to"/>
544 <xsl:call-template name="replace-string">
545 <xsl:with-param name="text" select="$after"/>
546 <xsl:with-param name="from" select="$from"/>
547 <xsl:with-param name="to" select="$to"/>
552 <xsl:value-of select="$text"/>
558 <!-- vim: et:ts=4:sw=4:sts=4