QGpCoreTools/XMLParser.h
Go to the documentation of this file.
00001 /***************************************************************************
00002 **
00003 **  This file is part of QGpCoreTools.
00004 **
00005 **  This library is free software; you can redistribute it and/or
00006 **  modify it under the terms of the GNU Lesser General Public
00007 **  License as published by the Free Software Foundation; either
00008 **  version 2.1 of the License, or (at your option) any later version.
00009 **
00010 **  This file is distributed in the hope that it will be useful, but WITHOUT
00011 **  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 **  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
00013 **  License for more details.
00014 **
00015 **  You should have received a copy of the GNU Lesser General Public
00016 **  License along with this library; if not, write to the Free Software
00017 **  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00018 **
00019 **  See http://www.geopsy.org for more information.
00020 **
00021 **  Created : 2009-06-07
00022 **  Authors :
00023 **    Marc Wathelet
00024 **    Marc Wathelet (LGIT, Grenoble, France)
00025 **
00026 ***************************************************************************/
00027 
00028 #ifndef XMLPARSER_H
00029 #define XMLPARSER_H
00030 
00031 #include "XMLClass.h"
00032 #include "Translations.h"
00033 
00034 namespace QGpCoreTools {
00035 
00036 class XMLParser
00037 {
00038   TRANSLATIONS("XMLParser")
00039 public:
00040   XMLParser(XMLStream * s, XMLContext * context=0);
00041   ~XMLParser();
00042 
00043   void setLine(int l) {_line=l;}
00044   void setPointer(const QChar * ptr) {_ptr=ptr;}
00045   XMLClass::Error parse(XMLClass * object);
00046 private:
00047   void openContext();
00048   void closeContext();
00049   void smallContext();
00050   QString currentContextTag();
00051   void restoreBinaryData();
00052   void restoreBinaryData200510();
00053   void skipSpecChar();
00054   void skipDoubleQuoteString();
00055   void skipSimpleQuoteString();
00056   void skip();
00057   void restoreSpecChar();
00058   void setTag();
00059   void setAttributes();
00060   void finish(XMLClass::Error err);
00061   static QChar specialCharacter(const StringSection& code, bool& ok);
00062 
00063   class Tag
00064   {
00065   public:
00066     Tag() : _member(XMLMember::Unknown) {}
00067     Tag(const StringSection& t) : _member(XMLMember::Unknown), _tag(t) {}
00068     Tag(const StringSection& t, const XMLMember& m) : _member(m), _tag(t) {}
00069     Tag(const Tag& t) : _member(t._member), _tag(t._tag) {}
00070 
00071     const XMLMember&  member() const {return _member;}
00072     const StringSection&  tag() const {return _tag;}
00073   private:
00074     XMLMember _member;
00075     StringSection _tag;
00076   };
00077 
00078   class Object
00079   {
00080   public:
00081     Object() : _context(0), _object(0) {}
00082     Object(XMLContext * context, XMLClass * object=0) : _context(context), _object(object) {}
00083     Object(const Object& o) : _context(o._context), _object(o._object) {}
00084 
00085     void setObject(XMLClass * object) {_object=object;}
00086     XMLContext * context() const {return _context;}
00087     XMLClass * object() const {return _object;}
00088   private:
00089     XMLContext * _context;
00090     XMLClass * _object;
00091   };
00092 
00093   QStack<Tag> _tagStack;
00094   QStack<Object> _objectStack;
00095 
00096   Object _current;
00097   StringSection _tag;
00098   XMLMember _member;
00099   StringSection _content;
00100   XMLRestoreAttributes _attributes;
00101 
00102   XMLStream * _stream;
00103   const QChar * _ptr;
00104   int _line;
00105   XMLClass::Error _error;
00106   const QChar * _specChar;
00107   enum TagType {Unknown, OpenTagNoAttributes, OpenTagAttributes, SingleTagNoAttributes, SingleTagAttributes,
00108                 Attributes, QuestionTagNoAttributes, QuestionTagAttributes, CloseTag};
00109   TagType _tagType;
00110   /* If the content must be altered (restoreSpecChar),
00111      it is redirected to this temp string to keep using a StringSection which requires a permanent string */
00112   QVector<QString *> _tmpStrings;
00113 };
00114 
00115 } // namespace QGpCoreTools
00116 
00117 #endif // XMLPARSER_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines