Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

xmlsource.h

Go to the documentation of this file.
00001 /**********************************************************************
00002 ** Copyright (C) 2000 Trolltech AS.  All rights reserved.
00003 **
00004 ** This file is part of Qtopia Environment.
00005 **
00006 ** This file may be distributed and/or modified under the terms of the
00007 ** GNU General Public License version 2 as published by the Free Software
00008 ** Foundation and appearing in the file LICENSE.GPL included in the
00009 ** packaging of this file.
00010 **
00011 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00013 **
00014 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00015 **
00016 ** Contact info@trolltech.com if any conditions of this licensing are
00017 ** not clear to you.
00018 **
00019 **********************************************************************/
00020 
00021 /* A Class to parse an xml docment of the form
00022  * <database name="...">
00023  * <header>
00024  * <key name=key_name type=String>Displayed Name</key>
00025  * <key name=key2name>key2name</key>
00026  * <key name=key3name type=Date>Key 3</key>
00027  * <key name=key4name type=Int>key 4</key>
00028  * </header>
00029  * <record> 
00030  * <key_name>string</key_name>
00031  * <key4name>int</key4name>
00032  * <key2name>string</key2name>
00033  * </record>
00034  * <record>
00035  * ....
00036  * </record>
00037  * ....
00038  * </database>
00039  *
00040  * There is some room for improvment mostly around using better checking 
00041  * and the use of more advanced xml features.
00042  */
00043 
00044 #ifndef __XMLSOURCE_H__
00045 #define __XMLSOURCE_H__
00046 
00047 #include <qxml.h>
00048 #include <qstring.h>
00049 #include <qstringlist.h>
00050 #include <qstack.h>
00051 #include <qdict.h>
00052 #include "datacache.h"
00053 #include "common.h"
00054 
00055 
00056 class DBXml : public DBAccess
00057 {
00058 public:
00059     /* create connection and either open or initialize */
00060     DBXml(DBStore *d);
00061     QString type();
00062     bool openSource(QIODevice *);
00063     bool saveSource(QIODevice *);
00064     /* does a db write */
00065     ~DBXml();
00066 };
00067 
00068 
00069 class DBXmlHandler : public QXmlDefaultHandler
00070 {
00071 
00072 public:
00073         DBXmlHandler(DBStore *ds);
00074         virtual ~DBXmlHandler();
00075 
00076         // return the error protocol if parsing failed
00077         QString errorProtocol();
00078 
00079         // overloaded handler functions
00080         bool startDocument();
00081         bool startElement(const QString& namespaceURI, const QString& localName,
00082                                         const QString& qName, const QXmlAttributes& atts);
00083         bool endElement(const QString& namespaceURI, const QString& localName,
00084                                         const QString& qName);
00085         bool characters(const QString& ch);
00086 
00087         QString errorString();
00088 
00089         bool warning(const QXmlParseException& exception);
00090         bool error(const QXmlParseException& exception);
00091         bool fatalError(const QXmlParseException& exception);
00092 
00093 private:
00094 
00095         QStack<QString> stack;
00096     KeyList *current_keyrep;
00097     DataElem *current_data;
00098     TVVariant::KeyType last_key_type;
00099 
00100         QString errorProt;
00101         DBStore *data_store;
00102 
00103         enum State {
00104                 StateInit,
00105         StateHeader,
00106         StateKey,
00107                 StateDocument,
00108                 StateRecord,
00109                 StateField
00110         };
00111 
00112         State state;
00113 
00114     QDict<int> keyIndexList;
00115         int keyIndex;
00116     QString key;
00117 };
00118 
00119 #endif

Generated on Sat Nov 5 16:17:08 2005 for OPIE by  doxygen 1.4.2