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

Generated by: LCOV version 1.10