fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / xmloff / source / transform / ChartPlotAreaOOoTContext.cxx
blob65769067fe4b534eeb6d3c1fd3ce38a5a93328e6
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"
29 using namespace ::com::sun::star;
30 using namespace ::xmloff::token;
32 using ::com::sun::star::uno::Reference;
34 class XMLAxisOOoContext : public XMLPersElemContentTContext
36 public:
37 TYPEINFO();
39 XMLAxisOOoContext( XMLTransformerBase& rTransformer,
40 const OUString& rQName );
41 ~XMLAxisOOoContext();
43 virtual void StartElement( const Reference< xml::sax::XAttributeList >& rAttrList );
45 bool IsCategoryAxis() const;
47 private:
48 bool m_bIsCategoryAxis;
51 TYPEINIT1( XMLAxisOOoContext, XMLPersElemContentTContext );
53 XMLAxisOOoContext::XMLAxisOOoContext(
54 XMLTransformerBase& rTransformer,
55 const OUString& rQName ) :
56 XMLPersElemContentTContext( rTransformer, rQName ),
57 m_bIsCategoryAxis( false )
60 XMLAxisOOoContext::~XMLAxisOOoContext()
63 void XMLAxisOOoContext::StartElement(
64 const Reference< xml::sax::XAttributeList >& rAttrList )
66 Reference< xml::sax::XAttributeList > xAttrList( rAttrList );
67 XMLMutableAttributeList *pMutableAttrList = 0;
68 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
69 for( sal_Int16 i=0; i < nAttrCount; i++ )
71 const OUString& rAttrName = xAttrList->getNameByIndex( i );
72 OUString aLocalName;
73 sal_uInt16 nPrefix =
74 GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName );
76 if( nPrefix == XML_NAMESPACE_CHART &&
77 IsXMLToken( aLocalName, XML_CLASS ) )
79 if( !pMutableAttrList )
81 pMutableAttrList = new XMLMutableAttributeList( xAttrList );
82 xAttrList = pMutableAttrList;
85 const OUString& rAttrValue = xAttrList->getValueByIndex( i );
86 XMLTokenEnum eToken = XML_TOKEN_INVALID;
87 if( IsXMLToken( rAttrValue, XML_DOMAIN ) ||
88 IsXMLToken( rAttrValue, XML_CATEGORY ))
90 eToken = XML_X;
91 if( IsXMLToken( rAttrValue, XML_CATEGORY ) )
92 m_bIsCategoryAxis = true;
94 else if( IsXMLToken( rAttrValue, XML_VALUE ))
96 eToken = XML_Y;
98 else if( IsXMLToken( rAttrValue, XML_SERIES ))
100 eToken = XML_Z;
102 else
104 OSL_FAIL( "ChartAxis: Invalid attribute value" );
107 if( eToken != XML_TOKEN_INVALID )
109 OUString aNewAttrQName(
110 GetTransformer().GetNamespaceMap().GetQNameByKey(
111 XML_NAMESPACE_CHART, GetXMLToken( XML_DIMENSION )));
112 pMutableAttrList->RenameAttributeByIndex( i, aNewAttrQName );
113 pMutableAttrList->SetValueByIndex( i, GetXMLToken( eToken ));
118 XMLPersElemContentTContext::StartElement( xAttrList );
121 bool XMLAxisOOoContext::IsCategoryAxis() const
123 return m_bIsCategoryAxis;
127 TYPEINIT1( XMLChartPlotAreaOOoTContext, XMLProcAttrTransformerContext )
129 XMLChartPlotAreaOOoTContext::XMLChartPlotAreaOOoTContext(
130 XMLTransformerBase & rTransformer, const OUString & rQName ) :
131 XMLProcAttrTransformerContext( rTransformer, rQName, OOO_SHAPE_ACTIONS )
135 XMLChartPlotAreaOOoTContext::~XMLChartPlotAreaOOoTContext()
138 XMLTransformerContext * XMLChartPlotAreaOOoTContext::CreateChildContext(
139 sal_uInt16 nPrefix,
140 const OUString& rLocalName,
141 const OUString& rQName,
142 const uno::Reference< xml::sax::XAttributeList >& xAttrList )
144 XMLTransformerContext *pContext = 0;
146 if( XML_NAMESPACE_CHART == nPrefix &&
147 IsXMLToken( rLocalName, XML_AXIS ) )
149 XMLAxisOOoContext * pAxisContext( new XMLAxisOOoContext( GetTransformer(), rQName ));
150 AddContent( pAxisContext );
151 pContext = pAxisContext;
153 else if( XML_NAMESPACE_CHART == nPrefix &&
154 IsXMLToken( rLocalName, XML_CATEGORIES ) )
156 pContext = new XMLPersAttrListTContext( GetTransformer(), rQName );
158 // put categories at correct axis
159 XMLAxisContextVector::iterator aIter = m_aChildContexts.begin();
160 bool bFound =false;
162 // iterate over axis elements
163 for( ; ! bFound && aIter != m_aChildContexts.end(); ++aIter )
165 XMLAxisOOoContext * pAxisContext = (*aIter).get();
166 if( pAxisContext != 0 )
168 // iterate over attributes to find category axis
169 Reference< xml::sax::XAttributeList > xNewAttrList( pAxisContext->GetAttrList());
170 sal_Int16 nAttrCount = xNewAttrList.is() ? xNewAttrList->getLength() : 0;
172 for( sal_Int16 i=0; i < nAttrCount; i++ )
174 const OUString & rAttrName = xNewAttrList->getNameByIndex( i );
175 OUString aLocalName;
176 sal_uInt16 nNewPrefix =
177 GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName,
178 &aLocalName );
179 if( nNewPrefix == XML_NAMESPACE_CHART &&
180 pAxisContext->IsCategoryAxis() &&
181 IsXMLToken( aLocalName, XML_DIMENSION ) )
183 // category axis found
184 pAxisContext->AddContent( pContext );
185 bFound = true;
186 break;
191 OSL_ENSURE( bFound, "No suitable axis for categories found." );
193 else
195 ExportContent();
196 pContext = XMLProcAttrTransformerContext::CreateChildContext(
197 nPrefix, rLocalName, rQName, xAttrList );
200 return pContext;
203 void XMLChartPlotAreaOOoTContext::EndElement()
205 ExportContent();
206 XMLProcAttrTransformerContext::EndElement();
209 void XMLChartPlotAreaOOoTContext::AddContent( XMLAxisOOoContext *pContext )
211 OSL_ENSURE( pContext && pContext->IsPersistent(),
212 "non-persistent context" );
213 XMLAxisContextVector::value_type aVal( pContext );
214 m_aChildContexts.push_back( aVal );
218 void XMLChartPlotAreaOOoTContext::ExportContent()
220 XMLAxisContextVector::iterator aIter = m_aChildContexts.begin();
222 for( ; aIter != m_aChildContexts.end(); ++aIter )
224 (*aIter)->Export();
227 m_aChildContexts.clear();
230 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */