LCOV - code coverage report
Current view: top level - oox/source/helper - propertyset.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 44 48 91.7 %
Date: 2014-04-11 Functions: 8 8 100.0 %
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 "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             : 
      34             : 
      35       20759 : void PropertySet::set( const Reference< XPropertySet >& rxPropSet )
      36             : {
      37       20759 :     mxPropSet = rxPropSet;
      38       20759 :     mxMultiPropSet.set( mxPropSet, UNO_QUERY );
      39       20759 :     if( mxPropSet.is() ) try
      40             :     {
      41       20749 :         mxPropSetInfo = mxPropSet->getPropertySetInfo();
      42             :     }
      43           0 :     catch( Exception& )
      44             :     {
      45             :     }
      46       20759 : }
      47             : 
      48        2029 : bool PropertySet::hasProperty( sal_Int32 nPropId ) const
      49             : {
      50        2029 :     if( mxPropSetInfo.is() ) try
      51             :     {
      52        2027 :         const OUString& rPropName = PropertyMap::getPropertyName( nPropId );
      53        2027 :         return mxPropSetInfo->hasPropertyByName( rPropName );
      54             :     }
      55           0 :     catch( Exception& )
      56             :     {
      57             :     }
      58           2 :     return false;
      59             : }
      60             : 
      61             : // Get properties -------------------------------------------------------------
      62             : 
      63        4553 : Any PropertySet::getAnyProperty( sal_Int32 nPropId ) const
      64             : {
      65        4553 :     Any aValue;
      66        4553 :     return implGetPropertyValue( aValue, PropertyMap::getPropertyName( nPropId ) ) ? aValue : Any();
      67             : }
      68             : 
      69             : // Set properties -------------------------------------------------------------
      70             : 
      71       19135 : bool PropertySet::setAnyProperty( sal_Int32 nPropId, const Any& rValue )
      72             : {
      73       19135 :     return implSetPropertyValue( PropertyMap::getPropertyName( nPropId ), rValue );
      74             : }
      75             : 
      76        5648 : void PropertySet::setProperties( const Sequence< OUString >& rPropNames, const Sequence< Any >& rValues )
      77             : {
      78             :     OSL_ENSURE( rPropNames.getLength() == rValues.getLength(),
      79             :         "PropertySet::setProperties - length of sequences different" );
      80             : 
      81        5648 :     if( mxMultiPropSet.is() ) try
      82             :     {
      83        4596 :         mxMultiPropSet->setPropertyValues( rPropNames, rValues );
      84       10241 :         return;
      85             :     }
      86           3 :     catch( Exception& )
      87             :     {
      88             :         SAL_WARN( "oox", "PropertySet::setProperties - cannot set all property values, fallback to single mode" );
      89             :     }
      90             : 
      91        1055 :     if( mxPropSet.is() )
      92             :     {
      93        1053 :         const OUString* pPropName = rPropNames.getConstArray();
      94        1053 :         const OUString* pPropNameEnd = pPropName + rPropNames.getLength();
      95        1053 :         const Any* pValue = rValues.getConstArray();
      96       16030 :         for( ; pPropName != pPropNameEnd; ++pPropName, ++pValue )
      97       14977 :             implSetPropertyValue( *pPropName, *pValue );
      98             :     }
      99             : }
     100             : 
     101        5948 : void PropertySet::setProperties( const PropertyMap& rPropertyMap )
     102             : {
     103        5948 :     if( !rPropertyMap.empty() )
     104             :     {
     105        5648 :         Sequence< OUString > aPropNames;
     106       11296 :         Sequence< Any > aValues;
     107        5648 :         rPropertyMap.fillSequences( aPropNames, aValues );
     108       11296 :         setProperties( aPropNames, aValues );
     109             :     }
     110        5948 : }
     111             : 
     112             : // private --------------------------------------------------------------------
     113             : 
     114        4553 : bool PropertySet::implGetPropertyValue( Any& orValue, const OUString& rPropName ) const
     115             : {
     116        4553 :     if( mxPropSet.is() ) try
     117             :     {
     118        4553 :         orValue = mxPropSet->getPropertyValue( rPropName );
     119        4553 :         return true;
     120             :     }
     121           0 :     catch( Exception& e)
     122             :     {
     123             :         SAL_WARN( "oox", "PropertySet::implGetPropertyValue - cannot get property \"" <<
     124             :                   rPropName << "\" Error: " << e.Message);
     125             :     }
     126           0 :     return false;
     127             : }
     128             : 
     129       34112 : bool PropertySet::implSetPropertyValue( const OUString& rPropName, const Any& rValue )
     130             : {
     131       34112 :     if( mxPropSet.is() ) try
     132             :     {
     133       34098 :         mxPropSet->setPropertyValue( rPropName, rValue );
     134       30929 :         return true;
     135             :     }
     136        3169 :     catch( Exception& e)
     137             :     {
     138             :         SAL_WARN( "oox", "PropertySet::implSetPropertyValue - cannot set property \"" <<
     139             :                   rPropName << "\" Error: " << e.Message);
     140             :     }
     141        3183 :     return false;
     142             : }
     143             : 
     144             : #ifdef DBG_UTIL
     145             : void PropertySet::dump()
     146             : {
     147             :     PropertyMap::dump( Reference< XPropertySet >( getXPropertySet(), UNO_QUERY ) );
     148             : }
     149             : #endif
     150             : 
     151             : } // namespace oox
     152             : 
     153             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10