source: trunk/tools/assistant/compat/docuparser.h@ 235

Last change on this file since 235 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 5.1 KB
Line 
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 Qt Assistant 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#ifndef DOCUPARSER_H
43#define DOCUPARSER_H
44
45#include <QList>
46#include <QMap>
47#include <QXmlDefaultHandler>
48#include <QXmlAttributes>
49#include <QXmlParseException>
50
51QT_BEGIN_NAMESPACE
52
53class Profile;
54
55struct ContentItem {
56 ContentItem()
57 : title( QString() ), reference( QString() ), depth( 0 ) {}
58 ContentItem( const QString &t, const QString &r, int d )
59 : title( t ), reference( r ), depth( d ) {}
60 QString title;
61 QString reference;
62 int depth;
63 Q_DUMMY_COMPARISON_OPERATOR(ContentItem)
64};
65
66QDataStream &operator>>( QDataStream &s, ContentItem &ci );
67QDataStream &operator<<( QDataStream &s, const ContentItem &ci );
68
69struct IndexItem {
70 IndexItem( const QString &k, const QString &r )
71 : keyword( k ), reference( r ) {}
72 QString keyword;
73 QString reference;
74};
75
76
77
78class DocuParser : public QXmlDefaultHandler
79{
80public:
81 enum ParserVersion { Qt310, Qt320 };
82 // Since We don't want problems with documentation
83 // from version to version, this string stores the correct
84 // version string to save documents.
85 static const QString DocumentKey;
86
87 static DocuParser *createParser( const QString &fileName );
88
89 virtual bool parse( QFile *file );
90
91 QList<ContentItem> getContentItems();
92 QList<IndexItem*> getIndexItems();
93
94 QString errorProtocol() const;
95 QString contentsURL() const { return conURL; }
96
97 virtual ParserVersion parserVersion() const = 0;
98 virtual void addTo( Profile *p ) = 0;
99
100 QString fileName() const { return fname; }
101 void setFileName( const QString &file ) { fname = file; }
102
103protected:
104 QString absolutify( const QString &input, bool makeUrl = true ) const;
105
106 QString contentRef, indexRef, errorProt, conURL;
107 QString docTitle, title, iconName;
108 QList<ContentItem> contentList;
109 QList<IndexItem*> indexList;
110 QString fname;
111};
112
113
114class DocuParser310 : public DocuParser
115{
116public:
117 enum States{ StateInit, StateContent, StateSect, StateKeyword };
118
119 bool startDocument();
120 bool startElement( const QString&, const QString&, const QString& ,
121 const QXmlAttributes& );
122 bool endElement( const QString&, const QString&, const QString& );
123 bool characters( const QString & );
124 bool fatalError( const QXmlParseException& exception );
125
126 virtual ParserVersion parserVersion() const { return Qt310; }
127 virtual void addTo( Profile *p );
128
129private:
130 States state;
131 int depth;
132};
133
134
135class DocuParser320 : public DocuParser
136{
137public:
138 enum States { StateInit, StateDocRoot, StateProfile, StateProperty,
139 StateContent, StateSect, StateKeyword };
140
141 DocuParser320();
142
143 bool startDocument();
144 bool startElement( const QString&, const QString&, const QString& ,
145 const QXmlAttributes& );
146 bool endElement( const QString&, const QString&, const QString& );
147 bool characters( const QString & );
148 bool fatalError( const QXmlParseException& exception );
149
150 virtual ParserVersion parserVersion() const { return Qt320; }
151 virtual void addTo( Profile *p );
152 Profile *profile() const { return prof; }
153
154private:
155
156 States state;
157 int depth;
158 int docfileCounter;
159 QString propertyValue;
160 QString propertyName;
161 Profile *prof;
162};
163
164QT_END_NAMESPACE
165
166#endif // DOCUPARSER_H
Note: See TracBrowser for help on using the repository browser.