bump product version to 5.0.4.1
[LibreOffice.git] / xmloff / source / transform / ChartPlotAreaOOoTContext.cxx
blobbf0b25649ca57190edce78025678917a202d396b
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 "ChartPlotAreaOOoTContext.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 "ActionMapTypesOOo.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 XMLAxisOOoContext : public XMLPersElemContentTContext
37 public:
38 TYPEINFO_OVERRIDE();
40 XMLAxisOOoContext( XMLTransformerBase& rTransformer,
41 const OUString& rQName );
42 virtual ~XMLAxisOOoContext();
44 virtual void StartElement( const Reference< xml::sax::XAttributeList >& rAttrList ) SAL_OVERRIDE;
46 bool IsCategoryAxis() const { return m_bIsCategoryAxis;}
48 private:
49 bool m_bIsCategoryAxis;
52 TYPEINIT1( XMLAxisOOoContext, XMLPersElemContentTContext );
54 XMLAxisOOoContext::XMLAxisOOoContext(
55 XMLTransformerBase& rTransformer,
56 const OUString& rQName ) :
57 XMLPersElemContentTContext( rTransformer, rQName ),
58 m_bIsCategoryAxis( false )
61 XMLAxisOOoContext::~XMLAxisOOoContext()
64 void XMLAxisOOoContext::StartElement(
65 const Reference< xml::sax::XAttributeList >& rAttrList )
67 Reference< xml::sax::XAttributeList > xAttrList( rAttrList );
68 XMLMutableAttributeList *pMutableAttrList = 0;
69 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
70 for( sal_Int16 i=0; i < nAttrCount; i++ )
72 const OUString& rAttrName = xAttrList->getNameByIndex( i );
73 OUString aLocalName;
74 sal_uInt16 nPrefix =
75 GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName );
77 if( nPrefix == XML_NAMESPACE_CHART &&
78 IsXMLToken( aLocalName, XML_CLASS ) )
80 if( !pMutableAttrList )
82 pMutableAttrList = new XMLMutableAttributeList( xAttrList );
83 xAttrList = pMutableAttrList;
86 const OUString& rAttrValue = xAttrList->getValueByIndex( i );
87 XMLTokenEnum eToken = XML_TOKEN_INVALID;
88 if( IsXMLToken( rAttrValue, XML_DOMAIN ) ||
89 IsXMLToken( rAttrValue, XML_CATEGORY ))
91 eToken = XML_X;
92 if( IsXMLToken( rAttrValue, XML_CATEGORY ) )
93 m_bIsCategoryAxis = true;
95 else if( IsXMLToken( rAttrValue, XML_VALUE ))
97 eToken = XML_Y;
99 else if( IsXMLToken( rAttrValue, XML_SERIES ))
101 eToken = XML_Z;
103 else
105 OSL_FAIL( "ChartAxis: Invalid attribute value" );
108 if( eToken != XML_TOKEN_INVALID )
110 OUString aNewAttrQName(
111 GetTransformer().GetNamespaceMap().GetQNameByKey(
112 XML_NAMESPACE_CHART, GetXMLToken( XML_DIMENSION )));
113 pMutableAttrList->RenameAttributeByIndex( i, aNewAttrQName );
114 pMutableAttrList->SetValueByIndex( i, GetXMLToken( eToken ));
119 XMLPersElemContentTContext::StartElement( xAttrList );
124 TYPEINIT1( XMLChartPlotAreaOOoTContext, XMLProcAttrTransformerContext )
126 XMLChartPlotAreaOOoTContext::XMLChartPlotAreaOOoTContext(
127 XMLTransformerBase & rTransformer, const OUString & rQName ) :
128 XMLProcAttrTransformerContext( rTransformer, rQName, OOO_SHAPE_ACTIONS )
132 XMLChartPlotAreaOOoTContext::~XMLChartPlotAreaOOoTContext()
135 XMLTransformerContext * XMLChartPlotAreaOOoTContext::CreateChildContext(
136 sal_uInt16 nPrefix,
137 const OUString& rLocalName,
138 const OUString& rQName,
139 const uno::Reference< xml::sax::XAttributeList >& xAttrList )
141 XMLTransformerContext *pContext = 0;
143 if( XML_NAMESPACE_CHART == nPrefix &&
144 IsXMLToken( rLocalName, XML_AXIS ) )
146 XMLAxisOOoContext * pAxisContext( new XMLAxisOOoContext( GetTransformer(), rQName ));
147 AddContent( pAxisContext );
148 pContext = pAxisContext;
150 else if( XML_NAMESPACE_CHART == nPrefix &&
151 IsXMLToken( rLocalName, XML_CATEGORIES ) )
153 pContext = new XMLPersAttrListTContext( GetTransformer(), rQName );
155 // put categories at correct axis
156 XMLAxisContextVector::iterator aIter = m_aChildContexts.begin();
157 bool bFound =false;
159 // iterate over axis elements
160 for( ; ! bFound && aIter != m_aChildContexts.end(); ++aIter )
162 XMLAxisOOoContext * pAxisContext = (*aIter).get();
163 if( pAxisContext != 0 )
165 // iterate over attributes to find category axis
166 Reference< xml::sax::XAttributeList > xNewAttrList( pAxisContext->GetAttrList());
167 sal_Int16 nAttrCount = xNewAttrList.is() ? xNewAttrList->getLength() : 0;
169 for( sal_Int16 i=0; i < nAttrCount; i++ )
171 const OUString & rAttrName = xNewAttrList->getNameByIndex( i );
172 OUString aLocalName;
173 sal_uInt16 nNewPrefix =
174 GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName,
175 &aLocalName );
176 if( nNewPrefix == XML_NAMESPACE_CHART &&
177 pAxisContext->IsCategoryAxis() &&
178 IsXMLToken( aLocalName, XML_DIMENSION ) )
180 // category axis found
181 pAxisContext->AddContent( pContext );
182 bFound = true;
183 break;
188 OSL_ENSURE( bFound, "No suitable axis for categories found." );
190 else
192 ExportContent();
193 pContext = XMLProcAttrTransformerContext::CreateChildContext(
194 nPrefix, rLocalName, rQName, xAttrList );
197 return pContext;
200 void XMLChartPlotAreaOOoTContext::EndElement()
202 ExportContent();
203 XMLProcAttrTransformerContext::EndElement();
206 void XMLChartPlotAreaOOoTContext::AddContent( XMLAxisOOoContext *pContext )
208 OSL_ENSURE( pContext && pContext->IsPersistent(),
209 "non-persistent context" );
210 XMLAxisContextVector::value_type aVal( pContext );
211 m_aChildContexts.push_back( aVal );
215 void XMLChartPlotAreaOOoTContext::ExportContent()
217 XMLAxisContextVector::iterator aIter = m_aChildContexts.begin();
219 for( ; aIter != m_aChildContexts.end(); ++aIter )
221 (*aIter)->Export();
224 m_aChildContexts.clear();
227 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */