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