LibreOffice Module oox (master) 1
propertyset.cxx
Go to the documentation of this file.
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
21
22#include <com/sun/star/beans/XMultiPropertySet.hpp>
23#include <com/sun/star/beans/XPropertySet.hpp>
24#include <osl/diagnose.h>
25#include <sal/log.hxx>
28
29namespace oox {
30
31using namespace ::com::sun::star::beans;
32using namespace ::com::sun::star::uno;
33
34void PropertySet::set( const Reference< XPropertySet >& rxPropSet )
35{
36 mxPropSet = rxPropSet;
37 mxMultiPropSet.set( mxPropSet, UNO_QUERY );
38 if( mxPropSet.is() ) try
39 {
40 mxPropSetInfo = mxPropSet->getPropertySetInfo();
41 }
42 catch( Exception& )
43 {
44 }
45}
46
47bool PropertySet::hasProperty( sal_Int32 nPropId ) const
48{
49 if( mxPropSetInfo.is() ) try
50 {
51 const OUString& rPropName = PropertyMap::getPropertyName( nPropId );
52 return mxPropSetInfo->hasPropertyByName( rPropName );
53 }
54 catch( Exception& )
55 {
56 }
57 return false;
58}
59
60// Get properties -------------------------------------------------------------
61
62Any PropertySet::getAnyProperty( sal_Int32 nPropId ) const
63{
64 Any aValue;
65 return implGetPropertyValue( aValue, PropertyMap::getPropertyName( nPropId ) ) ? aValue : Any();
66}
67
68// Set properties -------------------------------------------------------------
69
70bool PropertySet::setAnyProperty( sal_Int32 nPropId, const Any& rValue )
71{
72 return implSetPropertyValue( PropertyMap::getPropertyName( nPropId ), rValue );
73}
74
75void PropertySet::setProperties( const Sequence< OUString >& rPropNames, const Sequence< Any >& rValues )
76{
77 OSL_ENSURE( rPropNames.getLength() == rValues.getLength(),
78 "PropertySet::setProperties - length of sequences different" );
79
80 if( mxMultiPropSet.is() ) try
81 {
82 mxMultiPropSet->setPropertyValues( rPropNames, rValues );
83 return;
84 }
85 catch( Exception& )
86 {
87 SAL_WARN( "oox", "PropertySet::setProperties - cannot set all property values, fallback to single mode" );
88 }
89
90 if( mxPropSet.is() )
91 {
92 const Any* pValue = rValues.getConstArray();
93 for( const OUString& rPropName : rPropNames )
94 implSetPropertyValue( rPropName, *pValue++ );
95 }
96}
97
98void PropertySet::setProperties( const PropertyMap& rPropertyMap )
99{
100 if( !rPropertyMap.empty() )
101 {
102 Sequence< OUString > aPropNames;
103 Sequence< Any > aValues;
104 rPropertyMap.fillSequences( aPropNames, aValues );
105 setProperties( aPropNames, aValues );
106 }
107}
108
109// private --------------------------------------------------------------------
110
111bool PropertySet::implGetPropertyValue( Any& orValue, const OUString& rPropName ) const
112{
113 if( mxPropSet.is() ) try
114 {
115 orValue = mxPropSet->getPropertyValue( rPropName );
116 return true;
117 }
118 catch( const Exception&)
119 {
120 TOOLS_WARN_EXCEPTION( "oox", "PropertySet::implGetPropertyValue - cannot get property \"" <<
121 rPropName << "\"");
122 }
123 return false;
124}
125
126bool PropertySet::implSetPropertyValue( const OUString& rPropName, const Any& rValue )
127{
128 if( mxPropSet.is() ) try
129 {
130 mxPropSet->setPropertyValue( rPropName, rValue );
131 return true;
132 }
133 catch( const Exception&)
134 {
135 TOOLS_WARN_EXCEPTION( "oox", "PropertySet::implSetPropertyValue - cannot set property \"" <<
136 rPropName << "\"");
137 }
138 return false;
139}
140
141#ifdef DBG_UTIL
143{
145}
146#endif
147
148} // namespace oox
149
150/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
A helper that maps property identifiers to property values.
Definition: propertymap.hxx:52
void fillSequences(css::uno::Sequence< OUString > &rNames, css::uno::Sequence< css::uno::Any > &rValues) const
Fills the passed sequences of names and anys with all contained properties.
bool empty() const
static const OUString & getPropertyName(sal_Int32 nPropId)
Returns the name of the passed property identifier.
static void dump(const css::uno::Reference< css::beans::XPropertySet > &rXPropSet)
css::uno::Reference< css::beans::XPropertySet > mxPropSet
The mandatory property set interface.
void set(const css::uno::Reference< css::beans::XPropertySet > &rxPropSet)
Sets the passed UNO property set and releases the old UNO property set.
bool implSetPropertyValue(const OUString &rPropName, const css::uno::Any &rValue)
Puts the passed any into the property set.
css::uno::Any getAnyProperty(sal_Int32 nPropId) const
Gets the specified property from the property set.
Definition: propertyset.cxx:62
css::uno::Reference< css::beans::XPropertySetInfo > mxPropSetInfo
Property information.
void setProperties(const css::uno::Sequence< OUString > &rPropNames, const css::uno::Sequence< css::uno::Any > &rValues)
Puts the passed properties into the property set.
bool setAnyProperty(sal_Int32 nPropId, const css::uno::Any &rValue)
Puts the passed any into the property set.
Definition: propertyset.cxx:70
bool implGetPropertyValue(css::uno::Any &orValue, const OUString &rPropName) const
Gets the specified property from the property set.
bool hasProperty(sal_Int32 nPropId) const
Returns true, if the specified property is supported by the property set.
Definition: propertyset.cxx:47
css::uno::Reference< css::beans::XMultiPropertySet > mxMultiPropSet
The optional multi property set interface.
#define TOOLS_WARN_EXCEPTION(area, stream)
#define SAL_WARN(area, stream)
@ Exception
const PropertyStruct aPropNames[]