LCOV - code coverage report
Current view: top level - oox/source/helper - propertyset.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 44 48 91.7 %
Date: 2014-11-03 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             : using namespace ::com::sun::star::beans;
      29             : using namespace ::com::sun::star::uno;
      30             : 
      31       71904 : void PropertySet::set( const Reference< XPropertySet >& rxPropSet )
      32             : {
      33       71904 :     mxPropSet = rxPropSet;
      34       71904 :     mxMultiPropSet.set( mxPropSet, UNO_QUERY );
      35       71904 :     if( mxPropSet.is() ) try
      36             :     {
      37       71870 :         mxPropSetInfo = mxPropSet->getPropertySetInfo();
      38             :     }
      39           0 :     catch( Exception& )
      40             :     {
      41             :     }
      42       71904 : }
      43             : 
      44        7850 : bool PropertySet::hasProperty( sal_Int32 nPropId ) const
      45             : {
      46        7850 :     if( mxPropSetInfo.is() ) try
      47             :     {
      48        7846 :         const OUString& rPropName = PropertyMap::getPropertyName( nPropId );
      49        7846 :         return mxPropSetInfo->hasPropertyByName( rPropName );
      50             :     }
      51           0 :     catch( Exception& )
      52             :     {
      53             :     }
      54           4 :     return false;
      55             : }
      56             : 
      57             : // Get properties -------------------------------------------------------------
      58             : 
      59       13346 : Any PropertySet::getAnyProperty( sal_Int32 nPropId ) const
      60             : {
      61       13346 :     Any aValue;
      62       13346 :     return implGetPropertyValue( aValue, PropertyMap::getPropertyName( nPropId ) ) ? aValue : Any();
      63             : }
      64             : 
      65             : // Set properties -------------------------------------------------------------
      66             : 
      67       67930 : bool PropertySet::setAnyProperty( sal_Int32 nPropId, const Any& rValue )
      68             : {
      69       67930 :     return implSetPropertyValue( PropertyMap::getPropertyName( nPropId ), rValue );
      70             : }
      71             : 
      72       19080 : void PropertySet::setProperties( const Sequence< OUString >& rPropNames, const Sequence< Any >& rValues )
      73             : {
      74             :     OSL_ENSURE( rPropNames.getLength() == rValues.getLength(),
      75             :         "PropertySet::setProperties - length of sequences different" );
      76             : 
      77       19080 :     if( mxMultiPropSet.is() ) try
      78             :     {
      79       16064 :         mxMultiPropSet->setPropertyValues( rPropNames, rValues );
      80       35138 :         return;
      81             :     }
      82           6 :     catch( Exception& )
      83             :     {
      84             :         SAL_WARN( "oox", "PropertySet::setProperties - cannot set all property values, fallback to single mode" );
      85             :     }
      86             : 
      87        3022 :     if( mxPropSet.is() )
      88             :     {
      89        3018 :         const OUString* pPropName = rPropNames.getConstArray();
      90        3018 :         const OUString* pPropNameEnd = pPropName + rPropNames.getLength();
      91        3018 :         const Any* pValue = rValues.getConstArray();
      92       41810 :         for( ; pPropName != pPropNameEnd; ++pPropName, ++pValue )
      93       38792 :             implSetPropertyValue( *pPropName, *pValue );
      94             :     }
      95             : }
      96             : 
      97       20358 : void PropertySet::setProperties( const PropertyMap& rPropertyMap )
      98             : {
      99       20358 :     if( !rPropertyMap.empty() )
     100             :     {
     101       19080 :         Sequence< OUString > aPropNames;
     102       38160 :         Sequence< Any > aValues;
     103       19080 :         rPropertyMap.fillSequences( aPropNames, aValues );
     104       38160 :         setProperties( aPropNames, aValues );
     105             :     }
     106       20358 : }
     107             : 
     108             : // private --------------------------------------------------------------------
     109             : 
     110       13346 : bool PropertySet::implGetPropertyValue( Any& orValue, const OUString& rPropName ) const
     111             : {
     112       13346 :     if( mxPropSet.is() ) try
     113             :     {
     114       13346 :         orValue = mxPropSet->getPropertyValue( rPropName );
     115       13346 :         return true;
     116             :     }
     117           0 :     catch( Exception& e)
     118             :     {
     119             :         SAL_WARN( "oox", "PropertySet::implGetPropertyValue - cannot get property \"" <<
     120             :                   rPropName << "\" Error: " << e.Message);
     121             :     }
     122           0 :     return false;
     123             : }
     124             : 
     125      106722 : bool PropertySet::implSetPropertyValue( const OUString& rPropName, const Any& rValue )
     126             : {
     127      106722 :     if( mxPropSet.is() ) try
     128             :     {
     129      106676 :         mxPropSet->setPropertyValue( rPropName, rValue );
     130      104706 :         return true;
     131             :     }
     132        1970 :     catch( Exception& e)
     133             :     {
     134             :         SAL_WARN( "oox", "PropertySet::implSetPropertyValue - cannot set property \"" <<
     135             :                   rPropName << "\" Error: " << e.Message);
     136             :     }
     137        2016 :     return false;
     138             : }
     139             : 
     140             : #ifdef DBG_UTIL
     141             : void PropertySet::dump()
     142             : {
     143             :     PropertyMap::dump( Reference< XPropertySet >( getXPropertySet(), UNO_QUERY ) );
     144             : }
     145             : #endif
     146             : 
     147             : } // namespace oox
     148             : 
     149             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10