1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
30 using namespace ::com::sun::star
;
31 using namespace ::xmloff::token
;
33 using ::com::sun::star::uno::Reference
;
37 class XMLAxisOASISContext
: public XMLPersElemContentTContext
40 XMLAxisOASISContext( XMLTransformerBase
& rTransformer
,
41 const OUString
& rQName
,
42 ::rtl::Reference
< XMLPersAttrListTContext
> & rOutCategoriesContext
);
44 virtual rtl::Reference
<XMLTransformerContext
> CreateChildContext(
46 const OUString
& rLocalName
,
47 const OUString
& rQName
,
48 const Reference
< xml::sax::XAttributeList
>& xAttrList
) override
;
50 virtual void StartElement( const Reference
< xml::sax::XAttributeList
>& rAttrList
) override
;
51 virtual void EndElement() override
;
54 ::rtl::Reference
< XMLPersAttrListTContext
> & m_rCategoriesContext
;
55 bool m_bHasCategories
;
60 XMLAxisOASISContext::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 )
69 rtl::Reference
<XMLTransformerContext
> XMLAxisOASISContext::CreateChildContext(
71 const OUString
& rLocalName
,
72 const OUString
& rQName
,
73 const Reference
< xml::sax::XAttributeList
>& xAttrList
)
75 rtl::Reference
<XMLTransformerContext
> pContext
;
77 if( XML_NAMESPACE_CHART
== nPrefix
&&
78 IsXMLToken( rLocalName
, XML_CATEGORIES
) )
80 // store categories element at parent
81 m_rCategoriesContext
.set( new XMLPersAttrListTContext( GetTransformer(), rQName
));
82 m_bHasCategories
= true;
83 pContext
= m_rCategoriesContext
.get();
87 pContext
= XMLPersElemContentTContext::CreateChildContext(
88 nPrefix
, rLocalName
, rQName
, xAttrList
);
94 void XMLAxisOASISContext::StartElement(
95 const Reference
< xml::sax::XAttributeList
>& rAttrList
)
97 Reference
< xml::sax::XAttributeList
> xAttrList( rAttrList
);
98 rtl::Reference
<XMLMutableAttributeList
> pMutableAttrList
;
99 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
100 for( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
102 const OUString aAttrName
= xAttrList
->getNameByIndex( i
);
105 GetTransformer().GetNamespaceMap().GetKeyByAttrName( aAttrName
, &aLocalName
);
107 if( nPrefix
== XML_NAMESPACE_CHART
&&
108 IsXMLToken( aLocalName
, XML_DIMENSION
) )
110 if( !pMutableAttrList
)
112 pMutableAttrList
= new XMLMutableAttributeList( xAttrList
);
113 xAttrList
= pMutableAttrList
;
116 const OUString aAttrValue
= xAttrList
->getValueByIndex( i
);
117 XMLTokenEnum eToken
= XML_TOKEN_INVALID
;
118 if( IsXMLToken( aAttrValue
, XML_X
))
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.
125 else if( IsXMLToken( aAttrValue
, XML_Y
))
129 else if( IsXMLToken( aAttrValue
, XML_Z
))
135 OSL_FAIL( "ChartAxis: Invalid attribute value" );
138 if( eToken
!= XML_TOKEN_INVALID
)
140 OUString
aNewAttrQName(
141 GetTransformer().GetNamespaceMap().GetQNameByKey(
142 XML_NAMESPACE_CHART
, GetXMLToken( XML_CLASS
)));
143 pMutableAttrList
->RenameAttributeByIndex( i
, aNewAttrQName
);
145 pMutableAttrList
->SetValueByIndex( i
, GetXMLToken( eToken
));
150 XMLPersElemContentTContext::StartElement( xAttrList
);
153 void XMLAxisOASISContext::EndElement()
155 // if we have categories, change the "class" attribute
156 if( m_bHasCategories
&&
157 m_rCategoriesContext
.is() )
159 OSL_ENSURE( GetAttrList().is(), "Invalid attribute list" );
160 rtl::Reference
<XMLMutableAttributeList
> pMutableAttrList
=
161 new XMLMutableAttributeList( GetAttrList());
162 OUString
aAttrQName( GetTransformer().GetNamespaceMap().GetQNameByKey(
163 XML_NAMESPACE_CHART
, GetXMLToken( XML_CLASS
)));
164 sal_Int16 nIndex
= pMutableAttrList
->GetIndexByName( aAttrQName
);
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" );
174 GetTransformer().GetDocHandler()->startElement(
176 Reference
< xml::sax::XAttributeList
>( pMutableAttrList
));
178 GetTransformer().GetDocHandler()->endElement( GetExportQName());
185 XMLChartPlotAreaOASISTContext::XMLChartPlotAreaOASISTContext(
186 XMLTransformerBase
& rTransformer
, const OUString
& rQName
) :
187 XMLProcAttrTransformerContext( rTransformer
, rQName
, OASIS_SHAPE_ACTIONS
)
191 XMLChartPlotAreaOASISTContext::~XMLChartPlotAreaOASISTContext()
194 rtl::Reference
<XMLTransformerContext
> XMLChartPlotAreaOASISTContext::CreateChildContext(
196 const OUString
& rLocalName
,
197 const OUString
& rQName
,
198 const uno::Reference
< xml::sax::XAttributeList
>& xAttrList
)
200 rtl::Reference
<XMLTransformerContext
> pContext
;
202 if( XML_NAMESPACE_CHART
== nPrefix
&&
203 IsXMLToken( rLocalName
, XML_AXIS
) )
205 pContext
.set(new XMLAxisOASISContext( GetTransformer(), rQName
, m_rCategoriesContext
));
209 // export (and forget) categories if found in an axis-element
210 // otherwise export regularly
212 pContext
= XMLProcAttrTransformerContext::CreateChildContext(
213 nPrefix
, rLocalName
, rQName
, xAttrList
);
219 void XMLChartPlotAreaOASISTContext::EndElement()
222 XMLProcAttrTransformerContext::EndElement();
225 void XMLChartPlotAreaOASISTContext::ExportCategories()
227 if( m_rCategoriesContext
.is())
229 m_rCategoriesContext
->Export();
230 m_rCategoriesContext
.clear();
234 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */