koxmlwriter.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef XMLWRITER_H
00021 #define XMLWRITER_H
00022
00023 #include <qstring.h>
00024 #include <qvaluestack.h>
00025 #include <qmap.h>
00026 #include <koffice_export.h>
00027
00028 class QIODevice;
00029
00036 class KOSTORE_EXPORT KoXmlWriter
00037 {
00038 public:
00043 KoXmlWriter( QIODevice* dev, int indentLevel = 0 );
00044
00046 ~KoXmlWriter();
00047
00048 QIODevice *device() const { return m_dev; }
00049
00057 void startDocument( const char* rootElemName, const char* publicId = 0, const char* systemId = 0 );
00058
00060 void endDocument();
00061
00070 void startElement( const char* tagName, bool indentInside = true );
00071
00076 inline void addAttribute( const char* attrName, const QString& value ) {
00077 addAttribute( attrName, value.utf8() );
00078 }
00082 inline void addAttribute( const char* attrName, int value ) {
00083 QCString str;
00084 str.setNum( value );
00085 addAttribute( attrName, str.data() );
00086 }
00090 inline void addAttribute( const char* attrName, uint value ) {
00091 QCString str;
00092 str.setNum( value );
00093 addAttribute( attrName, str.data() );
00094 }
00100 void addAttribute( const char* attrName, double value );
00107 void addAttributePt( const char* attrName, double value );
00108
00110 inline void addAttribute( const char* attrName, const QCString& value ) {
00111 addAttribute( attrName, value.data() );
00112 }
00116 void addAttribute( const char* attrName, const char* value );
00121 void endElement();
00126 inline void addTextNode( const QString& str ) {
00127 addTextNode( str.utf8() );
00128 }
00130 inline void addTextNode( const QCString& cstr ) {
00131 addTextNode( cstr.data() );
00132 }
00140 void addTextNode( const char* cstr );
00141
00151 void addProcessingInstruction( const char* cstr );
00152
00159 void addCompleteElement( const char* cstr );
00160
00168 void addCompleteElement( QIODevice* dev );
00169
00170
00178 void addManifestEntry( const QString& fullPath, const QString& mediaType );
00179
00184 void addConfigItem( const QString & configName, const QString& value );
00186 void addConfigItem( const QString & configName, bool value );
00188 void addConfigItem( const QString & configName, int value );
00190 void addConfigItem( const QString & configName, double value );
00192 void addConfigItem( const QString & configName, long value );
00194 void addConfigItem( const QString & configName, short value );
00195
00196
00197
00208 void addTextSpan( const QString& text );
00214 void addTextSpan( const QString& text, const QMap<int, int>& tabCache );
00215
00220 int indentLevel() const { return m_tags.size() + m_baseIndentLevel; }
00221
00222 private:
00223 struct Tag {
00224 Tag( const char* t = 0, bool ind = true )
00225 : tagName( t ), hasChildren( false ), lastChildIsText( false ),
00226 openingTagClosed( false ), indentInside( ind ) {}
00227 const char* tagName;
00228 bool hasChildren;
00229 bool lastChildIsText;
00230 bool openingTagClosed;
00231 bool indentInside;
00232 };
00233
00235 void writeIndent();
00236
00237
00238
00239 void writeString( const QString& str );
00240
00241
00242
00243
00244
00245
00246 inline void writeCString( const char* cstr ) {
00247 m_dev->writeBlock( cstr, qstrlen( cstr ) );
00248 }
00249 inline void writeChar( char c ) {
00250 m_dev->putch( c );
00251 }
00252 inline void closeStartElement( Tag& tag ) {
00253 if ( !tag.openingTagClosed ) {
00254 tag.openingTagClosed = true;
00255 writeChar( '>' );
00256 }
00257 }
00258 char* escapeForXML( const char* source, int length ) const;
00259 bool prepareForChild();
00260 void prepareForTextNode();
00261 void init();
00262
00263 QIODevice* m_dev;
00264 QValueStack<Tag> m_tags;
00265 int m_baseIndentLevel;
00266
00267 class Private;
00268 Private *d;
00269
00270 char* m_indentBuffer;
00271
00272 char* m_escapeBuffer;
00273 static const int s_escapeBufferLen = 10000;
00274
00275 KoXmlWriter( const KoXmlWriter & );
00276 KoXmlWriter& operator=( const KoXmlWriter & );
00277 };
00278
00279 #endif
00280
This file is part of the documentation for lib Library Version 1.4.2.