Eneboo - Documentación para desarrolladores
src/qt/src/xml/qxml.h
Ir a la documentación de este archivo.
00001 /****************************************************************************
00002 ** $Id: qt/qxml.h   3.3.8   edited Jan 11 14:39 $
00003 **
00004 ** Definition of QXmlSimpleReader and related classes.
00005 **
00006 ** Created : 000518
00007 **
00008 ** Copyright (C) 1992-2007 Trolltech ASA.  All rights reserved.
00009 **
00010 ** This file is part of the xml module of the Qt GUI Toolkit.
00011 **
00012 ** This file may be distributed under the terms of the Q Public License
00013 ** as defined by Trolltech ASA of Norway and appearing in the file
00014 ** LICENSE.QPL included in the packaging of this file.
00015 **
00016 ** This file may be distributed and/or modified under the terms of the
00017 ** GNU General Public License version 2 as published by the Free Software
00018 ** Foundation and appearing in the file LICENSE.GPL included in the
00019 ** packaging of this file.
00020 **
00021 ** Licensees holding valid Qt Enterprise Edition licenses may use this
00022 ** file in accordance with the Qt Commercial License Agreement provided
00023 ** with the Software.
00024 **
00025 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00026 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00027 **
00028 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
00029 **   information about Qt Commercial License Agreements.
00030 ** See http://www.trolltech.com/qpl/ for QPL licensing information.
00031 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00032 **
00033 ** Contact info@trolltech.com if any conditions of this licensing are
00034 ** not clear to you.
00035 **
00036 **********************************************************************/
00037 
00038 #ifndef QXML_H
00039 #define QXML_H
00040 
00041 #ifndef QT_H
00042 #include "qtextstream.h"
00043 #include "qfile.h"
00044 #include "qstring.h"
00045 #include "qstringlist.h"
00046 #include "qvaluevector.h"
00047 #endif // QT_H
00048 
00049 #if !defined(QT_MODULE_XML) || defined( QT_LICENSE_PROFESSIONAL ) || defined( QT_INTERNAL_XML )
00050 #define QM_EXPORT_XML
00051 #else
00052 #define QM_EXPORT_XML Q_EXPORT
00053 #endif
00054 
00055 #ifndef QT_NO_XML
00056 
00057 class QXmlNamespaceSupport;
00058 class QXmlAttributes;
00059 class QXmlContentHandler;
00060 class QXmlDefaultHandler;
00061 class QXmlDTDHandler;
00062 class QXmlEntityResolver;
00063 class QXmlErrorHandler;
00064 class QXmlLexicalHandler;
00065 class QXmlDeclHandler;
00066 class QXmlInputSource;
00067 class QXmlLocator;
00068 class QXmlNamespaceSupport;
00069 class QXmlParseException;
00070 
00071 class QXmlReader;
00072 class QXmlSimpleReader;
00073 
00074 class QXmlSimpleReaderPrivate;
00075 class QXmlNamespaceSupportPrivate;
00076 class QXmlAttributesPrivate;
00077 class QXmlInputSourcePrivate;
00078 class QXmlParseExceptionPrivate;
00079 class QXmlLocatorPrivate;
00080 class QXmlDefaultHandlerPrivate;
00081 
00082 
00083 //
00084 // SAX Namespace Support
00085 //
00086 
00087 class QM_EXPORT_XML QXmlNamespaceSupport
00088 {
00089 public:
00090     QXmlNamespaceSupport();
00091     ~QXmlNamespaceSupport();
00092 
00093     void setPrefix( const QString&, const QString& );
00094 
00095     QString prefix( const QString& ) const;
00096     QString uri( const QString& ) const;
00097     void splitName( const QString&, QString&, QString& ) const;
00098     void processName( const QString&, bool, QString&, QString& ) const;
00099     QStringList prefixes() const;
00100     QStringList prefixes( const QString& ) const;
00101 
00102     void pushContext();
00103     void popContext();
00104     void reset();
00105 
00106 private:
00107     QXmlNamespaceSupportPrivate *d;
00108 
00109     friend class QXmlSimpleReader;
00110 };
00111 
00112 
00113 //
00114 // SAX Attributes
00115 //
00116 
00117 class QM_EXPORT_XML QXmlAttributes
00118 {
00119 public:
00120     QXmlAttributes() {}
00121     virtual ~QXmlAttributes() {}
00122 
00123     int index( const QString& qName ) const;
00124     int index( const QString& uri, const QString& localPart ) const;
00125     int length() const;
00126     int count() const;
00127     QString localName( int index ) const;
00128     QString qName( int index ) const;
00129     QString uri( int index ) const;
00130     QString type( int index ) const;
00131     QString type( const QString& qName ) const;
00132     QString type( const QString& uri, const QString& localName ) const;
00133     QString value( int index ) const;
00134     QString value( const QString& qName ) const;
00135     QString value( const QString& uri, const QString& localName ) const;
00136 
00137     void clear();
00138     void append( const QString &qName, const QString &uri, const QString &localPart, const QString &value );
00139 
00140 private:
00141     QStringList qnameList;
00142     QStringList uriList;
00143     QStringList localnameList;
00144     QStringList valueList;
00145 
00146     QXmlAttributesPrivate *d;
00147 };
00148 
00149 //
00150 // SAX Input Source
00151 //
00152 
00153 class QM_EXPORT_XML QXmlInputSource
00154 {
00155 public:
00156     QXmlInputSource();
00157     QXmlInputSource( QIODevice *dev );
00158     QXmlInputSource( QFile& file ); // obsolete
00159     QXmlInputSource( QTextStream& stream ); // obsolete
00160     virtual ~QXmlInputSource();
00161 
00162     virtual void setData( const QString& dat );
00163     virtual void setData( const QByteArray& dat );
00164     virtual void fetchData();
00165     virtual QString data();
00166     virtual QChar next();
00167     virtual void reset();
00168 
00169     static const QChar EndOfData;
00170     static const QChar EndOfDocument;
00171 
00172 protected:
00173     virtual QString fromRawData( const QByteArray &data, bool beginning = FALSE );
00174 
00175 private:
00176     void init();
00177 
00178     QIODevice *inputDevice;
00179     QTextStream *inputStream;
00180 
00181     QString str;
00182     const QChar *unicode;
00183     int pos;
00184     int length;
00185     bool nextReturnedEndOfData;
00186     QTextDecoder *encMapper;
00187 
00188     QXmlInputSourcePrivate *d;
00189 };
00190 
00191 //
00192 // SAX Exception Classes
00193 //
00194 
00195 class QM_EXPORT_XML QXmlParseException
00196 {
00197 public:
00198     QXmlParseException( const QString& name="", int c=-1, int l=-1, const QString& p="", const QString& s="" )
00199         : msg( name ), column( c ), line( l ), pub( p ), sys( s )
00200     { }
00201 
00202     int columnNumber() const;
00203     int lineNumber() const;
00204     QString publicId() const;
00205     QString systemId() const;
00206     QString message() const;
00207 
00208 private:
00209     QString msg;
00210     int column;
00211     int line;
00212     QString pub;
00213     QString sys;
00214 
00215     QXmlParseExceptionPrivate *d;
00216 };
00217 
00218 
00219 //
00220 // XML Reader
00221 //
00222 
00223 class QM_EXPORT_XML QXmlReader
00224 {
00225 public:
00226     virtual bool feature( const QString& name, bool *ok = 0 ) const = 0;
00227     virtual void setFeature( const QString& name, bool value ) = 0;
00228     virtual bool hasFeature( const QString& name ) const = 0;
00229     virtual void* property( const QString& name, bool *ok = 0 ) const = 0;
00230     virtual void setProperty( const QString& name, void* value ) = 0;
00231     virtual bool hasProperty( const QString& name ) const = 0;
00232     virtual void setEntityResolver( QXmlEntityResolver* handler ) = 0;
00233     virtual QXmlEntityResolver* entityResolver() const = 0;
00234     virtual void setDTDHandler( QXmlDTDHandler* handler ) = 0;
00235     virtual QXmlDTDHandler* DTDHandler() const = 0;
00236     virtual void setContentHandler( QXmlContentHandler* handler ) = 0;
00237     virtual QXmlContentHandler* contentHandler() const = 0;
00238     virtual void setErrorHandler( QXmlErrorHandler* handler ) = 0;
00239     virtual QXmlErrorHandler* errorHandler() const = 0;
00240     virtual void setLexicalHandler( QXmlLexicalHandler* handler ) = 0;
00241     virtual QXmlLexicalHandler* lexicalHandler() const = 0;
00242     virtual void setDeclHandler( QXmlDeclHandler* handler ) = 0;
00243     virtual QXmlDeclHandler* declHandler() const = 0;
00244     virtual bool parse( const QXmlInputSource& input ) = 0;
00245     virtual bool parse( const QXmlInputSource* input ) = 0;
00246 };
00247 
00248 class QM_EXPORT_XML QXmlSimpleReader : public QXmlReader
00249 {
00250 public:
00251     QXmlSimpleReader();
00252     virtual ~QXmlSimpleReader();
00253 
00254     bool feature( const QString& name, bool *ok = 0 ) const;
00255     void setFeature( const QString& name, bool value );
00256     bool hasFeature( const QString& name ) const;
00257 
00258     void* property( const QString& name, bool *ok = 0 ) const;
00259     void setProperty( const QString& name, void* value );
00260     bool hasProperty( const QString& name ) const;
00261 
00262     void setEntityResolver( QXmlEntityResolver* handler );
00263     QXmlEntityResolver* entityResolver() const;
00264     void setDTDHandler( QXmlDTDHandler* handler );
00265     QXmlDTDHandler* DTDHandler() const;
00266     void setContentHandler( QXmlContentHandler* handler );
00267     QXmlContentHandler* contentHandler() const;
00268     void setErrorHandler( QXmlErrorHandler* handler );
00269     QXmlErrorHandler* errorHandler() const;
00270     void setLexicalHandler( QXmlLexicalHandler* handler );
00271     QXmlLexicalHandler* lexicalHandler() const;
00272     void setDeclHandler( QXmlDeclHandler* handler );
00273     QXmlDeclHandler* declHandler() const;
00274 
00275     bool parse( const QXmlInputSource& input );
00276     bool parse( const QXmlInputSource* input );
00277     virtual bool parse( const QXmlInputSource* input, bool incremental );
00278     virtual bool parseContinue();
00279 
00280 private:
00281     // variables
00282     QXmlContentHandler *contentHnd;
00283     QXmlErrorHandler   *errorHnd;
00284     QXmlDTDHandler     *dtdHnd;
00285     QXmlEntityResolver *entityRes;
00286     QXmlLexicalHandler *lexicalHnd;
00287     QXmlDeclHandler    *declHnd;
00288 
00289     QXmlInputSource *inputSource;
00290 
00291     QChar c; // the character at reading position
00292     int   lineNr; // number of line
00293     int   columnNr; // position in line
00294 
00295     int     nameArrayPos;
00296     QChar   nameArray[256]; // only used for names
00297     QString nameValue; // only used for names
00298     int     refArrayPos;
00299     QChar   refArray[256]; // only used for references
00300     QString refValue; // only used for references
00301     int     stringArrayPos;
00302     QChar   stringArray[256]; // used for any other strings that are parsed
00303     QString stringValue; // used for any other strings that are parsed
00304 
00305     QXmlSimpleReaderPrivate* d;
00306 
00307     const QString &string();
00308     void stringClear();
00309     inline void stringAddC() { stringAddC(c); }
00310     void stringAddC(const QChar&);
00311     const QString& name();
00312     void nameClear();
00313     inline void nameAddC() { nameAddC(c); }
00314     void nameAddC(const QChar&);
00315     const QString& ref();
00316     void refClear();
00317     inline void refAddC() { refAddC(c); }
00318     void refAddC(const QChar&);
00319 
00320     // used by parseReference() and parsePEReference()
00321     enum EntityRecognitionContext { InContent, InAttributeValue, InEntityValue, InDTD };
00322 
00323     // private functions
00324     bool eat_ws();
00325     bool next_eat_ws();
00326 
00327     void next();
00328     bool atEnd();
00329 
00330     void init( const QXmlInputSource* i );
00331     void initData();
00332 
00333     bool entityExist( const QString& ) const;
00334 
00335     bool parseBeginOrContinue( int state, bool incremental );
00336 
00337     bool parseProlog();
00338     bool parseElement();
00339     bool processElementEmptyTag();
00340     bool processElementETagBegin2();
00341     bool processElementAttribute();
00342     bool parseMisc();
00343     bool parseContent();
00344 
00345     bool parsePI();
00346     bool parseDoctype();
00347     bool parseComment();
00348 
00349     bool parseName();
00350     bool parseNmtoken();
00351     bool parseAttribute();
00352     bool parseReference();
00353     bool processReference();
00354 
00355     bool parseExternalID();
00356     bool parsePEReference();
00357     bool parseMarkupdecl();
00358     bool parseAttlistDecl();
00359     bool parseAttType();
00360     bool parseAttValue();
00361     bool parseElementDecl();
00362     bool parseNotationDecl();
00363     bool parseChoiceSeq();
00364     bool parseEntityDecl();
00365     bool parseEntityValue();
00366 
00367     bool parseString();
00368 
00369     bool insertXmlRef( const QString&, const QString&, bool );
00370 
00371     bool reportEndEntities();
00372     void reportParseError( const QString& error );
00373 
00374     typedef bool (QXmlSimpleReader::*ParseFunction) ();
00375     void unexpectedEof( ParseFunction where, int state );
00376     void parseFailed( ParseFunction where, int state );
00377     void pushParseState( ParseFunction function, int state );
00378 
00379     void setUndefEntityInAttrHack(bool b);
00380 
00381     friend class QXmlSimpleReaderPrivate;
00382     friend class QXmlSimpleReaderLocator;
00383     friend class QDomDocumentPrivate;
00384 };
00385 
00386 //
00387 // SAX Locator
00388 //
00389 
00390 class QM_EXPORT_XML QXmlLocator
00391 {
00392 public:
00393     QXmlLocator();
00394     virtual ~QXmlLocator();
00395 
00396     virtual int columnNumber() = 0;
00397     virtual int lineNumber() = 0;
00398 //    QString getPublicId()
00399 //    QString getSystemId()
00400 };
00401 
00402 //
00403 // SAX handler classes
00404 //
00405 
00406 class QM_EXPORT_XML QXmlContentHandler
00407 {
00408 public:
00409     virtual void setDocumentLocator( QXmlLocator* locator ) = 0;
00410     virtual bool startDocument() = 0;
00411     virtual bool endDocument() = 0;
00412     virtual bool startPrefixMapping( const QString& prefix, const QString& uri ) = 0;
00413     virtual bool endPrefixMapping( const QString& prefix ) = 0;
00414     virtual bool startElement( const QString& namespaceURI, const QString& localName, const QString& qName, const QXmlAttributes& atts ) = 0;
00415     virtual bool endElement( const QString& namespaceURI, const QString& localName, const QString& qName ) = 0;
00416     virtual bool characters( const QString& ch ) = 0;
00417     virtual bool ignorableWhitespace( const QString& ch ) = 0;
00418     virtual bool processingInstruction( const QString& target, const QString& data ) = 0;
00419     virtual bool skippedEntity( const QString& name ) = 0;
00420     virtual QString errorString() = 0;
00421 };
00422 
00423 class QM_EXPORT_XML QXmlErrorHandler
00424 {
00425 public:
00426     virtual bool warning( const QXmlParseException& exception ) = 0;
00427     virtual bool error( const QXmlParseException& exception ) = 0;
00428     virtual bool fatalError( const QXmlParseException& exception ) = 0;
00429     virtual QString errorString() = 0;
00430 };
00431 
00432 class QM_EXPORT_XML QXmlDTDHandler
00433 {
00434 public:
00435     virtual bool notationDecl( const QString& name, const QString& publicId, const QString& systemId ) = 0;
00436     virtual bool unparsedEntityDecl( const QString& name, const QString& publicId, const QString& systemId, const QString& notationName ) = 0;
00437     virtual QString errorString() = 0;
00438 };
00439 
00440 class QM_EXPORT_XML QXmlEntityResolver
00441 {
00442 public:
00443     virtual bool resolveEntity( const QString& publicId, const QString& systemId, QXmlInputSource*& ret ) = 0;
00444     virtual QString errorString() = 0;
00445 };
00446 
00447 class QM_EXPORT_XML QXmlLexicalHandler
00448 {
00449 public:
00450     virtual bool startDTD( const QString& name, const QString& publicId, const QString& systemId ) = 0;
00451     virtual bool endDTD() = 0;
00452     virtual bool startEntity( const QString& name ) = 0;
00453     virtual bool endEntity( const QString& name ) = 0;
00454     virtual bool startCDATA() = 0;
00455     virtual bool endCDATA() = 0;
00456     virtual bool comment( const QString& ch ) = 0;
00457     virtual QString errorString() = 0;
00458 };
00459 
00460 class QM_EXPORT_XML QXmlDeclHandler
00461 {
00462 public:
00463     virtual bool attributeDecl( const QString& eName, const QString& aName, const QString& type, const QString& valueDefault, const QString& value ) = 0;
00464     virtual bool internalEntityDecl( const QString& name, const QString& value ) = 0;
00465     virtual bool externalEntityDecl( const QString& name, const QString& publicId, const QString& systemId ) = 0;
00466     virtual QString errorString() = 0;
00467 };
00468 
00469 
00470 class QM_EXPORT_XML QXmlDefaultHandler : public QXmlContentHandler, public QXmlErrorHandler, public QXmlDTDHandler, public QXmlEntityResolver, public QXmlLexicalHandler, public QXmlDeclHandler
00471 {
00472 public:
00473     QXmlDefaultHandler() { }
00474     virtual ~QXmlDefaultHandler() { }
00475 
00476     void setDocumentLocator( QXmlLocator* locator );
00477     bool startDocument();
00478     bool endDocument();
00479     bool startPrefixMapping( const QString& prefix, const QString& uri );
00480     bool endPrefixMapping( const QString& prefix );
00481     bool startElement( const QString& namespaceURI, const QString& localName, const QString& qName, const QXmlAttributes& atts );
00482     bool endElement( const QString& namespaceURI, const QString& localName, const QString& qName );
00483     bool characters( const QString& ch );
00484     bool ignorableWhitespace( const QString& ch );
00485     bool processingInstruction( const QString& target, const QString& data );
00486     bool skippedEntity( const QString& name );
00487 
00488     bool warning( const QXmlParseException& exception );
00489     bool error( const QXmlParseException& exception );
00490     bool fatalError( const QXmlParseException& exception );
00491 
00492     bool notationDecl( const QString& name, const QString& publicId, const QString& systemId );
00493     bool unparsedEntityDecl( const QString& name, const QString& publicId, const QString& systemId, const QString& notationName );
00494 
00495     bool resolveEntity( const QString& publicId, const QString& systemId, QXmlInputSource*& ret );
00496 
00497     bool startDTD( const QString& name, const QString& publicId, const QString& systemId );
00498     bool endDTD();
00499     bool startEntity( const QString& name );
00500     bool endEntity( const QString& name );
00501     bool startCDATA();
00502     bool endCDATA();
00503     bool comment( const QString& ch );
00504 
00505     bool attributeDecl( const QString& eName, const QString& aName, const QString& type, const QString& valueDefault, const QString& value );
00506     bool internalEntityDecl( const QString& name, const QString& value );
00507     bool externalEntityDecl( const QString& name, const QString& publicId, const QString& systemId );
00508 
00509     QString errorString();
00510 
00511 private:
00512     QXmlDefaultHandlerPrivate *d;
00513 };
00514 
00515 
00516 //
00517 // inlines
00518 //
00519 
00520 inline bool QXmlSimpleReader::atEnd()
00521 { return (c.unicode()|0x0001) == 0xffff; }
00522 inline int QXmlAttributes::count() const
00523 { return length(); }
00524 
00525 
00526 #endif //QT_NO_XML
00527 
00528 #endif
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'