Coverage Report

Created: 2026-11-06 11:29

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/xmloff/source/transform/ChartPlotAreaOOoTContext.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 "ChartPlotAreaOOoTContext.hxx"
21
#include "TransformerBase.hxx"
22
#include <xmloff/namespacemap.hxx>
23
#include <xmloff/xmlnamespace.hxx>
24
#include <xmloff/xmltoken.hxx>
25
#include "DeepTContext.hxx"
26
#include "ActionMapTypesOOo.hxx"
27
#include "MutableAttrList.hxx"
28
#include <osl/diagnose.h>
29
30
using namespace ::com::sun::star;
31
using namespace ::xmloff::token;
32
33
using ::com::sun::star::uno::Reference;
34
35
class XMLAxisOOoContext : public XMLPersElemContentTContext
36
{
37
public:
38
    XMLAxisOOoContext( XMLTransformerBase& rTransformer,
39
                       const OUString& rQName );
40
41
    virtual void StartElement( const Reference< xml::sax::XAttributeList >& rAttrList ) override;
42
43
0
    bool IsCategoryAxis() const { return m_bIsCategoryAxis;}
44
45
private:
46
    bool m_bIsCategoryAxis;
47
};
48
49
XMLAxisOOoContext::XMLAxisOOoContext(
50
    XMLTransformerBase& rTransformer,
51
    const OUString& rQName ) :
52
0
        XMLPersElemContentTContext( rTransformer, rQName ),
53
0
        m_bIsCategoryAxis( false )
54
0
{}
55
56
void XMLAxisOOoContext::StartElement(
57
    const Reference< xml::sax::XAttributeList >& rAttrList )
58
0
{
59
0
    Reference< xml::sax::XAttributeList > xAttrList( rAttrList );
60
0
    rtl::Reference<XMLMutableAttributeList> pMutableAttrList;
61
0
    sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
62
0
    for( sal_Int16 i=0; i < nAttrCount; i++ )
63
0
    {
64
0
        const OUString aAttrName = xAttrList->getNameByIndex( i );
65
0
        OUString aLocalName;
66
0
        sal_uInt16 nPrefix =
67
0
            GetTransformer().GetNamespaceMap().GetKeyByAttrName( aAttrName, &aLocalName );
68
69
0
        if( nPrefix == XML_NAMESPACE_CHART &&
70
0
            IsXMLToken( aLocalName, XML_CLASS ) )
71
0
        {
72
0
            if( !pMutableAttrList )
73
0
            {
74
0
                pMutableAttrList = new XMLMutableAttributeList( xAttrList );
75
0
                xAttrList = pMutableAttrList;
76
0
            }
77
78
0
            const OUString aAttrValue = xAttrList->getValueByIndex( i );
79
0
            XMLTokenEnum eToken = XML_TOKEN_INVALID;
80
0
            if( IsXMLToken( aAttrValue, XML_DOMAIN ) ||
81
0
                IsXMLToken( aAttrValue, XML_CATEGORY ))
82
0
            {
83
0
                eToken = XML_X;
84
0
                if( IsXMLToken( aAttrValue, XML_CATEGORY ) )
85
0
                    m_bIsCategoryAxis = true;
86
0
            }
87
0
            else if( IsXMLToken( aAttrValue, XML_VALUE ))
88
0
            {
89
0
                eToken = XML_Y;
90
0
            }
91
0
            else if( IsXMLToken( aAttrValue, XML_SERIES ))
92
0
            {
93
0
                eToken = XML_Z;
94
0
            }
95
0
            else
96
0
            {
97
0
                OSL_FAIL( "ChartAxis: Invalid attribute value" );
98
0
            }
99
100
0
            if( eToken != XML_TOKEN_INVALID )
101
0
            {
102
0
                OUString aNewAttrQName(
103
0
                    GetTransformer().GetNamespaceMap().GetQNameByKey(
104
0
                        XML_NAMESPACE_CHART, GetXMLToken( XML_DIMENSION )));
105
0
                pMutableAttrList->RenameAttributeByIndex( i, aNewAttrQName );
106
0
                pMutableAttrList->SetValueByIndex( i, GetXMLToken( eToken ));
107
0
            }
108
0
        }
109
0
    }
110
111
0
    XMLPersElemContentTContext::StartElement( xAttrList );
112
0
}
113
114
XMLChartPlotAreaOOoTContext::XMLChartPlotAreaOOoTContext(
115
    XMLTransformerBase & rTransformer, const OUString & rQName ) :
