Coverage Report

Created: 2026-05-16 09:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/xmloff/source/transform/ChartPlotAreaOASISTContext.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 "ChartPlotAreaOASISTContext.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 "ActionMapTypesOASIS.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
namespace {
36
37
class XMLAxisOASISContext : public XMLPersElemContentTContext
38
{
39
public:
40
    XMLAxisOASISContext( XMLTransformerBase& rTransformer,
41
                         const OUString& rQName,
42
                         ::rtl::Reference< XMLPersAttrListTContext > & rOutCategoriesContext );
43
44
    virtual rtl::Reference<XMLTransformerContext> CreateChildContext(
45
        sal_uInt16 nPrefix,
46
        const OUString& rLocalName,
47
        const OUString& rQName,
48
        const Reference< xml::sax::XAttributeList >& xAttrList ) override;
49
50
    virtual void StartElement( const Reference< xml::sax::XAttributeList >& rAttrList ) override;
51
    virtual void EndElement() override;
52
53
private:
54
    ::rtl::Reference< XMLPersAttrListTContext > &   m_rCategoriesContext;
55
    bool                                            m_bHasCategories;
56
};
57
58
}
59
60
XMLAxisOASISContext::XMLAxisOASISContext(
61
    XMLTransformerBase& rTransformer,
62
    const OUString& rQName,
63
    ::rtl::Reference< XMLPersAttrListTContext > & rOutCategoriesContext ) :
64
0
        XMLPersElemContentTContext( rTransformer, rQName ),
65
0
        m_rCategoriesContext( rOutCategoriesContext ),
66
0
        m_bHasCategories( false )
67
0
{}
68
69
rtl::Reference<XMLTransformerContext> XMLAxisOASISContext::CreateChildContext(
70
    sal_uInt16 nPrefix,
71
    const OUString& rLocalName,
72
    const OUString& rQName,
73
    const Reference< xml::sax::XAttributeList >& xAttrList )
74
0
{
75
0
    rtl::Reference<XMLTransformerContext> pContext;
76
77
0
    if( XML_NAMESPACE_CHART == nPrefix &&
78
0
        IsXMLToken( rLocalName, XML_CATEGORIES ) )
79
0
    {
80
        // store categories element at parent
81
0
        m_rCategoriesContext.set( new XMLPersAttrListTContext( GetTransformer(), rQName ));
82
0
        m_bHasCategories = true;
83
0
        pContext = m_rCategoriesContext.get();
84
0
    }
85
0
    else
86
0
    {
87
0
        pContext =  XMLPersElemContentTContext::CreateChildContext(
88
0
            nPrefix, rLocalName, rQName, xAttrList );
89
0
    }
90
91
0
    return pContext;
92
0
}
93
94
void XMLAxisOASISContext::StartElement(
95
    const Reference< xml::sax::XAttributeList >& rAttrList )
