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 44614 : void PropertySet::set( const Reference< XPropertySet >& rxPropSet )
32 : {
33 44614 : mxPropSet = rxPropSet;
34 44614 : mxMultiPropSet.set( mxPropSet, UNO_QUERY );
35 44614 : if( mxPropSet.is() ) try
36 : {
37 44557 : mxPropSetInfo = mxPropSet->getPropertySetInfo();
38 : }
39 0 : catch( Exception& )
40 : {
41 : }
42 44614 : }
43 :
44 5125 : bool PropertySet::hasProperty( sal_Int32 nPropId ) const
45 : {
46 5125 : if( mxPropSetInfo.is() ) try
47 : {
48 5123 : const OUString& rPropName = PropertyMap::getPropertyName( nPropId );
49 5123 : return mxPropSetInfo->hasPropertyByName( rPropName );
50 : }
51 0 : catch( Exception& )
52 : {
53 : }
54 2 : return false;
55 : }
56 :
57 : // Get properties -------------------------------------------------------------
58 :
59 9454 : Any PropertySet::getAnyProperty( sal_Int32 nPropId ) const
60 : {
61 9454 : Any aValue;
62 9454 : return implGetPropertyValue( aValue, PropertyMap::getPropertyName( nPropId ) ) ? aValue : Any();
63 : }
64 :
65 : // Set properties -------------------------------------------------------------
66 :
67 43603 : bool PropertySet::setAnyProperty( sal_Int32 nPropId, const Any& rValue )
68 : {
69 43603 : return implSetPropertyValue( PropertyMap::getPropertyName( nPropId ), rValue );
70 : }
71 :
72 12324 : 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 12324 : if( mxMultiPropSet.is() ) try
78 : {
79 9983 : mxMultiPropSet->setPropertyValues( rPropNames, rValues );
80 22304 : return;
81 : }
82 3 : catch( Exception& )
83 : {
84 : SAL_WARN( "oox", "PropertySet::setProperties - cannot set all property values, fallback to single mode" );
85 : }
86 :
87 2344 : if( mxPropSet.is() )
88 : {
89 2342 : const OUString* pPropName = rPropNames.getConstArray();
90 2342 : const OUString* pPropNameEnd = pPropName + rPropNames.getLength();
91 2342 : const Any* pValue = rValues.getConstArray();
92 32679 : for( ; pPropName != pPropNameEnd; ++pPropName, ++pValue )
93 30337 : implSetPropertyValue( *pPropName, *pValue );
94 : }
95 : }
96 :
97 13512 : void PropertySet::setProperties( const PropertyMap& rPropertyMap )
98 : {
99 13512 : if( !rPropertyMap.empty() )
100 : {
101 12324 : Sequence< OUString > aPropNames;
102 24648 : Sequence< Any > aValues;
103 12324 : rPropertyMap.fillSequences( aPropNames, aValues );
104 24648 : setProperties( aPropNames, aValues );
105 : }
106 13512 : }
107 :
108 : // private --------------------------------------------------------------------
109 :
110 9454 : bool PropertySet::implGetPropertyValue( Any& orValue, const OUString& rPropName ) const
111 : {
112 9454 : if( mxPropSet.is() ) try
113 : {
114 9454 : orValue = mxPropSet->getPropertyValue( rPropName );
115 9454 : 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 73940 : bool PropertySet::implSetPropertyValue( const OUString& rPropName, const Any& rValue )
126 : {
127 73940 : if( mxPropSet.is() ) try
128 : {
129 73877 : mxPropSet->setPropertyValue( rPropName, rValue );
130 72464 : return true;
131 : }
132 1413 : catch( Exception& e)
133 : {
134 : SAL_WARN( "oox", "PropertySet::implSetPropertyValue - cannot set property \"" <<
135 : rPropName << "\" Error: " << e.Message);
136 : }
137 1476 : 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: */
|