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/nmspmap.hxx>
23 #include "xmloff/xmlnmspe.hxx"
24 #include <xmloff/xmltoken.hxx>
25 #include "DeepTContext.hxx"
26 #include "ActionMapTypesOASIS.hxx"
27 #include "MutableAttrList.hxx"
29 using namespace ::com::sun::star
;
30 using namespace ::xmloff::token
;
32 using ::com::sun::star::uno::Reference
;
33 using ::rtl::OUString
;
35 class XMLAxisOASISContext
: public XMLPersElemContentTContext
40 XMLAxisOASISContext( XMLTransformerBase
& rTransformer
,
41 const ::rtl::OUString
& rQName
,
42 ::rtl::Reference
< XMLPersAttrListTContext
> & rOutCategoriesContext
);
43 ~XMLAxisOASISContext();
45 virtual XMLTransformerContext
*CreateChildContext(
47 const ::rtl::OUString
& rLocalName
,
48 const ::rtl::OUString
& rQName
,
49 const Reference
< xml::sax::XAttributeList
>& xAttrList
);
51 virtual void StartElement( const Reference
< xml::sax::XAttributeList
>& rAttrList
);
52 virtual void EndElement();
54 bool IsCategoryAxis() const;
57 ::rtl::Reference
< XMLPersAttrListTContext
> & m_rCategoriesContext
;
58 bool m_bHasCategories
;
61 TYPEINIT1( XMLAxisOASISContext
, XMLPersElemContentTContext
);
63 XMLAxisOASISContext::XMLAxisOASISContext(
64 XMLTransformerBase
& rTransformer
,
65 const ::rtl::OUString
& rQName
,
66 ::rtl::Reference
< XMLPersAttrListTContext
> & rOutCategoriesContext
) :
67 XMLPersElemContentTContext( rTransformer
, rQName
),
68 m_rCategoriesContext( rOutCategoriesContext
),
69 m_bHasCategories( false )
72 XMLAxisOASISContext::~XMLAxisOASISContext()
75 XMLTransformerContext
* XMLAxisOASISContext::CreateChildContext(
77 const ::rtl::OUString
& rLocalName
,
78 const ::rtl::OUString
& rQName
,
79 const Reference
< xml::sax::XAttributeList
>& xAttrList
)
81 XMLTransformerContext
* pContext
= 0;
83 if( XML_NAMESPACE_CHART
== nPrefix
&&
84 IsXMLToken( rLocalName
, XML_CATEGORIES
) )
86 // store categories element at parent
87 m_rCategoriesContext
.set( new XMLPersAttrListTContext( GetTransformer(), rQName
));
88 m_bHasCategories
= true;
89 pContext
= m_rCategoriesContext
.get();
93 pContext
= XMLPersElemContentTContext::CreateChildContext(
94 nPrefix
, rLocalName
, rQName
, xAttrList
);
100 void XMLAxisOASISContext::StartElement(
101 const Reference
< xml::sax::XAttributeList
>& rAttrList
)
103 Reference
< xml::sax::XAttributeList
> xAttrList( rAttrList
);
104 XMLMutableAttributeList
*pMutableAttrList
= 0;
105 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
106 for( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
108 const OUString
& rAttrName
= xAttrList
->getNameByIndex( i
);
111 GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName
, &aLocalName
);
113 if( nPrefix
== XML_NAMESPACE_CHART
&&
114 IsXMLToken( aLocalName
, XML_DIMENSION
) )
116 if( !pMutableAttrList
)
118 pMutableAttrList
= new XMLMutableAttributeList( xAttrList
);
119 xAttrList
= pMutableAttrList
;
122 const OUString
& rAttrValue
= xAttrList
->getValueByIndex( i
);
123 XMLTokenEnum eToken
= XML_TOKEN_INVALID
;
124 if( IsXMLToken( rAttrValue
, XML_X
))
127 // has to be XML_CATEGORY for axes with a categories
128 // sub-element. The attribute is changed later (when it is
129 // known that there is a categories sub-element) in this case.
131 else if( IsXMLToken( rAttrValue
, XML_Y
))
135 else if( IsXMLToken( rAttrValue
, XML_Z
))
141 OSL_FAIL( "ChartAxis: Invalid attribute value" );
144 if( eToken
!= XML_TOKEN_INVALID
)
146 OUString
aNewAttrQName(
147 GetTransformer().GetNamespaceMap().GetQNameByKey(
148 XML_NAMESPACE_CHART
, GetXMLToken( XML_CLASS
)));
149 pMutableAttrList
->RenameAttributeByIndex( i
, aNewAttrQName
);
151 pMutableAttrList
->SetValueByIndex( i
, GetXMLToken( eToken
));
156 XMLPersElemContentTContext::StartElement( xAttrList
);
159 void XMLAxisOASISContext::EndElement()
161 // if we have categories, change the "class" attribute
162 if( IsCategoryAxis() &&
163 m_rCategoriesContext
.is() )
165 OSL_ENSURE( GetAttrList().is(), "Invalid attribute list" );
166 XMLMutableAttributeList
* pMutableAttrList
=
167 new XMLMutableAttributeList( GetAttrList());
168 OUString
aAttrQName( GetTransformer().GetNamespaceMap().GetQNameByKey(
169 XML_NAMESPACE_CHART
, GetXMLToken( XML_CLASS
)));
170 sal_Int16 nIndex
= pMutableAttrList
->GetIndexByName( aAttrQName
);
173 OSL_ENSURE( IsXMLToken( pMutableAttrList
->getValueByIndex( nIndex
),
174 XML_DOMAIN
), "Axis Dimension: invalid former value" );
175 pMutableAttrList
->SetValueByIndex( nIndex
, GetXMLToken( XML_CATEGORY
));
176 OSL_ENSURE( IsXMLToken( pMutableAttrList
->getValueByIndex( nIndex
),
177 XML_CATEGORY
), "Axis Dimension: invalid new value" );
180 GetTransformer().GetDocHandler()->startElement(
182 Reference
< xml::sax::XAttributeList
>( pMutableAttrList
));
184 GetTransformer().GetDocHandler()->endElement( GetExportQName());
190 bool XMLAxisOASISContext::IsCategoryAxis() const
192 return m_bHasCategories
;
196 TYPEINIT1( XMLChartPlotAreaOASISTContext
, XMLProcAttrTransformerContext
);
198 XMLChartPlotAreaOASISTContext::XMLChartPlotAreaOASISTContext(
199 XMLTransformerBase
& rTransformer
, const ::rtl::OUString
& rQName
) :
200 XMLProcAttrTransformerContext( rTransformer
, rQName
, OASIS_SHAPE_ACTIONS
)
204 XMLChartPlotAreaOASISTContext::~XMLChartPlotAreaOASISTContext()
207 XMLTransformerContext
* XMLChartPlotAreaOASISTContext::CreateChildContext(
209 const ::rtl::OUString
& rLocalName
,
210 const ::rtl::OUString
& rQName
,
211 const uno::Reference
< xml::sax::XAttributeList
>& xAttrList
)
213 XMLTransformerContext
*pContext
= 0;
215 if( XML_NAMESPACE_CHART
== nPrefix
&&
216 IsXMLToken( rLocalName
, XML_AXIS
) )
218 pContext
= new XMLAxisOASISContext( GetTransformer(), rQName
, m_rCategoriesContext
);
222 // export (and forget) categories if found in an axis-element
223 // otherwise export regularly
225 pContext
= XMLProcAttrTransformerContext::CreateChildContext(
226 nPrefix
, rLocalName
, rQName
, xAttrList
);
232 void XMLChartPlotAreaOASISTContext::EndElement()
235 XMLProcAttrTransformerContext::EndElement();
238 void XMLChartPlotAreaOASISTContext::ExportCategories()
240 if( m_rCategoriesContext
.is())
242 m_rCategoriesContext
->Export();
243 m_rCategoriesContext
.clear();
247 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */