Branch libreoffice-5-0-4
[LibreOffice.git] / oox / source / helper / propertyset.cxx
blobff092e029b0534c625c8ba43deebd4141805add2
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "oox/helper/propertyset.hxx"
22 #include <osl/diagnose.h>
23 #include <rtl/strbuf.hxx>
24 #include "oox/helper/propertymap.hxx"
26 namespace oox {
28 using namespace ::com::sun::star::beans;
29 using namespace ::com::sun::star::uno;
31 void PropertySet::set( const Reference< XPropertySet >& rxPropSet )
33 mxPropSet = rxPropSet;
34 mxMultiPropSet.set( mxPropSet, UNO_QUERY );
35 if( mxPropSet.is() ) try
37 mxPropSetInfo = mxPropSet->getPropertySetInfo();
39 catch( Exception& )
44 bool PropertySet::hasProperty( sal_Int32 nPropId ) const
46 if( mxPropSetInfo.is() ) try
48 const OUString& rPropName = PropertyMap::getPropertyName( nPropId );
49 return mxPropSetInfo->hasPropertyByName( rPropName );
51 catch( Exception& )
54 return false;
57 // Get properties -------------------------------------------------------------
59 Any PropertySet::getAnyProperty( sal_Int32 nPropId ) const
61 Any aValue;
62 return implGetPropertyValue( aValue, PropertyMap::getPropertyName( nPropId ) ) ? aValue : Any();
65 // Set properties -------------------------------------------------------------
67 bool PropertySet::setAnyProperty( sal_Int32 nPropId, const Any& rValue )
69 return implSetPropertyValue( PropertyMap::getPropertyName( nPropId ), rValue );
72 void PropertySet::setProperties( const Sequence< OUString >& rPropNames, const Sequence< Any >& rValues )
74 OSL_ENSURE( rPropNames.getLength() == rValues.getLength(),
75 "PropertySet::setProperties - length of sequences different" );
77 if( mxMultiPropSet.is() ) try
79 mxMultiPropSet->setPropertyValues( rPropNames, rValues );
80 return;
82 catch( Exception& )
84 SAL_WARN( "oox", "PropertySet::setProperties - cannot set all property values, fallback to single mode" );
87 if( mxPropSet.is() )
89 const OUString* pPropName = rPropNames.getConstArray();
90 const OUString* pPropNameEnd = pPropName + rPropNames.getLength();
91 const Any* pValue = rValues.getConstArray();
92 for( ; pPropName != pPropNameEnd; ++pPropName, ++pValue )
93 implSetPropertyValue( *pPropName, *pValue );
97 void PropertySet::setProperties( const PropertyMap& rPropertyMap )
99 if( !rPropertyMap.empty() )
101 Sequence< OUString > aPropNames;
102 Sequence< Any > aValues;
103 rPropertyMap.fillSequences( aPropNames, aValues );
104 setProperties( aPropNames, aValues );
108 // private --------------------------------------------------------------------
110 bool PropertySet::implGetPropertyValue( Any& orValue, const OUString& rPropName ) const
112 if( mxPropSet.is() ) try
114 orValue = mxPropSet->getPropertyValue( rPropName );
115 return true;
117 catch( Exception& e)
119 SAL_WARN( "oox", "PropertySet::implGetPropertyValue - cannot get property \"" <<
120 rPropName << "\" Error: " << e.Message);
122 return false;
125 bool PropertySet::implSetPropertyValue( const OUString& rPropName, const Any& rValue )
127 if( mxPropSet.is() ) try
129 mxPropSet->setPropertyValue( rPropName, rValue );
130 return true;
132 catch( Exception& e)
134 SAL_WARN( "oox", "PropertySet::implSetPropertyValue - cannot set property \"" <<
135 rPropName << "\" Error: " << e.Message);
137 return false;
140 #ifdef DBG_UTIL
141 void PropertySet::dump()
143 PropertyMap::dump( Reference< XPropertySet >( getXPropertySet(), UNO_QUERY ) );
145 #endif
147 } // namespace oox
149 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */