Coverage Report

Created: 2026-04-09 11:41

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/editeng/source/items/xmlcnitm.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 <memory>
21
22
#include <com/sun/star/xml/AttributeData.hpp>
23
#include <o3tl/any.hxx>
24
#include <xmloff/xmlcnimp.hxx>
25
#include <xmloff/unoatrcn.hxx>
26
#include <editeng/xmlcnitm.hxx>
27
28
using namespace ::com::sun::star::uno;
29
using namespace ::com::sun::star::container;
30
using namespace ::com::sun::star::xml;
31
32
33
SvXMLAttrContainerItem::SvXMLAttrContainerItem( sal_uInt16 _nWhich ) :
34
4.87k
    SfxPoolItem( _nWhich )
35
4.87k
{
36
4.87k
}
37
38
SvXMLAttrContainerItem::SvXMLAttrContainerItem(
39
                                        const SvXMLAttrContainerItem& rItem ) :
40
30.4k
    SfxPoolItem( rItem ),
41
30.4k
    maContainerData( rItem.maContainerData )
42
30.4k
{
43
30.4k
}
44
45
SvXMLAttrContainerItem::~SvXMLAttrContainerItem()
46
35.3k
{
47
35.3k
}
48
49
bool SvXMLAttrContainerItem::operator==( const SfxPoolItem& rItem ) const
50
305k
{
51
305k
    return SfxPoolItem::operator==(rItem) &&
52
305k
        maContainerData == static_cast<const SvXMLAttrContainerItem&>(rItem).maContainerData;
53
305k
}
54
55
bool SvXMLAttrContainerItem::GetPresentation(
56
                    SfxItemPresentation /*ePresentation*/,
57
                    MapUnit /*eCoreMetric*/,
58
                    MapUnit /*ePresentationMetric*/,
59
                    OUString & /*rText*/,
60
                    const IntlWrapper& /*rIntlWrapper*/ ) const
61
0
{
62
0
    return false;
63
0
}
64
65
bool SvXMLAttrContainerItem::QueryValue( css::uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const
66
89
{
67
89
    Reference<XNameContainer> xContainer
68
89
        = new SvUnoAttributeContainer(std::make_unique<SvXMLAttrContainerData>(maContainerData));
69
70
89
    rVal <<= xContainer;
71
89
    return true;
72
89
}
73
74
bool SvXMLAttrContainerItem::PutValue( const css::uno::Any& rVal, sal_uInt8 /*nMemberId*/ )
75
24.0k
{
76
24.0k
    Reference<XInterface> xTunnel(rVal, UNO_QUERY);
77
24.0k
    if (auto pContainer = dynamic_cast<SvUnoAttributeContainer*>(xTunnel.get()))
78
24.0k
    {
79
24.0k
        maContainerData = *pContainer->GetContainerImpl();
80
24.0k
    }
81
0
    else
82
0
    {
83
0
        SvXMLAttrContainerData aNewImpl;
84
85
0
        try
86
0
        {
87
0
            Reference<XNameContainer> xContainer( rVal, UNO_QUERY );
88
0
            if( !xContainer.is() )
89
0
                return false;
90
91
0
            for (const OUString& aName : xContainer->getElementNames())
92
0
            {
93
0
                Any aAny = xContainer->getByName(aName);
94
0
                auto pData = o3tl::tryAccess<AttributeData>(aAny);
95
0
                if( !pData )
96
0
                    return false;
97
98
0
                sal_Int32 pos = aName.indexOf( ':' );
99
0
                if( pos != -1 )
100
0
                {
101
0
                    const OUString aPrefix( aName.copy( 0, pos ));
102
0
                    const OUString aLName( aName.copy( pos+1 ));
103
104
0
                    if( pData->Namespace.isEmpty() )
105
0
                    {
106
0
                        if( !aNewImpl.AddAttr( aPrefix, aLName, pData->Value ) )
107
0
                            return false;
108
0
                    }
109
0
                    else
110
0
                    {
111
0
                        if( !aNewImpl.AddAttr( aPrefix, pData->Namespace, aLName, pData->Value ) )
112
0
                            return false;
113
0
                    }
114
0
                }
115
0
                else
116
0
                {
117
0
                    if( !aNewImpl.AddAttr( aName, pData->Value ) )
118
0
                        return false;
119
0
                }
120
0
            }
121
122
0
            maContainerData = std::move(aNewImpl);
123
0
        }
124
0
        catch(...)
125
0
        {
126
0
            return false;
127
0
        }
128
0
    }
129
24.0k
    return true;
130
24.0k
}
131
132
133
bool SvXMLAttrContainerItem::AddAttr( const OUString& rLName,
134
                                        const OUString& rValue )
135
1.13k
{
136
1.13k
    return maContainerData.AddAttr( rLName, rValue );
137
1.13k
}
138
139
bool SvXMLAttrContainerItem::AddAttr( const OUString& rPrefix,
140
          const OUString& rNamespace, const OUString& rLName,
141
          const OUString& rValue )
142
6.00k
{
143
6.00k
    return maContainerData.AddAttr( rPrefix, rNamespace, rLName, rValue );
144
6.00k
}
145
146
sal_uInt16 SvXMLAttrContainerItem::GetAttrCount() const
147
0
{
148
0
    return static_cast<sal_uInt16>(maContainerData.GetAttrCount());
149
0
}
150
151
OUString SvXMLAttrContainerItem::GetAttrNamespace( sal_uInt16 i ) const
152
0
{
153
0
    return maContainerData.GetAttrNamespace( i );
154
0
}
155
156
OUString SvXMLAttrContainerItem::GetAttrPrefix( sal_uInt16 i ) const
157
0
{
158
0
    return maContainerData.GetAttrPrefix( i );
159
0
}
160
161
const OUString& SvXMLAttrContainerItem::GetAttrLName( sal_uInt16 i ) const
162
0
{
163
0
    return maContainerData.GetAttrLName( i );
164
0
}
165
166
const OUString& SvXMLAttrContainerItem::GetAttrValue( sal_uInt16 i ) const
167
0
{
168
0
    return maContainerData.GetAttrValue( i );
169
0
}
170
171
172
sal_uInt16 SvXMLAttrContainerItem::GetFirstNamespaceIndex() const
173
0
{
174
0
    return maContainerData.GetFirstNamespaceIndex();
175
0
}
176
177
sal_uInt16 SvXMLAttrContainerItem::GetNextNamespaceIndex( sal_uInt16 nIdx ) const
178
0
{
179
0
    return maContainerData.GetNextNamespaceIndex( nIdx );
180
0
}
181
182
const OUString& SvXMLAttrContainerItem::GetNamespace( sal_uInt16 i ) const
183
0
{
184
0
    return maContainerData.GetNamespace( i );
185
0
}
186
187
const OUString& SvXMLAttrContainerItem::GetPrefix( sal_uInt16 i ) const
188
0
{
189
0
    return maContainerData.GetPrefix( i );
190
0
}
191
192
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */