LCOV - code coverage report
Current view: top level - desktop/source/app - configinit.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 6 45 13.3 %
Date: 2012-08-25 Functions: 2 15 13.3 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 2 36 5.6 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include "configinit.hxx"
      30                 :            : 
      31                 :            : #include "desktop.hrc"
      32                 :            : #include "app.hxx"
      33                 :            : #include <comphelper/processfactory.hxx>
      34                 :            : #include <uno/current_context.hxx>
      35                 :            : #include <cppuhelper/implbase1.hxx>
      36                 :            : #include <rtl/ustrbuf.hxx>
      37                 :            : #include <osl/diagnose.h>
      38                 :            : #include <stdio.h>
      39                 :            : 
      40                 :            : // ----------------------------------------------------------------------------
      41                 :            : 
      42                 :            : namespace uno           = ::com::sun::star::uno;
      43                 :            : namespace lang          = ::com::sun::star::lang;
      44                 :            : using rtl::OUString;
      45                 :            : using uno::UNO_QUERY;
      46                 :            : 
      47                 :            : // ----------------------------------------------------------------------------
      48                 :            : static char const CONFIGURATION_ERROR_HANDLER[]  = "com.sun.star.configuration.backend.InteractionHandler";
      49                 :            : 
      50                 :            : // must be aligned with configmgr/source/misc/configinteractionhandler
      51                 :            : static char const CONFIG_ERROR_HANDLER[] = "configuration.interaction-handler";
      52                 :            : // ----------------------------------------------------------------------------
      53                 :            : 
      54                 :            : #define OUSTRING( constascii ) OUString( RTL_CONSTASCII_USTRINGPARAM( constascii ) )
      55                 :            : 
      56                 :            : #define k_ERRORHANDLER OUSTRING( CONFIGURATION_ERROR_HANDLER )
      57                 :            : 
      58                 :            : // ----------------------------------------------------------------------------
      59                 :            : // ConfigurationErrorHandler
      60                 :            : // ----------------------------------------------------------------------------
      61                 :            : 
      62                 :            : namespace
      63                 :            : {
      64                 :            :     typedef uno::Reference< uno::XCurrentContext > CurrentContext;
      65         [ #  # ]:          0 :     class SimpleCurrentContext : public cppu::WeakImplHelper1< uno::XCurrentContext >
      66                 :            :     {
      67                 :            :         CurrentContext m_xChainedContext;
      68                 :            :     public:
      69                 :            :         explicit
      70                 :          0 :         SimpleCurrentContext(const CurrentContext & xChainedContext)
      71                 :          0 :         : m_xChainedContext(xChainedContext)
      72                 :          0 :         {}
      73                 :            : 
      74         [ #  # ]:          0 :         void install()      { uno::setCurrentContext(this); }
      75                 :          0 :         void deinstall()    { uno::setCurrentContext(m_xChainedContext); }
      76                 :            : 
      77                 :          0 :         uno::Any getChainedValueByName( OUString const & aName) const
      78                 :            :         {
      79                 :          0 :             return m_xChainedContext.is()
      80                 :          0 :                             ? m_xChainedContext->getValueByName(aName)
      81         [ #  # ]:          0 :                             : uno::Any();
      82                 :            :         }
      83                 :            : 
      84                 :            :         // XCurrentContext
      85                 :            :         virtual uno::Any SAL_CALL
      86                 :            :             getValueByName( OUString const & aName)
      87                 :            :                 throw (uno::RuntimeException);
      88                 :            :     };
      89                 :            : 
      90                 :            :     uno::Any SAL_CALL
      91                 :          0 :         SimpleCurrentContext::getValueByName( OUString const & aName)
      92                 :            :             throw (uno::RuntimeException)
      93                 :            :     {
      94                 :          0 :         return getChainedValueByName(aName);
      95                 :            :     }
      96                 :            : 
      97                 :            : }
      98                 :            : 
      99                 :            : // ----------------------------------------------------------------------------
     100                 :            : class ConfigurationErrorHandler::Context : public SimpleCurrentContext
     101                 :            : {
     102                 :            : public:
     103                 :          0 :     Context()
     104         [ #  # ]:          0 :     : SimpleCurrentContext( uno::getCurrentContext() )
     105                 :            :     {
     106                 :          0 :     }
     107                 :            : 
     108                 :          0 :     ~Context()
     109                 :          0 :     {
     110         [ #  # ]:          0 :     }
     111                 :            : 
     112                 :            :     // XCurrentContext
     113                 :            :     virtual uno::Any SAL_CALL
     114                 :            :         getValueByName( OUString const & aName)
     115                 :            :             throw (uno::RuntimeException);
     116                 :            : 
     117                 :            : private:
     118                 :            :     InteractionHandler  m_xHandler;
     119                 :            : };
     120                 :            : 
     121                 :            : //------------------------------------------------------------------------------
     122                 :          0 : uno::Any SAL_CALL ConfigurationErrorHandler::Context::getValueByName( OUString const & aName)
     123                 :            :         throw (uno::RuntimeException)
     124                 :            : {
     125         [ #  # ]:          0 :     if ( aName == CONFIG_ERROR_HANDLER )
     126                 :            :     {
     127         [ #  # ]:          0 :         if ( !m_xHandler.is() )
     128         [ #  # ]:          0 :             m_xHandler = ConfigurationErrorHandler::getDefaultInteractionHandler();
     129                 :          0 :         return uno::Any( m_xHandler );
     130                 :            :     }
     131                 :          0 :     return SimpleCurrentContext::getValueByName( aName );
     132                 :            : }
     133                 :            : 
     134                 :            : //------------------------------------------------------------------------------
     135                 :        158 : ConfigurationErrorHandler::~ConfigurationErrorHandler()
     136                 :            : {
     137         [ +  - ]:        158 :     deactivate();
     138                 :        158 : }
     139                 :            : 
     140                 :            : //------------------------------------------------------------------------------
     141                 :            : /// installs the handler into the current context
     142                 :          0 : void ConfigurationErrorHandler::activate()
     143                 :            : {
     144         [ #  # ]:          0 :     if (!m_pContext)
     145                 :            :     {
     146         [ #  # ]:          0 :         m_pContext = new Context;
     147                 :          0 :         m_pContext->acquire();
     148                 :            :     }
     149                 :          0 :     m_pContext->install();
     150                 :          0 : }
     151                 :            : 
     152                 :            : //------------------------------------------------------------------------------
     153                 :            : /// deinstalls the handler from the current context, restoring the previous context
     154                 :        254 : void ConfigurationErrorHandler::deactivate()
     155                 :            : {
     156         [ -  + ]:        254 :     if (m_pContext)
     157                 :            :     {
     158                 :          0 :         m_pContext->deinstall();
     159                 :          0 :         m_pContext->release();
     160                 :          0 :         m_pContext = 0;
     161                 :            :     }
     162                 :        254 : }
     163                 :            : //------------------------------------------------------------------------------
     164                 :            : 
     165                 :          0 : ConfigurationErrorHandler::InteractionHandler ConfigurationErrorHandler::getDefaultInteractionHandler()
     166                 :            : {
     167         [ #  # ]:          0 :     uno::Reference< lang::XMultiServiceFactory > xServiceManager = ::comphelper::getProcessServiceFactory();
     168                 :            : 
     169                 :            :     OSL_ENSURE( xServiceManager.is(),"No ServiceManager set for ConfigurationErrorHandler");
     170                 :            : 
     171                 :          0 :     InteractionHandler xHandler;
     172                 :            : 
     173         [ #  # ]:          0 :     if (xServiceManager.is())
     174                 :            :     {
     175 [ #  # ][ #  # ]:          0 :         xHandler.set( xServiceManager->createInstance(k_ERRORHANDLER), UNO_QUERY );
         [ #  # ][ #  # ]
     176                 :            :     }
     177                 :            : 
     178                 :          0 :     return xHandler;
     179                 :            : }
     180                 :            : //------------------------------------------------------------------------------
     181                 :            : 
     182                 :            : 
     183                 :            : 
     184                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10