LCOV - code coverage report
Current view: top level - ucbhelper/source/provider - contentinfo.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 79 123 64.2 %
Date: 2012-08-25 Functions: 17 29 58.6 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 61 254 24.0 %

           Branch data     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                 :            :                                 TODO
      22                 :            :  **************************************************************************
      23                 :            : 
      24                 :            :  *************************************************************************/
      25                 :            : #include <com/sun/star/beans/PropertyValue.hpp>
      26                 :            : #include <com/sun/star/ucb/XPropertySetRegistry.hpp>
      27                 :            : 
      28                 :            : #include "osl/diagnose.h"
      29                 :            : #include "osl/mutex.hxx"
      30                 :            : #include <ucbhelper/contenthelper.hxx>
      31                 :            : #include <ucbhelper/contentinfo.hxx>
      32                 :            : 
      33                 :            : using namespace com::sun::star;
      34                 :            : 
      35                 :            : //=========================================================================
      36                 :            : //=========================================================================
      37                 :            : //
      38                 :            : // PropertySetInfo Implementation.
      39                 :            : //
      40                 :            : //=========================================================================
      41                 :            : //=========================================================================
      42                 :            : 
      43                 :            : namespace ucbhelper {
      44                 :            : 
      45                 :         44 : PropertySetInfo::PropertySetInfo(
      46                 :            :     const uno::Reference< lang::XMultiServiceFactory >& rxSMgr,
      47                 :            :     const uno::Reference< com::sun::star::ucb::XCommandEnvironment >& rxEnv,
      48                 :            :     ContentImplHelper* pContent )
      49                 :            : : m_xSMgr( rxSMgr ),
      50                 :            :   m_xEnv( rxEnv ),
      51                 :            :   m_pProps( 0 ),
      52         [ +  - ]:         44 :   m_pContent( pContent )
      53                 :            : {
      54                 :         44 : }
      55                 :            : 
      56                 :            : //=========================================================================
      57                 :            : // virtual
      58         [ +  - ]:         44 : PropertySetInfo::~PropertySetInfo()
      59                 :            : {
      60 [ +  + ][ +  - ]:         44 :     delete m_pProps;
      61         [ -  + ]:         88 : }
      62                 :            : 
      63                 :            : //=========================================================================
      64                 :            : //
      65                 :            : // XInterface methods.
      66                 :            : //
      67                 :            : //=========================================================================
      68                 :            : 
      69 [ #  # ][ #  # ]:        452 : XINTERFACE_IMPL_2( PropertySetInfo,
                 [ #  # ]
      70                 :            :                    lang::XTypeProvider,
      71                 :            :                    beans::XPropertySetInfo );
      72                 :            : 
      73                 :            : //=========================================================================
      74                 :            : //
      75                 :            : // XTypeProvider methods.
      76                 :            : //
      77                 :            : //=========================================================================
      78                 :            : 
      79 [ #  # ][ #  # ]:          0 : XTYPEPROVIDER_IMPL_2( PropertySetInfo,
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      80                 :            :                           lang::XTypeProvider,
      81                 :            :                           beans::XPropertySetInfo );
      82                 :            : 
      83                 :            : //=========================================================================
      84                 :            : //
      85                 :            : // XPropertySetInfo methods.
      86                 :            : //
      87                 :            : //=========================================================================
      88                 :            : 
      89                 :            : // virtual
      90                 :         82 : uno::Sequence< beans::Property > SAL_CALL PropertySetInfo::getProperties()
      91                 :            :     throw( uno::RuntimeException )
      92                 :            : {
      93         [ +  + ]:         82 :     if ( !m_pProps )
      94                 :            :     {
      95         [ +  - ]:         50 :         osl::MutexGuard aGuard( m_aMutex );
      96         [ +  - ]:         50 :         if ( !m_pProps )
      97                 :            :         {
      98                 :            :             //////////////////////////////////////////////////////////////
      99                 :            :             // Get info for core ( native) properties.
     100                 :            :             //////////////////////////////////////////////////////////////
     101                 :            : 
     102                 :            :             try
     103                 :            :             {
     104                 :            :                 uno::Sequence< beans::Property > aProps
     105         [ +  - ]:         50 :                     = m_pContent->getProperties( m_xEnv );
     106 [ +  - ][ +  - ]:         50 :                 m_pProps = new uno::Sequence< beans::Property >( aProps );
     107                 :            :             }
     108                 :          0 :             catch ( uno::RuntimeException const & )
     109                 :            :             {
     110                 :          0 :                 throw;
     111                 :            :             }
     112   [ #  #  #  #  :          0 :             catch ( uno::Exception const & )
                      # ]
     113                 :            :             {
     114         [ #  # ]:          0 :                 m_pProps = new uno::Sequence< beans::Property >( 0 );
     115                 :            :             }
     116                 :            : 
     117                 :            :             //////////////////////////////////////////////////////////////
     118                 :            :             // Get info for additional properties.
     119                 :            :             //////////////////////////////////////////////////////////////
     120                 :            : 
     121                 :            :             uno::Reference< com::sun::star::ucb::XPersistentPropertySet >
     122         [ +  - ]:         50 :                 xSet ( m_pContent->getAdditionalPropertySet( sal_False ) );
     123                 :            : 
     124         [ +  + ]:         50 :             if ( xSet.is() )
     125                 :            :             {
     126                 :            :                 // Get property set info.
     127                 :            :                 uno::Reference< beans::XPropertySetInfo > xInfo(
     128 [ +  - ][ +  - ]:          6 :                     xSet->getPropertySetInfo() );
     129         [ +  - ]:          6 :                 if ( xInfo.is() )
     130                 :            :                 {
     131                 :            :                     const uno::Sequence< beans::Property >& rAddProps
     132 [ +  - ][ +  - ]:          6 :                         = xInfo->getProperties();
     133                 :          6 :                     sal_Int32 nAddProps = rAddProps.getLength();
     134         [ +  - ]:          6 :                     if ( nAddProps > 0 )
     135                 :            :                     {
     136                 :          6 :                         sal_Int32 nPos = m_pProps->getLength();
     137         [ +  - ]:          6 :                         m_pProps->realloc( nPos + nAddProps );
     138                 :            : 
     139         [ +  - ]:          6 :                         beans::Property* pProps = m_pProps->getArray();
     140                 :            :                         const beans::Property* pAddProps
     141                 :          6 :                             = rAddProps.getConstArray();
     142                 :            : 
     143         [ +  + ]:         18 :                         for ( sal_Int32 n = 0; n < nAddProps; ++n, ++nPos )
     144                 :         12 :                             pProps[ nPos ] = pAddProps[ n ];
     145         [ +  - ]:          6 :                     }
     146                 :          6 :                 }
     147                 :         50 :             }
     148         [ +  - ]:         50 :         }
     149                 :            :     }
     150                 :         82 :     return *m_pProps;
     151                 :            : }
     152                 :            : 
     153                 :            : //=========================================================================
     154                 :            : // virtual
     155                 :          0 : beans::Property SAL_CALL PropertySetInfo::getPropertyByName(
     156                 :            :         const rtl::OUString& aName )
     157                 :            :     throw( beans::UnknownPropertyException, uno::RuntimeException )
     158                 :            : {
     159                 :          0 :     beans::Property aProp;
     160 [ #  # ][ #  # ]:          0 :     if ( queryProperty( aName, aProp ) )
     161                 :          0 :         return aProp;
     162                 :            : 
     163         [ #  # ]:          0 :     throw beans::UnknownPropertyException();
     164                 :            : }
     165                 :            : 
     166                 :            : //=========================================================================
     167                 :            : // virtual
     168                 :         66 : sal_Bool SAL_CALL PropertySetInfo::hasPropertyByName(
     169                 :            :         const rtl::OUString& Name )
     170                 :            :     throw( uno::RuntimeException )
     171                 :            : {
     172                 :         66 :     beans::Property aProp;
     173         [ +  - ]:         66 :     return queryProperty( Name, aProp );
     174                 :            : }
     175                 :            : 
     176                 :            : //=========================================================================
     177                 :            : //
     178                 :            : // Non-Interface methods.
     179                 :            : //
     180                 :            : //=========================================================================
     181                 :            : 
     182                 :         32 : void PropertySetInfo::reset()
     183                 :            : {
     184         [ +  - ]:         32 :     osl::MutexGuard aGuard( m_aMutex );
     185 [ +  - ][ +  - ]:         32 :     delete m_pProps;
     186         [ +  - ]:         32 :     m_pProps = 0;
     187                 :         32 : }
     188                 :            : 
     189                 :            : //=========================================================================
     190                 :         66 : sal_Bool PropertySetInfo::queryProperty(
     191                 :            :     const rtl::OUString& rName, beans::Property& rProp )
     192                 :            : {
     193         [ +  - ]:         66 :     osl::MutexGuard aGuard( m_aMutex );
     194                 :            : 
     195 [ +  - ][ +  - ]:         66 :     getProperties();
     196                 :            : 
     197                 :         66 :     const beans::Property* pProps = m_pProps->getConstArray();
     198                 :         66 :     sal_Int32 nCount = m_pProps->getLength();
     199         [ +  + ]:        450 :     for ( sal_Int32 n = 0; n < nCount; ++n )
     200                 :            :     {
     201                 :        386 :         const beans::Property& rCurrProp = pProps[ n ];
     202         [ +  + ]:        386 :         if ( rCurrProp.Name == rName )
     203                 :            :         {
     204                 :          2 :             rProp = rCurrProp;
     205                 :          2 :             return sal_True;
     206                 :            :         }
     207                 :            :     }
     208                 :            : 
     209         [ +  - ]:         66 :     return sal_False;
     210                 :            : }
     211                 :            : 
     212                 :            : //=========================================================================
     213                 :            : //=========================================================================
     214                 :            : //
     215                 :            : // CommandProcessorInfo Implementation.
     216                 :            : //
     217                 :            : //=========================================================================
     218                 :            : //=========================================================================
     219                 :            : 
     220                 :        124 : CommandProcessorInfo::CommandProcessorInfo(
     221                 :            :     const uno::Reference< lang::XMultiServiceFactory >& rxSMgr,
     222                 :            :     const uno::Reference< com::sun::star::ucb::XCommandEnvironment >& rxEnv,
     223                 :            :     ContentImplHelper* pContent )
     224                 :            : : m_xSMgr( rxSMgr ),
     225                 :            :   m_xEnv( rxEnv ),
     226                 :            :   m_pCommands( 0 ),
     227         [ +  - ]:        124 :   m_pContent( pContent )
     228                 :            : {
     229                 :        124 : }
     230                 :            : 
     231                 :            : //=========================================================================
     232                 :            : // virtual
     233         [ +  - ]:        124 : CommandProcessorInfo::~CommandProcessorInfo()
     234                 :            : {
     235 [ +  - ][ +  - ]:        124 :     delete m_pCommands;
     236         [ -  + ]:        248 : }
     237                 :            : 
     238                 :            : //=========================================================================
     239                 :            : //
     240                 :            : // XInterface methods.
     241                 :            : //
     242                 :            : //=========================================================================
     243                 :            : 
     244 [ #  # ][ #  # ]:       1240 : XINTERFACE_IMPL_2( CommandProcessorInfo,
                 [ #  # ]
     245                 :            :                    lang::XTypeProvider,
     246                 :            :                    com::sun::star::ucb::XCommandInfo );
     247                 :            : 
     248                 :            : //=========================================================================
     249                 :            : //
     250                 :            : // XTypeProvider methods.
     251                 :            : //
     252                 :            : //=========================================================================
     253                 :            : 
     254 [ #  # ][ #  # ]:          0 : XTYPEPROVIDER_IMPL_2( CommandProcessorInfo,
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     255                 :            :                          lang::XTypeProvider,
     256                 :            :                          com::sun::star::ucb::XCommandInfo );
     257                 :            : 
     258                 :            : //=========================================================================
     259                 :            : //
     260                 :            : // XCommandInfo methods.
     261                 :            : //
     262                 :            : //=========================================================================
     263                 :            : 
     264                 :            : // virtual
     265                 :            : uno::Sequence< com::sun::star::ucb::CommandInfo > SAL_CALL
     266                 :        124 : CommandProcessorInfo::getCommands()
     267                 :            :     throw( uno::RuntimeException )
     268                 :            : {
     269         [ +  - ]:        124 :     if ( !m_pCommands )
     270                 :            :     {
     271         [ +  - ]:        124 :         osl::MutexGuard aGuard( m_aMutex );
     272         [ +  - ]:        124 :         if ( !m_pCommands )
     273                 :            :         {
     274                 :            :             //////////////////////////////////////////////////////////////
     275                 :            :             // Get info for commands.
     276                 :            :             //////////////////////////////////////////////////////////////
     277                 :            : 
     278                 :            :             try
     279                 :            :             {
     280                 :            :                 uno::Sequence< com::sun::star::ucb::CommandInfo > aCmds
     281         [ +  - ]:        124 :                     = m_pContent->getCommands( m_xEnv );
     282                 :            :                 m_pCommands
     283                 :            :                     = new uno::Sequence< com::sun::star::ucb::CommandInfo >(
     284 [ +  - ][ +  - ]:        124 :                         aCmds );
     285                 :            :             }
     286                 :          0 :             catch ( uno::RuntimeException const & )
     287                 :            :             {
     288                 :          0 :                 throw;
     289                 :            :             }
     290   [ #  #  #  #  :          0 :             catch ( uno::Exception const & )
                      # ]
     291                 :            :             {
     292                 :            :                 m_pCommands
     293                 :            :                     = new uno::Sequence< com::sun::star::ucb::CommandInfo >(
     294         [ #  # ]:          0 :                         0 );
     295                 :            :             }
     296         [ +  - ]:        124 :         }
     297                 :            :     }
     298                 :        124 :     return *m_pCommands;
     299                 :            : }
     300                 :            : 
     301                 :            : //=========================================================================
     302                 :            : // virtual
     303                 :            : com::sun::star::ucb::CommandInfo SAL_CALL
     304                 :          0 : CommandProcessorInfo::getCommandInfoByName(
     305                 :            :         const rtl::OUString& Name )
     306                 :            :     throw( com::sun::star::ucb::UnsupportedCommandException,
     307                 :            :            uno::RuntimeException )
     308                 :            : {
     309                 :          0 :     com::sun::star::ucb::CommandInfo aInfo;
     310 [ #  # ][ #  # ]:          0 :     if ( queryCommand( Name, aInfo ) )
     311                 :          0 :         return aInfo;
     312                 :            : 
     313         [ #  # ]:          0 :     throw com::sun::star::ucb::UnsupportedCommandException();
     314                 :            : }
     315                 :            : 
     316                 :            : //=========================================================================
     317                 :            : // virtual
     318                 :            : com::sun::star::ucb::CommandInfo SAL_CALL
     319                 :          0 : CommandProcessorInfo::getCommandInfoByHandle( sal_Int32 Handle )
     320                 :            :     throw( com::sun::star::ucb::UnsupportedCommandException,
     321                 :            :            uno::RuntimeException )
     322                 :            : {
     323                 :          0 :     com::sun::star::ucb::CommandInfo aInfo;
     324 [ #  # ][ #  # ]:          0 :     if ( queryCommand( Handle, aInfo ) )
     325                 :          0 :         return aInfo;
     326                 :            : 
     327         [ #  # ]:          0 :     throw com::sun::star::ucb::UnsupportedCommandException();
     328                 :            : }
     329                 :            : 
     330                 :            : //=========================================================================
     331                 :            : // virtual
     332                 :        124 : sal_Bool SAL_CALL CommandProcessorInfo::hasCommandByName(
     333                 :            :        const rtl::OUString& Name )
     334                 :            :     throw( uno::RuntimeException )
     335                 :            : {
     336                 :        124 :     com::sun::star::ucb::CommandInfo aInfo;
     337         [ +  - ]:        124 :     return queryCommand( Name, aInfo );
     338                 :            : }
     339                 :            : 
     340                 :            : //=========================================================================
     341                 :            : // virtual
     342                 :          0 : sal_Bool SAL_CALL CommandProcessorInfo::hasCommandByHandle( sal_Int32 Handle )
     343                 :            :     throw( uno::RuntimeException )
     344                 :            : {
     345                 :          0 :     com::sun::star::ucb::CommandInfo aInfo;
     346         [ #  # ]:          0 :     return queryCommand( Handle, aInfo );
     347                 :            : }
     348                 :            : 
     349                 :            : //=========================================================================
     350                 :            : //
     351                 :            : // Non-Interface methods.
     352                 :            : //
     353                 :            : //=========================================================================
     354                 :            : 
     355                 :          0 : void CommandProcessorInfo::reset()
     356                 :            : {
     357         [ #  # ]:          0 :     osl::MutexGuard aGuard( m_aMutex );
     358 [ #  # ][ #  # ]:          0 :     delete m_pCommands;
     359         [ #  # ]:          0 :     m_pCommands = 0;
     360                 :          0 : }
     361                 :            : 
     362                 :            : 
     363                 :            : //=========================================================================
     364                 :        124 : sal_Bool CommandProcessorInfo::queryCommand(
     365                 :            :     const rtl::OUString& rName,
     366                 :            :     com::sun::star::ucb::CommandInfo& rCommand )
     367                 :            : {
     368         [ +  - ]:        124 :     osl::MutexGuard aGuard( m_aMutex );
     369                 :            : 
     370 [ +  - ][ +  - ]:        124 :     getCommands();
     371                 :            : 
     372                 :            :     const com::sun::star::ucb::CommandInfo* pCommands
     373                 :        124 :         = m_pCommands->getConstArray();
     374                 :        124 :     sal_Int32 nCount = m_pCommands->getLength();
     375         [ +  - ]:       1116 :     for ( sal_Int32 n = 0; n < nCount; ++n )
     376                 :            :     {
     377                 :       1116 :         const com::sun::star::ucb::CommandInfo& rCurrCommand = pCommands[ n ];
     378         [ +  + ]:       1116 :         if ( rCurrCommand.Name == rName )
     379                 :            :         {
     380                 :        124 :             rCommand = rCurrCommand;
     381                 :        124 :             return sal_True;
     382                 :            :         }
     383                 :            :     }
     384                 :            : 
     385         [ +  - ]:        124 :     return sal_False;
     386                 :            : }
     387                 :            : 
     388                 :            : //=========================================================================
     389                 :          0 : sal_Bool CommandProcessorInfo::queryCommand(
     390                 :            :     sal_Int32 nHandle,
     391                 :            :     com::sun::star::ucb::CommandInfo& rCommand )
     392                 :            : {
     393         [ #  # ]:          0 :     osl::MutexGuard aGuard( m_aMutex );
     394                 :            : 
     395 [ #  # ][ #  # ]:          0 :     getCommands();
     396                 :            : 
     397                 :            :     const com::sun::star::ucb::CommandInfo* pCommands
     398                 :          0 :         = m_pCommands->getConstArray();
     399                 :          0 :     sal_Int32 nCount = m_pCommands->getLength();
     400         [ #  # ]:          0 :     for ( sal_Int32 n = 0; n < nCount; ++n )
     401                 :            :     {
     402                 :          0 :         const com::sun::star::ucb::CommandInfo& rCurrCommand = pCommands[ n ];
     403         [ #  # ]:          0 :         if ( rCurrCommand.Handle == nHandle )
     404                 :            :         {
     405                 :          0 :             rCommand = rCurrCommand;
     406                 :          0 :             return sal_True;
     407                 :            :         }
     408                 :            :     }
     409                 :            : 
     410         [ #  # ]:          0 :     return sal_False;
     411                 :            : }
     412                 :            : 
     413                 :            : } // namespace ucbhelper
     414                 :            : 
     415                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10