bump product version to 4.1.6.2
[LibreOffice.git] / xmloff / source / transform / ChartPlotAreaOASISTContext.cxx
blob18a56b465a725fa6a6246c412ef9b825dce5e3e2
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"
29 using namespace ::com::sun::star;
30 using namespace ::xmloff::token;
32 using ::com::sun::star::uno::Reference;
34 class XMLAxisOASISContext : public XMLPersElemContentTContext
36 public:
37 TYPEINFO();
39 XMLAxisOASISContext( XMLTransformerBase& rTransformer,
40 const OUString& rQName,
41 ::rtl::Reference< XMLPersAttrListTContext > & rOutCategoriesContext );
42 ~XMLAxisOASISContext();
44 virtual XMLTransformerContext *CreateChildContext(
45 sal_uInt16 nPrefix,
46 const OUString& rLocalName,
47 const OUString& rQName,
48 const Reference< xml::sax::XAttributeList >& xAttrList );
50 virtual void StartElement( const Reference< xml::sax::XAttributeList >& rAttrList );
51 virtual void EndElement();
53 bool IsCategoryAxis() const;
55 private:
56 ::rtl::Reference< XMLPersAttrListTContext > & m_rCategoriesContext;
57 bool m_bHasCategories;
60 TYPEINIT1( XMLAxisOASISContext, XMLPersElemContentTContext );
62 XMLAxisOASISContext::XMLAxisOASISContext(
63 XMLTransformerBase& rTransformer,
64 const OUString& rQName,
65 ::rtl::Reference< XMLPersAttrListTContext > & rOutCategoriesContext ) :
66 XMLPersElemContentTContext( rTransformer, rQName ),
67 m_rCategoriesContext( rOutCategoriesContext ),
68 m_bHasCategories( false )
71 XMLAxisOASISContext::~XMLAxisOASISContext()
74 XMLTransformerContext * XMLAxisOASISContext::CreateChildContext(
75 sal_uInt16 nPrefix,
76 const OUString& rLocalName,
77 const OUString& rQName,
78 const Reference< xml::sax::XAttributeList >& xAttrList )
80 XMLTransformerContext * pContext = 0;
82 if( XML_NAMESPACE_CHART == nPrefix &&
83 IsXMLToken( rLocalName, XML_CATEGORIES ) )
85 // store categories element at parent
86 m_rCategoriesContext.set( new XMLPersAttrListTContext( GetTransformer(), rQName ));
87 m_bHasCategories = true;
88 pContext = m_rCategoriesContext.get();
90 else
92 pContext = XMLPersElemContentTContext::CreateChildContext(
93 nPrefix, rLocalName, rQName, xAttrList );
96 return pContext;
99 void XMLAxisOASISContext::StartElement(
100 const Reference< xml::sax::XAttributeList >& rAttrList )
102 Reference< xml::sax::XAttributeList > xAttrList( rAttrList );
103 XMLMutableAttributeList *pMutableAttrList = 0;
104 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
105 for( sal_Int16 i=0; i < nAttrCount; i++ )
107 const OUString& rAttrName = xAttrList->getNameByIndex( i );
108 OUString aLocalName;
109 sal_uInt16 nPrefix =
110 GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName );
112 if( nPrefix == XML_NAMESPACE_CHART &&
113 IsXMLToken( aLocalName, XML_DIMENSION ) )
115 if( !pMutableAttrList )
117 pMutableAttrList = new XMLMutableAttributeList( xAttrList );
118 xAttrList = pMutableAttrList;
121 const OUString& rAttrValue = xAttrList->getValueByIndex( i );
122 XMLTokenEnum eToken = XML_TOKEN_INVALID;
123 if( IsXMLToken( rAttrValue, XML_X ))
125 eToken = XML_DOMAIN;
126 // has to be XML_CATEGORY for axes with a categories
127 // sub-element. The attribute is changed later (when it is
128 // known that there is a categories sub-element) in this case.
130 else if( IsXMLToken( rAttrValue, XML_Y ))
132 eToken = XML_VALUE;
134 else if( IsXMLToken( rAttrValue, XML_Z ))
136 eToken = XML_SERIES;
138 else
140 OSL_FAIL( "ChartAxis: Invalid attribute value" );
143 if( eToken != XML_TOKEN_INVALID )
145 OUString aNewAttrQName(
146 GetTransformer().GetNamespaceMap().GetQNameByKey(
147 XML_NAMESPACE_CHART, GetXMLToken( XML_CLASS )));
148 pMutableAttrList->RenameAttributeByIndex( i, aNewAttrQName );
150 pMutableAttrList->SetValueByIndex( i, GetXMLToken( eToken ));
155 XMLPersElemContentTContext::StartElement( xAttrList );
158 void XMLAxisOASISContext::EndElement()
160 // if we have categories, change the "class" attribute
161 if( IsCategoryAxis() &&
162 m_rCategoriesContext.is() )
164 OSL_ENSURE( GetAttrList().is(), "Invalid attribute list" );
165 XMLMutableAttributeList * pMutableAttrList =
166 new XMLMutableAttributeList( GetAttrList());
167 OUString aAttrQName( GetTransformer().GetNamespaceMap().GetQNameByKey(
168 XML_NAMESPACE_CHART, GetXMLToken( XML_CLASS )));
169 sal_Int16 nIndex = pMutableAttrList->GetIndexByName( aAttrQName );
170 if( nIndex != -1 )
172 OSL_ENSURE( IsXMLToken( pMutableAttrList->getValueByIndex( nIndex ),
173 XML_DOMAIN ), "Axis Dimension: invalid former value" );
174 pMutableAttrList->SetValueByIndex( nIndex, GetXMLToken( XML_CATEGORY ));
175 OSL_ENSURE( IsXMLToken( pMutableAttrList->getValueByIndex( nIndex ),
176 XML_CATEGORY ), "Axis Dimension: invalid new value" );
179 GetTransformer().GetDocHandler()->startElement(
180 GetExportQName(),
181 Reference< xml::sax::XAttributeList >( pMutableAttrList ));
182 ExportContent();
183 GetTransformer().GetDocHandler()->endElement( GetExportQName());
185 else
186 Export();
189 bool XMLAxisOASISContext::IsCategoryAxis() const
191 return m_bHasCategories;
195 TYPEINIT1( XMLChartPlotAreaOASISTContext, XMLProcAttrTransformerContext );
197 XMLChartPlotAreaOASISTContext::XMLChartPlotAreaOASISTContext(
198 XMLTransformerBase & rTransformer, const OUString & rQName ) :
199 XMLProcAttrTransformerContext( rTransformer, rQName, OASIS_SHAPE_ACTIONS )
203 XMLChartPlotAreaOASISTContext::~XMLChartPlotAreaOASISTContext()
206 XMLTransformerContext * XMLChartPlotAreaOASISTContext::CreateChildContext(
207 sal_uInt16 nPrefix,
208 const OUString& rLocalName,
209 const OUString& rQName,
210 const uno::Reference< xml::sax::XAttributeList >& xAttrList )
212 XMLTransformerContext *pContext = 0;
214 if( XML_NAMESPACE_CHART == nPrefix &&
215 IsXMLToken( rLocalName, XML_AXIS ) )
217 pContext = new XMLAxisOASISContext( GetTransformer(), rQName, m_rCategoriesContext );
219 else
221 // export (and forget) categories if found in an axis-element
222 // otherwise export regularly
223 ExportCategories();
224 pContext = XMLProcAttrTransformerContext::CreateChildContext(
225 nPrefix, rLocalName, rQName, xAttrList );
228 return pContext;
231 void XMLChartPlotAreaOASISTContext::EndElement()
233 ExportCategories();
234 XMLProcAttrTransformerContext::EndElement();
237 void XMLChartPlotAreaOASISTContext::ExportCategories()
239 if( m_rCategoriesContext.is())
241 m_rCategoriesContext->Export();
242 m_rCategoriesContext.clear();
246 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */