1 | /**********************************************************************
|
---|
2 | ** Copyright (C) 2000-2007 Trolltech ASA. All rights reserved.
|
---|
3 | **
|
---|
4 | ** This file is part of the Qt Assistant.
|
---|
5 | **
|
---|
6 | ** This file may be distributed and/or modified under the terms of the
|
---|
7 | ** GNU General Public License version 2 as published by the Free Software
|
---|
8 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
9 | ** packaging of this file.
|
---|
10 | **
|
---|
11 | ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
|
---|
12 | ** licenses may use this file in accordance with the Qt Commercial License
|
---|
13 | ** Agreement provided with the Software.
|
---|
14 | **
|
---|
15 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
---|
16 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
---|
17 | **
|
---|
18 | ** See http://www.trolltech.com/gpl/ for GPL licensing information.
|
---|
19 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
|
---|
20 | ** information about Qt Commercial License Agreements.
|
---|
21 | **
|
---|
22 | ** Contact info@trolltech.com if any conditions of this licensing are
|
---|
23 | ** not clear to you.
|
---|
24 | **
|
---|
25 | **********************************************************************/
|
---|
26 |
|
---|
27 | #ifndef DOCUPARSER_H
|
---|
28 | #define DOCUPARSER_H
|
---|
29 |
|
---|
30 | #include <qxml.h>
|
---|
31 | #include <qptrlist.h>
|
---|
32 | #include <qmap.h>
|
---|
33 |
|
---|
34 | class Profile;
|
---|
35 |
|
---|
36 | struct ContentItem {
|
---|
37 | ContentItem()
|
---|
38 | : title( QString::null ), reference( QString::null ), depth( 0 ) {}
|
---|
39 | ContentItem( const QString &t, const QString &r, int d )
|
---|
40 | : title( t ), reference( r ), depth( d ) {}
|
---|
41 | QString title;
|
---|
42 | QString reference;
|
---|
43 | int depth;
|
---|
44 | Q_DUMMY_COMPARISON_OPERATOR(ContentItem)
|
---|
45 | };
|
---|
46 |
|
---|
47 | QDataStream &operator>>( QDataStream &s, ContentItem &ci );
|
---|
48 | QDataStream &operator<<( QDataStream &s, const ContentItem &ci );
|
---|
49 |
|
---|
50 | struct IndexItem {
|
---|
51 | IndexItem( const QString &k, const QString &r )
|
---|
52 | : keyword( k ), reference( r ) {}
|
---|
53 | QString keyword;
|
---|
54 | QString reference;
|
---|
55 | };
|
---|
56 |
|
---|
57 |
|
---|
58 |
|
---|
59 | class DocuParser : public QXmlDefaultHandler
|
---|
60 | {
|
---|
61 | public:
|
---|
62 | enum ParserVersion { Qt310, Qt320 };
|
---|
63 | // Since We don't want problems with documentation
|
---|
64 | // from version to version, this string stores the correct
|
---|
65 | // version string to save documents.
|
---|
66 | static const QString DocumentKey;
|
---|
67 |
|
---|
68 | static DocuParser *createParser( const QString &fileName );
|
---|
69 |
|
---|
70 | virtual bool parse( QFile *file );
|
---|
71 |
|
---|
72 | QValueList<ContentItem> getContentItems();
|
---|
73 | QPtrList<IndexItem> getIndexItems();
|
---|
74 |
|
---|
75 | QString errorProtocol() const;
|
---|
76 | QString contentsURL() const { return conURL; }
|
---|
77 |
|
---|
78 | virtual ParserVersion parserVersion() const = 0;
|
---|
79 | virtual void addTo( Profile *p ) = 0;
|
---|
80 |
|
---|
81 | QString fileName() const { return fname; }
|
---|
82 | void setFileName( const QString &file ) { fname = file; }
|
---|
83 |
|
---|
84 | protected:
|
---|
85 | QString absolutify( const QString &input ) const;
|
---|
86 |
|
---|
87 | QString contentRef, indexRef, errorProt, conURL;
|
---|
88 | QString docTitle, title, iconName;
|
---|
89 | QValueList<ContentItem> contentList;
|
---|
90 | QPtrList<IndexItem> indexList;
|
---|
91 | QString fname;
|
---|
92 | };
|
---|
93 |
|
---|
94 |
|
---|
95 | class DocuParser310 : public DocuParser
|
---|
96 | {
|
---|
97 | public:
|
---|
98 | enum States{ StateInit, StateContent, StateSect, StateKeyword };
|
---|
99 |
|
---|
100 | bool startDocument();
|
---|
101 | bool startElement( const QString&, const QString&, const QString& ,
|
---|
102 | const QXmlAttributes& );
|
---|
103 | bool endElement( const QString&, const QString&, const QString& );
|
---|
104 | bool characters( const QString & );
|
---|
105 | bool fatalError( const QXmlParseException& exception );
|
---|
106 |
|
---|
107 | virtual ParserVersion parserVersion() const { return Qt310; }
|
---|
108 | virtual void addTo( Profile *p );
|
---|
109 |
|
---|
110 | private:
|
---|
111 | States state;
|
---|
112 | int depth;
|
---|
113 | };
|
---|
114 |
|
---|
115 |
|
---|
116 | class DocuParser320 : public DocuParser
|
---|
117 | {
|
---|
118 | public:
|
---|
119 | enum States { StateInit, StateDocRoot, StateProfile, StateProperty,
|
---|
120 | StateContent, StateSect, StateKeyword };
|
---|
121 |
|
---|
122 | DocuParser320();
|
---|
123 |
|
---|
124 | bool startDocument();
|
---|
125 | bool startElement( const QString&, const QString&, const QString& ,
|
---|
126 | const QXmlAttributes& );
|
---|
127 | bool endElement( const QString&, const QString&, const QString& );
|
---|
128 | bool characters( const QString & );
|
---|
129 | bool fatalError( const QXmlParseException& exception );
|
---|
130 |
|
---|
131 | virtual ParserVersion parserVersion() const { return Qt320; }
|
---|
132 | virtual void addTo( Profile *p );
|
---|
133 | Profile *profile() const { return prof; }
|
---|
134 |
|
---|
135 | private:
|
---|
136 |
|
---|
137 | States state;
|
---|
138 | int depth;
|
---|
139 | int docfileCounter;
|
---|
140 | QString propertyValue;
|
---|
141 | QString propertyName;
|
---|
142 | Profile *prof;
|
---|
143 | };
|
---|
144 | #endif //DOCUPARSER_H
|
---|