LibreOffice Module xmloff (master) 1
ChartPlotAreaOASISTContext.cxx
Go to the documentation of this file.
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
21#include "TransformerBase.hxx"
24#include <xmloff/xmltoken.hxx>
25#include "DeepTContext.hxx"
27#include "MutableAttrList.hxx"
28#include <osl/diagnose.h>
29
30using namespace ::com::sun::star;
31using namespace ::xmloff::token;
32
33using ::com::sun::star::uno::Reference;
34
35namespace {
36
37class XMLAxisOASISContext : public XMLPersElemContentTContext
38{
39public:
40 XMLAxisOASISContext( XMLTransformerBase& rTransformer,
41 const OUString& rQName,
42 ::rtl::Reference< XMLPersAttrListTContext > & rOutCategoriesContext );
43
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
53private:
55 bool m_bHasCategories;
56};
57
58}
59
60XMLAxisOASISContext::XMLAxisOASISContext(
61 XMLTransformerBase& rTransformer,
62 const OUString& rQName,
63 ::rtl::Reference< XMLPersAttrListTContext > & rOutCategoriesContext ) :
64 XMLPersElemContentTContext( rTransformer, rQName ),
65 m_rCategoriesContext( rOutCategoriesContext ),
66 m_bHasCategories( false )
67{}
68
69rtl::Reference<XMLTransformerContext> XMLAxisOASISContext::CreateChildContext(
70 sal_uInt16 nPrefix,
71 const OUString& rLocalName,
72 const OUString& rQName,
73 const Reference< xml::sax::XAttributeList >& xAttrList )
74{
76
77 if( XML_NAMESPACE_CHART == nPrefix &&
78 IsXMLToken( rLocalName, XML_CATEGORIES ) )
79 {
80 // store categories element at parent
81 m_rCategoriesContext.set( new XMLPersAttrListTContext( GetTransformer(), rQName ));
82 m_bHasCategories = true;
83 pContext = m_rCategoriesContext.get();
84 }
85 else
86 {
88 nPrefix, rLocalName, rQName, xAttrList );
89 }
90
91 return pContext;
92}
93
94void XMLAxisOASISContext::StartElement(
95 const Reference< xml::sax::XAttributeList >& rAttrList )
96{
97 Reference< xml::sax::XAttributeList > xAttrList( rAttrList );
99 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
100 for( sal_Int16 i=0; i < nAttrCount; i++ )
101 {
102 const OUString& rAttrName = xAttrList->getNameByIndex( i );
103 OUString aLocalName;
104 sal_uInt16 nPrefix =
105 GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName );
106
107 if( nPrefix == XML_NAMESPACE_CHART &&
108 IsXMLToken( aLocalName, XML_DIMENSION ) )
109 {
110 if( !pMutableAttrList )
111 {
112 pMutableAttrList = new XMLMutableAttributeList( xAttrList );
113 xAttrList = pMutableAttrList;
114 }
115
116 const OUString& rAttrValue = xAttrList->getValueByIndex( i );
118 if( IsXMLToken( rAttrValue, XML_X ))
119 {
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 }
125 else if( IsXMLToken( rAttrValue, XML_Y ))
126 {
128 }
129 else if( IsXMLToken( rAttrValue, XML_Z ))
130 {
132 }
133 else
134 {
135 OSL_FAIL( "ChartAxis: Invalid attribute value" );
136 }
137
139 {
140 OUString aNewAttrQName(
141 GetTransformer().GetNamespaceMap().GetQNameByKey(
143 pMutableAttrList->RenameAttributeByIndex( i, aNewAttrQName );
144
145 pMutableAttrList->SetValueByIndex( i, GetXMLToken( eToken ));
146 }
147 }
148 }
149
151}
152
153void XMLAxisOASISContext::EndElement()
154{
155 // if we have categories, change the "class" attribute
156 if( m_bHasCategories &&
157 m_rCategoriesContext.is() )
158 {
159 OSL_ENSURE( GetAttrList().is(), "Invalid attribute list" );
161 new XMLMutableAttributeList( GetAttrList());
162 OUString aAttrQName( GetTransformer().GetNamespaceMap().GetQNameByKey(
164 sal_Int16 nIndex = pMutableAttrList->GetIndexByName( aAttrQName );
165 if( nIndex != -1 )
166 {
167 OSL_ENSURE( IsXMLToken( pMutableAttrList->getValueByIndex( nIndex ),
168 XML_DOMAIN ), "Axis Dimension: invalid former value" );
169 pMutableAttrList->SetValueByIndex( nIndex, GetXMLToken( XML_CATEGORY ));
170 OSL_ENSURE( IsXMLToken( pMutableAttrList->getValueByIndex( nIndex ),
171 XML_CATEGORY ), "Axis Dimension: invalid new value" );
172 }
173
174 GetTransformer().GetDocHandler()->startElement(
175 GetExportQName(),
176 Reference< xml::sax::XAttributeList >( pMutableAttrList ));
177 ExportContent();
178 GetTransformer().GetDocHandler()->endElement( GetExportQName());
179 }
180 else
181 Export();
182}
183
184
186 XMLTransformerBase & rTransformer, const OUString & rQName ) :
188{
189}
190
192{}
193
195 sal_uInt16 nPrefix,
196 const OUString& rLocalName,
197 const OUString& rQName,
198 const uno::Reference< xml::sax::XAttributeList >& xAttrList )
199{
201
202 if( XML_NAMESPACE_CHART == nPrefix &&
203 IsXMLToken( rLocalName, XML_AXIS ) )
204 {
205 pContext.set(new XMLAxisOASISContext( GetTransformer(), rQName, m_rCategoriesContext ));
206 }
207 else
208 {
209 // export (and forget) categories if found in an axis-element
210 // otherwise export regularly
213 nPrefix, rLocalName, rQName, xAttrList );
214 }
215
216 return pContext;
217}
218
220{
223}
224
226{
227 if( m_rCategoriesContext.is())
228 {
229 m_rCategoriesContext->Export();
230 m_rCategoriesContext.clear();
231 }
232}
233
234/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
@ OASIS_SHAPE_ACTIONS
virtual rtl::Reference< XMLTransformerContext > CreateChildContext(sal_uInt16 nPrefix, const OUString &rLocalName, const OUString &rQName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList) override
XMLChartPlotAreaOASISTContext(XMLTransformerBase &rTransformer, const OUString &rQName)
::rtl::Reference< XMLPersAttrListTContext > m_rCategoriesContext
virtual void StartElement(const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList) override
virtual void EndElement() override
virtual rtl::Reference< XMLTransformerContext > CreateChildContext(sal_uInt16 nPrefix, const OUString &rLocalName, const OUString &rQName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList) override
virtual void EndElement() override
virtual rtl::Reference< XMLTransformerContext > CreateChildContext(sal_uInt16 nPrefix, const OUString &rLocalName, const OUString &rQName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList)
XMLTransformerBase & GetTransformer()
sal_Int32 nIndex
int i
Handling of tokens in XML:
XMLTokenEnum
The enumeration of all XML tokens.
Definition: xmltoken.hxx:50
bool IsXMLToken(std::u16string_view rString, enum XMLTokenEnum eToken)
compare eToken to the string
Definition: xmltoken.cxx:3575
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
return the OUString representation for eToken
Definition: xmltoken.cxx:3519
constexpr sal_uInt16 XML_NAMESPACE_CHART
XMLTokenEnum eToken
Definition: xmltoken.cxx:40