96
0
{
97
0
    Reference< xml::sax::XAttributeList > xAttrList( rAttrList );
98
0
    rtl::Reference<XMLMutableAttributeList> pMutableAttrList;
99
0
    sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
100
0
    for( sal_Int16 i=0; i < nAttrCount; i++ )
101
0
    {
102
0
        const OUString aAttrName = xAttrList->getNameByIndex( i );
103
0
        OUString aLocalName;
104
0
        sal_uInt16 nPrefix =
105
0
            GetTransformer().GetNamespaceMap().GetKeyByAttrName( aAttrName, &aLocalName );
106
107
0
        if( nPrefix == XML_NAMESPACE_CHART &&
108
0
            IsXMLToken( aLocalName, XML_DIMENSION ) )
109
0
        {
110
0
            if( !pMutableAttrList )
111
0
            {
112
0
                pMutableAttrList = new XMLMutableAttributeList( xAttrList );
113
0
                xAttrList = pMutableAttrList;
114
0
            }
115
116
0
            const OUString aAttrValue = xAttrList->getValueByIndex( i );
117
0
            XMLTokenEnum eToken = XML_TOKEN_INVALID;
118
0
            if( IsXMLToken( aAttrValue, XML_X ))
119
0
            {
120
0
                eToken = XML_DOMAIN;
121
                // has to be XML_CATEGORY for axes with a categories
122
                // sub-element.  The attribute is changed later (when it is
123
                // known that there is a categories sub-element) in this case.
124
0
            }
125
0
            else if( IsXMLToken( aAttrValue, XML_Y ))
126
0
            {
127
0
                eToken = XML_VALUE;
128
0
            }
129
0
            else if( IsXMLToken( aAttrValue, XML_Z ))
130
0
            {
131
0
                eToken = XML_SERIES;
132
0
            }
133
0
            else
134
0
            {
135
0
                OSL_FAIL( "ChartAxis: Invalid attribute value" );
136
0
            }
137
138
0
            if( eToken != XML_TOKEN_INVALID )
139
0
            {
140
0
                OUString aNewAttrQName(
141
0
                    GetTransformer().GetNamespaceMap().GetQNameByKey(
142
0
                        XML_NAMESPACE_CHART, GetXMLToken( XML_CLASS )));
143
0
                pMutableAttrList->RenameAttributeByIndex( i, aNewAttrQName );
144
145
0
                pMutableAttrList->SetValueByIndex( i, GetXMLToken( eToken ));
146
0
            }
147
0
        }
148
0
    }
149
150
0
    XMLPersElemContentTContext::StartElement( xAttrList );
151
0
}
152
153
void XMLAxisOASISContext::EndElement()
154
0
{
155
    // if we have categories, change the "class" attribute
156
0
    if( m_bHasCategories &&
157
0
        m_rCategoriesContext.is() )
158
0
    {
159
0
        OSL_ENSURE( GetAttrList().is(), "Invalid attribute list" );
160
0
        rtl::Reference<XMLMutableAttributeList> pMutableAttrList =
161
0
            new XMLMutableAttributeList( GetAttrList());
162
0
        OUString aAttrQName( GetTransformer().GetNamespaceMap().GetQNameByKey(
163
0
                                 XML_NAMESPACE_CHART, GetXMLToken( XML_CLASS )));
164
0
        sal_Int16 nIndex = pMutableAttrList->GetIndexByName( aAttrQName );
165
0
        if( nIndex != -1 )
166
0
        {
167
0
            OSL_ENSURE( IsXMLToken( pMutableAttrList->getValueByIndex( nIndex ),
168
0
                                    XML_DOMAIN ), "Axis Dimension: invalid former value" );
169
0
            pMutableAttrList->SetValueByIndex( nIndex, GetXMLToken( XML_CATEGORY ));
170
0
            OSL_ENSURE( IsXMLToken( pMutableAttrList->getValueByIndex( nIndex ),
171
0
                                    XML_CATEGORY ), "Axis Dimension: invalid new value" );
172
0
        }
173
174
0
        GetTransformer().GetDocHandler()->startElement(
175
0
            GetExportQName(),
176
0
            Reference< xml::sax::XAttributeList >( pMutableAttrList ));
177
0
        ExportContent();
178
0
        GetTransformer().GetDocHandler()->endElement( GetExportQName());
179
0
    }
180
0
    else
181
0
        Export();
182
0
}
183
184
185
XMLChartPlotAreaOASISTContext::XMLChartPlotAreaOASISTContext(
186
    XMLTransformerBase & rTransformer, const OUString & rQName ) :
187
0
        XMLProcAttrTransformerContext( rTransformer, rQName, OASIS_SHAPE_ACTIONS )
188
0
{
189
0
}
190
191
XMLChartPlotAreaOASISTContext::~XMLChartPlotAreaOASISTContext()
192
0
{}
193
194
rtl::Reference<XMLTransformerContext> XMLChartPlotAreaOASISTContext::CreateChildContext(
195
    sal_uInt16 nPrefix,
196
    const OUString& rLocalName,
197
    const OUString& rQName,
198
    const uno::Reference< xml::sax::XAttributeList >& xAttrList )
199
0
{
200
0
    rtl::Reference<XMLTransformerContext> pContext;
201
202
0
    if( XML_NAMESPACE_CHART == nPrefix &&
203
0
        IsXMLToken( rLocalName, XML_AXIS ) )
204
0
    {
205
0
        pContext.set(new XMLAxisOASISContext( GetTransformer(), rQName, m_rCategoriesContext ));
206
0
    }
207
0
    else
208
0
    {
209
        // export (and forget) categories if found in an axis-element
210
        // otherwise export regularly
211
0
        ExportCategories();
212
0
        pContext =  XMLProcAttrTransformerContext::CreateChildContext(
213
0
                nPrefix, rLocalName, rQName, xAttrList );
214
0
    }
215
216
0
    return pContext;
217
0
}
218
219
void XMLChartPlotAreaOASISTContext::EndElement()
220
0
{
221
0
    ExportCategories();
222
0
    XMLProcAttrTransformerContext::EndElement();
223
0
}
224
225
void XMLChartPlotAreaOASISTContext::ExportCategories()
226
0
{
227
0
    if( m_rCategoriesContext.is())
228
0
    {
229
0
        m_rCategoriesContext->Export();
230
0
        m_rCategoriesContext.clear();
231
0
    }
232
0
}
233
234
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */