update dev300-m58
[ooovba.git] / oox / source / helper / propertyset.cxx
blobe7bb191070364481eaa60df71180a033e19c49b0
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: propertyset.cxx,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "oox/helper/propertyset.hxx"
32 #include <rtl/strbuf.hxx>
33 #include <osl/diagnose.h>
34 #include "oox/helper/propertymap.hxx"
36 using ::rtl::OUString;
37 using ::rtl::OStringBuffer;
38 using ::rtl::OUStringToOString;
39 using ::com::sun::star::uno::Any;
40 using ::com::sun::star::uno::Reference;
41 using ::com::sun::star::uno::Sequence;
42 using ::com::sun::star::uno::Exception;
43 using ::com::sun::star::uno::UNO_QUERY;
44 using ::com::sun::star::beans::XPropertySet;
46 namespace oox {
48 // ============================================================================
50 void PropertySet::set( const Reference< XPropertySet >& rxPropSet )
52 mxPropSet = rxPropSet;
53 mxMultiPropSet.set( mxPropSet, UNO_QUERY );
56 // Get properties -------------------------------------------------------------
58 bool PropertySet::getAnyProperty( Any& orValue, sal_Int32 nPropId ) const
60 return getAnyProperty( orValue, PropertyMap::getPropertyName( nPropId ) );
63 bool PropertySet::getBoolProperty( sal_Int32 nPropId ) const
65 Any aAny;
66 bool bValue = false;
67 return getAnyProperty( aAny, nPropId ) && (aAny >>= bValue) && bValue;
70 void PropertySet::getProperties( Sequence< Any >& orValues, const Sequence< OUString >& rPropNames ) const
72 if( mxMultiPropSet.is() ) // first try the XMultiPropertySet
74 try
76 orValues = mxMultiPropSet->getPropertyValues( rPropNames );
78 catch( Exception& )
80 OSL_ENSURE( false, "PropertySet::getProperties - cannot get all property values" );
83 else if( mxPropSet.is() )
85 sal_Int32 nLen = rPropNames.getLength();
86 const OUString* pPropName = rPropNames.getConstArray();
87 const OUString* pPropNameEnd = pPropName + nLen;
88 orValues.realloc( nLen );
89 Any* pValue = orValues.getArray();
90 for( ; pPropName != pPropNameEnd; ++pPropName, ++pValue )
91 getAnyProperty( *pValue, *pPropName );
95 // Set properties -------------------------------------------------------------
97 void PropertySet::setAnyProperty( sal_Int32 nPropId, const Any& rValue )
99 setAnyProperty( PropertyMap::getPropertyName( nPropId ), rValue );
102 void PropertySet::setProperties( const Sequence< OUString >& rPropNames, const Sequence< Any >& rValues )
104 OSL_ENSURE( rPropNames.getLength() == rValues.getLength(),
105 "PropertySet::setProperties - length of sequences different" );
107 if( mxMultiPropSet.is() ) // first try the XMultiPropertySet
111 mxMultiPropSet->setPropertyValues( rPropNames, rValues );
113 catch( Exception& )
115 OSL_ENSURE( false, "PropertySet::setProperties - cannot set all property values" );
118 else if( mxPropSet.is() )
120 const OUString* pPropName = rPropNames.getConstArray();
121 const OUString* pPropNameEnd = pPropName + rPropNames.getLength();
122 const Any* pValue = rValues.getConstArray();
123 for( ; pPropName != pPropNameEnd; ++pPropName, ++pValue )
124 setAnyProperty( *pPropName, *pValue );
128 void PropertySet::setProperties( const PropertyMap& rPropertyMap )
130 if( !rPropertyMap.empty() )
132 Sequence< OUString > aPropNames;
133 Sequence< Any > aValues;
134 rPropertyMap.fillSequences( aPropNames, aValues );
135 setProperties( aPropNames, aValues );
139 // private --------------------------------------------------------------------
141 bool PropertySet::getAnyProperty( Any& orValue, const OUString& rPropName ) const
143 bool bHasValue = false;
146 if( mxPropSet.is() )
148 orValue = mxPropSet->getPropertyValue( rPropName );
149 bHasValue = true;
152 catch( Exception& )
154 OSL_ENSURE( false, OStringBuffer( "PropertySet::getAnyProperty - cannot get property \"" ).
155 append( OUStringToOString( rPropName, RTL_TEXTENCODING_ASCII_US ) ).append( '"' ).getStr() );
157 return bHasValue;
160 void PropertySet::setAnyProperty( const OUString& rPropName, const Any& rValue )
164 if( mxPropSet.is() )
165 mxPropSet->setPropertyValue( rPropName, rValue );
167 catch( Exception& )
169 OSL_ENSURE( false, OStringBuffer( "PropertySet::setAnyProperty - cannot set property \"" ).
170 append( OUStringToOString( rPropName, RTL_TEXTENCODING_ASCII_US ) ).append( '"' ).getStr() );
174 // ============================================================================
176 } // namespace oox