14#include <tqdatetime.h>
15#include <tqtextcodec.h>
20#include "rtfimport_dom.h"
25TQString CheckAndEscapeXmlText( const TQString& strText)
27 TQString strReturn(strText);
30 for (uint i=0; i<strReturn.length(); i++)
33 const int test = ch.unicode();
36 if (test == 38) { strReturn.replace(i, 1, "&"); i+=4; }
37 else if (test == 60) { strReturn.replace(i, 1, "<"); i+=3; }
38 else if (test == 62) { strReturn.replace(i, 1, ">"); i+=3; }
39 else if (test == 34) { strReturn.replace(i, 1, """); i+=5; }
40 else if (test == 39) { strReturn.replace(i, 1, "'"); i+=5; }
41 else if (test >= 32) continue;
42 else if ((test == 9) || (test == 10) || (test == 13) ) continue;
49 kdDebug(30515) << "Control character in XML stream: " << test << endl;
50 strReturn.replace(i, 1, '?');
67DomNode::DomNode( const char *doctype )
71 hasAttributes = false;
72 str += "<?xml version = '1.0' encoding = 'UTF-8'?><!DOCTYPE " ;
82void DomNode::clear( int level )
85 documentLevel = level;
87 hasAttributes = false;
94void DomNode::addNode( const char *name )
107void DomNode::addTextNode( const char *text, TQTextCodec* codec )
113 kdError(30515) << "No TQTextCodec available!" << endl;
117 str += CheckAndEscapeXmlText(codec->toUnicode(text));
124void DomNode::addBorder( int id, const TQColor &color, int style, double width )
127 sprintf( attr, "%cRed", id );
128 setAttribute( attr, color.red() );
129 sprintf( attr, "%cGreen", id );
130 setAttribute( attr, color.green() );
131 sprintf( attr, "%cBlue", id );
132 setAttribute( attr, color.blue() );
133 sprintf( attr, "%cStyle", id );
134 setAttribute( attr, style );
135 sprintf( attr, "%cWidth", id );
136 setAttribute( attr, width );
143void DomNode::addColor( const TQColor &color )
145 setAttribute( "red", color.red() );
146 setAttribute( "green", color.green() );
147 setAttribute( "blue", color.blue() );
153void DomNode::addRect( int left, int top, int right, int bottom )
155 setAttribute( "left", .05*left );
156 setAttribute( "top", .05*top );
157 setAttribute( "right", .05*right );
158 setAttribute( "bottom", .05*bottom );
167void DomNode::addKey( const TQDateTime& dt, const TQString& filename, const TQString& name )
169 const TQDate date ( dt.date() );
170 const TQTime time ( dt.time() );
173 setAttribute( "filename", CheckAndEscapeXmlText(filename) );
174 setAttribute( "year", date.year() );
175 setAttribute( "month", date.month() );
176 setAttribute( "day", date.day() );
177 setAttribute( "hour", time.hour() );
178 setAttribute( "minute", time.minute() );
179 setAttribute( "second", time.second() );
180 setAttribute( "msec", time.msec() );
184 setAttribute( "name", CheckAndEscapeXmlText(name) );
192void DomNode::addFrameSet( const char *name, int frameType, int frameInfo )
194 addNode( "FRAMESET" );
195 setAttribute( "name", name );
196 setAttribute( "frameType", frameType );
197 setAttribute( "frameInfo", frameInfo );
198 setAttribute( "removable", 0 );
199 setAttribute( "visible", 1 );
205void DomNode::addFrame( int left, int top, int right, int bottom,
206 int autoCreateNewFrame, int newFrameBehaviour,
210 addRect( left, top, right, bottom );
211 setAttribute( "runaround", 1 );
212 setAttribute( "runaroundGap", 2 );
213 setAttribute( "autoCreateNewFrame", autoCreateNewFrame );
214 setAttribute( "newFrameBehaviour", newFrameBehaviour );
215 setAttribute( "sheetSide", sheetSide );
221void DomNode::setAttribute( const TQString& attribute, const TQString& value )
227 str += CheckAndEscapeXmlText( value );
229 hasAttributes = true;
235void DomNode::setAttribute( const char *attribute, int value )
238 sprintf( strvalue, "%d", value );
239 setAttribute( attribute, ( const char *)strvalue );
245void DomNode::setAttribute( const char *attribute, double value )
248 sprintf( strvalue, "%f", value );
249 setAttribute( attribute, ( const char *)strvalue );
256void DomNode::closeNode( const char *name )
270 for ( int i=documentLevel-1; i>0; i--)
281void DomNode::closeTag( bool nl )
291 for ( int i=documentLevel-1; i>0; i--)
298 hasAttributes = false;
305void DomNode::appendNode( const DomNode &child )
307 const TQString childStr ( child.toString() );
308 closeTag( (childStr.length() >= 2 && (childStr[0] == '<' || childStr[1] == '<')) );
315void DomNode::append( const TQString& _str)
320void DomNode::append( const TQCString& cstr)
322 str += TQString::fromUtf8(cstr);
325void DomNode::append( const char ch)
333bool DomNode::isEmpty( void ) const
335 return str.isEmpty();
341TQString DomNode::toString( void ) const
|