LCOV - code coverage report
Current view: top level - sd/source/ui/tools - ConfigurationAccess.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 63 73 86.3 %
Date: 2012-08-25 Functions: 7 8 87.5 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 65 138 47.1 %

           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                 :            : 
      30                 :            : #include "tools/ConfigurationAccess.hxx"
      31                 :            : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      32                 :            : #include <com/sun/star/beans/PropertyValue.hpp>
      33                 :            : #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
      34                 :            : #include <com/sun/star/util/XChangesBatch.hpp>
      35                 :            : #include <comphelper/processfactory.hxx>
      36                 :            : #include <tools/diagnose_ex.h>
      37                 :            : 
      38                 :            : using namespace ::com::sun::star;
      39                 :            : using namespace ::com::sun::star::uno;
      40                 :            : using ::rtl::OUString;
      41                 :            : 
      42                 :            : namespace sd { namespace tools {
      43                 :            : 
      44                 :        130 : ConfigurationAccess::ConfigurationAccess (
      45                 :            :     const Reference<XComponentContext>& rxContext,
      46                 :            :     const OUString& rsRootName,
      47                 :            :     const WriteMode eMode)
      48                 :        130 :     : mxRoot()
      49                 :            : {
      50 [ +  - ][ +  - ]:        130 :     Reference<lang::XMultiComponentFactory> xFactory (rxContext->getServiceManager());
      51         [ +  - ]:        130 :     if (xFactory.is())
      52                 :            :     {
      53                 :            :         Reference<lang::XMultiServiceFactory> xProvider (
      54         [ +  - ]:        130 :             xFactory->createInstanceWithContext(
      55                 :            :                 "com.sun.star.configuration.ConfigurationProvider",
      56                 :        130 :                 rxContext),
      57 [ +  - ][ +  - ]:        130 :             UNO_QUERY);
      58         [ +  - ]:        130 :         if (xProvider.is())
      59         [ +  - ]:        130 :             Initialize(xProvider, rsRootName, eMode);
      60                 :        130 :     }
      61                 :        130 : }
      62                 :            : 
      63                 :            : 
      64                 :            : 
      65                 :            : 
      66                 :        130 : ConfigurationAccess::ConfigurationAccess (
      67                 :            :     const OUString& rsRootName,
      68                 :            :     const WriteMode eMode)
      69                 :        130 :     : mxRoot()
      70                 :            : {
      71                 :            :     Reference<lang::XMultiServiceFactory> xProvider (
      72 [ +  - ][ +  - ]:        260 :         ::comphelper::getProcessServiceFactory()->createInstance(
      73                 :        130 :             "com.sun.star.configuration.ConfigurationProvider"),
      74 [ +  - ][ +  - ]:        130 :         UNO_QUERY);
      75         [ +  - ]:        130 :     if (xProvider.is())
      76         [ +  - ]:        130 :         Initialize(xProvider, rsRootName, eMode);
      77                 :        130 : }
      78                 :            : 
      79                 :            : 
      80                 :            : 
      81                 :            : 
      82                 :        260 : void ConfigurationAccess::Initialize (
      83                 :            :     const Reference<lang::XMultiServiceFactory>& rxProvider,
      84                 :            :     const OUString& rsRootName,
      85                 :            :     const WriteMode eMode)
      86                 :            : {
      87                 :            :     try
      88                 :            :     {
      89         [ +  - ]:        260 :         Sequence<Any> aCreationArguments(3);
      90         [ +  - ]:        260 :         aCreationArguments[0] = makeAny(beans::PropertyValue(
      91                 :            :             "nodepath",
      92                 :            :             0,
      93                 :            :             makeAny(rsRootName),
      94 [ +  - ][ +  - ]:        520 :             beans::PropertyState_DIRECT_VALUE));
      95         [ +  - ]:        260 :         aCreationArguments[1] = makeAny(beans::PropertyValue(
      96                 :            :             "depth",
      97                 :            :             0,
      98                 :            :             makeAny((sal_Int32)-1),
      99 [ +  - ][ +  - ]:        520 :             beans::PropertyState_DIRECT_VALUE));
     100         [ +  - ]:        260 :         aCreationArguments[2] = makeAny(beans::PropertyValue(
     101                 :            :             "lazywrite",
     102                 :            :             0,
     103                 :            :             makeAny(true),
     104 [ +  - ][ +  - ]:        520 :             beans::PropertyState_DIRECT_VALUE));
     105                 :        260 :         OUString sAccessService;
     106         [ +  - ]:        260 :         if (eMode == READ_ONLY)
     107                 :        260 :             sAccessService = "com.sun.star.configuration.ConfigurationAccess";
     108                 :            :         else
     109                 :          0 :             sAccessService = "com.sun.star.configuration.ConfigurationUpdateAccess";
     110                 :            : 
     111         [ +  - ]:        260 :         mxRoot = rxProvider->createInstanceWithArguments(
     112                 :            :             sAccessService,
     113 [ +  - ][ +  - ]:        260 :             aCreationArguments);
         [ +  - ][ #  # ]
     114                 :            :     }
     115                 :          0 :     catch (Exception&)
     116                 :            :     {
     117                 :            :         DBG_UNHANDLED_EXCEPTION();
     118                 :            :     }
     119                 :        260 : }
     120                 :            : 
     121                 :            : 
     122                 :            : 
     123                 :            : 
     124                 :        260 : Any ConfigurationAccess::GetConfigurationNode (
     125                 :            :     const OUString& sPathToNode)
     126                 :            : {
     127                 :            :     return GetConfigurationNode(
     128                 :            :         Reference<container::XHierarchicalNameAccess>(mxRoot, UNO_QUERY),
     129         [ +  - ]:        260 :         sPathToNode);
     130                 :            : }
     131                 :            : 
     132                 :            : 
     133                 :            : 
     134                 :            : 
     135                 :        260 : Any ConfigurationAccess::GetConfigurationNode (
     136                 :            :     const css::uno::Reference<css::container::XHierarchicalNameAccess>& rxNode,
     137                 :            :     const OUString& sPathToNode)
     138                 :            : {
     139         [ -  + ]:        260 :     if (sPathToNode.isEmpty())
     140                 :          0 :         return Any(rxNode);
     141                 :            : 
     142                 :            :     try
     143                 :            :     {
     144         [ +  - ]:        260 :         if (rxNode.is())
     145                 :            :         {
     146 [ +  - ][ +  - ]:        260 :             return rxNode->getByHierarchicalName(sPathToNode);
     147                 :            :         }
     148                 :            :     }
     149                 :          0 :     catch (const Exception& rException)
     150                 :            :     {
     151                 :            :         OSL_TRACE ("caught exception while getting configuration node %s: %s",
     152                 :            :             ::rtl::OUStringToOString(sPathToNode, RTL_TEXTENCODING_UTF8).getStr(),
     153                 :            :             ::rtl::OUStringToOString(rException.Message, RTL_TEXTENCODING_UTF8).getStr());
     154                 :            :     }
     155                 :            : 
     156         [ #  # ]:        260 :     return Any();
     157                 :            : }
     158                 :            : 
     159                 :            : 
     160                 :            : 
     161                 :            : 
     162                 :          0 : void ConfigurationAccess::CommitChanges (void)
     163                 :            : {
     164         [ #  # ]:          0 :     Reference<util::XChangesBatch> xConfiguration (mxRoot, UNO_QUERY);
     165         [ #  # ]:          0 :     if (xConfiguration.is())
     166 [ #  # ][ #  # ]:          0 :         xConfiguration->commitChanges();
     167                 :          0 : }
     168                 :            : 
     169                 :            : 
     170                 :            : 
     171                 :            : 
     172                 :        260 : void ConfigurationAccess::ForAll (
     173                 :            :     const Reference<container::XNameAccess>& rxContainer,
     174                 :            :     const ::std::vector<OUString>& rArguments,
     175                 :            :     const Functor& rFunctor)
     176                 :            : {
     177         [ +  - ]:        260 :     if (rxContainer.is())
     178                 :            :     {
     179         [ +  - ]:        260 :         ::std::vector<Any> aValues(rArguments.size());
     180 [ +  - ][ +  - ]:        260 :         Sequence<OUString> aKeys (rxContainer->getElementNames());
     181         [ +  + ]:        910 :         for (sal_Int32 nItemIndex=0; nItemIndex < aKeys.getLength(); ++nItemIndex)
     182                 :            :         {
     183         [ +  - ]:        650 :             const OUString& rsKey (aKeys[nItemIndex]);
     184 [ +  - ][ +  - ]:        650 :             Reference<container::XNameAccess> xSetItem (rxContainer->getByName(rsKey), UNO_QUERY);
                 [ +  - ]
     185         [ +  - ]:        650 :             if (xSetItem.is())
     186                 :            :             {
     187                 :            :                 // Get from the current item of the container the children
     188                 :            :                 // that match the names in the rArguments list.
     189         [ +  + ]:       1820 :                 for (sal_uInt32 nValueIndex=0; nValueIndex<aValues.size(); ++nValueIndex)
     190 [ +  - ][ +  - ]:       1170 :                     aValues[nValueIndex] = xSetItem->getByName(rArguments[nValueIndex]);
     191                 :            :             }
     192         [ +  - ]:        650 :             rFunctor(rsKey, aValues);
     193         [ +  - ]:        910 :         }
     194                 :            :     }
     195                 :        260 : }
     196                 :            : 
     197                 :            : 
     198                 :            : 
     199                 :            : 
     200                 :        520 : void ConfigurationAccess::FillList(
     201                 :            :     const Reference<container::XNameAccess>& rxContainer,
     202                 :            :     const ::rtl::OUString& rsArgument,
     203                 :            :     ::std::vector<OUString>& rList)
     204                 :            : {
     205                 :            :     try
     206                 :            :     {
     207         [ +  - ]:        520 :         if (rxContainer.is())
     208                 :            :         {
     209 [ +  - ][ +  - ]:        520 :             Sequence<OUString> aKeys (rxContainer->getElementNames());
     210         [ +  - ]:        520 :             rList.resize(aKeys.getLength());
     211         [ +  + ]:       2860 :             for (sal_Int32 nItemIndex=0; nItemIndex<aKeys.getLength(); ++nItemIndex)
     212                 :            :             {
     213                 :            :                 Reference<container::XNameAccess> xSetItem (
     214 [ +  - ][ +  - ]:       2340 :                     rxContainer->getByName(aKeys[nItemIndex]), UNO_QUERY);
         [ +  - ][ +  - ]
     215         [ +  - ]:       2340 :                 if (xSetItem.is())
     216                 :            :                 {
     217 [ +  - ][ +  - ]:       2340 :                     xSetItem->getByName(rsArgument) >>= rList[nItemIndex];
     218                 :            :                 }
     219 [ +  - ][ #  # ]:       2860 :             }
     220                 :            :         }
     221                 :            :     }
     222                 :          0 :     catch (RuntimeException&)
     223                 :            :     {}
     224                 :        520 : }
     225                 :            : 
     226                 :            : 
     227                 :            : } } // end of namespace sd::tools
     228                 :            : 
     229                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10