LCOV - code coverage report
Current view: top level - oox/source/helper - propertyset.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 44 48 91.7 %
Date: 2012-08-25 Functions: 8 8 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 36 68 52.9 %

           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                 :            : #include "oox/helper/propertyset.hxx"
      21                 :            : 
      22                 :            : #include <osl/diagnose.h>
      23                 :            : #include <rtl/strbuf.hxx>
      24                 :            : #include "oox/helper/propertymap.hxx"
      25                 :            : 
      26                 :            : namespace oox {
      27                 :            : 
      28                 :            : // ============================================================================
      29                 :            : 
      30                 :            : using namespace ::com::sun::star::beans;
      31                 :            : using namespace ::com::sun::star::uno;
      32                 :            : 
      33                 :            : using ::rtl::OStringBuffer;
      34                 :            : using ::rtl::OUString;
      35                 :            : using ::rtl::OUStringToOString;
      36                 :            : 
      37                 :            : // ============================================================================
      38                 :            : 
      39                 :       2587 : void PropertySet::set( const Reference< XPropertySet >& rxPropSet )
      40                 :            : {
      41                 :       2587 :     mxPropSet = rxPropSet;
      42                 :       2587 :     mxMultiPropSet.set( mxPropSet, UNO_QUERY );
      43         [ +  + ]:       2587 :     if( mxPropSet.is() ) try
      44                 :            :     {
      45 [ +  - ][ +  - ]:       2545 :         mxPropSetInfo = mxPropSet->getPropertySetInfo();
         [ +  - ][ #  # ]
      46                 :            :     }
      47                 :          0 :     catch( Exception& )
      48                 :            :     {
      49                 :            :     }
      50                 :       2587 : }
      51                 :            : 
      52                 :         48 : bool PropertySet::hasProperty( sal_Int32 nPropId ) const
      53                 :            : {
      54         [ +  - ]:         48 :     if( mxPropSetInfo.is() ) try
      55                 :            :     {
      56         [ +  - ]:         48 :         const OUString& rPropName = PropertyMap::getPropertyName( nPropId );
      57 [ +  - ][ +  - ]:         48 :         return mxPropSetInfo->hasPropertyByName( rPropName );
      58                 :            :     }
      59                 :          0 :     catch( Exception& )
      60                 :            :     {
      61                 :            :     }
      62         [ #  # ]:         48 :     return false;
      63                 :            : }
      64                 :            : 
      65                 :            : // Get properties -------------------------------------------------------------
      66                 :            : 
      67                 :        914 : Any PropertySet::getAnyProperty( sal_Int32 nPropId ) const
      68                 :            : {
      69                 :        914 :     Any aValue;
      70 [ +  - ][ +  - ]:        914 :     return implGetPropertyValue( aValue, PropertyMap::getPropertyName( nPropId ) ) ? aValue : Any();
                 [ +  - ]
      71                 :            : }
      72                 :            : 
      73                 :            : // Set properties -------------------------------------------------------------
      74                 :            : 
      75                 :       2337 : bool PropertySet::setAnyProperty( sal_Int32 nPropId, const Any& rValue )
      76                 :            : {
      77                 :       2337 :     return implSetPropertyValue( PropertyMap::getPropertyName( nPropId ), rValue );
      78                 :            : }
      79                 :            : 
      80                 :        770 : void PropertySet::setProperties( const Sequence< OUString >& rPropNames, const Sequence< Any >& rValues )
      81                 :            : {
      82                 :            :     OSL_ENSURE( rPropNames.getLength() == rValues.getLength(),
      83                 :            :         "PropertySet::setProperties - length of sequences different" );
      84                 :            : 
      85         [ +  + ]:        770 :     if( mxMultiPropSet.is() ) try
      86                 :            :     {
      87 [ +  - ][ +  - ]:        512 :         mxMultiPropSet->setPropertyValues( rPropNames, rValues );
      88         [ #  # ]:        770 :         return;
      89                 :            :     }
      90                 :          0 :     catch( Exception& )
      91                 :            :     {
      92                 :            :         OSL_FAIL( "PropertySet::setProperties - cannot set all property values, fallback to single mode" );
      93                 :            :     }
      94                 :            : 
      95         [ +  - ]:        258 :     if( mxPropSet.is() )
      96                 :            :     {
      97                 :        258 :         const OUString* pPropName = rPropNames.getConstArray();
      98                 :        258 :         const OUString* pPropNameEnd = pPropName + rPropNames.getLength();
      99                 :        258 :         const Any* pValue = rValues.getConstArray();
     100         [ +  + ]:       3189 :         for( ; pPropName != pPropNameEnd; ++pPropName, ++pValue )
     101                 :       2931 :             implSetPropertyValue( *pPropName, *pValue );
     102                 :            :     }
     103                 :            : }
     104                 :            : 
     105                 :        893 : void PropertySet::setProperties( const PropertyMap& rPropertyMap )
     106                 :            : {
     107         [ +  + ]:        893 :     if( !rPropertyMap.empty() )
     108                 :            :     {
     109         [ +  - ]:        770 :         Sequence< OUString > aPropNames;
     110         [ +  - ]:        770 :         Sequence< Any > aValues;
     111         [ +  - ]:        770 :         rPropertyMap.fillSequences( aPropNames, aValues );
     112 [ +  - ][ +  - ]:        770 :         setProperties( aPropNames, aValues );
                 [ +  - ]
     113                 :            :     }
     114                 :        893 : }
     115                 :            : 
     116                 :            : // private --------------------------------------------------------------------
     117                 :            : 
     118                 :        914 : bool PropertySet::implGetPropertyValue( Any& orValue, const OUString& rPropName ) const
     119                 :            : {
     120         [ +  - ]:        914 :     if( mxPropSet.is() ) try
     121                 :            :     {
     122 [ +  - ][ +  - ]:        914 :         orValue = mxPropSet->getPropertyValue( rPropName );
     123                 :        914 :         return true;
     124                 :            :     }
     125                 :          0 :     catch( Exception& )
     126                 :            :     {
     127                 :            :         OSL_FAIL( OStringBuffer( "PropertySet::implGetPropertyValue - cannot get property \"" ).
     128                 :            :             append( OUStringToOString( rPropName, RTL_TEXTENCODING_ASCII_US ) ).append( '"' ).getStr() );
     129                 :            :     }
     130         [ #  # ]:        914 :     return false;
     131                 :            : }
     132                 :            : 
     133                 :       5268 : bool PropertySet::implSetPropertyValue( const OUString& rPropName, const Any& rValue )
     134                 :            : {
     135         [ +  + ]:       5268 :     if( mxPropSet.is() ) try
     136                 :            :     {
     137 [ +  - ][ +  + ]:       5226 :         mxPropSet->setPropertyValue( rPropName, rValue );
     138                 :       4896 :         return true;
     139                 :            :     }
     140                 :        330 :     catch( Exception& )
     141                 :            :     {
     142                 :            :         OSL_FAIL( OStringBuffer( "PropertySet::implSetPropertyValue - cannot set property \"" ).
     143                 :            :             append( OUStringToOString( rPropName, RTL_TEXTENCODING_ASCII_US ) ).append( '"' ).getStr() );
     144                 :            :     }
     145         [ -  + ]:       5598 :     return false;
     146                 :            : }
     147                 :            : 
     148                 :            : #ifdef DBG_UTIL
     149                 :            : void PropertySet::dump()
     150                 :            : {
     151                 :            :     PropertyMap::dump( Reference< XPropertySet >( getXPropertySet(), UNO_QUERY ) );
     152                 :            : }
     153                 :            : #endif
     154                 :            : 
     155                 :            : } // namespace oox
     156                 :            : 
     157                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10