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"
28 #include <osl/diagnose.h>
30 using namespace ::com::sun::star
;
31 using namespace ::xmloff::token
;
33 using ::com::sun::star::uno::Reference
;
35 class XMLAxisOASISContext
: public XMLPersElemContentTContext
40 XMLAxisOASISContext( XMLTransformerBase
& rTransformer
,
41 const OUString
& rQName
,
42 ::rtl::Reference
< XMLPersAttrListTContext
> & rOutCategoriesContext
);
43 virtual ~XMLAxisOASISContext();
45 virtual XMLTransformerContext
*CreateChildContext(
47 const OUString
& rLocalName
,
48 const OUString
& rQName
,
49 const Reference
< xml::sax::XAttributeList
>& xAttrList
) SAL_OVERRIDE
;
51 virtual void StartElement( const Reference
< xml::sax::XAttributeList
>& rAttrList
) SAL_OVERRIDE
;
52 virtual void EndElement() SAL_OVERRIDE
;
54 bool IsCategoryAxis() const { return m_bHasCategories
;}
57 ::rtl::Reference
< XMLPersAttrListTContext
> & m_rCategoriesContext
;
58 bool m_bHasCategories
;
61 TYPEINIT1( XMLAxisOASISContext
, XMLPersElemContentTContext
);
63 XMLAxisOASISContext::XMLAxisOASISContext(
64 XMLTransformerBase
& rTransformer
,
65 const 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 OUString
& rLocalName
,
78 const 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());
192 TYPEINIT1( XMLChartPlotAreaOASISTContext
, XMLProcAttrTransformerContext
);
194 XMLChartPlotAreaOASISTContext::XMLChartPlotAreaOASISTContext(
195 XMLTransformerBase
& rTransformer
, const OUString
& rQName
) :
196 XMLProcAttrTransformerContext( rTransformer
, rQName
, OASIS_SHAPE_ACTIONS
)
200 XMLChartPlotAreaOASISTContext::~XMLChartPlotAreaOASISTContext()
203 XMLTransformerContext
* XMLChartPlotAreaOASISTContext::CreateChildContext(
205 const OUString
& rLocalName
,
206 const OUString
& rQName
,
207 const uno::Reference
< xml::sax::XAttributeList
>& xAttrList
)
209 XMLTransformerContext
*pContext
= 0;
211 if( XML_NAMESPACE_CHART
== nPrefix
&&
212 IsXMLToken( rLocalName
, XML_AXIS
) )
214 pContext
= new XMLAxisOASISContext( GetTransformer(), rQName
, m_rCategoriesContext
);
218 // export (and forget) categories if found in an axis-element
219 // otherwise export regularly
221 pContext
= XMLProcAttrTransformerContext::CreateChildContext(
222 nPrefix
, rLocalName
, rQName
, xAttrList
);
228 void XMLChartPlotAreaOASISTContext::EndElement()
231 XMLProcAttrTransformerContext::EndElement();
234 void XMLChartPlotAreaOASISTContext::ExportCategories()
236 if( m_rCategoriesContext
.is())
238 m_rCategoriesContext
->Export();
239 m_rCategoriesContext
.clear();
243 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */