tools/assistant/compat/docuparser.h
changeset 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the Qt Assistant of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    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 
       
    51 QT_BEGIN_NAMESPACE
       
    52 
       
    53 class Profile;
       
    54 
       
    55 struct 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 
       
    66 QDataStream &operator>>( QDataStream &s, ContentItem &ci );
       
    67 QDataStream &operator<<( QDataStream &s, const ContentItem &ci );
       
    68 
       
    69 struct IndexItem {
       
    70     IndexItem( const QString &k, const QString &r )
       
    71 	: keyword( k ), reference( r ) {}
       
    72     QString keyword;
       
    73     QString reference;
       
    74 };
       
    75 
       
    76 
       
    77 
       
    78 class DocuParser : public QXmlDefaultHandler
       
    79 {
       
    80 public:
       
    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 
       
   103 protected:
       
   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 
       
   114 class DocuParser310 : public DocuParser
       
   115 {
       
   116 public:
       
   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     
       
   129 private:
       
   130     States state;
       
   131     int depth;
       
   132 };
       
   133 
       
   134 
       
   135 class DocuParser320 : public DocuParser
       
   136 {
       
   137 public:
       
   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 
       
   154 private:
       
   155     
       
   156     States state;
       
   157     int depth;
       
   158     int docfileCounter;
       
   159     QString propertyValue;
       
   160     QString propertyName;
       
   161     Profile *prof;
       
   162 };
       
   163 
       
   164 QT_END_NAMESPACE
       
   165 
       
   166 #endif // DOCUPARSER_H