1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** Contact: Qt Software Information ([email protected])
|
---|
5 | **
|
---|
6 | ** This file is part of the documentation of the Qt Toolkit.
|
---|
7 | **
|
---|
8 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
9 | ** Commercial Usage
|
---|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
11 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
12 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
13 | ** a written agreement between you and Nokia.
|
---|
14 | **
|
---|
15 | ** GNU Lesser General Public License Usage
|
---|
16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
17 | ** General Public License version 2.1 as published by the Free Software
|
---|
18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
19 | ** packaging of this file. Please review the following information to
|
---|
20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
22 | **
|
---|
23 | ** In addition, as a special exception, Nokia gives you certain
|
---|
24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
---|
25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
---|
26 | ** package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you are unsure which license is appropriate for your use, please
|
---|
37 | ** contact the sales department at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | /*
|
---|
43 | handler.cpp
|
---|
44 |
|
---|
45 | Provides a handler for processing XML elements found by the reader.
|
---|
46 |
|
---|
47 | The handler stores the names of elements it finds and their indentation
|
---|
48 | levels. The indentation level is initially set to zero.
|
---|
49 | When a starting element is found, the indentation level is increased;
|
---|
50 | when an ending element is found, the indentation level is decreased.
|
---|
51 | */
|
---|
52 |
|
---|
53 | #include <QDebug>
|
---|
54 | #include "handler.h"
|
---|
55 |
|
---|
56 | /*!
|
---|
57 | Reset the state of the handler to ensure that new documents are
|
---|
58 | read correctly.
|
---|
59 |
|
---|
60 | We return true to indicate that parsing should continue.
|
---|
61 | */
|
---|
62 |
|
---|
63 | bool Handler::startDocument()
|
---|
64 | {
|
---|
65 | elementName.clear();
|
---|
66 | elementIndentation.clear();
|
---|
67 | indentationLevel = 0;
|
---|
68 |
|
---|
69 | return true;
|
---|
70 | }
|
---|
71 |
|
---|
72 | /*!
|
---|
73 | Process each starting element in the XML document.
|
---|
74 |
|
---|
75 | Append the element name to the list of elements found; add its
|
---|
76 | corresponding indentation level to the list of indentation levels.
|
---|
77 |
|
---|
78 | Increase the level of indentation by one column.
|
---|
79 |
|
---|
80 | We return true to indicate that parsing should continue.
|
---|
81 | */
|
---|
82 |
|
---|
83 | bool Handler::startElement(const QString &, const QString &,
|
---|
84 | const QString & qName, const QXmlAttributes &)
|
---|
85 | {
|
---|
86 | elementName.append(qName);
|
---|
87 | elementIndentation.append(indentationLevel);
|
---|
88 | indentationLevel += 1;
|
---|
89 |
|
---|
90 | return true;
|
---|
91 | }
|
---|
92 |
|
---|
93 | /*!
|
---|
94 | Process each ending element in the XML document.
|
---|
95 |
|
---|
96 | Decrease the level of indentation by one column.
|
---|
97 |
|
---|
98 | We return true to indicate that parsing should continue.
|
---|
99 | */
|
---|
100 |
|
---|
101 | bool Handler::endElement(const QString &, const QString &,
|
---|
102 | const QString &)
|
---|
103 | {
|
---|
104 | indentationLevel -= 1;
|
---|
105 |
|
---|
106 | return true;
|
---|
107 | }
|
---|
108 |
|
---|
109 | /*!
|
---|
110 | Report a fatal parsing error, and return false to indicate to the reader
|
---|
111 | that parsing should stop.
|
---|
112 | */
|
---|
113 |
|
---|
114 | bool Handler::fatalError (const QXmlParseException & exception)
|
---|
115 | {
|
---|
116 | qWarning() << QString("Fatal error on line %1, column %2: %3").arg(
|
---|
117 | exception.lineNumber()).arg(exception.columnNumber()).arg(
|
---|
118 | exception.message());
|
---|
119 |
|
---|
120 | return false;
|
---|
121 | }
|
---|
122 |
|
---|
123 | /*!
|
---|
124 | Return the list of element names found.
|
---|
125 | */
|
---|
126 |
|
---|
127 | QStringList& Handler::names ()
|
---|
128 | {
|
---|
129 | return elementName;
|
---|
130 | }
|
---|
131 |
|
---|
132 | /*!
|
---|
133 | Return the list of indentations used for each element found.
|
---|
134 | */
|
---|
135 |
|
---|
136 | QList<int>& Handler::indentations ()
|
---|
137 | {
|
---|
138 | return elementIndentation;
|
---|
139 | }
|
---|