LCOV - code coverage report
Current view: top level - libreoffice/framework/source/uifactory - windowcontentfactorymanager.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 20 81 24.7 %
Date: 2012-12-27 Functions: 2 14 14.3 %
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 <uifactory/windowcontentfactorymanager.hxx>
      21             : #include <uifactory/uielementfactorymanager.hxx>
      22             : #include <threadhelp/resetableguard.hxx>
      23             : #include "services.h"
      24             : 
      25             : #include <com/sun/star/beans/PropertyValue.hpp>
      26             : #include <com/sun/star/beans/XPropertySet.hpp>
      27             : #include <com/sun/star/container/XNameAccess.hpp>
      28             : #include <com/sun/star/container/XNameContainer.hpp>
      29             : #include <com/sun/star/container/XContainer.hpp>
      30             : #include <com/sun/star/frame/ModuleManager.hpp>
      31             : #include <com/sun/star/frame/XFrame.hpp>
      32             : #include <com/sun/star/awt/XControlModel.hpp>
      33             : #include <com/sun/star/awt/XControl.hpp>
      34             : 
      35             : #include <rtl/ustrbuf.hxx>
      36             : #include <cppuhelper/weak.hxx>
      37             : #include <tools/urlobj.hxx>
      38             : #include <tools/diagnose_ex.h>
      39             : #include <vcl/svapp.hxx>
      40             : 
      41             : //_________________________________________________________________________________________________________________
      42             : //  Defines
      43             : //_________________________________________________________________________________________________________________
      44             : 
      45             : using namespace ::com::sun::star;
      46             : 
      47             : //_________________________________________________________________________________________________________________
      48             : //  Namespace
      49             : //_________________________________________________________________________________________________________________
      50             : 
      51             : namespace framework
      52             : {
      53             : 
      54             : //*****************************************************************************************************************
      55             : //  XInterface, XTypeProvider, XServiceInfo
      56             : //*****************************************************************************************************************
      57          38 : DEFINE_XSERVICEINFO_ONEINSTANCESERVICE_2  (   WindowContentFactoryManager                     ,
      58             :                                             ::cppu::OWeakObject                             ,
      59             :                                             DECLARE_ASCII("com.sun.star.ui.WindowContentFactoryManager"),
      60             :                                             IMPLEMENTATIONNAME_WINDOWCONTENTFACTORYMANAGER
      61             :                                         )
      62             : 
      63           0 : DEFINE_INIT_SERVICE                     (   WindowContentFactoryManager, {} )
      64             : 
      65           0 : WindowContentFactoryManager::WindowContentFactoryManager( const uno::Reference< uno::XComponentContext >& rxContext ) :
      66           0 :     ThreadHelpBase( &Application::GetSolarMutex() ),
      67           0 :     m_bConfigRead( sal_False )
      68             : {
      69           0 :     m_pConfigAccess = new ConfigurationAccess_FactoryManager( rxContext, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/org.openoffice.Office.UI.WindowContentFactories/Registered/ContentFactories" )) );
      70           0 :     m_pConfigAccess->acquire();
      71           0 :     m_xModuleManager = frame::ModuleManager::create( rxContext );
      72           0 : }
      73             : 
      74           0 : WindowContentFactoryManager::~WindowContentFactoryManager()
      75             : {
      76           0 :     ResetableGuard aLock( m_aLock );
      77             : 
      78             :     // reduce reference count
      79           0 :     m_pConfigAccess->release();
      80           0 : }
      81             : 
      82        1439 : void WindowContentFactoryManager::RetrieveTypeNameFromResourceURL( const rtl::OUString& aResourceURL, rtl::OUString& aType, rtl::OUString& aName )
      83             : {
      84        1439 :     const sal_Int32 RESOURCEURL_PREFIX_SIZE = 17;
      85        1439 :     const char      RESOURCEURL_PREFIX[] = "private:resource/";
      86             : 
      87        2878 :     if (( aResourceURL.indexOf( RESOURCEURL_PREFIX ) == 0 ) &&
      88        1439 :         ( aResourceURL.getLength() > RESOURCEURL_PREFIX_SIZE ))
      89             :     {
      90        1439 :         rtl::OUString aTmpStr( aResourceURL.copy( RESOURCEURL_PREFIX_SIZE ));
      91        1439 :         sal_Int32 nToken = 0;
      92        1439 :         sal_Int32 nPart  = 0;
      93        2878 :         do
      94             :         {
      95        2878 :             ::rtl::OUString sToken = aTmpStr.getToken( 0, '/', nToken);
      96        2878 :             if ( !sToken.isEmpty() )
      97             :             {
      98        2878 :                 if ( nPart == 0 )
      99        1439 :                     aType = sToken;
     100        1439 :                 else if ( nPart == 1 )
     101        1439 :                     aName = sToken;
     102             :                 else
     103             :                     break;
     104        2878 :                 nPart++;
     105        2878 :             }
     106             :         }
     107        1439 :         while( nToken >=0 );
     108             :     }
     109        1439 : }
     110             : 
     111             : // XSingleComponentFactory
     112           0 : uno::Reference< uno::XInterface > SAL_CALL WindowContentFactoryManager::createInstanceWithContext(
     113             :     const uno::Reference< uno::XComponentContext >& /*xContext*/ )
     114             : throw (uno::Exception, uno::RuntimeException)
     115             : {
     116           0 :     uno::Reference< uno::XInterface > xWindow;
     117           0 :     return xWindow;
     118             : }
     119             : 
     120           0 : uno::Reference< uno::XInterface > SAL_CALL WindowContentFactoryManager::createInstanceWithArgumentsAndContext(
     121             :     const uno::Sequence< uno::Any >& Arguments, const uno::Reference< uno::XComponentContext >& Context )
     122             : throw (uno::Exception, uno::RuntimeException)
     123             : {
     124           0 :     uno::Reference< uno::XInterface > xWindow;
     125           0 :     uno::Reference< frame::XFrame >   xFrame;
     126           0 :     ::rtl::OUString                   aResourceURL;
     127             : 
     128           0 :     for (sal_Int32 i=0; i < Arguments.getLength(); i++ )
     129             :     {
     130           0 :         beans::PropertyValue aPropValue;
     131           0 :         if ( Arguments[i] >>= aPropValue )
     132             :         {
     133           0 :             if ( aPropValue.Name == "Frame" )
     134           0 :                 aPropValue.Value >>= xFrame;
     135           0 :             else if ( aPropValue.Name == "ResourceURL" )
     136           0 :                 aPropValue.Value >>= aResourceURL;
     137             :         }
     138           0 :     }
     139             : 
     140           0 :     uno::Reference< frame::XModuleManager2 > xModuleManager;
     141             :     // SAFE
     142             :     {
     143           0 :         ResetableGuard aLock( m_aLock );
     144           0 :         xModuleManager = m_xModuleManager;
     145             :     }
     146             :     // UNSAFE
     147             : 
     148             :     // Determine the module identifier
     149           0 :     ::rtl::OUString aType;
     150           0 :     ::rtl::OUString aName;
     151           0 :     ::rtl::OUString aModuleId;
     152             :     try
     153             :     {
     154           0 :         if ( xFrame.is() && xModuleManager.is() )
     155           0 :             aModuleId = xModuleManager->identify( uno::Reference< uno::XInterface >( xFrame, uno::UNO_QUERY ) );
     156             :     }
     157           0 :     catch ( const frame::UnknownModuleException& )
     158             :     {
     159             :     }
     160             : 
     161           0 :     RetrieveTypeNameFromResourceURL( aResourceURL, aType, aName );
     162           0 :     if ( !aType.isEmpty() &&
     163           0 :          !aName.isEmpty() &&
     164           0 :          !aModuleId.isEmpty() )
     165             :     {
     166           0 :         ::rtl::OUString                   aImplementationName;
     167           0 :         uno::Reference< uno::XInterface > xHolder( static_cast<cppu::OWeakObject*>(this), uno::UNO_QUERY );
     168             : 
     169             :         // Detetmine the implementation name of the window content factory dependent on the
     170             :         // module identifier, user interface element type and name
     171             :         // SAFE
     172           0 :         ResetableGuard aLock( m_aLock );
     173             : 
     174           0 :         if ( !m_bConfigRead )
     175             :         {
     176           0 :             m_bConfigRead = sal_True;
     177           0 :             m_pConfigAccess->readConfigurationData();
     178             :         }
     179             : 
     180           0 :         aImplementationName = m_pConfigAccess->getFactorySpecifierFromTypeNameModule( aType, aName, aModuleId );
     181           0 :         if ( !aImplementationName.isEmpty() )
     182             :         {
     183           0 :             aLock.unlock();
     184             :             // UNSAFE
     185             : 
     186           0 :             uno::Reference< lang::XMultiServiceFactory > xServiceManager( Context->getServiceManager(), uno::UNO_QUERY );
     187           0 :             if ( xServiceManager.is() )
     188             :             {
     189             :                 uno::Reference< lang::XSingleComponentFactory > xFactory(
     190           0 :                     xServiceManager->createInstance( aImplementationName ), uno::UNO_QUERY );
     191           0 :                 if ( xFactory.is() )
     192             :                 {
     193             :                     // Be careful: We call external code. Therefore here we have to catch all exceptions
     194             :                     try
     195             :                     {
     196           0 :                         xWindow = xFactory->createInstanceWithArgumentsAndContext( Arguments, Context );
     197             :                     }
     198           0 :                     catch ( uno::Exception& )
     199             :                     {
     200             :                         DBG_UNHANDLED_EXCEPTION();
     201             :                     }
     202           0 :                 }
     203           0 :             }
     204           0 :         }
     205             :     }
     206             : 
     207             :     // UNSAFE
     208           0 :     if ( !xWindow.is())
     209             :     {
     210             :         // Fallback: Use internal factory code to create a toolkit dialog as a content window
     211           0 :         xWindow = createInstanceWithContext(Context);
     212             :     }
     213             : 
     214           0 :     return xWindow;
     215             : }
     216             : 
     217             : } // namespace framework
     218             : 
     219             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10