lib
KoXmlWriter.h00001
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 );
00215 void addTextSpan( const QString& text, const QMap<int, int>& tabCache );
00216
00221 int indentLevel() const { return m_tags.size() + m_baseIndentLevel; }
00222
00223 private:
00224 struct Tag {
00225 Tag( const char* t = 0, bool ind = true )
00226 : tagName( t ), hasChildren( false ), lastChildIsText( false ),
00227 openingTagClosed( false ), indentInside( ind ) {}
00228 const char* tagName;
00229 bool hasChildren;
00230 bool lastChildIsText;
00231 bool openingTagClosed;
00232 bool indentInside;
00233 };
00234
00236 void writeIndent();
00237
00238
00239
00240 void writeString( const QString& str );
00241
00242
00243
00244
00245
00246
00247 inline void writeCString( const char* cstr ) {
00248 m_dev->writeBlock( cstr, qstrlen( cstr ) );
00249 }
00250 inline void writeChar( char c ) {
00251 m_dev->putch( c );
00252 }
00253 inline void closeStartElement( Tag& tag ) {
00254 if ( !tag.openingTagClosed ) {
00255 tag.openingTagClosed = true;
00256 writeChar( '>' );
00257 }
00258 }
00259 char* escapeForXML( const char* source, int length ) const;
00260 bool prepareForChild();
00261 void prepareForTextNode();
00262 void init();
00263
00264 QIODevice* m_dev;
00265 QValueStack<Tag> m_tags;
00266 int m_baseIndentLevel;
00267
00268 class Private;
00269 Private *d;
00270
00271 char* m_indentBuffer;
00272
00273 char* m_escapeBuffer;
00274 static const int s_escapeBufferLen = 10000;
00275
00276 KoXmlWriter( const KoXmlWriter & );
00277 KoXmlWriter& operator=( const KoXmlWriter & );
00278 };
00279
00280 #endif
00281
|