116
0
        XMLProcAttrTransformerContext( rTransformer, rQName, OOO_SHAPE_ACTIONS )
117
0
{
118
0
}
119
120
rtl::Reference<XMLTransformerContext> XMLChartPlotAreaOOoTContext::CreateChildContext(
121
    sal_uInt16 nPrefix,
122
    const OUString& rLocalName,
123
    const OUString& rQName,
124
    const uno::Reference< xml::sax::XAttributeList >& xAttrList )
125
0
{
126
0
    rtl::Reference<XMLTransformerContext> pContext;
127
128
0
    if( XML_NAMESPACE_CHART == nPrefix &&
129
0
        IsXMLToken( rLocalName, XML_AXIS ) )
130
0
    {
131
0
        rtl::Reference<XMLAxisOOoContext> pAxisContext( new XMLAxisOOoContext( GetTransformer(), rQName ));
132
0
        AddContent( pAxisContext );
133
0
        pContext = pAxisContext;
134
0
    }
135
0
    else if( XML_NAMESPACE_CHART == nPrefix &&
136
0
             IsXMLToken( rLocalName, XML_CATEGORIES ) )
137
0
    {
138
0
        pContext.set(new XMLPersAttrListTContext( GetTransformer(), rQName ));
139
140
        // put categories at correct axis
141
0
        bool bFound =false;
142
143
        // iterate over axis elements
144
0
        for( const auto& rChildContext : m_aChildContexts )
145
0
        {
146
0
            XMLAxisOOoContext * pAxisContext = rChildContext.get();
147
0
            if( pAxisContext != nullptr )
148
0
            {
149
                // iterate over attributes to find category axis
150
0
                Reference< xml::sax::XAttributeList > xNewAttrList( pAxisContext->GetAttrList());
151
0
                sal_Int16 nAttrCount = xNewAttrList.is() ? xNewAttrList->getLength() : 0;
152
153
0
                for( sal_Int16 i=0; i < nAttrCount; i++ )
154
0
                {
155
0
                    const OUString aAttrName = xNewAttrList->getNameByIndex( i );
156
0
                    OUString aLocalName;
157
0
                    sal_uInt16 nNewPrefix =
158
0
                        GetTransformer().GetNamespaceMap().GetKeyByAttrName( aAttrName,
159
0
                                                                             &aLocalName );
160
0
                    if( nNewPrefix == XML_NAMESPACE_CHART &&
161
0
                        pAxisContext->IsCategoryAxis() &&
162
0
                        IsXMLToken( aLocalName, XML_DIMENSION ) )
163
0
                    {
164
                        // category axis found
165
0
                        pAxisContext->AddContent( pContext );
166
0
                        bFound = true;
167
0
                        break;
168
0
                    }
169
0
                }
170
0
            }
171
172
0
            if (bFound)
173
0
                break;
174
0
        }
175
0
        OSL_ENSURE( bFound, "No suitable axis for categories found." );
176
0
    }
177
0
    else
178
0
    {
179
0
        ExportContent();
180
0
        pContext =  XMLProcAttrTransformerContext::CreateChildContext(
181
0
            nPrefix, rLocalName, rQName, xAttrList );
182
0
    }
183
184
0
    return pContext;
185
0
}
186
187
void XMLChartPlotAreaOOoTContext::EndElement()
188
0
{
189
0
    ExportContent();
190
0
    XMLProcAttrTransformerContext::EndElement();
191
0
}
192
193
void XMLChartPlotAreaOOoTContext::AddContent(rtl::Reference<XMLAxisOOoContext> const & pContext)
194
0
{
195
0
    OSL_ENSURE( pContext.is() && pContext->IsPersistent(),
196
0
                "non-persistent context" );
197
0
    m_aChildContexts.push_back(pContext);
198
0
}
199
200
201
void XMLChartPlotAreaOOoTContext::ExportContent()
202
0
{
203
0
    for( auto& rChildContext : m_aChildContexts )
204
0
    {
205
0
        rChildContext->Export();
206
0
    }
207
208
0
    m_aChildContexts.clear();
209
0
}
210
211
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */