Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "flt_reghelper.hxx"
21 : #include "xmlservices.hxx"
22 : #include "xmlstrings.hrc"
23 :
24 : #include <com/sun/star/beans/NamedValue.hpp>
25 : #include <com/sun/star/beans/XPropertySet.hpp>
26 : #include <com/sun/star/document/XEventListener.hpp>
27 : #include <com/sun/star/document/XExtendedFilterDetection.hpp>
28 : #include <com/sun/star/document/XFilter.hpp>
29 : #include <com/sun/star/embed/ElementModes.hpp>
30 : #include <com/sun/star/embed/XStorage.hpp>
31 : #include <com/sun/star/frame/Desktop.hpp>
32 : #include <com/sun/star/frame/XController.hpp>
33 : #include <com/sun/star/frame/XFrame.hpp>
34 : #include <com/sun/star/frame/XFrameLoader.hpp>
35 : #include <com/sun/star/frame/XFramesSupplier.hpp>
36 : #include <com/sun/star/frame/XLoadEventListener.hpp>
37 : #include <com/sun/star/frame/XModel2.hpp>
38 : #include <com/sun/star/io/XInputStream.hpp>
39 : #include <com/sun/star/lang/XInitialization.hpp>
40 : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
41 : #include <com/sun/star/lang/XServiceInfo.hpp>
42 : #include <com/sun/star/registry/XRegistryKey.hpp>
43 : #include <com/sun/star/sdb/DatabaseContext.hpp>
44 : #include <com/sun/star/sdb/XDocumentDataSource.hpp>
45 : #include <com/sun/star/task/XJobExecutor.hpp>
46 : #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
47 : #include <com/sun/star/task/InteractionHandler.hpp>
48 : #include <com/sun/star/util/URLTransformer.hpp>
49 : #include <com/sun/star/util/XURLTransformer.hpp>
50 : #include <com/sun/star/view/XSelectionSupplier.hpp>
51 : #include <com/sun/star/sdb/application/DatabaseObjectContainer.hpp>
52 : #include <com/sun/star/sdb/application/NamedDatabaseObject.hpp>
53 : #include <com/sun/star/frame/XLoadable.hpp>
54 :
55 : #include <comphelper/documentconstants.hxx>
56 : #include <comphelper/namedvaluecollection.hxx>
57 : #include <comphelper/processfactory.hxx>
58 : #include <comphelper/sequenceashashmap.hxx>
59 : #include <comphelper/storagehelper.hxx>
60 : #include <comphelper/types.hxx>
61 : #include <cppuhelper/implbase2.hxx>
62 : #include <cppuhelper/supportsservice.hxx>
63 : #include <osl/file.hxx>
64 : #include <sfx2/docfile.hxx>
65 : #include <unotools/moduleoptions.hxx>
66 : #include <toolkit/awt/vclxwindow.hxx>
67 : #include <toolkit/helper/vclunohelper.hxx>
68 : #include <tools/diagnose_ex.h>
69 : #include <ucbhelper/commandenvironment.hxx>
70 : #include <ucbhelper/content.hxx>
71 : #include <vcl/msgbox.hxx>
72 : #include <vcl/svapp.hxx>
73 :
74 : using namespace ::ucbhelper;
75 : using namespace ::com::sun::star::task;
76 : using namespace ::com::sun::star::uno;
77 : using namespace ::com::sun::star::ucb;
78 : using namespace ::com::sun::star::io;
79 : using namespace ::com::sun::star::util;
80 : using namespace ::com::sun::star::frame;
81 : using namespace ::com::sun::star::beans;
82 : using namespace ::com::sun::star::container;
83 : using namespace ::com::sun::star::lang;
84 : using namespace ::com::sun::star::document;
85 : using namespace ::com::sun::star::registry;
86 : using namespace ::com::sun::star::sdb;
87 : using namespace ::com::sun::star::embed;
88 : using namespace ::com::sun::star::ui::dialogs;
89 : using ::com::sun::star::awt::XWindow;
90 : using ::com::sun::star::sdb::application::NamedDatabaseObject;
91 :
92 : namespace dbaxml
93 : {
94 :
95 184 : class DBTypeDetection : public ::cppu::WeakImplHelper2< XExtendedFilterDetection, XServiceInfo>
96 : {
97 : const Reference< XComponentContext > m_aContext;
98 :
99 : public:
100 : DBTypeDetection(const Reference< XComponentContext >&);
101 :
102 : // XServiceInfo
103 : OUString SAL_CALL getImplementationName() throw(std::exception ) SAL_OVERRIDE;
104 : sal_Bool SAL_CALL supportsService(const OUString& ServiceName) throw(std::exception ) SAL_OVERRIDE;
105 : Sequence< OUString > SAL_CALL getSupportedServiceNames() throw(std::exception ) SAL_OVERRIDE;
106 :
107 : // static methods
108 47 : static OUString getImplementationName_Static() throw( )
109 : {
110 47 : return OUString("org.openoffice.comp.dbflt.DBTypeDetection");
111 : }
112 : static Sequence< OUString> getSupportedServiceNames_Static() throw( );
113 : static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
114 : SAL_CALL Create(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&);
115 :
116 : virtual OUString SAL_CALL detect( ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& Descriptor ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
117 : };
118 :
119 92 : DBTypeDetection::DBTypeDetection(const Reference< XComponentContext >& _rxContext)
120 92 : :m_aContext( _rxContext )
121 : {
122 92 : }
123 :
124 91 : OUString SAL_CALL DBTypeDetection::detect( ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& Descriptor ) throw (::com::sun::star::uno::RuntimeException, std::exception)
125 : {
126 : try
127 : {
128 91 : ::comphelper::NamedValueCollection aMedia( Descriptor );
129 91 : bool bStreamFromDescr = false;
130 175 : OUString sURL = aMedia.getOrDefault( "URL", OUString() );
131 :
132 175 : Reference< XInputStream > xInStream( aMedia.getOrDefault( "InputStream", Reference< XInputStream >() ) );
133 175 : Reference< XPropertySet > xStorageProperties;
134 91 : if ( xInStream.is() )
135 : {
136 91 : bStreamFromDescr = true;
137 : xStorageProperties.set( ::comphelper::OStorageHelper::GetStorageFromInputStream(
138 91 : xInStream, m_aContext ), UNO_QUERY );
139 : }
140 : else
141 : {
142 0 : OUString sSalvagedURL( aMedia.getOrDefault( "SalvagedFile", OUString() ) );
143 :
144 0 : OUString sFileLocation( sSalvagedURL.isEmpty() ? sURL : sSalvagedURL );
145 0 : if ( !sFileLocation.isEmpty() )
146 : {
147 : xStorageProperties.set( ::comphelper::OStorageHelper::GetStorageFromURL(
148 0 : sFileLocation, ElementModes::READ, m_aContext ), UNO_QUERY );
149 0 : }
150 : }
151 :
152 7 : if ( xStorageProperties.is() )
153 : {
154 7 : OUString sMediaType;
155 7 : xStorageProperties->getPropertyValue( INFO_MEDIATYPE ) >>= sMediaType;
156 7 : if ( sMediaType == MIMETYPE_OASIS_OPENDOCUMENT_DATABASE_ASCII || sMediaType == MIMETYPE_VND_SUN_XML_BASE_ASCII )
157 : {
158 7 : if ( bStreamFromDescr && !sURL.startsWith( "private:stream" ) )
159 : {
160 : // After fixing of the i88522 issue ( use the new file locking for database files ) the stream from the type detection can be used further
161 : // for now the file should be reopened to have read/write access
162 7 : aMedia.remove( OUString( "InputStream" ) );
163 7 : aMedia.remove( OUString( "Stream" ) );
164 7 : aMedia >>= Descriptor;
165 : try
166 : {
167 7 : ::comphelper::disposeComponent(xStorageProperties);
168 7 : if ( xInStream.is() )
169 7 : xInStream->closeInput();
170 : }
171 0 : catch( Exception& )
172 : {
173 : DBG_UNHANDLED_EXCEPTION();
174 : }
175 : }
176 :
177 7 : return OUString("StarBase");
178 : }
179 0 : ::comphelper::disposeComponent(xStorageProperties);
180 84 : }
181 84 : } catch(Exception&){}
182 84 : return OUString();
183 : }
184 :
185 92 : Reference< XInterface > SAL_CALL DBTypeDetection::Create( const Reference< XMultiServiceFactory > & rSMgr )
186 : {
187 92 : return *(new DBTypeDetection( comphelper::getComponentContext(rSMgr) ));
188 : }
189 :
190 : // XServiceInfo
191 1 : OUString SAL_CALL DBTypeDetection::getImplementationName() throw(std::exception )
192 : {
193 1 : return getImplementationName_Static();
194 : }
195 :
196 : // XServiceInfo
197 0 : sal_Bool SAL_CALL DBTypeDetection::supportsService(const OUString& ServiceName) throw(std::exception )
198 : {
199 0 : return cppu::supportsService(this, ServiceName);
200 : }
201 :
202 : // XServiceInfo
203 1 : Sequence< OUString > SAL_CALL DBTypeDetection::getSupportedServiceNames() throw(std::exception )
204 : {
205 1 : return getSupportedServiceNames_Static();
206 : }
207 :
208 : // ORegistryServiceManager_Static
209 24 : Sequence< OUString > DBTypeDetection::getSupportedServiceNames_Static() throw( )
210 : {
211 24 : Sequence< OUString > aSNS( 1 );
212 24 : aSNS[0] = "com.sun.star.document.ExtendedTypeDetection";
213 24 : return aSNS;
214 : }
215 :
216 : } // namespace dbaxml
217 :
218 23 : extern "C" void SAL_CALL createRegistryInfo_DBTypeDetection()
219 : {
220 23 : static ::dbaxml::OMultiInstanceAutoRegistration< ::dbaxml::DBTypeDetection > aAutoRegistration;
221 23 : }
222 :
223 : namespace dbaxml
224 : {
225 :
226 : class DBContentLoader : public ::cppu::WeakImplHelper2< XFrameLoader, XServiceInfo>
227 : {
228 : private:
229 : const Reference< XComponentContext > m_aContext;
230 : Reference< XFrameLoader > m_xMySelf;
231 : OUString m_sCurrentURL;
232 : ImplSVEvent * m_nStartWizard;
233 :
234 : DECL_LINK( OnStartTableWizard, void* );
235 : public:
236 : DBContentLoader(const Reference< XComponentContext >&);
237 : virtual ~DBContentLoader();
238 :
239 : // XServiceInfo
240 : OUString SAL_CALL getImplementationName() throw(std::exception ) SAL_OVERRIDE;
241 : sal_Bool SAL_CALL supportsService(const OUString& ServiceName) throw(std::exception ) SAL_OVERRIDE;
242 : Sequence< OUString > SAL_CALL getSupportedServiceNames() throw(std::exception ) SAL_OVERRIDE;
243 :
244 : // static methods
245 47 : static OUString getImplementationName_Static() throw( )
246 : {
247 47 : return OUString("org.openoffice.comp.dbflt.DBContentLoader2");
248 : }
249 : static Sequence< OUString > getSupportedServiceNames_Static() throw( );
250 : static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
251 : SAL_CALL Create(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&);
252 :
253 : // XLoader
254 : virtual void SAL_CALL load( const Reference< XFrame > & _rFrame, const OUString& _rURL,
255 : const Sequence< PropertyValue >& _rArgs,
256 : const Reference< XLoadEventListener > & _rListener) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
257 : virtual void SAL_CALL cancel() throw(std::exception) SAL_OVERRIDE;
258 :
259 : private:
260 : bool impl_executeNewDatabaseWizard( Reference< XModel >& _rxModel, bool& _bShouldStartTableWizard );
261 : };
262 :
263 :
264 9 : DBContentLoader::DBContentLoader(const Reference< XComponentContext >& _rxFactory)
265 : :m_aContext( _rxFactory )
266 9 : ,m_nStartWizard(0)
267 : {
268 :
269 9 : }
270 :
271 18 : DBContentLoader::~DBContentLoader()
272 : {
273 :
274 18 : }
275 :
276 9 : Reference< XInterface > SAL_CALL DBContentLoader::Create( const Reference< XMultiServiceFactory > & rSMgr )
277 : {
278 9 : return *(new DBContentLoader( comphelper::getComponentContext(rSMgr) ));
279 : }
280 :
281 : // XServiceInfo
282 1 : OUString SAL_CALL DBContentLoader::getImplementationName() throw(std::exception )
283 : {
284 1 : return getImplementationName_Static();
285 : }
286 :
287 : // XServiceInfo
288 0 : sal_Bool SAL_CALL DBContentLoader::supportsService(const OUString& ServiceName) throw(std::exception )
289 : {
290 0 : return cppu::supportsService(this, ServiceName);
291 : }
292 :
293 : // XServiceInfo
294 1 : Sequence< OUString > SAL_CALL DBContentLoader::getSupportedServiceNames() throw(std::exception )
295 : {
296 1 : return getSupportedServiceNames_Static();
297 : }
298 :
299 : // ORegistryServiceManager_Static
300 24 : Sequence< OUString > DBContentLoader::getSupportedServiceNames_Static() throw( )
301 : {
302 24 : Sequence< OUString > aSNS( 1 );
303 24 : aSNS[0] = "com.sun.star.frame.FrameLoader";
304 24 : return aSNS;
305 : }
306 :
307 : namespace
308 : {
309 0 : bool lcl_urlAllowsInteraction( const Reference<XComponentContext> & _rContext, const OUString& _rURL )
310 : {
311 0 : bool bDoesAllow = false;
312 : try
313 : {
314 0 : Reference< XURLTransformer > xTransformer( URLTransformer::create(_rContext) );
315 0 : URL aURL;
316 0 : aURL.Complete = _rURL;
317 0 : xTransformer->parseStrict( aURL );
318 0 : bDoesAllow = aURL.Arguments == "Interactive";
319 : }
320 0 : catch( const Exception& )
321 : {
322 : OSL_FAIL( "lcl_urlAllowsInteraction: caught an exception while analyzing the URL!" );
323 : }
324 0 : return bDoesAllow;
325 : }
326 :
327 0 : Reference< XWindow > lcl_getTopMostWindow( const Reference<XComponentContext> & _rxContext )
328 : {
329 0 : Reference< XWindow > xWindow;
330 : // get the top most window
331 0 : Reference < XDesktop2 > xDesktop = Desktop::create(_rxContext);
332 0 : Reference < XFrame > xActiveFrame = xDesktop->getActiveFrame();
333 0 : if ( xActiveFrame.is() )
334 : {
335 0 : xWindow = xActiveFrame->getContainerWindow();
336 0 : Reference<XFrame> xFrame = xActiveFrame;
337 0 : while ( xFrame.is() && !xFrame->isTop() )
338 0 : xFrame.set(xFrame->getCreator(),UNO_QUERY);
339 :
340 0 : if ( xFrame.is() )
341 0 : xWindow = xFrame->getContainerWindow();
342 : }
343 0 : return xWindow;
344 : }
345 : }
346 :
347 0 : bool DBContentLoader::impl_executeNewDatabaseWizard( Reference< XModel >& _rxModel, bool& _bShouldStartTableWizard )
348 : {
349 0 : Sequence< Any > aWizardArgs(2);
350 0 : aWizardArgs[0] <<= PropertyValue(
351 : OUString("ParentWindow"),
352 : 0,
353 : makeAny( lcl_getTopMostWindow( m_aContext ) ),
354 0 : PropertyState_DIRECT_VALUE);
355 :
356 0 : aWizardArgs[1] <<= PropertyValue(
357 : OUString("InitialSelection"),
358 : 0,
359 : makeAny( _rxModel ),
360 0 : PropertyState_DIRECT_VALUE);
361 :
362 : // create the dialog
363 0 : Reference< XExecutableDialog > xAdminDialog( m_aContext->getServiceManager()->createInstanceWithArgumentsAndContext("com.sun.star.sdb.DatabaseWizardDialog", aWizardArgs, m_aContext), UNO_QUERY_THROW);
364 :
365 : // execute it
366 0 : if ( RET_OK != xAdminDialog->execute() )
367 0 : return false;
368 :
369 0 : Reference<XPropertySet> xProp(xAdminDialog,UNO_QUERY);
370 0 : bool bSuccess = false;
371 0 : xProp->getPropertyValue("OpenDatabase") >>= bSuccess;
372 0 : xProp->getPropertyValue("StartTableWizard") >>= _bShouldStartTableWizard;
373 0 : return bSuccess;
374 : }
375 :
376 7 : void SAL_CALL DBContentLoader::load(const Reference< XFrame > & rFrame, const OUString& _rURL,
377 : const Sequence< PropertyValue >& rArgs,
378 : const Reference< XLoadEventListener > & rListener) throw(::com::sun::star::uno::RuntimeException, std::exception)
379 : {
380 : // first check if preview is true, if so return with out creating a controller. Preview is not supported
381 7 : ::comphelper::NamedValueCollection aMediaDesc( rArgs );
382 7 : bool bPreview = aMediaDesc.getOrDefault( "Preview", sal_False );
383 7 : if ( bPreview )
384 : {
385 0 : if (rListener.is())
386 0 : rListener->loadCancelled(this);
387 0 : return;
388 : }
389 :
390 14 : Reference< XModel > xModel = aMediaDesc.getOrDefault( "Model", Reference< XModel >() );
391 14 : OUString sSalvagedURL = aMediaDesc.getOrDefault( "SalvagedFile", _rURL );
392 :
393 7 : bool bCreateNew = false; // does the URL denote the private:factory URL?
394 7 : bool bStartTableWizard = false; // start the table wizard after everything was loaded successfully?
395 :
396 7 : bool bSuccess = true;
397 :
398 : // If there's no interaction handler in the media descriptor, put one.
399 : // By definition, loading via loadComponentFromURL (and thus via the content loader here)
400 : // is allowed to raise UI. To not burden every place inside the document with creating
401 : // a default handler, we simply ensure there is one.
402 : // If a handler is present in the media descriptor, even if it is NULL, we will
403 : // not touch it.
404 7 : if ( !aMediaDesc.has( "InteractionHandler" ) )
405 : {
406 0 : Reference< XInteractionHandler2 > xHandler( InteractionHandler::createWithParent(m_aContext, 0) );
407 0 : aMediaDesc.put( "InteractionHandler", xHandler );
408 : }
409 :
410 : // it's allowed to pass an existing document
411 14 : Reference< XOfficeDatabaseDocument > xExistentDBDoc;
412 7 : xModel.set( aMediaDesc.getOrDefault( "Model", xExistentDBDoc ), UNO_QUERY );
413 7 : aMediaDesc.remove( "Model" );
414 :
415 : // also, it's allowed to specify the type of view which should be created
416 14 : OUString sViewName = aMediaDesc.getOrDefault( "ViewName", OUString( "Default" ) );
417 7 : aMediaDesc.remove( "ViewName" );
418 :
419 7 : sal_Int32 nInitialSelection = -1;
420 7 : if ( !xModel.is() )
421 : {
422 7 : Reference< XDatabaseContext > xDatabaseContext( DatabaseContext::create(m_aContext) );
423 :
424 14 : OUString sFactoryName = SvtModuleOptions().GetFactoryEmptyDocumentURL(SvtModuleOptions::EFactory::DATABASE);
425 7 : bCreateNew = sFactoryName.match(_rURL);
426 :
427 14 : Reference< XDocumentDataSource > xDocumentDataSource;
428 7 : bool bNewAndInteractive = false;
429 7 : if ( bCreateNew )
430 : {
431 0 : bNewAndInteractive = lcl_urlAllowsInteraction( m_aContext, _rURL );
432 0 : xDocumentDataSource.set( xDatabaseContext->createInstance(), UNO_QUERY_THROW );
433 : }
434 : else
435 : {
436 7 : ::comphelper::NamedValueCollection aCreationArgs;
437 7 : aCreationArgs.put( OUString(INFO_POOLURL), sSalvagedURL );
438 7 : xDocumentDataSource.set( xDatabaseContext->createInstanceWithArguments( aCreationArgs.getWrappedNamedValues() ), UNO_QUERY_THROW );
439 : }
440 :
441 7 : xModel.set( xDocumentDataSource->getDatabaseDocument(), UNO_QUERY );
442 :
443 7 : if ( bCreateNew && xModel.is() )
444 : {
445 0 : if ( bNewAndInteractive )
446 : {
447 0 : bSuccess = impl_executeNewDatabaseWizard( xModel, bStartTableWizard );
448 : }
449 : else
450 : {
451 : try
452 : {
453 0 : Reference< XLoadable > xLoad( xModel, UNO_QUERY_THROW );
454 0 : xLoad->initNew();
455 0 : bSuccess = true;
456 : }
457 0 : catch( const Exception& )
458 : {
459 0 : bSuccess = false;
460 : }
461 : }
462 :
463 : // initially select the "Tables" category (will be done below)
464 0 : nInitialSelection = ::com::sun::star::sdb::application::DatabaseObjectContainer::TABLES;
465 7 : }
466 : }
467 :
468 7 : if ( !xModel.is() )
469 : {
470 0 : if ( rListener.is() )
471 0 : rListener->loadCancelled(this);
472 0 : return;
473 : }
474 :
475 7 : if ( !bCreateNew )
476 : {
477 : // We need to XLoadable::load the document if it does not yet have an URL.
478 : // If it already *does* have an URL, then it was either passed in the arguments, or a previous incarnation
479 : // of that model existed before (which can happen if a model is closed, but an associated DataSource is kept
480 : // alive 'til loading the document again).
481 7 : bool bNeedLoad = ( xModel->getURL().isEmpty() );
482 : try
483 : {
484 7 : aMediaDesc.put( "FileName", _rURL );
485 7 : Sequence< PropertyValue > aResource( aMediaDesc.getPropertyValues() );
486 :
487 7 : if ( bNeedLoad )
488 : {
489 7 : Reference< XLoadable > xLoad( xModel, UNO_QUERY_THROW );
490 7 : xLoad->load( aResource );
491 : }
492 :
493 : // always attach the resource, even if the document has not been freshly loaded
494 7 : xModel->attachResource( _rURL, aResource );
495 : }
496 0 : catch(const Exception&)
497 : {
498 : DBG_UNHANDLED_EXCEPTION();
499 0 : bSuccess = false;
500 : }
501 : }
502 :
503 7 : if ( bSuccess )
504 : {
505 : try
506 : {
507 7 : Reference< XModel2 > xModel2( xModel, UNO_QUERY_THROW );
508 14 : Reference< XController2 > xController( xModel2->createViewController( sViewName, Sequence< PropertyValue >(), rFrame ), UNO_QUERY_THROW );
509 :
510 7 : xController->attachModel( xModel );
511 7 : xModel->connectController( xController.get() );
512 7 : rFrame->setComponent( xController->getComponentWindow(), xController.get() );
513 7 : xController->attachFrame( rFrame );
514 7 : xModel->setCurrentController( xController.get() );
515 :
516 14 : bSuccess = true;
517 : }
518 0 : catch( const Exception& )
519 : {
520 : DBG_UNHANDLED_EXCEPTION();
521 0 : bSuccess = false;
522 : }
523 : }
524 :
525 7 : if (bSuccess)
526 : {
527 7 : if ( rListener.is() )
528 7 : rListener->loadFinished(this);
529 :
530 7 : if ( nInitialSelection != -1 )
531 : {
532 0 : Reference< css::view::XSelectionSupplier > xDocView( xModel->getCurrentController(), UNO_QUERY );
533 0 : if ( xDocView.is() )
534 : {
535 0 : NamedDatabaseObject aSelection;
536 0 : aSelection.Type = nInitialSelection;
537 0 : xDocView->select( makeAny( aSelection ) );
538 0 : }
539 : }
540 :
541 7 : if ( bStartTableWizard )
542 : {
543 : // reset the data of the previous async drop (if any)
544 0 : if ( m_nStartWizard )
545 0 : Application::RemoveUserEvent(m_nStartWizard);
546 0 : m_sCurrentURL = xModel->getURL();
547 0 : m_xMySelf = this;
548 0 : m_nStartWizard = Application::PostUserEvent(LINK(this, DBContentLoader, OnStartTableWizard));
549 : }
550 : }
551 : else
552 : {
553 0 : if ( rListener.is() )
554 0 : rListener->loadCancelled( this );
555 : }
556 :
557 7 : if ( !bSuccess )
558 7 : ::comphelper::disposeComponent(xModel);
559 : }
560 :
561 0 : void DBContentLoader::cancel() throw(std::exception)
562 : {
563 0 : }
564 :
565 0 : IMPL_LINK_NOARG( DBContentLoader, OnStartTableWizard )
566 : {
567 0 : m_nStartWizard = 0;
568 : try
569 : {
570 0 : Sequence< Any > aWizArgs(1);
571 0 : PropertyValue aValue;
572 0 : aValue.Name = "DatabaseLocation";
573 0 : aValue.Value <<= m_sCurrentURL;
574 0 : aWizArgs[0] <<= aValue;
575 :
576 0 : SolarMutexGuard aGuard;
577 0 : Reference< XJobExecutor > xTableWizard( m_aContext->getServiceManager()->createInstanceWithArgumentsAndContext("com.sun.star.wizards.table.CallTableWizard", aWizArgs, m_aContext), UNO_QUERY);
578 0 : if ( xTableWizard.is() )
579 0 : xTableWizard->trigger(OUString("start"));
580 : }
581 0 : catch(const Exception&)
582 : {
583 : OSL_FAIL("caught an exception while starting the table wizard!");
584 : }
585 0 : m_xMySelf = NULL;
586 0 : return 0L;
587 : }
588 :
589 : }
590 :
591 23 : extern "C" void SAL_CALL createRegistryInfo_DBContentLoader2()
592 : {
593 23 : static ::dbaxml::OMultiInstanceAutoRegistration< ::dbaxml::DBContentLoader > aAutoRegistration;
594 23 : }
595 :
596 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|