LCOV - code coverage report
Current view: top level - dbaccess/source/ui/browser - dbloader.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 72 104 69.2 %
Date: 2014-11-03 Functions: 12 15 80.0 %
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 "dbu_reghelper.hxx"
      21             : #include "dbustrings.hrc"
      22             : #include "uiservices.hxx"
      23             : #include "UITools.hxx"
      24             : 
      25             : #include <com/sun/star/container/XChild.hpp>
      26             : #include <com/sun/star/container/XNameAccess.hpp>
      27             : #include <com/sun/star/container/XSet.hpp>
      28             : #include <com/sun/star/document/XEventListener.hpp>
      29             : #include <com/sun/star/frame/XController2.hpp>
      30             : #include <com/sun/star/frame/XFrame.hpp>
      31             : #include <com/sun/star/frame/XFrameLoader.hpp>
      32             : #include <com/sun/star/frame/XLoadEventListener.hpp>
      33             : #include <com/sun/star/lang/XInitialization.hpp>
      34             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      35             : #include <com/sun/star/lang/XServiceInfo.hpp>
      36             : #include <com/sun/star/lang/XSingleServiceFactory.hpp>
      37             : #include <com/sun/star/registry/XRegistryKey.hpp>
      38             : #include <com/sun/star/sdb/ReportDesign.hpp>
      39             : #include <com/sun/star/sdbc/XConnection.hpp>
      40             : #include <com/sun/star/frame/XModule.hpp>
      41             : 
      42             : #include <com/sun/star/sdbc/XDataSource.hpp>
      43             : #include <comphelper/namedvaluecollection.hxx>
      44             : #include <comphelper/processfactory.hxx>
      45             : #include <cppuhelper/implbase2.hxx>
      46             : #include <cppuhelper/supportsservice.hxx>
      47             : #include <toolkit/awt/vclxwindow.hxx>
      48             : #include <toolkit/helper/vclunohelper.hxx>
      49             : #include <tools/diagnose_ex.h>
      50             : #include <tools/urlobj.hxx>
      51             : #include <vcl/svapp.hxx>
      52             : 
      53             : using namespace ::com::sun::star;
      54             : using namespace ::com::sun::star::uno;
      55             : using namespace ::com::sun::star::frame;
      56             : using namespace ::com::sun::star::beans;
      57             : using namespace ::com::sun::star::sdb;
      58             : using namespace ::com::sun::star::sdbc;
      59             : using namespace ::com::sun::star::container;
      60             : using namespace ::com::sun::star::lang;
      61             : using namespace ::com::sun::star::registry;
      62             : using namespace dbaui;
      63             : 
      64             : class DBContentLoader : public ::cppu::WeakImplHelper2< XFrameLoader, XServiceInfo>
      65             : {
      66             : private:
      67             :     OUString                     m_aURL;
      68             :     Sequence< PropertyValue>            m_aArgs;
      69             :     Reference< XLoadEventListener >     m_xListener;
      70             :     Reference< XFrame >                 m_xFrame;
      71             :     Reference< XComponentContext >      m_xContext;
      72             : public:
      73             :     DBContentLoader(const Reference< XComponentContext >&);
      74             :     virtual ~DBContentLoader();
      75             : 
      76             :     // XServiceInfo
      77             :     OUString                 SAL_CALL getImplementationName() throw(std::exception  ) SAL_OVERRIDE;
      78             :     sal_Bool                        SAL_CALL supportsService(const OUString& ServiceName) throw(std::exception  ) SAL_OVERRIDE;
      79             :     Sequence< OUString >     SAL_CALL getSupportedServiceNames(void) throw(std::exception  ) SAL_OVERRIDE;
      80             : 
      81             :     // static methods
      82          50 :     static OUString          getImplementationName_Static() throw(  )
      83             :     {
      84          50 :         return OUString("org.openoffice.comp.dbu.DBContentLoader");
      85             :     }
      86             :     static Sequence< OUString> getSupportedServiceNames_Static(void) throw(  );
      87             :     static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
      88             :             SAL_CALL Create(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&);
      89             : 
      90             :     // XLoader
      91             :     virtual void SAL_CALL load( const Reference< XFrame > & _rFrame, const OUString& _rURL,
      92             :                                 const Sequence< PropertyValue >& _rArgs,
      93             :                                 const Reference< XLoadEventListener > & _rListener) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      94             :     virtual void SAL_CALL cancel(void) throw(std::exception) SAL_OVERRIDE;
      95             : };
      96             : 
      97             : 
      98           6 : DBContentLoader::DBContentLoader(const Reference< XComponentContext >& _rxContext)
      99           6 :     :m_xContext(_rxContext)
     100             : {
     101             : 
     102           6 : }
     103             : 
     104          12 : DBContentLoader::~DBContentLoader()
     105             : {
     106             : 
     107          12 : }
     108             : 
     109          24 : extern "C" void SAL_CALL createRegistryInfo_DBContentLoader()
     110             : {
     111          24 :     static ::dbaui::OMultiInstanceAutoRegistration< DBContentLoader > aAutoRegistration;
     112          24 : }
     113             : 
     114           6 : Reference< XInterface > SAL_CALL DBContentLoader::Create( const Reference< XMultiServiceFactory >  & rSMgr )
     115             : {
     116           6 :     return *(new DBContentLoader(comphelper::getComponentContext(rSMgr)));
     117             : }
     118             : 
     119             : // XServiceInfo
     120           2 : OUString SAL_CALL DBContentLoader::getImplementationName() throw(std::exception  )
     121             : {
     122           2 :     return getImplementationName_Static();
     123             : }
     124             : 
     125             : // XServiceInfo
     126           0 : sal_Bool SAL_CALL DBContentLoader::supportsService(const OUString& ServiceName) throw(std::exception  )
     127             : {
     128           0 :     return cppu::supportsService(this, ServiceName);
     129             : }
     130             : 
     131             : // XServiceInfo
     132           0 : Sequence< OUString > SAL_CALL DBContentLoader::getSupportedServiceNames(void) throw(std::exception  )
     133             : {
     134           0 :     return getSupportedServiceNames_Static();
     135             : }
     136             : 
     137             : // ORegistryServiceManager_Static
     138          24 : Sequence< OUString > DBContentLoader::getSupportedServiceNames_Static(void) throw(  )
     139             : {
     140          24 :     Sequence< OUString > aSNS( 2 );
     141          24 :     aSNS[0] = "com.sun.star.frame.FrameLoader";
     142          24 :     aSNS[1] = "com.sun.star.sdb.ContentLoader";
     143          24 :     return aSNS;
     144             : }
     145             : 
     146           2 : void SAL_CALL DBContentLoader::load(const Reference< XFrame > & rFrame, const OUString& rURL,
     147             :         const Sequence< PropertyValue >& rArgs,
     148             :         const Reference< XLoadEventListener > & rListener) throw(::com::sun::star::uno::RuntimeException, std::exception)
     149             : {
     150           2 :     m_xFrame    = rFrame;
     151           2 :     m_xListener = rListener;
     152           2 :     m_aURL      = rURL;
     153           2 :     m_aArgs     = rArgs;
     154             : 
     155             :     struct ServiceNameToImplName
     156             :     {
     157             :         const sal_Char*     pAsciiServiceName;
     158             :         const sal_Char*     pAsciiImplementationName;
     159          12 :         ServiceNameToImplName( const sal_Char* _pService, const sal_Char* _pImpl )
     160             :             :pAsciiServiceName( _pService )
     161          12 :             ,pAsciiImplementationName( _pImpl )
     162             :         {
     163          12 :         }
     164             :     } aImplementations[] = {
     165             :         ServiceNameToImplName( URL_COMPONENT_FORMGRIDVIEW,      "org.openoffice.comp.dbu.OFormGridView"        ),
     166             :         ServiceNameToImplName( URL_COMPONENT_DATASOURCEBROWSER, "org.openoffice.comp.dbu.ODatasourceBrowser"   ),
     167             :         ServiceNameToImplName( URL_COMPONENT_QUERYDESIGN,       "org.openoffice.comp.dbu.OQueryDesign"         ),
     168             :         ServiceNameToImplName( URL_COMPONENT_TABLEDESIGN,       "org.openoffice.comp.dbu.OTableDesign"         ),
     169             :         ServiceNameToImplName( URL_COMPONENT_RELATIONDESIGN,    "org.openoffice.comp.dbu.ORelationDesign"      ),
     170             :         ServiceNameToImplName( URL_COMPONENT_VIEWDESIGN,        "org.openoffice.comp.dbu.OViewDesign"          )
     171           2 :     };
     172             : 
     173           2 :     INetURLObject aParser( rURL );
     174           4 :     Reference< XController2 > xController;
     175             : 
     176           4 :     const OUString sComponentURL( aParser.GetMainURL( INetURLObject::DECODE_TO_IURI ) );
     177           4 :     for ( size_t i=0; i < sizeof( aImplementations ) / sizeof( aImplementations[0] ); ++i )
     178             :     {
     179           4 :         if ( sComponentURL.equalsAscii( aImplementations[i].pAsciiServiceName ) )
     180             :         {
     181           4 :             xController.set( m_xContext->getServiceManager()->
     182           2 :                createInstanceWithContext( OUString::createFromAscii( aImplementations[i].pAsciiImplementationName ), m_xContext), UNO_QUERY_THROW );
     183           2 :             break;
     184             :         }
     185             :     }
     186             : 
     187             :     // if a data source browser is loaded without its tree pane, then we assume it to be a
     188             :     // table data view, effectively. In this case, we need to adjust the module identifier.
     189             :     // #i85879#
     190           4 :     ::comphelper::NamedValueCollection aLoadArgs( rArgs );
     191             : 
     192           2 :     if  ( sComponentURL == URL_COMPONENT_DATASOURCEBROWSER )
     193             :     {
     194           8 :         bool bDisableBrowser =  ( sal_False == aLoadArgs.getOrDefault( "ShowTreeViewButton", sal_True ) )   // compatibility name
     195           6 :                                 ||  ( sal_False == aLoadArgs.getOrDefault( OUString(PROPERTY_ENABLE_BROWSER), sal_True ) );
     196             : 
     197           2 :         if ( bDisableBrowser )
     198             :         {
     199             :             try
     200             :             {
     201           0 :                 Reference< XModule > xModule( xController, UNO_QUERY_THROW );
     202           0 :                 xModule->setIdentifier( OUString( "com.sun.star.sdb.TableDataView" ) );
     203             :             }
     204           0 :             catch( const Exception& )
     205             :             {
     206             :                 DBG_UNHANDLED_EXCEPTION();
     207             :             }
     208             :         }
     209             :     }
     210             : 
     211           2 :     if ( sComponentURL == URL_COMPONENT_REPORTDESIGN )
     212             :     {
     213           0 :         bool bPreview = aLoadArgs.getOrDefault( "Preview", sal_False );
     214           0 :         if ( bPreview )
     215             :         {   // report designs cannot be previewed
     216           0 :             if ( rListener.is() )
     217           0 :                 rListener->loadCancelled( this );
     218           2 :             return;
     219             :         }
     220           0 :         Reference< XModel > xReportModel( aLoadArgs.getOrDefault( "Model", Reference< XModel >() ) );
     221           0 :         if ( xReportModel.is() )
     222             :         {
     223           0 :             xController.set( ReportDesign::create( m_xContext ) );
     224           0 :             xController->attachModel( xReportModel );
     225           0 :             xReportModel->connectController( xController.get() );
     226           0 :             xReportModel->setCurrentController( xController.get() );
     227           0 :         }
     228             :     }
     229             : 
     230           2 :     bool bSuccess = xController.is();
     231           4 :     Reference< XModel > xDatabaseDocument;
     232           2 :     if ( bSuccess )
     233             :     {
     234           2 :         Reference< XDataSource > xDataSource    ( aLoadArgs.getOrDefault( "DataSource",       Reference< XDataSource >() ) );
     235           4 :         OUString          sDataSourceName( aLoadArgs.getOrDefault( "DataSourceName",   OUString()          ) );
     236           4 :         Reference< XConnection > xConnection    ( aLoadArgs.getOrDefault( "ActiveConnection", Reference< XConnection >() ) );
     237           2 :         if ( xDataSource.is() )
     238             :         {
     239           0 :             xDatabaseDocument.set( getDataSourceOrModel( xDataSource ), UNO_QUERY );
     240             :         }
     241           2 :         else if ( !sDataSourceName.isEmpty() )
     242             :         {
     243           0 :             ::dbtools::SQLExceptionInfo aError;
     244           0 :             xDataSource.set( getDataSourceByName( sDataSourceName, NULL, m_xContext, &aError ) );
     245           0 :             xDatabaseDocument.set( getDataSourceOrModel( xDataSource ), UNO_QUERY );
     246             :         }
     247           2 :         else if ( xConnection.is() )
     248             :         {
     249           0 :             Reference< XChild > xAsChild( xConnection, UNO_QUERY );
     250           0 :             if ( xAsChild.is() )
     251             :             {
     252             :                 OSL_ENSURE( Reference< XDataSource >( xAsChild->getParent(), UNO_QUERY ).is(),
     253             :                     "DBContentLoader::load: a connection whose parent is no data source?" );
     254           0 :                 xDatabaseDocument.set( getDataSourceOrModel( xAsChild->getParent() ), UNO_QUERY );
     255           0 :             }
     256             :         }
     257             : 
     258             :         // init controller
     259           4 :         SolarMutexGuard aGuard;
     260             :         try
     261             :         {
     262           2 :             Reference<XInitialization > xIni(xController,UNO_QUERY);
     263           4 :             PropertyValue aFrame(OUString("Frame"),0,makeAny(rFrame),PropertyState_DIRECT_VALUE);
     264           4 :             Sequence< Any > aInitArgs(m_aArgs.getLength()+1);
     265             : 
     266           2 :             Any* pBegin = aInitArgs.getArray();
     267           2 :             Any* pEnd   = pBegin + aInitArgs.getLength();
     268           2 :             *pBegin <<= aFrame;
     269           2 :             const PropertyValue* pIter      = m_aArgs.getConstArray();
     270          16 :             for(++pBegin;pBegin != pEnd;++pBegin,++pIter)
     271             :             {
     272          14 :                 *pBegin <<= *pIter;
     273             :             }
     274             : 
     275           4 :             xIni->initialize(aInitArgs);
     276             :         }
     277           0 :         catch(const Exception&)
     278             :         {
     279             :             // Does this need to be shown to the user?
     280           0 :             bSuccess = false;
     281             :             try
     282             :             {
     283           0 :                 ::comphelper::disposeComponent( xController );
     284             :             }
     285           0 :             catch( const Exception& )
     286             :             {
     287             :                 DBG_UNHANDLED_EXCEPTION();
     288             :             }
     289           2 :         }
     290             :     }
     291             : 
     292             :     // assign controller and frame
     293           2 :     if ( bSuccess )
     294             :     {
     295           2 :         if ( xController.is() && rFrame.is() )
     296             :         {
     297           2 :             rFrame->setComponent( xController->getComponentWindow(), xController.get() );
     298           2 :             xController->attachFrame(rFrame);
     299             :         }
     300             : 
     301           2 :         if ( rListener.is() )
     302           2 :             rListener->loadFinished( this );
     303             :     }
     304             :     else
     305           0 :         if ( rListener.is() )
     306           2 :             rListener->loadCancelled( this );
     307             : }
     308             : 
     309           0 : void DBContentLoader::cancel(void) throw(std::exception)
     310             : {
     311          72 : }
     312             : 
     313             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10