xref: /AOO41X/main/dbaccess/source/ui/misc/TokenWriter.cxx (revision 8809db7a87f97847b57a57f4cd2b0104b2b83182)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_dbaccess.hxx"
26 #include "TokenWriter.hxx"
27 #include <tools/debug.hxx>
28 #include <tools/diagnose_ex.h>
29 #include "RtfReader.hxx"
30 #include "HtmlReader.hxx"
31 #include "dbustrings.hrc"
32 #include <connectivity/dbtools.hxx>
33 #include <comphelper/types.hxx>
34 #include <com/sun/star/sdbc/XConnection.hpp>
35 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
36 #include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
37 #include <com/sun/star/sdbc/XRowSet.hpp>
38 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
39 #include <com/sun/star/sdb/XQueriesSupplier.hpp>
40 #include <com/sun/star/sdbc/XDataSource.hpp>
41 #include <com/sun/star/awt/FontWeight.hpp>
42 #include <com/sun/star/awt/FontStrikeout.hpp>
43 #include <com/sun/star/awt/FontSlant.hpp>
44 #include <com/sun/star/awt/FontUnderline.hpp>
45 #include <com/sun/star/document/XDocumentProperties.hpp>
46 #include <svtools/htmlkywd.hxx>
47 #include <svtools/rtfkeywd.hxx>
48 #include <tools/color.hxx>
49 #include <svtools/htmlout.hxx>
50 #include <sfx2/frmhtmlw.hxx>
51 #include <svl/numuno.hxx>
52 #include <vcl/svapp.hxx>
53 #include "UITools.hxx"
54 #include <toolkit/helper/vclunohelper.hxx>
55 #include <vcl/outdev.hxx>
56 #include <svtools/rtfout.hxx>
57 #include <svtools/htmlcfg.hxx>
58 #include <connectivity/formattedcolumnvalue.hxx>
59 #include <unotools/syslocale.hxx>
60 #include <comphelper/componentcontext.hxx>
61 #include <rtl/logfile.hxx>
62 
63 using namespace dbaui;
64 using namespace dbtools;
65 using namespace svx;
66 using namespace ::com::sun::star;
67 using namespace ::com::sun::star::uno;
68 using namespace ::com::sun::star::beans;
69 using namespace ::com::sun::star::container;
70 using namespace ::com::sun::star::sdbc;
71 using namespace ::com::sun::star::sdb;
72 using namespace ::com::sun::star::frame;
73 using namespace ::com::sun::star::lang;
74 using namespace ::com::sun::star::sdbcx;
75 using namespace ::com::sun::star::awt;
76 using namespace ::com::sun::star::util;
77 using ::com::sun::star::frame::XModel;
78 
79 #if defined(UNX)
80 const char __FAR_DATA ODatabaseImportExport::sNewLine = '\012';
81 #else
82 const char __FAR_DATA ODatabaseImportExport::sNewLine[] = "\015\012";
83 #endif
84 
85 const static char __FAR_DATA sMyBegComment[]    = "<!-- ";
86 const static char __FAR_DATA sMyEndComment[]    = " -->";
87 const static char __FAR_DATA sFontFamily[]      = "font-family: ";
88 const static char __FAR_DATA sFontSize[]        = "font-size: ";
89 
90 #define SBA_FORMAT_SELECTION_COUNT  4
91 #define CELL_X                      1437
92 
93 DBG_NAME(ODatabaseImportExport)
94 //======================================================================
95 ODatabaseImportExport::ODatabaseImportExport(const ::svx::ODataAccessDescriptor& _aDataDescriptor,
96                                              const Reference< XMultiServiceFactory >& _rM,
97                                              const Reference< ::com::sun::star::util::XNumberFormatter >& _rxNumberF,
98                                              const String& rExchange)
99     :m_bBookmarkSelection( sal_False )
100     ,m_xFormatter(_rxNumberF)
101     ,m_xFactory(_rM)
102     ,m_nCommandType(CommandType::TABLE)
103     ,m_bNeedToReInitialize(sal_False)
104     ,m_pReader(NULL)
105     ,m_pRowMarker(NULL)
106     ,m_bInInitialize(sal_False)
107     ,m_bCheckOnly(sal_False)
108 {
109     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "ODatabaseImportExport::ODatabaseImportExport" );
110     DBG_CTOR(ODatabaseImportExport,NULL);
111 
112     m_eDestEnc = osl_getThreadTextEncoding();
113 
114     osl_incrementInterlockedCount( &m_refCount );
115     impl_initFromDescriptor( _aDataDescriptor, false );
116 
117     xub_StrLen nCount = rExchange.GetTokenCount(char(11));
118     if( nCount > SBA_FORMAT_SELECTION_COUNT && rExchange.GetToken(4).Len())
119     {
120         m_pRowMarker = new sal_Int32[nCount-SBA_FORMAT_SELECTION_COUNT];
121         for(xub_StrLen i=SBA_FORMAT_SELECTION_COUNT;i<nCount;++i)
122             m_pRowMarker[i-SBA_FORMAT_SELECTION_COUNT] = rExchange.GetToken(i,char(11)).ToInt32();
123     }
124     osl_decrementInterlockedCount( &m_refCount );
125 }
126 // -----------------------------------------------------------------------------
127 // import data
128 ODatabaseImportExport::ODatabaseImportExport( const ::dbtools::SharedConnection& _rxConnection,
129         const Reference< XNumberFormatter >& _rxNumberF, const Reference< XMultiServiceFactory >& _rM )
130     :m_bBookmarkSelection( sal_False )
131     ,m_xConnection(_rxConnection)
132     ,m_xFormatter(_rxNumberF)
133     ,m_xFactory(_rM)
134     ,m_nCommandType(::com::sun::star::sdb::CommandType::TABLE)
135     ,m_bNeedToReInitialize(sal_False)
136     ,m_pReader(NULL)
137     ,m_pRowMarker(NULL)
138     ,m_bInInitialize(sal_False)
139     ,m_bCheckOnly(sal_False)
140 {
141     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "ODatabaseImportExport::ODatabaseImportExport" );
142     DBG_CTOR(ODatabaseImportExport,NULL);
143     m_eDestEnc = osl_getThreadTextEncoding();
144     try
145     {
146         SvtSysLocale aSysLocale;
147         m_aLocale = aSysLocale.GetLocaleData().getLocale();
148     }
149     catch(Exception&)
150     {
151     }
152 }
153 //-------------------------------------------------------------------
154 ODatabaseImportExport::~ODatabaseImportExport()
155 {
156     DBG_DTOR(ODatabaseImportExport,NULL);
157     acquire();
158 
159     dispose();
160 
161     if(m_pReader)
162         m_pReader->release();
163     delete m_pRowMarker;
164 }
165 // -----------------------------------------------------------------------------
166 void ODatabaseImportExport::dispose()
167 {
168     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "ODatabaseImportExport::disposing" );
169     DBG_CHKTHIS(ODatabaseImportExport,NULL);
170     // remove me as listener
171     Reference< XComponent >  xComponent(m_xConnection, UNO_QUERY);
172     if (xComponent.is())
173     {
174         Reference< XEventListener> xEvt((::cppu::OWeakObject*)this,UNO_QUERY);
175         xComponent->removeEventListener(xEvt);
176     }
177     m_xConnection.clear();
178 
179     ::comphelper::disposeComponent(m_xRow);
180 
181     m_xObject.clear();
182     m_xResultSetMetaData.clear();
183     m_xResultSet.clear();
184     m_xRow.clear();
185     m_xRowLocate.clear();
186     m_xFormatter.clear();
187 }
188 // -----------------------------------------------------------------------------
189 void SAL_CALL ODatabaseImportExport::disposing( const EventObject& Source ) throw(::com::sun::star::uno::RuntimeException)
190 {
191     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "ODatabaseImportExport::disposing" );
192     DBG_CHKTHIS(ODatabaseImportExport,NULL);
193     Reference<XConnection> xCon(Source.Source,UNO_QUERY);
194     if(m_xConnection.is() && m_xConnection == xCon)
195     {
196         m_xConnection.clear();
197         dispose();
198         m_bNeedToReInitialize = true;
199         //if(!m_bInInitialize)
200         //  initialize();
201     }
202 }
203 // -----------------------------------------------------------------------------
204 void ODatabaseImportExport::initialize( const ODataAccessDescriptor& _aDataDescriptor )
205 {
206     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "ODatabaseImportExport::initialize" );
207     impl_initFromDescriptor( _aDataDescriptor, true );
208 }
209 
210 // -----------------------------------------------------------------------------
211 void ODatabaseImportExport::impl_initFromDescriptor( const ODataAccessDescriptor& _aDataDescriptor, bool _bPlusDefaultInit)
212 {
213     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "ODatabaseImportExport::impl_initFromDescriptor" );
214     DBG_CHKTHIS(ODatabaseImportExport,NULL);
215     if ( !_bPlusDefaultInit )
216     {
217         m_sDataSourceName = _aDataDescriptor.getDataSource();
218         _aDataDescriptor[daCommandType] >>= m_nCommandType;
219         _aDataDescriptor[daCommand]     >>= m_sName;
220         // some additonal information
221         if(_aDataDescriptor.has(daConnection))
222         {
223             Reference< XConnection > xPureConn( _aDataDescriptor[daConnection], UNO_QUERY );
224             m_xConnection.reset( xPureConn, SharedConnection::NoTakeOwnership );
225             Reference< XEventListener> xEvt((::cppu::OWeakObject*)this,UNO_QUERY);
226             Reference< XComponent >  xComponent(m_xConnection, UNO_QUERY);
227             if (xComponent.is() && xEvt.is())
228                 xComponent->addEventListener(xEvt);
229         }
230 
231         if ( _aDataDescriptor.has( daSelection ) )
232             _aDataDescriptor[ daSelection ] >>= m_aSelection;
233 
234         if ( _aDataDescriptor.has( daBookmarkSelection ) )
235             _aDataDescriptor[ daBookmarkSelection ] >>= m_bBookmarkSelection;
236 
237         if ( _aDataDescriptor.has( daCursor ) )
238         {
239             _aDataDescriptor[ daCursor ] >>= m_xResultSet;
240             m_xRowLocate.set( m_xResultSet, UNO_QUERY );
241         }
242 
243         if ( m_aSelection.getLength() != 0 )
244         {
245             if ( !m_xResultSet.is() )
246             {
247                 OSL_ENSURE( false, "ODatabaseImportExport::impl_initFromDescriptor: selection without result set is nonsense!" );
248                 m_aSelection.realloc( 0 );
249             }
250         }
251 
252         if ( m_aSelection.getLength() != 0 )
253         {
254             if ( m_bBookmarkSelection && !m_xRowLocate.is() )
255             {
256                 OSL_ENSURE( false, "ODatabaseImportExport::impl_initFromDescriptor: no XRowLocate -> no bookmars!" );
257                 m_aSelection.realloc( 0 );
258             }
259         }
260     }
261     else
262         initialize();
263 
264     try
265     {
266         SvtSysLocale aSysLocale;
267         m_aLocale = aSysLocale.GetLocaleData().getLocale();
268     }
269     catch(Exception&)
270     {
271     }
272 }
273 // -----------------------------------------------------------------------------
274 void ODatabaseImportExport::initialize()
275 {
276     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "ODatabaseImportExport::initialize" );
277     DBG_CHKTHIS(ODatabaseImportExport,NULL);
278     m_bInInitialize = sal_True;
279     m_bNeedToReInitialize = false;
280 
281     if ( !m_xConnection.is() )
282     {   // we need a connection
283         OSL_ENSURE(m_sDataSourceName.getLength(),"There must be a datsource name!");
284         Reference<XNameAccess> xDatabaseContext = Reference< XNameAccess >(m_xFactory->createInstance(SERVICE_SDB_DATABASECONTEXT), UNO_QUERY);
285         Reference< XEventListener> xEvt((::cppu::OWeakObject*)this,UNO_QUERY);
286 
287         Reference< XConnection > xConnection;
288         SQLExceptionInfo aInfo = ::dbaui::createConnection( m_sDataSourceName, xDatabaseContext, m_xFactory, xEvt, xConnection );
289         m_xConnection.reset( xConnection );
290 
291         if(aInfo.isValid() && aInfo.getType() == SQLExceptionInfo::SQL_EXCEPTION)
292             throw *static_cast<const SQLException*>(aInfo);
293     }
294 
295     Reference<XNameAccess> xNameAccess;
296     switch(m_nCommandType)
297     {
298         case CommandType::TABLE:
299             {
300                 // only for tables
301                 Reference<XTablesSupplier> xSup(m_xConnection,UNO_QUERY);
302                 if(xSup.is())
303                     xNameAccess = xSup->getTables();
304             }
305             break;
306         case CommandType::QUERY:
307             {
308                 Reference<XQueriesSupplier> xSup(m_xConnection,UNO_QUERY);
309                 if(xSup.is())
310                     xNameAccess = xSup->getQueries();
311             }
312             break;
313     }
314     if(xNameAccess.is() && xNameAccess->hasByName(m_sName))
315     {
316         Reference<XPropertySet> xSourceObject;
317         xNameAccess->getByName(m_sName) >>= m_xObject;
318     }
319 
320     if(m_xObject.is())
321     {
322         try
323         {
324             if(m_xObject->getPropertySetInfo()->hasPropertyByName(PROPERTY_FONT))
325                 m_xObject->getPropertyValue(PROPERTY_FONT) >>= m_aFont;
326 
327             // the result set may be already set with the datadescriptor
328             if ( !m_xResultSet.is() )
329             {
330                 m_xResultSet.set( m_xFactory->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.sdb.RowSet" ) ), UNO_QUERY );
331                 Reference< XPropertySet > xProp( m_xResultSet, UNO_QUERY_THROW );
332                 xProp->setPropertyValue( PROPERTY_ACTIVE_CONNECTION, makeAny( m_xConnection.getTyped() ) );
333                 xProp->setPropertyValue( PROPERTY_COMMAND_TYPE, makeAny( m_nCommandType ) );
334                 xProp->setPropertyValue( PROPERTY_COMMAND, makeAny( m_sName ) );
335                 Reference< XRowSet > xRowSet( xProp, UNO_QUERY );
336                 xRowSet->execute();
337             }
338             impl_initializeRowMember_throw();
339         }
340         catch(Exception& )
341         {
342             m_xRow = NULL;
343             m_xResultSetMetaData = NULL;
344             ::comphelper::disposeComponent(m_xResultSet);
345             throw;
346         }
347     }
348     if ( !m_aFont.Name.getLength() )
349     {
350         Font aApplicationFont = OutputDevice::GetDefaultFont(
351             DEFAULTFONT_SANS_UNICODE,
352             Application::GetSettings().GetUILanguage(),
353             DEFAULTFONT_FLAGS_ONLYONE
354         );
355         m_aFont = VCLUnoHelper::CreateFontDescriptor( aApplicationFont );
356     }
357 
358     m_bInInitialize = sal_False;
359 }
360 // -----------------------------------------------------------------------------
361 sal_Bool ODatabaseImportExport::Write()
362 {
363     if ( m_bNeedToReInitialize )
364     {
365         if ( !m_bInInitialize )
366             initialize();
367     } // if ( m_bNeedToReInitialize )
368     return sal_True;
369 }
370 // -----------------------------------------------------------------------------
371 sal_Bool ODatabaseImportExport::Read()
372 {
373     if ( m_bNeedToReInitialize )
374     {
375         if ( !m_bInInitialize )
376             initialize();
377     } // if ( m_bNeedToReInitialize )
378     return sal_True;
379 }
380 // -----------------------------------------------------------------------------
381 void ODatabaseImportExport::impl_initializeRowMember_throw()
382 {
383     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "ODatabaseImportExport::impl_initializeRowMember_throw" );
384     if ( !m_xRow.is() && m_xResultSet.is() )
385     {
386         m_xRow.set( m_xResultSet, UNO_QUERY );
387         m_xRowLocate.set( m_xResultSet, UNO_QUERY );
388         m_xResultSetMetaData = Reference<XResultSetMetaDataSupplier>(m_xRow,UNO_QUERY)->getMetaData();
389         Reference<XColumnsSupplier> xSup(m_xResultSet,UNO_QUERY_THROW);
390         m_xRowSetColumns.set(xSup->getColumns(),UNO_QUERY_THROW);
391     }
392 }
393 //======================================================================
394 sal_Bool ORTFImportExport::Write()
395 {
396     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "ORTFImportExport::Write" );
397     ODatabaseImportExport::Write();
398     (*m_pStream) << '{'     << OOO_STRING_SVTOOLS_RTF_RTF;
399     (*m_pStream) << OOO_STRING_SVTOOLS_RTF_ANSI << ODatabaseImportExport::sNewLine;
400     rtl_TextEncoding eDestEnc = RTL_TEXTENCODING_MS_1252;
401 
402     /*
403     // Access RTF Export Beispiel
404     {\rtf1\ansi
405         {\colortbl\red0\green0\blue0;\red255\green255\blue255;\red192\green192\blue192;}
406         {\fonttbl\f0\fcharset0\fnil MS Sans Serif;\f1\fcharset0\fnil Arial;\f2\fcharset0\fnil Arial;}
407         \trowd\trgaph40
408                 \clbrdrl\brdrs\brdrcf0\clbrdrt\brdrs\brdrcf0\clbrdrb\brdrs\brdrcf0\clbrdrr\brdrs\brdrcf0\clshdng10000\clcfpat2\cellx1437
409                 \clbrdrl\brdrs\brdrcf0\clbrdrt\brdrs\brdrcf0\clbrdrb\brdrs\brdrcf0\clbrdrr\brdrs\brdrcf0\clshdng10000\clcfpat2\cellx2874
410         {
411             \trrh-270\pard\intbl
412                 {\qc\fs20\b\f1\cf0\cb2 text\cell}
413                 \pard\intbl
414                 {\qc\fs20\b\f1\cf0\cb2 datum\cell}
415                 \pard\intbl\row
416         }
417         \trowd\trgaph40\clbrdrl\brdrs\brdrcf2\clbrdrt\brdrs\brdrcf2\clbrdrb\brdrs\brdrcf2\clbrdrr\brdrs\brdrcf2\clshdng10000\clcfpat1\cellx1437\clbrdrl\brdrs\brdrcf2\clbrdrt\brdrs\brdrcf2\clbrdrb\brdrs\brdrcf2\clbrdrr\brdrs\brdrcf2\clshdng10000\clcfpat1\cellx2874
418         {\trrh-270\pard\intbl
419             {\ql\fs20\f2\cf0\cb1 heute\cell}
420             \pard\intbl
421             {\qr\fs20\f2\cf0\cb1 10.11.98\cell}
422             \pard\intbl\row
423         }
424         \trowd\trgaph40\clbrdrl\brdrs\brdrcf2\clbrdrt\brdrs\brdrcf2\clbrdrb\brdrs\brdrcf2\clbrdrr\brdrs\brdrcf2\clshdng10000\clcfpat1\cellx1437\clbrdrl\brdrs\brdrcf2\clbrdrt\brdrs\brdrcf2\clbrdrb\brdrs\brdrcf2\clbrdrr\brdrs\brdrcf2\clshdng10000\clcfpat1\cellx2874
425         {\trrh-270\pard\intbl
426             {\ql\fs20\f2\cf0\cb1 morgen\cell}
427             \pard\intbl
428             {\qr\fs20\f2\cf0\cb1 11.11.98\cell}
429             \pard\intbl\row
430         }
431         \trowd\trgaph40\clbrdrl\brdrs\brdrcf2\clbrdrt\brdrs\brdrcf2\clbrdrb\brdrs\brdrcf2\clbrdrr\brdrs\brdrcf2\clshdng10000\clcfpat1\cellx1437\clbrdrl\brdrs\brdrcf2\clbrdrt\brdrs\brdrcf2\clbrdrb\brdrs\brdrcf2\clbrdrr\brdrs\brdrcf2\clshdng10000\clcfpat1\cellx2874
432         {\trrh-270\pard\intbl
433             {\ql\fs20\f2\cf0\cb1 bruder\cell}
434             \pard\intbl
435             {\qr\fs20\f2\cf0\cb1 21.04.98\cell}
436             \pard\intbl\row
437         }
438         \trowd\trgaph40
439         \clbrdrl\brdrs\brdrcf2\clbrdrt\brdrs\brdrcf2\clbrdrb\brdrs\brdrcf2\clbrdrr\brdrs\brdrcf2\clshdng10000\clcfpat1\cellx
440         \clbrdrl\brdrs\brdrcf2\clbrdrt\brdrs\brdrcf2\clbrdrb\brdrs\brdrcf2\clbrdrr\brdrs\brdrcf2\clshdng10000\clcfpat1\cellx2874
441         {\trrh-270\pard\intbl
442             {\ql\fs20\f2\cf0\cb1 vater\cell}
443             \pard\intbl
444             {\qr\fs20\f2\cf0\cb1 28.06.98\cell}
445             \pard\intbl\row
446         }
447     }
448     */
449 
450     sal_Bool bBold          = ( ::com::sun::star::awt::FontWeight::BOLD     == m_aFont.Weight );
451     sal_Bool bItalic        = ( ::com::sun::star::awt::FontSlant_ITALIC     == m_aFont.Slant );
452     sal_Bool bUnderline     = ( ::com::sun::star::awt::FontUnderline::NONE  != m_aFont.Underline );
453     sal_Bool bStrikeout     = ( ::com::sun::star::awt::FontStrikeout::NONE  != m_aFont.Strikeout );
454 
455     sal_Int32 nColor = 0;
456     if(m_xObject.is())
457         m_xObject->getPropertyValue(PROPERTY_TEXTCOLOR) >>= nColor;
458     ::Color aColor(nColor);
459 
460     ByteString aFonts(String(m_aFont.Name),eDestEnc);
461     if(!aFonts.Len())
462     {
463         String aName = Application::GetSettings().GetStyleSettings().GetAppFont().GetName();
464         aFonts = ByteString (aName,eDestEnc);
465     }
466     ::rtl::OString aFormat("\\fcharset0\\fnil ");
467     ByteString aFontNr;
468 
469     (*m_pStream)    << "{\\fonttbl";
470     xub_StrLen nTokenCount = aFonts.GetTokenCount();
471     for(xub_StrLen j=0;j<nTokenCount;++j)
472     {
473         (*m_pStream) << "\\f";
474         m_pStream->WriteNumber(j);
475         (*m_pStream) << aFormat;
476         (*m_pStream) << aFonts.GetToken(j).GetBuffer();
477         (*m_pStream) << ';';
478     }
479     (*m_pStream) << '}' ;
480     (*m_pStream) << ODatabaseImportExport::sNewLine;
481     // write the rtf color table
482     (*m_pStream) << '{' << OOO_STRING_SVTOOLS_RTF_COLORTBL << OOO_STRING_SVTOOLS_RTF_RED;
483     m_pStream->WriteNumber(aColor.GetRed());
484     (*m_pStream) << OOO_STRING_SVTOOLS_RTF_GREEN;
485     m_pStream->WriteNumber(aColor.GetGreen());
486     (*m_pStream) << OOO_STRING_SVTOOLS_RTF_BLUE;
487     m_pStream->WriteNumber(aColor.GetBlue());
488 
489     (*m_pStream) << ";\\red255\\green255\\blue255;\\red192\\green192\\blue192;}"
490                  << ODatabaseImportExport::sNewLine;
491 
492     ::rtl::OString aTRRH("\\trrh-270\\pard\\intbl");
493     ::rtl::OString aFS("\\fs20\\f0\\cf0\\cb2");
494     ::rtl::OString aCell1("\\clbrdrl\\brdrs\\brdrcf0\\clbrdrt\\brdrs\\brdrcf0\\clbrdrb\\brdrs\\brdrcf0\\clbrdrr\\brdrs\\brdrcf0\\clshdng10000\\clcfpat2\\cellx");
495 
496     (*m_pStream) << OOO_STRING_SVTOOLS_RTF_TROWD << OOO_STRING_SVTOOLS_RTF_TRGAPH;
497     m_pStream->WriteNumber(40);
498     (*m_pStream) << ODatabaseImportExport::sNewLine;
499 
500     if(m_xObject.is())
501     {
502         Reference<XColumnsSupplier> xColSup(m_xObject,UNO_QUERY);
503         Reference<XNameAccess> xColumns = xColSup->getColumns();
504         Sequence< ::rtl::OUString> aNames(xColumns->getElementNames());
505         const ::rtl::OUString* pIter = aNames.getConstArray();
506 
507         sal_Int32 nCount = aNames.getLength();
508         sal_Bool bUseResultMetaData = sal_False;
509         if ( !nCount )
510         {
511             nCount = m_xResultSetMetaData->getColumnCount();
512             bUseResultMetaData = sal_True;
513         }
514 
515         for( sal_Int32 i=1; i<=nCount; ++i )
516         {
517             (*m_pStream) << aCell1;
518             m_pStream->WriteNumber(i*CELL_X);
519             (*m_pStream) << ODatabaseImportExport::sNewLine;
520         }
521 
522         // Spaltenbeschreibung
523         (*m_pStream) << '{' << ODatabaseImportExport::sNewLine;
524         (*m_pStream) << aTRRH;
525 
526 
527         ::rtl::OString* pHorzChar = new ::rtl::OString[nCount];
528 
529         for ( sal_Int32 i=1; i <= nCount; ++i )
530         {
531             sal_Int32 nAlign = 0;
532             ::rtl::OUString sColumnName;
533             if ( bUseResultMetaData )
534                 sColumnName = m_xResultSetMetaData->getColumnName(i);
535             else
536             {
537                 sColumnName = *pIter;
538                 Reference<XPropertySet> xColumn;
539                 xColumns->getByName(sColumnName) >>= xColumn;
540                 xColumn->getPropertyValue(PROPERTY_ALIGN) >>= nAlign;
541                 ++pIter;
542             }
543 
544             const char* pChar;
545             switch( nAlign )
546             {
547                 case 1: pChar = OOO_STRING_SVTOOLS_RTF_QC;  break;
548                 case 2: pChar = OOO_STRING_SVTOOLS_RTF_QR;  break;
549                 case 0:
550                 default:pChar = OOO_STRING_SVTOOLS_RTF_QL;  break;
551             }
552 
553             pHorzChar[i-1] = pChar; // um sp"ater nicht immer im ITEMSET zuw"uhlen
554 
555             (*m_pStream) << ODatabaseImportExport::sNewLine;
556             (*m_pStream) << '{';
557             (*m_pStream) << OOO_STRING_SVTOOLS_RTF_QC;   // column header always centered
558 
559             if ( bBold )        (*m_pStream) << OOO_STRING_SVTOOLS_RTF_B;
560             if ( bItalic )      (*m_pStream) << OOO_STRING_SVTOOLS_RTF_I;
561             if ( bUnderline )   (*m_pStream) << OOO_STRING_SVTOOLS_RTF_UL;
562             if ( bStrikeout )   (*m_pStream) << OOO_STRING_SVTOOLS_RTF_STRIKE;
563 
564             (*m_pStream) << aFS;
565             (*m_pStream) << ' ';
566             RTFOutFuncs::Out_String(*m_pStream,sColumnName,eDestEnc);
567 
568             (*m_pStream) << OOO_STRING_SVTOOLS_RTF_CELL;
569             (*m_pStream) << '}';
570             (*m_pStream) << ODatabaseImportExport::sNewLine;
571             (*m_pStream) << OOO_STRING_SVTOOLS_RTF_PARD << OOO_STRING_SVTOOLS_RTF_INTBL;
572         }
573 
574         (*m_pStream) << OOO_STRING_SVTOOLS_RTF_ROW;
575         (*m_pStream) << ODatabaseImportExport::sNewLine << '}';
576         (*m_pStream) << ODatabaseImportExport::sNewLine;
577 
578         ::comphelper::ComponentContext aContext(m_xFactory);
579         Reference< XRowSet > xRowSet(m_xRow,UNO_QUERY);
580         sal_Int32 k=1;
581         sal_Int32 kk=0;
582         if ( m_aSelection.getLength() )
583         {
584             const Any* pSelIter = m_aSelection.getConstArray();
585             const Any* pEnd   = pSelIter + m_aSelection.getLength();
586 
587             sal_Bool bContinue = sal_True;
588             for( ; pSelIter != pEnd && bContinue; ++pSelIter )
589             {
590                 if ( m_bBookmarkSelection )
591                 {
592                     bContinue = m_xRowLocate->moveToBookmark( *pSelIter );
593                 }
594                 else
595                 {
596                     sal_Int32 nPos = -1;
597                     OSL_VERIFY( *pSelIter >>= nPos );
598                     bContinue = ( m_xResultSet->absolute( nPos ) );
599                 }
600 
601                 if ( bContinue )
602                     appendRow( pHorzChar, nCount, k, kk );
603             }
604         }
605         else
606         {
607             m_xResultSet->beforeFirst(); // set back before the first row
608             while(m_xResultSet->next())
609             {
610                 appendRow(pHorzChar,nCount,k,kk);
611             }
612         }
613         delete [] pHorzChar;
614     }
615 
616     (*m_pStream) << '}' << ODatabaseImportExport::sNewLine;
617     (*m_pStream) << (sal_uInt8) 0;
618     return ((*m_pStream).GetError() == SVSTREAM_OK);
619 }
620 // -----------------------------------------------------------------------------
621 void ORTFImportExport::appendRow(::rtl::OString* pHorzChar,sal_Int32 _nColumnCount,sal_Int32& k,sal_Int32& kk)
622 {
623     if(!m_pRowMarker || m_pRowMarker[kk] == k)
624     {
625         ++kk;
626         (*m_pStream) << OOO_STRING_SVTOOLS_RTF_TROWD << OOO_STRING_SVTOOLS_RTF_TRGAPH;
627         m_pStream->WriteNumber(40);
628         (*m_pStream) << ODatabaseImportExport::sNewLine;
629 
630         static const ::rtl::OString aCell2("\\clbrdrl\\brdrs\\brdrcf2\\clbrdrt\\brdrs\\brdrcf2\\clbrdrb\\brdrs\\brdrcf2\\clbrdrr\\brdrs\\brdrcf2\\clshdng10000\\clcfpat1\\cellx");
631         static const ::rtl::OString aTRRH("\\trrh-270\\pard\\intbl");
632 
633         for ( sal_Int32 i=1; i<=_nColumnCount; ++i )
634         {
635             (*m_pStream) << aCell2;
636             m_pStream->WriteNumber(i*CELL_X);
637             (*m_pStream) << ODatabaseImportExport::sNewLine;
638         }
639 
640         const sal_Bool bBold            = ( ::com::sun::star::awt::FontWeight::BOLD     == m_aFont.Weight );
641         const sal_Bool bItalic      = ( ::com::sun::star::awt::FontSlant_ITALIC     == m_aFont.Slant );
642         const sal_Bool bUnderline       = ( ::com::sun::star::awt::FontUnderline::NONE  != m_aFont.Underline );
643         const sal_Bool bStrikeout       = ( ::com::sun::star::awt::FontStrikeout::NONE  != m_aFont.Strikeout );
644         static const ::rtl::OString aFS2("\\fs20\\f1\\cf0\\cb1");
645         ::comphelper::ComponentContext aContext(m_xFactory);
646         Reference< XRowSet > xRowSet(m_xRow,UNO_QUERY);
647 
648         (*m_pStream) << '{';
649         (*m_pStream) << aTRRH;
650         for ( sal_Int32 i=1; i <= _nColumnCount; ++i )
651         {
652             (*m_pStream) << ODatabaseImportExport::sNewLine;
653             (*m_pStream) << '{';
654             (*m_pStream) << pHorzChar[i-1];
655 
656             if ( bBold )        (*m_pStream) << OOO_STRING_SVTOOLS_RTF_B;
657             if ( bItalic )      (*m_pStream) << OOO_STRING_SVTOOLS_RTF_I;
658             if ( bUnderline )   (*m_pStream) << OOO_STRING_SVTOOLS_RTF_UL;
659             if ( bStrikeout )   (*m_pStream) << OOO_STRING_SVTOOLS_RTF_STRIKE;
660 
661             (*m_pStream) << aFS2;
662             (*m_pStream) << ' ';
663 
664             try
665             {
666                 Reference<XPropertySet> xColumn(m_xRowSetColumns->getByIndex(i-1),UNO_QUERY_THROW);
667                 dbtools::FormattedColumnValue aFormatedValue(aContext,xRowSet,xColumn);
668                 ::rtl::OUString sValue = aFormatedValue.getFormattedValue();
669                 // m_xRow->getString(i);
670                 //if (!m_xRow->wasNull())
671                 if ( sValue.getLength() )
672                     RTFOutFuncs::Out_String(*m_pStream,sValue,m_eDestEnc);
673             }
674             catch (Exception&)
675             {
676                 OSL_ENSURE(0,"RTF WRITE!");
677             }
678 
679             (*m_pStream) << OOO_STRING_SVTOOLS_RTF_CELL;
680             (*m_pStream) << '}';
681             (*m_pStream) << ODatabaseImportExport::sNewLine;
682             (*m_pStream) << OOO_STRING_SVTOOLS_RTF_PARD << OOO_STRING_SVTOOLS_RTF_INTBL;
683         }
684         (*m_pStream) << OOO_STRING_SVTOOLS_RTF_ROW << ODatabaseImportExport::sNewLine;
685         (*m_pStream) << '}';
686     }
687     ++k;
688 }
689 //-------------------------------------------------------------------
690 sal_Bool ORTFImportExport::Read()
691 {
692     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "ORTFImportExport::Read" );
693     ODatabaseImportExport::Read();
694     SvParserState eState = SVPAR_ERROR;
695     if ( m_pStream )
696     {
697         m_pReader = new ORTFReader((*m_pStream),m_xConnection,m_xFormatter,m_xFactory);
698         ((ORTFReader*)m_pReader)->AddRef();
699         if ( isCheckEnabled() )
700             m_pReader->enableCheckOnly();
701         eState = ((ORTFReader*)m_pReader)->CallParser();
702         m_pReader->release();
703         m_pReader = NULL;
704     }
705 
706     return eState != SVPAR_ERROR;
707 }
708 //-------------------------------------------------------------------
709 //===================================================================
710 const sal_Int16 __FAR_DATA OHTMLImportExport::nDefaultFontSize[SBA_HTML_FONTSIZES] =
711 {
712     HTMLFONTSZ1_DFLT, HTMLFONTSZ2_DFLT, HTMLFONTSZ3_DFLT, HTMLFONTSZ4_DFLT,
713     HTMLFONTSZ5_DFLT, HTMLFONTSZ6_DFLT, HTMLFONTSZ7_DFLT
714 };
715 
716 sal_Int16 OHTMLImportExport::nFontSize[SBA_HTML_FONTSIZES] = { 0 };
717 
718 const sal_Int16 OHTMLImportExport::nCellSpacing = 0;
719 const char __FAR_DATA OHTMLImportExport::sIndentSource[nIndentMax+1] = "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
720 
721 //========================================================================
722 // Makros fuer HTML-Export
723 //========================================================================
724 #define OUT_PROLOGUE()      ((*m_pStream) << sHTML30_Prologue << ODatabaseImportExport::sNewLine << ODatabaseImportExport::sNewLine)
725 #define TAG_ON( tag )       HTMLOutFuncs::Out_AsciiTag( (*m_pStream), tag )
726 #define TAG_OFF( tag )      HTMLOutFuncs::Out_AsciiTag( (*m_pStream), tag, sal_False )
727 #define OUT_STR( str )      HTMLOutFuncs::Out_String( (*m_pStream), str )
728 #define OUT_LF()            (*m_pStream) << ODatabaseImportExport::sNewLine << GetIndentStr()
729 #define lcl_OUT_LF()        (*m_pStream) << ODatabaseImportExport::sNewLine
730 #define TAG_ON_LF( tag )    (TAG_ON( tag ) << ODatabaseImportExport::sNewLine << GetIndentStr())
731 #define TAG_OFF_LF( tag )   (TAG_OFF( tag ) << ODatabaseImportExport::sNewLine << GetIndentStr())
732 #define OUT_HR()            TAG_ON_LF( OOO_STRING_SVTOOLS_HTML_horzrule )
733 #define OUT_COMMENT( comment )  ((*m_pStream) << sMyBegComment, OUT_STR( comment ) << sMyEndComment << ODatabaseImportExport::sNewLine << GetIndentStr())
734 #define lcl_OUT_COMMENT( comment )  ((*m_pStream) << sMyBegComment, OUT_STR( comment ) << sMyEndComment << ODatabaseImportExport::sNewLine)
735 
736 //-------------------------------------------------------------------
737 OHTMLImportExport::OHTMLImportExport(const ::svx::ODataAccessDescriptor& _aDataDescriptor,
738                                      const Reference< XMultiServiceFactory >& _rM,
739                                      const Reference< ::com::sun::star::util::XNumberFormatter >& _rxNumberF,
740                                      const String& rExchange)
741         : ODatabaseImportExport(_aDataDescriptor,_rM,_rxNumberF,rExchange)
742     ,m_nIndent(0)
743 #ifdef DBG_UTIL
744     ,m_bCheckFont(sal_False)
745 #endif
746 {
747     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "OHTMLImportExport::OHTMLImportExport" );
748     // set HTML configuration
749     SvxHtmlOptions* pHtmlOptions = SvxHtmlOptions::Get();
750     m_eDestEnc = pHtmlOptions->GetTextEncoding();
751     strncpy( sIndent, sIndentSource ,std::min(sizeof(sIndent),sizeof(sIndentSource)));
752     sIndent[0] = 0;
753 }
754 //-------------------------------------------------------------------
755 sal_Bool OHTMLImportExport::Write()
756 {
757     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "OHTMLImportExport::Write" );
758     ODatabaseImportExport::Write();
759     if(m_xObject.is())
760     {
761         (*m_pStream) << '<' << OOO_STRING_SVTOOLS_HTML_doctype << ' ' << OOO_STRING_SVTOOLS_HTML_doctype32 << '>' << ODatabaseImportExport::sNewLine << ODatabaseImportExport::sNewLine;
762         TAG_ON_LF( OOO_STRING_SVTOOLS_HTML_html );
763         WriteHeader();
764         OUT_LF();
765         WriteBody();
766         OUT_LF();
767         TAG_OFF_LF( OOO_STRING_SVTOOLS_HTML_html );
768 
769         return ((*m_pStream).GetError() == SVSTREAM_OK);
770     }
771     return sal_False;
772 }
773 //-------------------------------------------------------------------
774 sal_Bool OHTMLImportExport::Read()
775 {
776     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "OHTMLImportExport::Read" );
777     ODatabaseImportExport::Read();
778     SvParserState eState = SVPAR_ERROR;
779     if ( m_pStream )
780     {
781         m_pReader = new OHTMLReader((*m_pStream),m_xConnection,m_xFormatter,m_xFactory);
782         ((OHTMLReader*)m_pReader)->AddRef();
783         if ( isCheckEnabled() )
784             m_pReader->enableCheckOnly();
785         //dyf add 20070601
786         m_pReader->SetTableName(m_sDefaultTableName);
787         //dyf add end
788         eState = ((OHTMLReader*)m_pReader)->CallParser();
789         m_pReader->release();
790         m_pReader = NULL;
791     }
792 
793     return eState != SVPAR_ERROR;
794 }
795 //-------------------------------------------------------------------
796 void OHTMLImportExport::WriteHeader()
797 {
798     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "OHTMLImportExport::WriteHeader" );
799     uno::Reference<document::XDocumentProperties> xDocProps(
800         m_xFactory->createInstance(::rtl::OUString::createFromAscii(
801             "com.sun.star.document.DocumentProperties")),
802         uno::UNO_QUERY);
803     if (xDocProps.is()) {
804         xDocProps->setTitle(m_sName);
805     }
806 
807     IncIndent(1); TAG_ON_LF( OOO_STRING_SVTOOLS_HTML_head );
808 
809     SfxFrameHTMLWriter::Out_DocInfo( (*m_pStream), String(),
810         xDocProps, sIndent );
811     OUT_LF();
812     IncIndent(-1); OUT_LF(); TAG_OFF_LF( OOO_STRING_SVTOOLS_HTML_head );
813 }
814 //-----------------------------------------------------------------------
815 void OHTMLImportExport::WriteBody()
816 {
817     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "OHTMLImportExport::WriteBody" );
818 
819     IncIndent(1); TAG_ON_LF( OOO_STRING_SVTOOLS_HTML_style );
820 
821     (*m_pStream) << sMyBegComment; OUT_LF();
822     (*m_pStream) << OOO_STRING_SVTOOLS_HTML_body << " { " << sFontFamily << '\"' << ::rtl::OString(m_aFont.Name,m_aFont.Name.getLength(), gsl_getSystemTextEncoding()) << '\"';
823         // TODO : think about the encoding of the font name
824     (*m_pStream) << "; " << sFontSize;
825     m_pStream->WriteNumber(m_aFont.Height);
826     (*m_pStream) << '}';
827 
828     OUT_LF();
829     (*m_pStream) << sMyEndComment;
830     IncIndent(-1); OUT_LF(); TAG_OFF_LF( OOO_STRING_SVTOOLS_HTML_style );
831     OUT_LF();
832 
833     // default Textfarbe schwarz
834     (*m_pStream) << '<' << OOO_STRING_SVTOOLS_HTML_body << ' ' << OOO_STRING_SVTOOLS_HTML_O_text << '=';
835     sal_Int32 nColor = 0;
836     if(m_xObject.is())
837         m_xObject->getPropertyValue(PROPERTY_TEXTCOLOR) >>= nColor;
838     ::Color aColor(nColor);
839     HTMLOutFuncs::Out_Color( (*m_pStream), aColor );
840 
841     ::rtl::OString sOut( ' ' );
842     sOut = sOut + OOO_STRING_SVTOOLS_HTML_O_bgcolor;
843     sOut = sOut + "=";
844     (*m_pStream) << sOut;
845     HTMLOutFuncs::Out_Color( (*m_pStream), aColor );
846 
847     (*m_pStream) << '>'; OUT_LF();
848 
849     WriteTables();
850 
851     TAG_OFF_LF( OOO_STRING_SVTOOLS_HTML_body );
852 }
853 //-----------------------------------------------------------------------
854 void OHTMLImportExport::WriteTables()
855 {
856     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "OHTMLImportExport::WriteTables" );
857     ::rtl::OString aStrOut  = OOO_STRING_SVTOOLS_HTML_table;
858     aStrOut = aStrOut + " ";
859     aStrOut = aStrOut + OOO_STRING_SVTOOLS_HTML_frame;
860     aStrOut = aStrOut + "=";
861     aStrOut = aStrOut + OOO_STRING_SVTOOLS_HTML_TF_void;
862 
863     Sequence< ::rtl::OUString> aNames;
864     Reference<XNameAccess> xColumns;
865     sal_Bool bUseResultMetaData = sal_False;
866     if(m_xObject.is())
867     {
868         Reference<XColumnsSupplier> xColSup(m_xObject,UNO_QUERY);
869         xColumns = xColSup->getColumns();
870         aNames = xColumns->getElementNames();
871         if ( !aNames.getLength() )
872         {
873             sal_Int32 nCount = m_xResultSetMetaData->getColumnCount();
874             aNames.realloc(nCount);
875             for (sal_Int32 i= 0; i < nCount; ++i)
876                 aNames[i] = m_xResultSetMetaData->getColumnName(i+1);
877             bUseResultMetaData = sal_True;
878         }
879     }
880 
881     aStrOut = aStrOut + " ";
882     aStrOut = aStrOut + OOO_STRING_SVTOOLS_HTML_O_align;
883     aStrOut = aStrOut + "=";
884     aStrOut = aStrOut + OOO_STRING_SVTOOLS_HTML_AL_left;
885     aStrOut = aStrOut + " ";
886     aStrOut = aStrOut + OOO_STRING_SVTOOLS_HTML_O_cellspacing;
887     aStrOut = aStrOut + "=";
888     aStrOut = aStrOut + ::rtl::OString::valueOf((sal_Int32)nCellSpacing);
889     aStrOut = aStrOut + " ";
890     aStrOut = aStrOut + OOO_STRING_SVTOOLS_HTML_O_cols;
891     aStrOut = aStrOut + "=";
892     aStrOut = aStrOut + ::rtl::OString::valueOf(aNames.getLength());
893     aStrOut = aStrOut + " ";
894     aStrOut = aStrOut + OOO_STRING_SVTOOLS_HTML_O_border;
895     aStrOut = aStrOut + "=1";
896 
897     IncIndent(1);
898     TAG_ON( aStrOut );
899 
900     FontOn();
901 
902     TAG_ON( OOO_STRING_SVTOOLS_HTML_caption );
903     TAG_ON( OOO_STRING_SVTOOLS_HTML_bold );
904 
905     (*m_pStream)    << ::rtl::OString(m_sName,m_sName.getLength(), gsl_getSystemTextEncoding());
906         // TODO : think about the encoding of the name
907     TAG_OFF( OOO_STRING_SVTOOLS_HTML_bold );
908     TAG_OFF( OOO_STRING_SVTOOLS_HTML_caption );
909 
910     FontOff();
911     OUT_LF();
912     // </FONT>
913 
914     IncIndent(1);
915     TAG_ON_LF( OOO_STRING_SVTOOLS_HTML_thead );
916 
917     IncIndent(1);
918     TAG_ON_LF( OOO_STRING_SVTOOLS_HTML_tablerow );
919 
920     if(m_xObject.is())
921     {
922         sal_Int32* pFormat = new sal_Int32[aNames.getLength()];
923 
924         const char **pHorJustify = new const char*[aNames.getLength()];
925         sal_Int32 *pColWidth = new sal_Int32[aNames.getLength()];
926 
927 
928         sal_Int32 nHeight = 0;
929         m_xObject->getPropertyValue(PROPERTY_ROW_HEIGHT) >>= nHeight;
930 
931         // 1. die Spaltenbeschreibung rauspusten
932         const ::rtl::OUString* pIter = aNames.getConstArray();
933         const ::rtl::OUString* pEnd = pIter + aNames.getLength();
934 
935         for( sal_Int32 i=0;pIter != pEnd; ++pIter,++i )
936         {
937             sal_Int32 nAlign = 0;
938             pFormat[i] = 0;
939             pColWidth[i] = 100;
940             if ( !bUseResultMetaData )
941             {
942                 Reference<XPropertySet> xColumn;
943                 xColumns->getByName(*pIter) >>= xColumn;
944                 xColumn->getPropertyValue(PROPERTY_ALIGN) >>= nAlign;
945                 pFormat[i] = ::comphelper::getINT32(xColumn->getPropertyValue(PROPERTY_FORMATKEY));
946                 pColWidth[i] = ::comphelper::getINT32(xColumn->getPropertyValue(PROPERTY_WIDTH));
947             }
948 
949             switch( nAlign )
950             {
951                 case 1:     pHorJustify[i] = OOO_STRING_SVTOOLS_HTML_AL_center; break;
952                 case 2:     pHorJustify[i] = OOO_STRING_SVTOOLS_HTML_AL_right;  break;
953                 default:    pHorJustify[i] = OOO_STRING_SVTOOLS_HTML_AL_left;       break;
954             }
955 
956             if(i == aNames.getLength()-1)
957                 IncIndent(-1);
958 
959             WriteCell(pFormat[i],pColWidth[i],nHeight,pHorJustify[i],*pIter,OOO_STRING_SVTOOLS_HTML_tableheader);
960         }
961 
962         IncIndent(-1);
963         TAG_OFF_LF( OOO_STRING_SVTOOLS_HTML_tablerow );
964         TAG_OFF_LF( OOO_STRING_SVTOOLS_HTML_thead );
965 
966         IncIndent(1);
967         TAG_ON_LF( OOO_STRING_SVTOOLS_HTML_tbody );
968 
969         // 2. und jetzt die Daten
970         ::comphelper::ComponentContext aContext(m_xFactory);
971         Reference< XRowSet > xRowSet(m_xRow,UNO_QUERY);
972         sal_Int32 j=1;
973         sal_Int32 kk=0;
974         m_xResultSet->beforeFirst(); // set back before the first row
975         while(m_xResultSet->next())
976         {
977             IncIndent(1);
978             TAG_ON_LF( OOO_STRING_SVTOOLS_HTML_tablerow );
979 
980             if(!m_pRowMarker || m_pRowMarker[kk] == j)
981             {
982                 ++kk;
983                 for(sal_Int32 i=1;i<=aNames.getLength();++i)
984                 {
985                     if(i == aNames.getLength())
986                         IncIndent(-1);
987 
988                     String aValue;
989                     try
990                     {
991                         Reference<XPropertySet> xColumn(m_xRowSetColumns->getByIndex(i-1),UNO_QUERY_THROW);
992                         dbtools::FormattedColumnValue aFormatedValue(aContext,xRowSet,xColumn);
993                         ::rtl::OUString sValue = aFormatedValue.getFormattedValue();
994                         if (sValue.getLength())
995                         {
996                             aValue = sValue;
997                         }
998                     }
999                     catch( const Exception& )
1000                     {
1001                         DBG_UNHANDLED_EXCEPTION();
1002                     }
1003                     WriteCell(pFormat[i-1],pColWidth[i-1],nHeight,pHorJustify[i-1],aValue,OOO_STRING_SVTOOLS_HTML_tabledata);
1004                 }
1005             }
1006             ++j;
1007             TAG_OFF_LF( OOO_STRING_SVTOOLS_HTML_tablerow );
1008         }
1009 
1010         delete [] pFormat;
1011         delete [] pHorJustify;
1012         delete [] pColWidth;
1013     }
1014     else
1015     {
1016         IncIndent(-1);
1017         TAG_OFF_LF( OOO_STRING_SVTOOLS_HTML_tablerow );
1018         TAG_OFF_LF( OOO_STRING_SVTOOLS_HTML_thead );
1019 
1020         IncIndent(1);
1021         TAG_ON_LF( OOO_STRING_SVTOOLS_HTML_tbody );
1022     }
1023 
1024     IncIndent(-1); OUT_LF(); TAG_OFF_LF( OOO_STRING_SVTOOLS_HTML_tbody );
1025     IncIndent(-1); TAG_OFF_LF( OOO_STRING_SVTOOLS_HTML_table );
1026 }
1027 //-----------------------------------------------------------------------
1028 void OHTMLImportExport::WriteCell( sal_Int32 nFormat,sal_Int32 nWidthPixel,sal_Int32 nHeightPixel,const char* pChar,
1029                                    const String& rValue,const char* pHtmlTag)
1030 {
1031     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "OHTMLImportExport::WriteCell" );
1032     ::rtl::OString aStrTD = pHtmlTag;
1033 
1034     nWidthPixel  = nWidthPixel  ? nWidthPixel   : 86;
1035     nHeightPixel = nHeightPixel ? nHeightPixel  : 17;
1036 
1037     // trotz der <TABLE COLS=n> und <COL WIDTH=x> Angaben noetig,
1038     // da die nicht von Netscape beachtet werden..
1039     // Spaltenbreite
1040     aStrTD = aStrTD + " ";
1041     aStrTD = aStrTD + OOO_STRING_SVTOOLS_HTML_O_width;
1042     aStrTD = aStrTD + "=";
1043     aStrTD = aStrTD + ::rtl::OString::valueOf((sal_Int32)nWidthPixel);
1044     // Zeilenhoehe
1045     aStrTD = aStrTD + " ";
1046     aStrTD = aStrTD + OOO_STRING_SVTOOLS_HTML_O_height;
1047     aStrTD = aStrTD + "=";
1048     aStrTD = aStrTD + ::rtl::OString::valueOf((sal_Int32)nHeightPixel);
1049 
1050     aStrTD = aStrTD + " ";
1051     aStrTD = aStrTD + OOO_STRING_SVTOOLS_HTML_O_align;
1052     aStrTD = aStrTD + "=";
1053     aStrTD = aStrTD + pChar;
1054 
1055     double fVal = 0.0;
1056 
1057     Reference< ::com::sun::star::util::XNumberFormatsSupplier >  xSupplier = m_xFormatter->getNumberFormatsSupplier();
1058     SvNumberFormatsSupplierObj* pSupplierImpl = SvNumberFormatsSupplierObj::getImplementation( xSupplier );
1059     SvNumberFormatter* pFormatter = pSupplierImpl ? pSupplierImpl->GetNumberFormatter() : NULL;
1060     if(pFormatter)
1061     {
1062         try
1063         {
1064             fVal = m_xFormatter->convertStringToNumber(nFormat,rValue);
1065             ByteString aTmpString(aStrTD);
1066             HTMLOutFuncs::CreateTableDataOptionsValNum( aTmpString, sal_False, fVal,nFormat, *pFormatter );
1067         }
1068         catch(Exception&)
1069         {
1070             ByteString aTmpString(aStrTD);
1071             HTMLOutFuncs::CreateTableDataOptionsValNum( aTmpString, sal_False, fVal,nFormat, *pFormatter );
1072         }
1073     }
1074 
1075     TAG_ON( aStrTD );
1076 
1077     FontOn();
1078 
1079     sal_Bool bBold          = ( ::com::sun::star::awt::FontWeight::BOLD     == m_aFont.Weight );
1080     sal_Bool bItalic        = ( ::com::sun::star::awt::FontSlant_ITALIC     == m_aFont.Slant );
1081     sal_Bool bUnderline     = ( ::com::sun::star::awt::FontUnderline::NONE  != m_aFont.Underline );
1082     sal_Bool bStrikeout     = ( ::com::sun::star::awt::FontStrikeout::NONE  != m_aFont.Strikeout );
1083 
1084     if ( bBold )        TAG_ON( OOO_STRING_SVTOOLS_HTML_bold );
1085     if ( bItalic )      TAG_ON( OOO_STRING_SVTOOLS_HTML_italic );
1086     if ( bUnderline )   TAG_ON( OOO_STRING_SVTOOLS_HTML_underline );
1087     if ( bStrikeout )   TAG_ON( OOO_STRING_SVTOOLS_HTML_strike );
1088 
1089     if ( !rValue.Len() )
1090         TAG_ON( OOO_STRING_SVTOOLS_HTML_linebreak );        // #42573# keine komplett leere Zelle
1091     else
1092         HTMLOutFuncs::Out_String( (*m_pStream), rValue ,m_eDestEnc);
1093 
1094 
1095     if ( bStrikeout )   TAG_OFF( OOO_STRING_SVTOOLS_HTML_strike );
1096     if ( bUnderline )   TAG_OFF( OOO_STRING_SVTOOLS_HTML_underline );
1097     if ( bItalic )      TAG_OFF( OOO_STRING_SVTOOLS_HTML_italic );
1098     if ( bBold )        TAG_OFF( OOO_STRING_SVTOOLS_HTML_bold );
1099 
1100     FontOff();
1101 
1102     TAG_OFF_LF( pHtmlTag );
1103 }
1104 //-----------------------------------------------------------------------
1105 void OHTMLImportExport::FontOn()
1106 {
1107     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "OHTMLImportExport::FontOn" );
1108 #ifdef DBG_UTIL
1109         m_bCheckFont = sal_True;
1110 #endif
1111 
1112     // <FONT FACE="xxx">
1113     ::rtl::OString aStrOut  = "<";
1114     aStrOut  = aStrOut + OOO_STRING_SVTOOLS_HTML_font;
1115     aStrOut  = aStrOut + " ";
1116     aStrOut  = aStrOut + OOO_STRING_SVTOOLS_HTML_O_face;
1117     aStrOut  = aStrOut + "=";
1118     aStrOut  = aStrOut + "\"";
1119     aStrOut  = aStrOut + ::rtl::OString(m_aFont.Name,m_aFont.Name.getLength(),gsl_getSystemTextEncoding());
1120         // TODO : think about the encoding of the font name
1121     aStrOut  = aStrOut + "\"";
1122     aStrOut  = aStrOut + " ";
1123     aStrOut  = aStrOut + OOO_STRING_SVTOOLS_HTML_O_color;
1124     aStrOut  = aStrOut + "=";
1125     (*m_pStream) << aStrOut;
1126 
1127     sal_Int32 nColor = 0;
1128     if(m_xObject.is())
1129         m_xObject->getPropertyValue(PROPERTY_TEXTCOLOR) >>= nColor;
1130     ::Color aColor(nColor);
1131 
1132     HTMLOutFuncs::Out_Color( (*m_pStream), aColor );
1133     (*m_pStream) << ">";
1134 }
1135 //-----------------------------------------------------------------------
1136 inline void OHTMLImportExport::FontOff()
1137 {
1138     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "OHTMLImportExport::FontOff" );
1139     DBG_ASSERT(m_bCheckFont,"Kein FontOn() gerufen");
1140     TAG_OFF( OOO_STRING_SVTOOLS_HTML_font );
1141 #ifdef DBG_UTIL
1142     m_bCheckFont = sal_False;
1143 #endif
1144 }
1145 //-----------------------------------------------------------------------
1146 void OHTMLImportExport::IncIndent( sal_Int16 nVal )
1147 {
1148     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "OHTMLImportExport::IncIndent" );
1149     sIndent[m_nIndent] = '\t';
1150     m_nIndent = m_nIndent + nVal;
1151     if ( m_nIndent < 0 )
1152         m_nIndent = 0;
1153     else if ( m_nIndent > nIndentMax )
1154         m_nIndent = nIndentMax;
1155     sIndent[m_nIndent] = 0;
1156 }
1157 // -----------------------------------------------------------------------------
1158