LCOV - code coverage report
Current view: top level - dbaccess/source/filter/xml - dbloader2.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 106 214 49.5 %
Date: 2014-04-11 Functions: 16 28 57.1 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10