LCOV - code coverage report
Current view: top level - libreoffice/dbaccess/source/ui/browser - dbloader.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 123 0.0 %
Date: 2012-12-27 Functions: 0 14 0.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             : 
      21             : #include "dbu_reghelper.hxx"
      22             : #include "dbustrings.hrc"
      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/componentcontext.hxx>
      45             : #include <comphelper/processfactory.hxx>
      46             : #include <cppuhelper/implbase2.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             :     ::rtl::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             :     ~DBContentLoader();
      75             : 
      76             :     // XServiceInfo
      77             :     ::rtl::OUString                 SAL_CALL getImplementationName() throw(  );
      78             :     sal_Bool                        SAL_CALL supportsService(const ::rtl::OUString& ServiceName) throw(  );
      79             :     Sequence< ::rtl::OUString >     SAL_CALL getSupportedServiceNames(void) throw(  );
      80             : 
      81             :     // static methods
      82           0 :     static ::rtl::OUString          getImplementationName_Static() throw(  )
      83             :     {
      84           0 :         return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("org.openoffice.comp.dbu.DBContentLoader"));
      85             :     }
      86             :     static Sequence< ::rtl::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 ::rtl::OUString& _rURL,
      92             :                                 const Sequence< PropertyValue >& _rArgs,
      93             :                                 const Reference< XLoadEventListener > & _rListener) throw(::com::sun::star::uno::RuntimeException);
      94             :     virtual void SAL_CALL cancel(void) throw();
      95             : };
      96             : DBG_NAME(DBContentLoader)
      97             : 
      98           0 : DBContentLoader::DBContentLoader(const Reference< XComponentContext >& _rxContext)
      99           0 :     :m_xContext(_rxContext)
     100             : {
     101             :     DBG_CTOR(DBContentLoader,NULL);
     102             : 
     103           0 : }
     104             : // -------------------------------------------------------------------------
     105             : 
     106           0 : DBContentLoader::~DBContentLoader()
     107             : {
     108             : 
     109             :     DBG_DTOR(DBContentLoader,NULL);
     110           0 : }
     111             : // -------------------------------------------------------------------------
     112             : // -------------------------------------------------------------------------
     113           0 : extern "C" void SAL_CALL createRegistryInfo_DBContentLoader()
     114             : {
     115           0 :     static ::dbaui::OMultiInstanceAutoRegistration< DBContentLoader > aAutoRegistration;
     116           0 : }
     117             : // -------------------------------------------------------------------------
     118           0 : Reference< XInterface > SAL_CALL DBContentLoader::Create( const Reference< XMultiServiceFactory >  & rSMgr )
     119             : {
     120           0 :     return *(new DBContentLoader(comphelper::getComponentContext(rSMgr)));
     121             : }
     122             : // -------------------------------------------------------------------------
     123             : // XServiceInfo
     124           0 : ::rtl::OUString SAL_CALL DBContentLoader::getImplementationName() throw(  )
     125             : {
     126           0 :     return getImplementationName_Static();
     127             : }
     128             : // -------------------------------------------------------------------------
     129             : 
     130             : // XServiceInfo
     131           0 : sal_Bool SAL_CALL DBContentLoader::supportsService(const ::rtl::OUString& ServiceName) throw(  )
     132             : {
     133           0 :     Sequence< ::rtl::OUString > aSNL = getSupportedServiceNames();
     134           0 :     const ::rtl::OUString * pBegin  = aSNL.getConstArray();
     135           0 :     const ::rtl::OUString * pEnd    = pBegin + aSNL.getLength();
     136           0 :     for( ; pBegin != pEnd; ++pBegin)
     137           0 :         if( *pBegin == ServiceName )
     138           0 :             return sal_True;
     139           0 :     return sal_False;
     140             : }
     141             : // -------------------------------------------------------------------------
     142             : // XServiceInfo
     143           0 : Sequence< ::rtl::OUString > SAL_CALL DBContentLoader::getSupportedServiceNames(void) throw(  )
     144             : {
     145           0 :     return getSupportedServiceNames_Static();
     146             : }
     147             : // -------------------------------------------------------------------------
     148             : // ORegistryServiceManager_Static
     149           0 : Sequence< ::rtl::OUString > DBContentLoader::getSupportedServiceNames_Static(void) throw(  )
     150             : {
     151           0 :     Sequence< ::rtl::OUString > aSNS( 2 );
     152           0 :     aSNS.getArray()[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.frame.FrameLoader"));
     153           0 :     aSNS.getArray()[1] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdb.ContentLoader"));
     154           0 :     return aSNS;
     155             : }
     156             : // -------------------------------------------------------------------------
     157           0 : extern "C" void SAL_CALL writeDBLoaderInfo(void* pRegistryKey)
     158             : {
     159           0 :     Reference< XRegistryKey> xKey(reinterpret_cast< XRegistryKey*>(pRegistryKey));
     160             : 
     161             :     // register content loader for dispatch
     162           0 :     ::rtl::OUString aImpl(RTL_CONSTASCII_USTRINGPARAM("/"));
     163           0 :     aImpl += DBContentLoader::getImplementationName_Static();
     164             : 
     165           0 :     ::rtl::OUString aImpltwo = aImpl;
     166           0 :     aImpltwo += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/UNO/Loader"));
     167           0 :     Reference< XRegistryKey> xNewKey = xKey->createKey( aImpltwo );
     168           0 :     aImpltwo = aImpl;
     169           0 :     aImpltwo += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/Loader"));
     170           0 :     Reference< XRegistryKey >  xLoaderKey = xKey->createKey( aImpltwo );
     171           0 :     xNewKey = xLoaderKey->createKey( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Pattern")) );
     172           0 :     xNewKey->setAsciiValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".component:DB*")) );
     173           0 : }
     174             : 
     175             : // -----------------------------------------------------------------------
     176           0 : void SAL_CALL DBContentLoader::load(const Reference< XFrame > & rFrame, const ::rtl::OUString& rURL,
     177             :         const Sequence< PropertyValue >& rArgs,
     178             :         const Reference< XLoadEventListener > & rListener) throw(::com::sun::star::uno::RuntimeException)
     179             : {
     180           0 :     m_xFrame    = rFrame;
     181           0 :     m_xListener = rListener;
     182           0 :     m_aURL      = rURL;
     183           0 :     m_aArgs     = rArgs;
     184             : 
     185             :     struct ServiceNameToImplName
     186             :     {
     187             :         const sal_Char*     pAsciiServiceName;
     188             :         const sal_Char*     pAsciiImplementationName;
     189           0 :         ServiceNameToImplName( const sal_Char* _pService, const sal_Char* _pImpl )
     190             :             :pAsciiServiceName( _pService )
     191           0 :             ,pAsciiImplementationName( _pImpl )
     192             :         {
     193           0 :         }
     194             :     } aImplementations[] = {
     195             :         ServiceNameToImplName( URL_COMPONENT_FORMGRIDVIEW.ascii,      "org.openoffice.comp.dbu.OFormGridView"        ),
     196             :         ServiceNameToImplName( URL_COMPONENT_DATASOURCEBROWSER.ascii, "org.openoffice.comp.dbu.ODatasourceBrowser"   ),
     197             :         ServiceNameToImplName( URL_COMPONENT_QUERYDESIGN.ascii,       "org.openoffice.comp.dbu.OQueryDesign"         ),
     198             :         ServiceNameToImplName( URL_COMPONENT_TABLEDESIGN.ascii,       "org.openoffice.comp.dbu.OTableDesign"         ),
     199             :         ServiceNameToImplName( URL_COMPONENT_RELATIONDESIGN.ascii,    "org.openoffice.comp.dbu.ORelationDesign"      ),
     200             :         ServiceNameToImplName( URL_COMPONENT_VIEWDESIGN.ascii,        "org.openoffice.comp.dbu.OViewDesign"          )
     201           0 :     };
     202             : 
     203           0 :     INetURLObject aParser( rURL );
     204           0 :     Reference< XController2 > xController;
     205             : 
     206           0 :     const ::rtl::OUString sComponentURL( aParser.GetMainURL( INetURLObject::DECODE_TO_IURI ) );
     207           0 :     for ( size_t i=0; i < sizeof( aImplementations ) / sizeof( aImplementations[0] ); ++i )
     208             :     {
     209           0 :         if ( sComponentURL.equalsAscii( aImplementations[i].pAsciiServiceName ) )
     210             :         {
     211           0 :             xController.set( m_xContext->getServiceManager()->
     212           0 :                createInstanceWithContext( ::rtl::OUString::createFromAscii( aImplementations[i].pAsciiImplementationName ), m_xContext), UNO_QUERY_THROW );
     213           0 :             break;
     214             :         }
     215             :     }
     216             : 
     217             :     // if a data source browser is loaded without its tree pane, then we assume it to be a
     218             :     // table data view, effectively. In this case, we need to adjust the module identifier.
     219             :     // #i85879#
     220           0 :     ::comphelper::NamedValueCollection aLoadArgs( rArgs );
     221             : 
     222           0 :     if  ( sComponentURL == URL_COMPONENT_DATASOURCEBROWSER )
     223             :     {
     224           0 :         sal_Bool bDisableBrowser =  ( sal_False == aLoadArgs.getOrDefault( "ShowTreeViewButton", sal_True ) )   // compatibility name
     225           0 :                                 ||  ( sal_False == aLoadArgs.getOrDefault( (::rtl::OUString)PROPERTY_ENABLE_BROWSER, sal_True ) );
     226             : 
     227           0 :         if ( bDisableBrowser )
     228             :         {
     229             :             try
     230             :             {
     231           0 :                 Reference< XModule > xModule( xController, UNO_QUERY_THROW );
     232           0 :                 xModule->setIdentifier( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sdb.TableDataView" ) ) );
     233             :             }
     234           0 :             catch( const Exception& )
     235             :             {
     236             :                 DBG_UNHANDLED_EXCEPTION();
     237             :             }
     238             :         }
     239             :     }
     240             : 
     241           0 :     if ( sComponentURL == URL_COMPONENT_REPORTDESIGN )
     242             :     {
     243           0 :         sal_Bool bPreview = aLoadArgs.getOrDefault( "Preview", sal_False );
     244           0 :         if ( bPreview )
     245             :         {   // report designs cannot be previewed
     246           0 :             if ( rListener.is() )
     247           0 :                 rListener->loadCancelled( this );
     248           0 :             return;
     249             :         }
     250           0 :         Reference< XModel > xReportModel( aLoadArgs.getOrDefault( "Model", Reference< XModel >() ) );
     251           0 :         if ( xReportModel.is() )
     252             :         {
     253           0 :             xController.set( ReportDesign::create( m_xContext ) );
     254           0 :             xController->attachModel( xReportModel );
     255           0 :             xReportModel->connectController( xController.get() );
     256           0 :             xReportModel->setCurrentController( xController.get() );
     257           0 :         }
     258             :     }
     259             : 
     260           0 :     sal_Bool bSuccess = xController.is();
     261           0 :     Reference< XModel > xDatabaseDocument;
     262           0 :     if ( bSuccess )
     263             :     {
     264           0 :         Reference< XDataSource > xDataSource    ( aLoadArgs.getOrDefault( "DataSource",       Reference< XDataSource >() ) );
     265           0 :         ::rtl::OUString          sDataSourceName( aLoadArgs.getOrDefault( "DataSourceName",   ::rtl::OUString()          ) );
     266           0 :         Reference< XConnection > xConnection    ( aLoadArgs.getOrDefault( "ActiveConnection", Reference< XConnection >() ) );
     267           0 :         if ( xDataSource.is() )
     268             :         {
     269           0 :             xDatabaseDocument.set( getDataSourceOrModel( xDataSource ), UNO_QUERY );
     270             :         }
     271           0 :         else if ( !sDataSourceName.isEmpty() )
     272             :         {
     273           0 :             ::dbtools::SQLExceptionInfo aError;
     274           0 :             xDataSource.set( getDataSourceByName( sDataSourceName, NULL, m_xContext, &aError ) );
     275           0 :             xDatabaseDocument.set( getDataSourceOrModel( xDataSource ), UNO_QUERY );
     276             :         }
     277           0 :         else if ( xConnection.is() )
     278             :         {
     279           0 :             Reference< XChild > xAsChild( xConnection, UNO_QUERY );
     280           0 :             if ( xAsChild.is() )
     281             :             {
     282             :                 OSL_ENSURE( Reference< XDataSource >( xAsChild->getParent(), UNO_QUERY ).is(),
     283             :                     "DBContentLoader::load: a connection whose parent is no data source?" );
     284           0 :                 xDatabaseDocument.set( getDataSourceOrModel( xAsChild->getParent() ), UNO_QUERY );
     285           0 :             }
     286             :         }
     287             : 
     288             :         // init controller
     289           0 :         SolarMutexGuard aGuard;
     290             :         try
     291             :         {
     292           0 :             Reference<XInitialization > xIni(xController,UNO_QUERY);
     293           0 :             PropertyValue aFrame(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Frame")),0,makeAny(rFrame),PropertyState_DIRECT_VALUE);
     294           0 :             Sequence< Any > aInitArgs(m_aArgs.getLength()+1);
     295             : 
     296           0 :             Any* pBegin = aInitArgs.getArray();
     297           0 :             Any* pEnd   = pBegin + aInitArgs.getLength();
     298           0 :             *pBegin <<= aFrame;
     299           0 :             const PropertyValue* pIter      = m_aArgs.getConstArray();
     300           0 :             for(++pBegin;pBegin != pEnd;++pBegin,++pIter)
     301             :             {
     302           0 :                 *pBegin <<= *pIter;
     303             :             }
     304             : 
     305           0 :             xIni->initialize(aInitArgs);
     306             :         }
     307           0 :         catch(const Exception&)
     308             :         {
     309             :             // Does this need to be shown to the user?
     310           0 :             bSuccess = false;
     311             :             try
     312             :             {
     313           0 :                 ::comphelper::disposeComponent( xController );
     314             :             }
     315           0 :             catch( const Exception& )
     316             :             {
     317             :                 DBG_UNHANDLED_EXCEPTION();
     318             :             }
     319           0 :         }
     320             :     }
     321             : 
     322             :     // assign controller and frame
     323           0 :     if ( bSuccess )
     324             :     {
     325           0 :         if ( xController.is() && rFrame.is() )
     326             :         {
     327           0 :             rFrame->setComponent( xController->getComponentWindow(), xController.get() );
     328           0 :             xController->attachFrame(rFrame);
     329             :         }
     330             : 
     331           0 :         if ( rListener.is() )
     332           0 :             rListener->loadFinished( this );
     333             :     }
     334             :     else
     335           0 :         if ( rListener.is() )
     336           0 :             rListener->loadCancelled( this );
     337             : }
     338             : 
     339             : // -----------------------------------------------------------------------
     340           0 : void DBContentLoader::cancel(void) throw()
     341             : {
     342           0 : }
     343             : 
     344             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10