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