Coverage Report

Created: 2025-07-07 10:01

/src/libreoffice/oox/source/helper/propertyset.cxx
Line
Count
Source (jump to first uncovered line)
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 <com/sun/star/beans/XMultiPropertySet.hpp>
23
#include <com/sun/star/beans/XPropertySet.hpp>
24
#include <osl/diagnose.h>
25
#include <sal/log.hxx>
26
#include <comphelper/diagnose_ex.hxx>
27
#include <oox/helper/propertymap.hxx>
28
29
namespace oox {
30
31
using namespace ::com::sun::star::beans;
32
using namespace ::com::sun::star::uno;
33
34
void PropertySet::set( const Reference< XPropertySet >& rxPropSet )
35
1.00M
{
36
1.00M
    mxPropSet = rxPropSet;
37
1.00M
    mxMultiPropSet.set( mxPropSet, UNO_QUERY );
38
1.00M
    if( mxPropSet.is() ) try
39
1.00M
    {
40
1.00M
        mxPropSetInfo = mxPropSet->getPropertySetInfo();
41
1.00M
    }
42
1.00M
    catch( Exception& )
43
1.00M
    {
44
0
    }
45
1.00M
}
46
47
bool PropertySet::hasProperty( sal_Int32 nPropId ) const
48
527k
{
49
527k
    if( mxPropSetInfo.is() ) try
50
527k
    {
51
527k
        const OUString& rPropName = PropertyMap::getPropertyName( nPropId );
52
527k
        return mxPropSetInfo->hasPropertyByName( rPropName );
53
527k
    }
54
527k
    catch( Exception& )
55
527k
    {
56
0
    }
57
0
    return false;
58
527k
}
59
60
// Get properties -------------------------------------------------------------
61
62
Any PropertySet::getAnyProperty( sal_Int32 nPropId ) const
63
115k
{
64
115k
    Any aValue;
65
115k
    return implGetPropertyValue( aValue, PropertyMap::getPropertyName( nPropId ) ) ? aValue : Any();
66
115k
}
67
68
// Set properties -------------------------------------------------------------
69
70
bool PropertySet::setAnyProperty( sal_Int32 nPropId, const Any& rValue )
71
998k
{
72
998k
    return implSetPropertyValue( PropertyMap::getPropertyName( nPropId ), rValue );
73
998k
}
74
75
void PropertySet::setProperties( const Sequence< OUString >& rPropNames, const Sequence< Any >& rValues )
76
775k
{
77
775k
    OSL_ENSURE( rPropNames.getLength() == rValues.getLength(),
78
775k
        "PropertySet::setProperties - length of sequences different" );
79
80
775k
    if( mxMultiPropSet.is() ) try
81
774k
    {
82
774k
        mxMultiPropSet->setPropertyValues( rPropNames, rValues );
83
774k
        return;
84
774k
    }
85
774k
    catch( Exception& )
86
774k
    {
87
0
        SAL_WARN( "oox", "PropertySet::setProperties - cannot set all property values, fallback to single mode" );
88
0
    }
89
90
1.06k
    if( mxPropSet.is() )
91
1.06k
    {
92
1.06k
        const Any* pValue = rValues.getConstArray();
93
1.06k
        for( const OUString& rPropName : rPropNames )
94
5.74k
            implSetPropertyValue( rPropName, *pValue++ );
95
1.06k
    }
96
1.06k
}
97
98
void PropertySet::setProperties( const PropertyMap& rPropertyMap )
99
1.04M
{
100
1.04M
    if( !rPropertyMap.empty() )
101
775k
    {
102
775k
        Sequence< OUString > aPropNames;
103
775k
        Sequence< Any > aValues;
104
775k
        rPropertyMap.fillSequences( aPropNames, aValues );
105
775k
        setProperties( aPropNames, aValues );
106
775k
    }
107
1.04M
}
108
109
// private --------------------------------------------------------------------
110
111
bool PropertySet::implGetPropertyValue( Any& orValue, const OUString& rPropName ) const
112
115k
{
113
115k
    if( mxPropSet.is() ) try
114
115k
    {
115
115k
        orValue = mxPropSet->getPropertyValue( rPropName );
116
115k
        return true;
117
115k
    }
118
115k
    catch( const Exception&)
119
115k
    {
120
0
        TOOLS_WARN_EXCEPTION( "oox", "PropertySet::implGetPropertyValue - cannot get property \"" <<
121
0
                  rPropName << "\"");
122
0
    }
123
9
    return false;
124
115k
}
125
126
bool PropertySet::implSetPropertyValue( const OUString& rPropName, const Any& rValue )
127
1.00M
{
128
1.00M
    if( mxPropSet.is() ) try
129
1.00M
    {
130
1.00M
        mxPropSet->setPropertyValue( rPropName, rValue );
131
1.00M
        return true;
132
1.00M
    }
133
1.00M
    catch( const Exception&)
134
1.00M
    {
135
11.8k
        TOOLS_WARN_EXCEPTION( "oox", "PropertySet::implSetPropertyValue - cannot set property \"" <<
136
11.8k
                  rPropName << "\"");
137
11.8k
    }
138
11.8k
    return false;
139
1.00M
}
140
141
#ifdef DBG_UTIL
142
void PropertySet::dump()
143
{
144
    PropertyMap::dump( mxPropSet );
145
}
146
#endif
147
148
} // namespace oox
149
150
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */