Chameleon

Chameleon Svn Source Tree

Root/branches/xZenu/src/util/doxygen/qtools/qxml.h

Source at commit 1322 created 9 years 5 months ago.
By meklort, Add doxygen to utils folder
1/****************************************************************************
2**
3**
4** Definition of QXmlSimpleReader and related classes.
5**
6** Created : 000518
7**
8** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
9**
10** This file is part of the XML module of the Qt GUI Toolkit.
11**
12** This file may be distributed under the terms of the Q Public License
13** as defined by Trolltech AS of Norway and appearing in the file
14** LICENSE.QPL included in the packaging of this file.
15**
16** This file may be distributed and/or modified under the terms of the
17** GNU General Public License version 2 as published by the Free Software
18** Foundation and appearing in the file LICENSE.GPL included in the
19** packaging of this file.
20**
21** Licensees holding valid Qt Enterprise Edition licenses may use this
22** file in accordance with the Qt Commercial License Agreement provided
23** with the Software.
24**
25** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
26** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27**
28** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
29** information about Qt Commercial License Agreements.
30** See http://www.trolltech.com/qpl/ for QPL licensing information.
31** See http://www.trolltech.com/gpl/ for GPL licensing information.
32**
33** Contact info@trolltech.com if any conditions of this licensing are
34** not clear to you.
35**
36**********************************************************************/
37
38#ifndef QXML_H
39#define QXML_H
40
41#include <qmodules.h>
42
43#if !defined(QT_MODULE_XML)
44#define QM_EXPORT
45#else
46#define QM_EXPORT Q_EXPORT
47#endif
48
49#ifndef QT_H
50#include <qtextstream.h>
51#include <qfile.h>
52#include <qstring.h>
53#include <qstringlist.h>
54#include <qvaluestack.h>
55#include <qmap.h>
56#endif // QT_H
57
58#ifndef QT_NO_XML
59
60class QXmlNamespaceSupport;
61class QXmlAttributes;
62class QXmlContentHandler;
63class QXmlDefaultHandler;
64class QXmlDTDHandler;
65class QXmlEntityResolver;
66class QXmlErrorHandler;
67class QXmlLexicalHandler;
68class QXmlDeclHandler;
69class QXmlInputSource;
70class QXmlLocator;
71class QXmlNamespaceSupport;
72class QXmlParseException;
73
74class QXmlReader;
75class QXmlSimpleReader;
76
77class QXmlSimpleReaderPrivate;
78class QXmlNamespaceSupportPrivate;
79class QXmlAttributesPrivate;
80class QXmlInputSourcePrivate;
81class QXmlParseExceptionPrivate;
82class QXmlLocatorPrivate;
83class QXmlDefaultHandlerPrivate;
84
85
86//
87// SAX Namespace Support
88//
89
90#if defined(Q_TEMPLATEDLL)
91// MOC_SKIP_BEGIN
92template class QM_EXPORT QMap<QString, QString>;
93template class QM_EXPORT QValueStack<QMap<QString, QString> >;
94template class QM_EXPORT QValueStack<QString>;
95// MOC_SKIP_END
96#endif
97
98class QM_EXPORT QXmlNamespaceSupport
99{
100public:
101 QXmlNamespaceSupport();
102 ~QXmlNamespaceSupport();
103
104 void setPrefix( const QString&, const QString& );
105
106 QString prefix( const QString& ) const;
107 QString uri( const QString& ) const;
108 void splitName( const QString&, QString&, QString& ) const;
109 void processName( const QString&, bool, QString&, QString& ) const;
110 QStringList prefixes() const;
111 QStringList prefixes( const QString& ) const;
112
113 void pushContext();
114 void popContext();
115 void reset();
116private:
117 QValueStack<QMap<QString, QString> > nsStack;
118 QMap<QString, QString> ns;
119
120 QXmlNamespaceSupportPrivate *d;
121};
122
123
124//
125// SAX Attributes
126//
127
128class QM_EXPORT QXmlAttributes
129{
130public:
131 QXmlAttributes() {}
132 virtual ~QXmlAttributes() {}
133
134 int index( const QString& qName ) const;
135 int index( const QString& uri, const QString& localPart ) const;
136 int length() const;
137 QString localName( int index ) const;
138 QString qName( int index ) const;
139 QString uri( int index ) const;
140 QString type( int index ) const;
141 QString type( const QString& qName ) const;
142 QString type( const QString& uri, const QString& localName ) const;
143 QString value( int index ) const;
144 QString value( const QString& qName ) const;
145 QString value( const QString& uri, const QString& localName ) const;
146
147private:
148 QStringList qnameList;
149 QStringList uriList;
150 QStringList localnameList;
151 QStringList valueList;
152
153 QXmlAttributesPrivate *d;
154
155 friend class QXmlSimpleReader;
156};
157
158//
159// SAX Input Source
160//
161
162class QM_EXPORT QXmlInputSource
163{
164public:
165 QXmlInputSource();
166 QXmlInputSource( QTextStream& stream );
167 QXmlInputSource( QFile& file );
168 virtual ~QXmlInputSource();
169
170 virtual const QString& data() const;
171 virtual void setData( const QString& d );
172
173private:
174 void readInput( QByteArray& rawData );
175
176 QString input;
177
178 QXmlInputSourcePrivate *d;
179};
180
181//
182// SAX Exception Classes
183//
184
185class QM_EXPORT QXmlParseException
186{
187public:
188 QXmlParseException( const QString& name="", int c=-1, int l=-1, const QString& p="", const QString& s="" )
189: msg( name ), column( c ), line( l ), pub( p ), sys( s )
190 { }
191
192 int columnNumber() const;
193 int lineNumber() const;
194 QString publicId() const;
195 QString systemId() const;
196 QString message() const;
197
198private:
199 QString msg;
200 int column;
201 int line;
202 QString pub;
203 QString sys;
204
205 QXmlParseExceptionPrivate *d;
206};
207
208
209//
210// XML Reader
211//
212
213class QM_EXPORT QXmlReader
214{
215public:
216 virtual ~QXmlReader() {}
217 virtual bool feature( const QString& name, bool *ok = 0 ) const = 0;
218 virtual void setFeature( const QString& name, bool value ) = 0;
219 virtual bool hasFeature( const QString& name ) const = 0;
220 virtual void* property( const QString& name, bool *ok = 0 ) const = 0;
221 virtual void setProperty( const QString& name, void* value ) = 0;
222 virtual bool hasProperty( const QString& name ) const = 0;
223 virtual void setEntityResolver( QXmlEntityResolver* handler ) = 0;
224 virtual QXmlEntityResolver* entityResolver() const = 0;
225 virtual void setDTDHandler( QXmlDTDHandler* handler ) = 0;
226 virtual QXmlDTDHandler* DTDHandler() const = 0;
227 virtual void setContentHandler( QXmlContentHandler* handler ) = 0;
228 virtual QXmlContentHandler* contentHandler() const = 0;
229 virtual void setErrorHandler( QXmlErrorHandler* handler ) = 0;
230 virtual QXmlErrorHandler* errorHandler() const = 0;
231 virtual void setLexicalHandler( QXmlLexicalHandler* handler ) = 0;
232 virtual QXmlLexicalHandler* lexicalHandler() const = 0;
233 virtual void setDeclHandler( QXmlDeclHandler* handler ) = 0;
234 virtual QXmlDeclHandler* declHandler() const = 0;
235 virtual bool parse( const QXmlInputSource& input ) = 0;
236};
237
238class QM_EXPORT QXmlSimpleReader : public QXmlReader
239{
240public:
241 QXmlSimpleReader();
242 virtual ~QXmlSimpleReader();
243
244 bool feature( const QString& name, bool *ok = 0 ) const;
245 void setFeature( const QString& name, bool value );
246 bool hasFeature( const QString& name ) const;
247
248 void* property( const QString& name, bool *ok = 0 ) const;
249 void setProperty( const QString& name, void* value );
250 bool hasProperty( const QString& name ) const;
251
252 void setEntityResolver( QXmlEntityResolver* handler );
253 QXmlEntityResolver* entityResolver() const;
254 void setDTDHandler( QXmlDTDHandler* handler );
255 QXmlDTDHandler* DTDHandler() const;
256 void setContentHandler( QXmlContentHandler* handler );
257 QXmlContentHandler* contentHandler() const;
258 void setErrorHandler( QXmlErrorHandler* handler );
259 QXmlErrorHandler* errorHandler() const;
260 void setLexicalHandler( QXmlLexicalHandler* handler );
261 QXmlLexicalHandler* lexicalHandler() const;
262 void setDeclHandler( QXmlDeclHandler* handler );
263 QXmlDeclHandler* declHandler() const;
264
265 bool parse( const QXmlInputSource& input );
266
267private:
268 // variables
269 QXmlContentHandler* contentHnd;
270 QXmlErrorHandler* errorHnd;
271 QXmlDTDHandler* dtdHnd;
272 QXmlEntityResolver* entityRes;
273 QXmlLexicalHandler* lexicalHnd;
274 QXmlDeclHandler* declHnd;
275
276 QChar c; // the character at reading position
277 int lineNr; // number of line
278 int columnNr; // position in line
279 int pos; // position in string
280
281 int namePos;
282 QChar nameArray[256]; // only used for names
283 QString nameValue; // only used for names
284 int refPos;
285 QChar refArray[256]; // only used for references
286 QString refValue; // only used for references
287 int stringPos;
288 QChar stringArray[256]; // used for any other strings that are parsed
289 QString stringValue; // used for any other strings that are parsed
290
291 QString xml;
292 int xmlLength;
293 QString xmlRef; // used for parsing of entity references
294
295 QValueStack<QString> tags;
296
297 QXmlSimpleReaderPrivate* d;
298
299 static const QChar QEOF;
300
301 // inlines
302 virtual bool is_S( const QChar& );
303 virtual bool is_Letter( const QChar& );
304 virtual bool is_NameBeginning( const QChar& );
305 virtual bool is_Digit( const QChar& );
306 virtual bool is_CombiningChar( const QChar& );
307 virtual bool is_Extender( const QChar& );
308 virtual bool is_NameChar( const QChar& );
309
310 QString& string();
311 void stringClear();
312 void stringAddC();
313 void stringAddC(const QChar&);
314 QString& name();
315 void nameClear();
316 void nameAddC();
317 void nameAddC(const QChar&);
318 QString& ref();
319 void refClear();
320 void refAddC();
321 void refAddC(const QChar&);
322
323 // used by parseReference() and parsePEReference()
324 enum EntityRecognitionContext { InContent, InAttributeValue, InEntityValue, InDTD };
325
326 // private functions
327 void eat_ws();
328 void next_eat_ws();
329
330 void next();
331 bool atEnd();
332
333 void init( const QXmlInputSource& i );
334
335 bool entityExist( const QString& ) const;
336
337 bool parseProlog();
338 bool parseElement();
339 bool parseElementEmptyTag( bool &t, QString &uri, QString &lname );
340 bool parseElementETagBegin2();
341 bool parseElementAttribute( QString &prefix, QString &uri, QString &lname );
342 bool parseMisc();
343 bool parseContent();
344
345 bool parsePI(bool xmldecl=FALSE);
346 bool parseDoctype();
347 bool parseComment();
348
349 bool parseName( bool useRef=FALSE );
350 bool parseNmtoken();
351 bool parseAttribute();
352 bool parseReference( bool &charDataRead, EntityRecognitionContext context );
353 bool processReference( bool &charDataRead, EntityRecognitionContext context );
354
355 bool parseExternalID( bool allowPublicID = FALSE );
356 bool parsePEReference( EntityRecognitionContext context );
357 bool parseMarkupdecl();
358 bool parseAttlistDecl();
359 bool parseAttType();
360 bool parseAttValue();
361 bool parseElementDecl();
362 bool parseNotationDecl();
363 bool parseChoiceSeq();
364 bool parseEntityDecl();
365 bool parseEntityValue();
366
367 bool parseString( const QString& s );
368
369 void reportParseError();
370
371 friend class QXmlSimpleReaderPrivate;
372 friend class QXmlLocator;
373};
374
375//
376// SAX Locator
377//
378
379class QM_EXPORT QXmlLocator
380{
381public:
382 QXmlLocator( QXmlSimpleReader* parent )
383 { reader = parent; }
384 ~QXmlLocator()
385 { }
386
387 int columnNumber();
388 int lineNumber();
389// QString getPublicId()
390// QString getSystemId()
391
392private:
393 QXmlSimpleReader* reader;
394
395 QXmlLocatorPrivate *d;
396};
397
398//
399// SAX handler classes
400//
401
402class QM_EXPORT QXmlContentHandler
403{
404public:
405 virtual ~QXmlContentHandler() {}
406 virtual void setDocumentLocator( QXmlLocator* locator ) = 0;
407 virtual bool startDocument() = 0;
408 virtual bool endDocument() = 0;
409 virtual bool startPrefixMapping( const QString& prefix, const QString& uri ) = 0;
410 virtual bool endPrefixMapping( const QString& prefix ) = 0;
411 virtual bool startElement( const QString& namespaceURI, const QString& localName, const QString& qName, const QXmlAttributes& atts ) = 0;
412 virtual bool endElement( const QString& namespaceURI, const QString& localName, const QString& qName ) = 0;
413 virtual bool characters( const QString& ch ) = 0;
414 virtual bool ignorableWhitespace( const QString& ch ) = 0;
415 virtual bool processingInstruction( const QString& target, const QString& data ) = 0;
416 virtual bool skippedEntity( const QString& name ) = 0;
417 virtual QString errorString() = 0;
418};
419
420class QM_EXPORT QXmlErrorHandler
421{
422public:
423 virtual ~QXmlErrorHandler() {}
424 virtual bool warning( const QXmlParseException& exception ) = 0;
425 virtual bool error( const QXmlParseException& exception ) = 0;
426 virtual bool fatalError( const QXmlParseException& exception ) = 0;
427 virtual QString errorString() = 0;
428};
429
430class QM_EXPORT QXmlDTDHandler
431{
432public:
433 virtual ~QXmlDTDHandler() {}
434 virtual bool notationDecl( const QString& name, const QString& publicId, const QString& systemId ) = 0;
435 virtual bool unparsedEntityDecl( const QString& name, const QString& publicId, const QString& systemId, const QString& notationName ) = 0;
436 virtual QString errorString() = 0;
437};
438
439class QM_EXPORT QXmlEntityResolver
440{
441public:
442 virtual ~QXmlEntityResolver() {}
443 virtual bool resolveEntity( const QString& publicId, const QString& systemId, QXmlInputSource* ret ) = 0;
444 virtual QString errorString() = 0;
445};
446
447class QM_EXPORT QXmlLexicalHandler
448{
449public:
450 virtual ~QXmlLexicalHandler() {}
451 virtual bool startDTD( const QString& name, const QString& publicId, const QString& systemId ) = 0;
452 virtual bool endDTD() = 0;
453// virtual bool startEntity( const QString& name ) = 0;
454// virtual bool endEntity( const QString& name ) = 0;
455 virtual bool startCDATA() = 0;
456 virtual bool endCDATA() = 0;
457 virtual bool comment( const QString& ch ) = 0;
458 virtual QString errorString() = 0;
459};
460
461class QM_EXPORT QXmlDeclHandler
462{
463public:
464 virtual ~QXmlDeclHandler() {}
465 virtual bool attributeDecl( const QString& eName, const QString& aName, const QString& type, const QString& valueDefault, const QString& value ) = 0;
466 virtual bool internalEntityDecl( const QString& name, const QString& value ) = 0;
467 virtual bool externalEntityDecl( const QString& name, const QString& publicId, const QString& systemId ) = 0;
468 virtual QString errorString() = 0;
469};
470
471
472class QM_EXPORT QXmlDefaultHandler : public QXmlContentHandler, public QXmlErrorHandler, public QXmlDTDHandler, public QXmlEntityResolver, public QXmlLexicalHandler, public QXmlDeclHandler
473{
474public:
475 QXmlDefaultHandler() { }
476 virtual ~QXmlDefaultHandler() { }
477
478 void setDocumentLocator( QXmlLocator* locator );
479 bool startDocument();
480 bool endDocument();
481 bool startPrefixMapping( const QString& prefix, const QString& uri );
482 bool endPrefixMapping( const QString& prefix );
483 bool startElement( const QString& namespaceURI, const QString& localName, const QString& qName, const QXmlAttributes& atts );
484 bool endElement( const QString& namespaceURI, const QString& localName, const QString& qName );
485 bool characters( const QString& ch );
486 bool ignorableWhitespace( const QString& ch );
487 bool processingInstruction( const QString& target, const QString& data );
488 bool skippedEntity( const QString& name );
489
490 bool warning( const QXmlParseException& exception );
491 bool error( const QXmlParseException& exception );
492 bool fatalError( const QXmlParseException& exception );
493
494 bool notationDecl( const QString& name, const QString& publicId, const QString& systemId );
495 bool unparsedEntityDecl( const QString& name, const QString& publicId, const QString& systemId, const QString& notationName );
496
497 bool resolveEntity( const QString& publicId, const QString& systemId, QXmlInputSource* ret );
498
499 bool startDTD( const QString& name, const QString& publicId, const QString& systemId );
500 bool endDTD();
501// bool startEntity( const QString& name );
502// bool endEntity( const QString& name );
503 bool startCDATA();
504 bool endCDATA();
505 bool comment( const QString& ch );
506
507 bool attributeDecl( const QString& eName, const QString& aName, const QString& type, const QString& valueDefault, const QString& value );
508 bool internalEntityDecl( const QString& name, const QString& value );
509 bool externalEntityDecl( const QString& name, const QString& publicId, const QString& systemId );
510
511 QString errorString();
512
513private:
514 QXmlDefaultHandlerPrivate *d;
515};
516
517#ifdef _WS_QWS_
518#ifdef QT_XML_CPP
519#define inline
520#else
521#define QT_NO_XML_INLINE
522#endif
523#endif
524
525#ifndef QT_NO_XML_INLINE
526//
527// inlines
528//
529
530inline bool QXmlSimpleReader::is_S(const QChar& ch)
531{ return ch==' ' || ch=='\t' || ch=='\n' || ch=='\r'; }
532
533inline bool QXmlSimpleReader::is_Letter( const QChar& ch )
534{ return ch.isLetter(); }
535
536inline bool QXmlSimpleReader::is_NameBeginning( const QChar& ch )
537{ return ch=='_' || ch==':' || ch.isLetter(); }
538
539inline bool QXmlSimpleReader::is_Digit( const QChar& ch )
540{ return ch.isDigit(); }
541
542inline bool QXmlSimpleReader::is_CombiningChar( const QChar& )
543{ return FALSE; }
544
545inline bool QXmlSimpleReader::is_Extender( const QChar& )
546{ return FALSE; }
547
548inline bool QXmlSimpleReader::is_NameChar( const QChar& ch )
549{
550 return ch=='.' || ch=='-' || ch=='_' || ch==':' ||
551is_Letter(ch) || is_Digit(ch) ||
552is_CombiningChar(ch) || is_Extender(ch);
553}
554
555inline void QXmlSimpleReader::next()
556{
557 if ( !xmlRef.isEmpty() ) {
558c = xmlRef[0];
559xmlRef.remove( 0, 1 );
560 } else {
561if ( c=='\n' || c=='\r' ) {
562 lineNr++;
563 columnNr = -1;
564}
565if ( pos >= xmlLength ) {
566 c = QEOF;
567} else {
568 c = xml[pos];
569 columnNr++;
570 pos++;
571}
572 }
573}
574
575inline bool QXmlSimpleReader::atEnd()
576{ return c == QEOF; }
577
578inline void QXmlSimpleReader::eat_ws()
579{ while ( !atEnd() && is_S(c) ) next(); }
580
581inline void QXmlSimpleReader::next_eat_ws()
582{ next(); eat_ws(); }
583
584
585// use buffers instead of QString::operator+= when single characters are read
586inline QString& QXmlSimpleReader::string()
587{
588 stringValue += QString( stringArray, stringPos );
589 stringPos = 0;
590 return stringValue;
591}
592inline QString& QXmlSimpleReader::name()
593{
594 nameValue += QString( nameArray, namePos );
595 namePos = 0;
596 return nameValue;
597}
598inline QString& QXmlSimpleReader::ref()
599{
600 refValue += QString( refArray, refPos );
601 refPos = 0;
602 return refValue;
603}
604
605inline void QXmlSimpleReader::stringClear()
606{ stringValue = ""; stringPos = 0; }
607inline void QXmlSimpleReader::nameClear()
608{ nameValue = ""; namePos = 0; }
609inline void QXmlSimpleReader::refClear()
610{ refValue = ""; refPos = 0; }
611
612inline void QXmlSimpleReader::stringAddC()
613{
614 if ( stringPos >= 256 ) {
615stringValue += QString( stringArray, stringPos );
616stringPos = 0;
617 }
618 stringArray[stringPos++] = c;
619}
620inline void QXmlSimpleReader::nameAddC()
621{
622 if ( namePos >= 256 ) {
623nameValue += QString( nameArray, namePos );
624namePos = 0;
625 }
626 nameArray[namePos++] = c;
627}
628inline void QXmlSimpleReader::refAddC()
629{
630 if ( refPos >= 256 ) {
631refValue += QString( refArray, refPos );
632refPos = 0;
633 }
634 refArray[refPos++] = c;
635}
636
637inline void QXmlSimpleReader::stringAddC(const QChar& ch)
638{
639 if ( stringPos >= 256 ) {
640stringValue += QString( stringArray, stringPos );
641stringPos = 0;
642 }
643 stringArray[stringPos++] = ch;
644}
645inline void QXmlSimpleReader::nameAddC(const QChar& ch)
646{
647 if ( namePos >= 256 ) {
648nameValue += QString( nameArray, namePos );
649namePos = 0;
650 }
651 nameArray[namePos++] = ch;
652}
653inline void QXmlSimpleReader::refAddC(const QChar& ch)
654{
655 if ( refPos >= 256 ) {
656refValue += QString( refArray, refPos );
657refPos = 0;
658 }
659 refArray[refPos++] = ch;
660}
661#endif
662
663#ifdef _WS_QWS_
664#ifdef QT_XML_CPP
665#undef inline
666#endif
667#endif
668
669#endif //QT_NO_XML
670
671#endif
672

Archive Download this file

Revision: 1322