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