1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <com/sun/star/beans/XMultiPropertySet.hpp>
23 #include <com/sun/star/beans/XPropertySet.hpp>
24 #include <osl/diagnose.h>
25 #include <rtl/strbuf.hxx>
26 #include <oox/helper/propertymap.hxx>
30 using namespace ::com::sun::star::beans
;
31 using namespace ::com::sun::star::uno
;
33 void PropertySet::set( const Reference
< XPropertySet
>& rxPropSet
)
35 mxPropSet
= rxPropSet
;
36 mxMultiPropSet
.set( mxPropSet
, UNO_QUERY
);
37 if( mxPropSet
.is() ) try
39 mxPropSetInfo
= mxPropSet
->getPropertySetInfo();
46 bool PropertySet::hasProperty( sal_Int32 nPropId
) const
48 if( mxPropSetInfo
.is() ) try
50 const OUString
& rPropName
= PropertyMap::getPropertyName( nPropId
);
51 return mxPropSetInfo
->hasPropertyByName( rPropName
);
59 // Get properties -------------------------------------------------------------
61 Any
PropertySet::getAnyProperty( sal_Int32 nPropId
) const
64 return implGetPropertyValue( aValue
, PropertyMap::getPropertyName( nPropId
) ) ? aValue
: Any();
67 // Set properties -------------------------------------------------------------
69 bool PropertySet::setAnyProperty( sal_Int32 nPropId
, const Any
& rValue
)
71 return implSetPropertyValue( PropertyMap::getPropertyName( nPropId
), rValue
);
74 void PropertySet::setProperties( const Sequence
< OUString
>& rPropNames
, const Sequence
< Any
>& rValues
)
76 OSL_ENSURE( rPropNames
.getLength() == rValues
.getLength(),
77 "PropertySet::setProperties - length of sequences different" );
79 if( mxMultiPropSet
.is() ) try
81 mxMultiPropSet
->setPropertyValues( rPropNames
, rValues
);
86 SAL_WARN( "oox", "PropertySet::setProperties - cannot set all property values, fallback to single mode" );
91 const OUString
* pPropName
= rPropNames
.getConstArray();
92 const OUString
* pPropNameEnd
= pPropName
+ rPropNames
.getLength();
93 const Any
* pValue
= rValues
.getConstArray();
94 for( ; pPropName
!= pPropNameEnd
; ++pPropName
, ++pValue
)
95 implSetPropertyValue( *pPropName
, *pValue
);
99 void PropertySet::setProperties( const PropertyMap
& rPropertyMap
)
101 if( !rPropertyMap
.empty() )
103 Sequence
< OUString
> aPropNames
;
104 Sequence
< Any
> aValues
;
105 rPropertyMap
.fillSequences( aPropNames
, aValues
);
106 setProperties( aPropNames
, aValues
);
110 // private --------------------------------------------------------------------
112 bool PropertySet::implGetPropertyValue( Any
& orValue
, const OUString
& rPropName
) const
114 if( mxPropSet
.is() ) try
116 orValue
= mxPropSet
->getPropertyValue( rPropName
);
121 SAL_WARN( "oox", "PropertySet::implGetPropertyValue - cannot get property \"" <<
122 rPropName
<< "\" Error: " << e
);
127 bool PropertySet::implSetPropertyValue( const OUString
& rPropName
, const Any
& rValue
)
129 if( mxPropSet
.is() ) try
131 mxPropSet
->setPropertyValue( rPropName
, rValue
);
136 SAL_WARN( "oox", "PropertySet::implSetPropertyValue - cannot set property \"" <<
137 rPropName
<< "\" Error: " << e
);
143 void PropertySet::dump()
145 PropertyMap::dump( mxPropSet
);
151 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */