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