bump product version to 5.0.4.1
[LibreOffice.git] / xmloff / source / transform / ChartPlotAreaOASISTContext.cxx
blob25b26f9c0cc730eecb04149d0c2f53e944b019e8
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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
37 public:
38 TYPEINFO_OVERRIDE();
40 XMLAxisOASISContext( XMLTransformerBase& rTransformer,
41 const OUString& rQName,
42 ::rtl::Reference< XMLPersAttrListTContext > & rOutCategoriesContext );
43 virtual ~XMLAxisOASISContext();
45 virtual XMLTransformerContext *CreateChildContext(
46 sal_uInt16 nPrefix,
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;}
56 private:
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(
76 sal_uInt16 nPrefix,
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();
91 else
93 pContext = XMLPersElemContentTContext::CreateChildContext(
94 nPrefix, rLocalName, rQName, xAttrList );
97 return pContext;
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 );
109 OUString aLocalName;
110 sal_uInt16 nPrefix =
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 ))
126 eToken = XML_DOMAIN;
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 ))
133 eToken = XML_VALUE;
135 else if( IsXMLToken( rAttrValue, XML_Z ))
137 eToken = XML_SERIES;
139 else
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 );
171 if( nIndex != -1 )
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(
181 GetExportQName(),
182 Reference< xml::sax::XAttributeList >( pMutableAttrList ));
183 ExportContent();
184 GetTransformer().GetDocHandler()->endElement( GetExportQName());
186 else
187 Export();
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(
204 sal_uInt16 nPrefix,
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 );
216 else
218 // export (and forget) categories if found in an axis-element
219 // otherwise export regularly
220 ExportCategories();
221 pContext = XMLProcAttrTransformerContext::CreateChildContext(
222 nPrefix, rLocalName, rQName, xAttrList );
225 return pContext;
228 void XMLChartPlotAreaOASISTContext::EndElement()
230 ExportCategories();
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: */