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 #ifndef DBUI_TABLECOPYHELPER_HXX
31*cdf0e10cSrcweir #include "TableCopyHelper.hxx"
32*cdf0e10cSrcweir #endif
33*cdf0e10cSrcweir #ifndef DBACCESS_SHARED_DBUSTRINGS_HRC
34*cdf0e10cSrcweir #include "dbustrings.hrc"
35*cdf0e10cSrcweir #endif
36*cdf0e10cSrcweir #ifndef _DBAUI_SQLMESSAGE_HXX_
37*cdf0e10cSrcweir #include "sqlmessage.hxx"
38*cdf0e10cSrcweir #endif
39*cdf0e10cSrcweir #ifndef _SV_MSGBOX_HXX
40*cdf0e10cSrcweir #include <vcl/msgbox.hxx>
41*cdf0e10cSrcweir #endif
42*cdf0e10cSrcweir #ifndef DBAUI_WIZ_COPYTABLEDIALOG_HXX
43*cdf0e10cSrcweir #include "WCopyTable.hxx"
44*cdf0e10cSrcweir #endif
45*cdf0e10cSrcweir #ifndef DBAUI_GENERICCONTROLLER_HXX
46*cdf0e10cSrcweir #include "genericcontroller.hxx"
47*cdf0e10cSrcweir #endif
48*cdf0e10cSrcweir #ifndef DBAUI_WIZARD_CPAGE_HXX
49*cdf0e10cSrcweir #include "WCPage.hxx"
50*cdf0e10cSrcweir #endif
51*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_TASK_XINTERACTIONHANDLER_HPP_
52*cdf0e10cSrcweir #include <com/sun/star/task/XInteractionHandler.hpp>
53*cdf0e10cSrcweir #endif
54*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDB_XSINGLESELECTQUERYCOMPOSER_HPP_
55*cdf0e10cSrcweir #include <com/sun/star/sdb/XSingleSelectQueryComposer.hpp>
56*cdf0e10cSrcweir #endif
57*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDB_APPLICATION_COPYTABLEOPERATION_HPP_
58*cdf0e10cSrcweir #include <com/sun/star/sdb/application/CopyTableOperation.hpp>
59*cdf0e10cSrcweir #endif
60*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDB_APPLICATION_COPYTABLEWIZARD_HPP_
61*cdf0e10cSrcweir #include <com/sun/star/sdb/application/CopyTableWizard.hpp>
62*cdf0e10cSrcweir #endif
63*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDB_DATAACCESSDESCRIPTORFACTORY_HPP_
64*cdf0e10cSrcweir #include <com/sun/star/sdb/DataAccessDescriptorFactory.hpp>
65*cdf0e10cSrcweir #endif
66*cdf0e10cSrcweir 
67*cdf0e10cSrcweir #ifndef DBAUI_RTFREADER_HXX
68*cdf0e10cSrcweir #include "RtfReader.hxx"
69*cdf0e10cSrcweir #endif
70*cdf0e10cSrcweir #ifndef DBAUI_HTMLREADER_HXX
71*cdf0e10cSrcweir #include "HtmlReader.hxx"
72*cdf0e10cSrcweir #endif
73*cdf0e10cSrcweir #ifndef DBAUI_TOKENWRITER_HXX
74*cdf0e10cSrcweir #include "TokenWriter.hxx"
75*cdf0e10cSrcweir #endif
76*cdf0e10cSrcweir #ifndef DBAUI_TOOLS_HXX
77*cdf0e10cSrcweir #include "UITools.hxx"
78*cdf0e10cSrcweir #endif
79*cdf0e10cSrcweir #ifndef DBAUI_DATAVIEW_HXX
80*cdf0e10cSrcweir #include "dataview.hxx"
81*cdf0e10cSrcweir #endif
82*cdf0e10cSrcweir #ifndef _DBU_RESOURCE_HRC_
83*cdf0e10cSrcweir #include "dbu_resource.hrc"
84*cdf0e10cSrcweir #endif
85*cdf0e10cSrcweir #ifndef _UNOTOOLS_UCBHELPER_HXX
86*cdf0e10cSrcweir #include <unotools/ucbhelper.hxx>
87*cdf0e10cSrcweir #endif
88*cdf0e10cSrcweir #ifndef _URLOBJ_HXX
89*cdf0e10cSrcweir #include <tools/urlobj.hxx>
90*cdf0e10cSrcweir #endif
91*cdf0e10cSrcweir #ifndef TOOLS_DIAGNOSE_EX_H
92*cdf0e10cSrcweir #include <tools/diagnose_ex.h>
93*cdf0e10cSrcweir #endif
94*cdf0e10cSrcweir #ifndef COMPHELPER_COMPONENTCONTEXT_HXX
95*cdf0e10cSrcweir #include <comphelper/componentcontext.hxx>
96*cdf0e10cSrcweir #endif
97*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDBCX_XTABLESSUPPLIER_HPP_
98*cdf0e10cSrcweir #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
99*cdf0e10cSrcweir #endif
100*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDBCX_XVIEWSSUPPLIER_HPP_
101*cdf0e10cSrcweir #include <com/sun/star/sdbcx/XViewsSupplier.hpp>
102*cdf0e10cSrcweir #endif
103*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDB_XQUERYDEFINITIONSSUPPLIER_HPP_
104*cdf0e10cSrcweir #include <com/sun/star/sdb/XQueryDefinitionsSupplier.hpp>
105*cdf0e10cSrcweir #endif
106*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDB_SQLCONTEXT_HPP_
107*cdf0e10cSrcweir #include <com/sun/star/sdb/SQLContext.hpp>
108*cdf0e10cSrcweir #endif
109*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDBC_XPARAMETERS_HPP_
110*cdf0e10cSrcweir #include <com/sun/star/sdbc/XParameters.hpp>
111*cdf0e10cSrcweir #endif
112*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDBC_XRESULTSETMETADATASUPPLIER_HPP_
113*cdf0e10cSrcweir #include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
114*cdf0e10cSrcweir #endif
115*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDB_XQUERIESSUPPLIER_HPP_
116*cdf0e10cSrcweir #include <com/sun/star/sdb/XQueriesSupplier.hpp>
117*cdf0e10cSrcweir #endif
118*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDBC_XCOLUMNLOCATE_HPP_
119*cdf0e10cSrcweir #include <com/sun/star/sdbc/XColumnLocate.hpp>
120*cdf0e10cSrcweir #endif
121*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDBCX_XROWLOCATE_HPP_
122*cdf0e10cSrcweir #include <com/sun/star/sdbcx/XRowLocate.hpp>
123*cdf0e10cSrcweir #endif
124*cdf0e10cSrcweir #ifndef _SV_WAITOBJ_HXX
125*cdf0e10cSrcweir #include <vcl/waitobj.hxx>
126*cdf0e10cSrcweir #endif
127*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDB_XSQLQUERYCOMPOSERFACTORY_HPP_
128*cdf0e10cSrcweir #include <com/sun/star/sdb/XSQLQueryComposerFactory.hpp>
129*cdf0e10cSrcweir #endif
130*cdf0e10cSrcweir #ifndef _UNOTOOLS_TEMPFILE_HXX
131*cdf0e10cSrcweir #include <unotools/tempfile.hxx>
132*cdf0e10cSrcweir #endif
133*cdf0e10cSrcweir #ifndef _CPPUHELPER_EXC_HLP_HXX_
134*cdf0e10cSrcweir #include <cppuhelper/exc_hlp.hxx>
135*cdf0e10cSrcweir #endif
136*cdf0e10cSrcweir 
137*cdf0e10cSrcweir #ifndef DBAUI_DBEXCHANGE_HXX
138*cdf0e10cSrcweir #include "dbexchange.hxx"
139*cdf0e10cSrcweir #endif
140*cdf0e10cSrcweir #include <rtl/logfile.hxx>
141*cdf0e10cSrcweir //........................................................................
142*cdf0e10cSrcweir namespace dbaui
143*cdf0e10cSrcweir {
144*cdf0e10cSrcweir //........................................................................
145*cdf0e10cSrcweir using namespace ::dbtools;
146*cdf0e10cSrcweir using namespace ::svx;
147*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
148*cdf0e10cSrcweir using namespace ::com::sun::star::task;
149*cdf0e10cSrcweir using namespace ::com::sun::star::beans;
150*cdf0e10cSrcweir using namespace ::com::sun::star::lang;
151*cdf0e10cSrcweir using namespace ::com::sun::star::container;
152*cdf0e10cSrcweir using namespace ::com::sun::star::sdb;
153*cdf0e10cSrcweir using namespace ::com::sun::star::sdb::application;
154*cdf0e10cSrcweir using namespace ::com::sun::star::sdbc;
155*cdf0e10cSrcweir using namespace ::com::sun::star::sdbcx;
156*cdf0e10cSrcweir using namespace ::com::sun::star::frame;
157*cdf0e10cSrcweir using namespace ::com::sun::star::ucb;
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir // -----------------------------------------------------------------------------
160*cdf0e10cSrcweir OTableCopyHelper::OTableCopyHelper(OGenericUnoController* _pControler)
161*cdf0e10cSrcweir     :m_pController(_pControler)
162*cdf0e10cSrcweir {
163*cdf0e10cSrcweir }
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir // -----------------------------------------------------------------------------
166*cdf0e10cSrcweir void OTableCopyHelper::insertTable( const ::rtl::OUString& i_rSourceDataSource, const Reference<XConnection>& i_rSourceConnection,
167*cdf0e10cSrcweir         const ::rtl::OUString& i_rCommand, const sal_Int32 i_nCommandType,
168*cdf0e10cSrcweir         const Reference< XResultSet >& i_rSourceRows, const Sequence< Any >& i_rSelection, const sal_Bool i_bBookmarkSelection,
169*cdf0e10cSrcweir         const ::rtl::OUString& i_rDestDataSource, const Reference<XConnection>& i_rDestConnection)
170*cdf0e10cSrcweir {
171*cdf0e10cSrcweir     if ( CommandType::QUERY != i_nCommandType && CommandType::TABLE != i_nCommandType )
172*cdf0e10cSrcweir     {
173*cdf0e10cSrcweir 		DBG_ERROR( "OTableCopyHelper::insertTable: invalid call (no supported format found)!" );
174*cdf0e10cSrcweir         return;
175*cdf0e10cSrcweir     }
176*cdf0e10cSrcweir 
177*cdf0e10cSrcweir 	try
178*cdf0e10cSrcweir 	{
179*cdf0e10cSrcweir         Reference<XConnection> xSrcConnection( i_rSourceConnection );
180*cdf0e10cSrcweir         if ( i_rSourceDataSource == i_rDestDataSource )
181*cdf0e10cSrcweir             xSrcConnection = i_rDestConnection;
182*cdf0e10cSrcweir 
183*cdf0e10cSrcweir         if ( !xSrcConnection.is() || !i_rDestConnection.is() )
184*cdf0e10cSrcweir         {
185*cdf0e10cSrcweir             OSL_ENSURE( false, "OTableCopyHelper::insertTable: no connection/s!" );
186*cdf0e10cSrcweir             return;
187*cdf0e10cSrcweir         }
188*cdf0e10cSrcweir 
189*cdf0e10cSrcweir         ::comphelper::ComponentContext aContext( m_pController->getORB() );
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir         Reference< XDataAccessDescriptorFactory > xFactory( DataAccessDescriptorFactory::get( aContext.getUNOContext() ) );
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir         Reference< XPropertySet > xSource( xFactory->createDataAccessDescriptor(), UNO_SET_THROW );
194*cdf0e10cSrcweir         xSource->setPropertyValue( PROPERTY_COMMAND_TYPE, makeAny( i_nCommandType ) );
195*cdf0e10cSrcweir         xSource->setPropertyValue( PROPERTY_COMMAND, makeAny( i_rCommand ) );
196*cdf0e10cSrcweir         xSource->setPropertyValue( PROPERTY_ACTIVE_CONNECTION, makeAny( xSrcConnection ) );
197*cdf0e10cSrcweir         xSource->setPropertyValue( PROPERTY_RESULT_SET, makeAny( i_rSourceRows ) );
198*cdf0e10cSrcweir         xSource->setPropertyValue( PROPERTY_SELECTION, makeAny( i_rSelection ) );
199*cdf0e10cSrcweir         xSource->setPropertyValue( PROPERTY_BOOKMARK_SELECTION, makeAny( i_bBookmarkSelection ) );
200*cdf0e10cSrcweir 
201*cdf0e10cSrcweir         Reference< XPropertySet > xDest( xFactory->createDataAccessDescriptor(), UNO_SET_THROW );
202*cdf0e10cSrcweir         xDest->setPropertyValue( PROPERTY_ACTIVE_CONNECTION, makeAny( i_rDestConnection ) );
203*cdf0e10cSrcweir 
204*cdf0e10cSrcweir         Reference< XCopyTableWizard > xWizard( CopyTableWizard::create( aContext.getUNOContext(), xSource, xDest ), UNO_SET_THROW );
205*cdf0e10cSrcweir 
206*cdf0e10cSrcweir         ::rtl::OUString sTableNameForAppend( GetTableNameForAppend() );
207*cdf0e10cSrcweir         xWizard->setDestinationTableName( GetTableNameForAppend() );
208*cdf0e10cSrcweir 
209*cdf0e10cSrcweir         bool bAppendToExisting = ( sTableNameForAppend.getLength() != 0 );
210*cdf0e10cSrcweir         xWizard->setOperation( bAppendToExisting ? CopyTableOperation::AppendData : CopyTableOperation::CopyDefinitionAndData );
211*cdf0e10cSrcweir 
212*cdf0e10cSrcweir         xWizard->execute();
213*cdf0e10cSrcweir 	}
214*cdf0e10cSrcweir 	catch( const SQLException& )
215*cdf0e10cSrcweir     {
216*cdf0e10cSrcweir         m_pController->showError( SQLExceptionInfo( ::cppu::getCaughtException() ) );
217*cdf0e10cSrcweir     }
218*cdf0e10cSrcweir 	catch( const Exception& )
219*cdf0e10cSrcweir 	{
220*cdf0e10cSrcweir         DBG_UNHANDLED_EXCEPTION();
221*cdf0e10cSrcweir 	}
222*cdf0e10cSrcweir }
223*cdf0e10cSrcweir 
224*cdf0e10cSrcweir // -----------------------------------------------------------------------------
225*cdf0e10cSrcweir void OTableCopyHelper::pasteTable( const ::svx::ODataAccessDescriptor& _rPasteData, const ::rtl::OUString& i_rDestDataSourceName,
226*cdf0e10cSrcweir                                   const SharedConnection& i_rDestConnection )
227*cdf0e10cSrcweir {
228*cdf0e10cSrcweir     ::rtl::OUString sSrcDataSourceName = _rPasteData.getDataSource();
229*cdf0e10cSrcweir 
230*cdf0e10cSrcweir     ::rtl::OUString sCommand;
231*cdf0e10cSrcweir     _rPasteData[ daCommand ] >>= sCommand;
232*cdf0e10cSrcweir 
233*cdf0e10cSrcweir     Reference<XConnection> xSrcConnection;
234*cdf0e10cSrcweir     if ( _rPasteData.has(daConnection) )
235*cdf0e10cSrcweir     {
236*cdf0e10cSrcweir         OSL_VERIFY( _rPasteData[daConnection] >>= xSrcConnection );
237*cdf0e10cSrcweir     }
238*cdf0e10cSrcweir 
239*cdf0e10cSrcweir     Reference< XResultSet > xResultSet;
240*cdf0e10cSrcweir     if ( _rPasteData.has(daCursor) )
241*cdf0e10cSrcweir     {
242*cdf0e10cSrcweir         OSL_VERIFY( _rPasteData[ daCursor ] >>= xResultSet );
243*cdf0e10cSrcweir     }
244*cdf0e10cSrcweir 
245*cdf0e10cSrcweir     Sequence< Any > aSelection;
246*cdf0e10cSrcweir     if ( _rPasteData.has( daSelection ) )
247*cdf0e10cSrcweir     {
248*cdf0e10cSrcweir         OSL_VERIFY( _rPasteData[ daSelection ] >>= aSelection );
249*cdf0e10cSrcweir         OSL_ENSURE( _rPasteData.has( daBookmarkSelection ), "OTableCopyHelper::pasteTable: you should specify BookmarkSelection, too, to be on the safe side!" );
250*cdf0e10cSrcweir     }
251*cdf0e10cSrcweir 
252*cdf0e10cSrcweir 
253*cdf0e10cSrcweir     sal_Bool bBookmarkSelection( sal_True );
254*cdf0e10cSrcweir     if ( _rPasteData.has( daBookmarkSelection ) )
255*cdf0e10cSrcweir     {
256*cdf0e10cSrcweir         OSL_VERIFY( _rPasteData[ daBookmarkSelection ] >>= bBookmarkSelection );
257*cdf0e10cSrcweir     }
258*cdf0e10cSrcweir     OSL_ENSURE( bBookmarkSelection, "OTableCopyHelper::pasteTable: working with selection-indicies (instead of bookmarks) is error-prone, and thus deprecated!" );
259*cdf0e10cSrcweir 
260*cdf0e10cSrcweir     sal_Int32 nCommandType = CommandType::COMMAND;
261*cdf0e10cSrcweir     if ( _rPasteData.has(daCommandType) )
262*cdf0e10cSrcweir         _rPasteData[daCommandType] >>= nCommandType;
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir     insertTable( sSrcDataSourceName, xSrcConnection, sCommand, nCommandType,
265*cdf0e10cSrcweir                  xResultSet, aSelection, bBookmarkSelection,
266*cdf0e10cSrcweir                  i_rDestDataSourceName, i_rDestConnection );
267*cdf0e10cSrcweir }
268*cdf0e10cSrcweir 
269*cdf0e10cSrcweir // -----------------------------------------------------------------------------
270*cdf0e10cSrcweir void OTableCopyHelper::pasteTable( SotFormatStringId _nFormatId
271*cdf0e10cSrcweir                                   ,const TransferableDataHelper& _rTransData
272*cdf0e10cSrcweir                                   ,const ::rtl::OUString& i_rDestDataSource
273*cdf0e10cSrcweir                                   ,const SharedConnection& _xConnection)
274*cdf0e10cSrcweir {
275*cdf0e10cSrcweir     if ( _nFormatId == SOT_FORMATSTR_ID_DBACCESS_TABLE || _nFormatId == SOT_FORMATSTR_ID_DBACCESS_QUERY )
276*cdf0e10cSrcweir 	{
277*cdf0e10cSrcweir 		if ( ODataAccessObjectTransferable::canExtractObjectDescriptor(_rTransData.GetDataFlavorExVector()) )
278*cdf0e10cSrcweir 		{
279*cdf0e10cSrcweir 			::svx::ODataAccessDescriptor aPasteData = ODataAccessObjectTransferable::extractObjectDescriptor(_rTransData);
280*cdf0e10cSrcweir 			pasteTable( aPasteData,i_rDestDataSource,_xConnection);
281*cdf0e10cSrcweir 		}
282*cdf0e10cSrcweir 	}
283*cdf0e10cSrcweir 	else if ( _rTransData.HasFormat(_nFormatId) )
284*cdf0e10cSrcweir 	{
285*cdf0e10cSrcweir 		try
286*cdf0e10cSrcweir 		{
287*cdf0e10cSrcweir 			DropDescriptor aTrans;
288*cdf0e10cSrcweir 			if ( _nFormatId != SOT_FORMAT_RTF )
289*cdf0e10cSrcweir 				const_cast<TransferableDataHelper&>(_rTransData).GetSotStorageStream(SOT_FORMATSTR_ID_HTML ,aTrans.aHtmlRtfStorage);
290*cdf0e10cSrcweir 			else
291*cdf0e10cSrcweir 				const_cast<TransferableDataHelper&>(_rTransData).GetSotStorageStream(SOT_FORMAT_RTF,aTrans.aHtmlRtfStorage);
292*cdf0e10cSrcweir 
293*cdf0e10cSrcweir 			aTrans.nType			= E_TABLE;
294*cdf0e10cSrcweir 			aTrans.bHtml			= SOT_FORMATSTR_ID_HTML == _nFormatId;
295*cdf0e10cSrcweir 			aTrans.sDefaultTableName = GetTableNameForAppend();
296*cdf0e10cSrcweir 			if ( !copyTagTable(aTrans,sal_False,_xConnection) )
297*cdf0e10cSrcweir 				m_pController->showError(SQLException(String(ModuleRes(STR_NO_TABLE_FORMAT_INSIDE)),*m_pController,::rtl::OUString::createFromAscii("S1000") ,0,Any()));
298*cdf0e10cSrcweir 		}
299*cdf0e10cSrcweir         catch(const SQLException&)
300*cdf0e10cSrcweir         {
301*cdf0e10cSrcweir             m_pController->showError( SQLExceptionInfo( ::cppu::getCaughtException() ) );
302*cdf0e10cSrcweir         }
303*cdf0e10cSrcweir         catch( const Exception& )
304*cdf0e10cSrcweir         {
305*cdf0e10cSrcweir             DBG_UNHANDLED_EXCEPTION();
306*cdf0e10cSrcweir         }
307*cdf0e10cSrcweir 	}
308*cdf0e10cSrcweir 	else
309*cdf0e10cSrcweir 		m_pController->showError(SQLException(String(ModuleRes(STR_NO_TABLE_FORMAT_INSIDE)),*m_pController,::rtl::OUString::createFromAscii("S1000") ,0,Any()));
310*cdf0e10cSrcweir }
311*cdf0e10cSrcweir 
312*cdf0e10cSrcweir // -----------------------------------------------------------------------------
313*cdf0e10cSrcweir void OTableCopyHelper::pasteTable( const TransferableDataHelper& _rTransData
314*cdf0e10cSrcweir                                   ,const ::rtl::OUString& i_rDestDataSource
315*cdf0e10cSrcweir                                   ,const SharedConnection& _xConnection)
316*cdf0e10cSrcweir {
317*cdf0e10cSrcweir 	if ( _rTransData.HasFormat(SOT_FORMATSTR_ID_DBACCESS_TABLE) || _rTransData.HasFormat(SOT_FORMATSTR_ID_DBACCESS_QUERY) )
318*cdf0e10cSrcweir 		pasteTable( SOT_FORMATSTR_ID_DBACCESS_TABLE,_rTransData,i_rDestDataSource,_xConnection);
319*cdf0e10cSrcweir 	else if ( _rTransData.HasFormat(SOT_FORMATSTR_ID_HTML) )
320*cdf0e10cSrcweir 		pasteTable( SOT_FORMATSTR_ID_HTML,_rTransData,i_rDestDataSource,_xConnection);
321*cdf0e10cSrcweir 	else if ( _rTransData.HasFormat(SOT_FORMAT_RTF) )
322*cdf0e10cSrcweir 		pasteTable( SOT_FORMAT_RTF,_rTransData,i_rDestDataSource,_xConnection);
323*cdf0e10cSrcweir }
324*cdf0e10cSrcweir 
325*cdf0e10cSrcweir // -----------------------------------------------------------------------------
326*cdf0e10cSrcweir sal_Bool OTableCopyHelper::copyTagTable(OTableCopyHelper::DropDescriptor& _rDesc, sal_Bool _bCheck,const SharedConnection& _xConnection)
327*cdf0e10cSrcweir {
328*cdf0e10cSrcweir     Reference<XEventListener> xEvt;
329*cdf0e10cSrcweir 	ODatabaseImportExport* pImport = NULL;
330*cdf0e10cSrcweir 	if ( _rDesc.bHtml )
331*cdf0e10cSrcweir 		pImport = new OHTMLImportExport(_xConnection,getNumberFormatter(_xConnection,m_pController->getORB()),m_pController->getORB());
332*cdf0e10cSrcweir 	else
333*cdf0e10cSrcweir 		pImport = new ORTFImportExport(_xConnection,getNumberFormatter(_xConnection,m_pController->getORB()),m_pController->getORB());
334*cdf0e10cSrcweir 
335*cdf0e10cSrcweir 	xEvt = pImport;
336*cdf0e10cSrcweir 	SvStream* pStream = (SvStream*)(SotStorageStream*)_rDesc.aHtmlRtfStorage;
337*cdf0e10cSrcweir 	if ( _bCheck )
338*cdf0e10cSrcweir 		pImport->enableCheckOnly();
339*cdf0e10cSrcweir 
340*cdf0e10cSrcweir 	//dyf add 20070601
341*cdf0e10cSrcweir 	//set the selected tablename
342*cdf0e10cSrcweir 	pImport->setSTableName(_rDesc.sDefaultTableName);
343*cdf0e10cSrcweir 	//dyf add end
344*cdf0e10cSrcweir 	pImport->setStream(pStream);
345*cdf0e10cSrcweir 	return pImport->Read();
346*cdf0e10cSrcweir }
347*cdf0e10cSrcweir // -----------------------------------------------------------------------------
348*cdf0e10cSrcweir sal_Bool OTableCopyHelper::isTableFormat(const TransferableDataHelper& _rClipboard)  const
349*cdf0e10cSrcweir {
350*cdf0e10cSrcweir 	sal_Bool bTableFormat	=	_rClipboard.HasFormat(SOT_FORMATSTR_ID_DBACCESS_TABLE)
351*cdf0e10cSrcweir 				||	_rClipboard.HasFormat(SOT_FORMATSTR_ID_DBACCESS_QUERY)
352*cdf0e10cSrcweir 				||	_rClipboard.HasFormat(SOT_FORMAT_RTF)
353*cdf0e10cSrcweir 				||	_rClipboard.HasFormat(SOT_FORMATSTR_ID_HTML);
354*cdf0e10cSrcweir 
355*cdf0e10cSrcweir 	return bTableFormat;
356*cdf0e10cSrcweir }
357*cdf0e10cSrcweir // -----------------------------------------------------------------------------
358*cdf0e10cSrcweir sal_Bool OTableCopyHelper::copyTagTable(const TransferableDataHelper& _aDroppedData
359*cdf0e10cSrcweir                                         ,DropDescriptor& _rAsyncDrop
360*cdf0e10cSrcweir                                         ,const SharedConnection& _xConnection)
361*cdf0e10cSrcweir {
362*cdf0e10cSrcweir     sal_Bool bRet = sal_False;
363*cdf0e10cSrcweir     sal_Bool bHtml = _aDroppedData.HasFormat(SOT_FORMATSTR_ID_HTML);
364*cdf0e10cSrcweir 	if ( bHtml || _aDroppedData.HasFormat(SOT_FORMAT_RTF) )
365*cdf0e10cSrcweir 	{
366*cdf0e10cSrcweir 		if ( bHtml )
367*cdf0e10cSrcweir 			const_cast<TransferableDataHelper&>(_aDroppedData).GetSotStorageStream(SOT_FORMATSTR_ID_HTML ,_rAsyncDrop.aHtmlRtfStorage);
368*cdf0e10cSrcweir 		else
369*cdf0e10cSrcweir 			const_cast<TransferableDataHelper&>(_aDroppedData).GetSotStorageStream(SOT_FORMAT_RTF,_rAsyncDrop.aHtmlRtfStorage);
370*cdf0e10cSrcweir 
371*cdf0e10cSrcweir 		_rAsyncDrop.bHtml			= bHtml;
372*cdf0e10cSrcweir 		_rAsyncDrop.bError			= !copyTagTable(_rAsyncDrop,sal_True,_xConnection);
373*cdf0e10cSrcweir 
374*cdf0e10cSrcweir         bRet = ( !_rAsyncDrop.bError && _rAsyncDrop.aHtmlRtfStorage.Is() );
375*cdf0e10cSrcweir 		if ( bRet )
376*cdf0e10cSrcweir 		{
377*cdf0e10cSrcweir 			// now we need to copy the stream
378*cdf0e10cSrcweir 			::utl::TempFile aTmp;
379*cdf0e10cSrcweir 			aTmp.EnableKillingFile(sal_False);
380*cdf0e10cSrcweir 			_rAsyncDrop.aUrl = aTmp.GetURL();
381*cdf0e10cSrcweir 			SotStorageStreamRef aNew = new SotStorageStream( aTmp.GetFileName() );
382*cdf0e10cSrcweir 			_rAsyncDrop.aHtmlRtfStorage->Seek(STREAM_SEEK_TO_BEGIN);
383*cdf0e10cSrcweir 			_rAsyncDrop.aHtmlRtfStorage->CopyTo( aNew );
384*cdf0e10cSrcweir 			aNew->Commit();
385*cdf0e10cSrcweir 			_rAsyncDrop.aHtmlRtfStorage = aNew;
386*cdf0e10cSrcweir 		}
387*cdf0e10cSrcweir 		else
388*cdf0e10cSrcweir 			_rAsyncDrop.aHtmlRtfStorage = NULL;
389*cdf0e10cSrcweir 	}
390*cdf0e10cSrcweir     return bRet;
391*cdf0e10cSrcweir }
392*cdf0e10cSrcweir // -----------------------------------------------------------------------------
393*cdf0e10cSrcweir void OTableCopyHelper::asyncCopyTagTable(  DropDescriptor& _rDesc
394*cdf0e10cSrcweir                                 ,const ::rtl::OUString& i_rDestDataSource
395*cdf0e10cSrcweir                                 ,const SharedConnection& _xConnection)
396*cdf0e10cSrcweir {
397*cdf0e10cSrcweir     if ( _rDesc.aHtmlRtfStorage.Is() )
398*cdf0e10cSrcweir 	{
399*cdf0e10cSrcweir 		copyTagTable(_rDesc,sal_False,_xConnection);
400*cdf0e10cSrcweir 		_rDesc.aHtmlRtfStorage = NULL;
401*cdf0e10cSrcweir 		// we now have to delete the temp file created in executeDrop
402*cdf0e10cSrcweir 		INetURLObject aURL;
403*cdf0e10cSrcweir 		aURL.SetURL(_rDesc.aUrl);
404*cdf0e10cSrcweir 		::utl::UCBContentHelper::Kill(aURL.GetMainURL(INetURLObject::NO_DECODE));
405*cdf0e10cSrcweir 	}
406*cdf0e10cSrcweir 	else if ( !_rDesc.bError )
407*cdf0e10cSrcweir 		pasteTable(_rDesc.aDroppedData,i_rDestDataSource,_xConnection);
408*cdf0e10cSrcweir 	else
409*cdf0e10cSrcweir 		m_pController->showError(SQLException(String(ModuleRes(STR_NO_TABLE_FORMAT_INSIDE)),*m_pController,::rtl::OUString::createFromAscii("S1000") ,0,Any()));
410*cdf0e10cSrcweir }
411*cdf0e10cSrcweir // -----------------------------------------------------------------------------
412*cdf0e10cSrcweir //........................................................................
413*cdf0e10cSrcweir }	// namespace dbaui
414*cdf0e10cSrcweir //........................................................................
415*cdf0e10cSrcweir 
416