Coverage Report

Created: 2026-05-16 09:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/oox/source/helper/propertyset.cxx
Line
Count
Source
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
917k
{
36
917k
    mxPropSet = rxPropSet;
37
917k
    mxMultiPropSet.set( mxPropSet, UNO_QUERY );
38
917k
    if( mxPropSet.is() ) try
39
917k
    {
40
917k
        mxPropSetInfo = mxPropSet->getPropertySetInfo();
41
917k
    }
42
917k
    catch( Exception& )
43
917k
    {
44
0
    }
45
917k
}
46
47
bool PropertySet::hasProperty( sal_Int32 nPropId ) const
48
613k
{
49
613k
    if( mxPropSetInfo.is() ) try
50
613k
    {
51
613k
        const OUString& rPropName = PropertyMap::getPropertyName( nPropId );
52
613k
        return mxPropSetInfo->hasPropertyByName( rPropName );
53
613k
    }
54
613k
    catch( Exception& )
55
613k
    {
56
0
    }
57
0
    return false;
58
613k
}
59
60
// Get properties -------------------------------------------------------------
61
62
Any PropertySet::getAnyProperty( sal_Int32 nPropId ) const
63
168k
{
64
168k
    Any aValue;
65
168k
    return implGetPropertyValue( aValue, PropertyMap::getPropertyName( nPropId ) ) ? aValue : Any();
66
168k
}
67
68
// Set properties -------------------------------------------------------------
69
70
bool PropertySet::setAnyProperty( sal_Int32 nPropId, const Any& rValue )
71
1.47M
{
72
1.47M
    return implSetPropertyValue( PropertyMap::getPropertyName( nPropId ), rValue );
73
1.47M
}
74
75
void PropertySet::setProperties( const Sequence< OUString >& rPropNames, const Sequence< Any >& rValues )
76
712k
{
77
712k
    OSL_ENSURE( rPropNames.getLength() == rValues.getLength(),
78
712k
        "PropertySet::setProperties - length of sequences different" );
79
80
712k
    if( mxMultiPropSet.is() ) try
81
712k
    {
82
712k
        mxMultiPropSet->setPropertyValues( rPropNames, rValues );
83
712k
        return;
84
712k
    }
85
712k
    catch( Exception& )
86
712k
    {
87
0
        SAL_WARN( "oox", "PropertySet::setProperties - cannot set all property values, fallback to single mode" );
88
0
    }
89
90
847
    if( mxPropSet.is() )
91
847
    {
92
847
        const Any* pValue = rValues.getConstArray();
93
847
        for( const OUString& rPropName : rPropNames )
94
4.25k
            implSetPropertyValue( rPropName, *pValue++ );
95
847
    }
96
847
}
97
98
void PropertySet::setProperties( const PropertyMap& rPropertyMap )
99
952k
{
100
952k
    if( !rPropertyMap.empty() )
101
712k
    {
102
712k
        Sequence< OUString > aPropNames;
103
712k
        Sequence< Any > aValues;
104
712k
        rPropertyMap.fillSequences( aPropNames, aValues );
105
712k
        setProperties( aPropNames, aValues );
106
712k
    }
107
952k
}
108
109
// private --------------------------------------------------------------------
110
111
bool PropertySet::implGetPropertyValue( Any& orValue, const OUString& rPropName ) const
112
168k
{
113
168k
    if( mxPropSet.is() ) try
114
168k
    {
115
168k
        orValue = mxPropSet->getPropertyValue( rPropName );
116
168k
        return true;
117
168k
    }
118
168k
    catch( const Exception&)
119
168k
    {
120
0
        TOOLS_WARN_EXCEPTION( "oox", "PropertySet::implGetPropertyValue - cannot get property \"" <<
121
0
                  rPropName << "\"");
122
0
    }
123
10
    return false;
124
168k
}
125
126
bool PropertySet::implSetPropertyValue( const OUString& rPropName, const Any& rValue )
127
1.48M
{
128
1.48M
    if( mxPropSet.is() ) try
129
1.48M
    {
130
1.48M
        mxPropSet->setPropertyValue( rPropName, rValue );
131
1.48M
        return true;
132
1.48M
    }
133
1.48M
    catch( const Exception&)
134
1.48M
    {
135
2.87k
        TOOLS_WARN_EXCEPTION( "oox", "PropertySet::implSetPropertyValue - cannot set property \"" <<
136
2.87k
                  rPropName << "\"");
137
2.87k
    }
138
2.87k
    return false;
139
1.48M
}
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: */