Teach symstore more duplicated DLLs
[LibreOffice.git] / xmloff / source / transform / ChartPlotAreaOOoTContext.cxx
blob76a732799daf6fc15f978ed1b542352243ac3d1b
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 XMLAxisOOoContext( XMLTransformerBase& rTransformer,
39 const OUString& rQName );
41 virtual void StartElement( const Reference< xml::sax::XAttributeList >& rAttrList ) override;
43 bool IsCategoryAxis() const { return m_bIsCategoryAxis;}
45 private:
46 bool m_bIsCategoryAxis;
49 XMLAxisOOoContext::XMLAxisOOoContext(
50 XMLTransformerBase& rTransformer,
51 const OUString& rQName ) :
52 XMLPersElemContentTContext( rTransformer, rQName ),
53 m_bIsCategoryAxis( false )
56 void XMLAxisOOoContext::StartElement(
57 const Reference< xml::sax::XAttributeList >& rAttrList )
59 Reference< xml::sax::XAttributeList > xAttrList( rAttrList );
60 XMLMutableAttributeList *pMutableAttrList = nullptr;
61 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
62 for( sal_Int16 i=0; i < nAttrCount; i++ )
64 const OUString& rAttrName = xAttrList->getNameByIndex( i );
65 OUString aLocalName;
66 sal_uInt16 nPrefix =
67 GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName );
69 if( nPrefix == XML_NAMESPACE_CHART &&
70 IsXMLToken( aLocalName, XML_CLASS ) )
72 if( !pMutableAttrList )
74 pMutableAttrList = new XMLMutableAttributeList( xAttrList );
75 xAttrList = pMutableAttrList;
78 const OUString& rAttrValue = xAttrList->getValueByIndex( i );
79 XMLTokenEnum eToken = XML_TOKEN_INVALID;
80 if( IsXMLToken( rAttrValue, XML_DOMAIN ) ||
81 IsXMLToken( rAttrValue, XML_CATEGORY ))
83 eToken = XML_X;
84 if( IsXMLToken( rAttrValue, XML_CATEGORY ) )
85 m_bIsCategoryAxis = true;
87 else if( IsXMLToken( rAttrValue, XML_VALUE ))
89 eToken = XML_Y;
91 else if( IsXMLToken( rAttrValue, XML_SERIES ))
93 eToken = XML_Z;
95 else
97 OSL_FAIL( "ChartAxis: Invalid attribute value" );
100 if( eToken != XML_TOKEN_INVALID )
102 OUString aNewAttrQName(
103 GetTransformer().GetNamespaceMap().GetQNameByKey(
104 XML_NAMESPACE_CHART, GetXMLToken( XML_DIMENSION )));
105 pMutableAttrList->RenameAttributeByIndex( i, aNewAttrQName );
106 pMutableAttrList->SetValueByIndex( i, GetXMLToken( eToken ));
111 XMLPersElemContentTContext::StartElement( xAttrList );
114 XMLChartPlotAreaOOoTContext::XMLChartPlotAreaOOoTContext(
115 XMLTransformerBase & rTransformer, const OUString & rQName ) :
116 XMLProcAttrTransformerContext( rTransformer, rQName, OOO_SHAPE_ACTIONS )
120 rtl::Reference<XMLTransformerContext> XMLChartPlotAreaOOoTContext::CreateChildContext(
121 sal_uInt16 nPrefix,
122 const OUString& rLocalName,
123 const OUString& rQName,
124 const uno::Reference< xml::sax::XAttributeList >& xAttrList )
126 rtl::Reference<XMLTransformerContext> pContext;
128 if( XML_NAMESPACE_CHART == nPrefix &&
129 IsXMLToken( rLocalName, XML_AXIS ) )
131 rtl::Reference<XMLAxisOOoContext> pAxisContext( new XMLAxisOOoContext( GetTransformer(), rQName ));
132 AddContent( pAxisContext );
133 pContext.set(pAxisContext.get());
135 else if( XML_NAMESPACE_CHART == nPrefix &&
136 IsXMLToken( rLocalName, XML_CATEGORIES ) )
138 pContext.set(new XMLPersAttrListTContext( GetTransformer(), rQName ));
140 // put categories at correct axis
141 bool bFound =false;
143 // iterate over axis elements
144 for( const auto& rChildContext : m_aChildContexts )
146 XMLAxisOOoContext * pAxisContext = rChildContext.get();
147 if( pAxisContext != nullptr )
149 // iterate over attributes to find category axis
150 Reference< xml::sax::XAttributeList > xNewAttrList( pAxisContext->GetAttrList());
151 sal_Int16 nAttrCount = xNewAttrList.is() ? xNewAttrList->getLength() : 0;
153 for( sal_Int16 i=0; i < nAttrCount; i++ )
155 const OUString & rAttrName = xNewAttrList->getNameByIndex( i );
156 OUString aLocalName;
157 sal_uInt16 nNewPrefix =
158 GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName,
159 &aLocalName );
160 if( nNewPrefix == XML_NAMESPACE_CHART &&
161 pAxisContext->IsCategoryAxis() &&
162 IsXMLToken( aLocalName, XML_DIMENSION ) )
164 // category axis found
165 pAxisContext->AddContent( pContext );
166 bFound = true;
167 break;
172 if (bFound)
173 break;
175 OSL_ENSURE( bFound, "No suitable axis for categories found." );
177 else
179 ExportContent();
180 pContext = XMLProcAttrTransformerContext::CreateChildContext(
181 nPrefix, rLocalName, rQName, xAttrList );
184 return pContext;
187 void XMLChartPlotAreaOOoTContext::EndElement()
189 ExportContent();
190 XMLProcAttrTransformerContext::EndElement();
193 void XMLChartPlotAreaOOoTContext::AddContent(rtl::Reference<XMLAxisOOoContext> const & pContext)
195 OSL_ENSURE( pContext.is() && pContext->IsPersistent(),
196 "non-persistent context" );
197 m_aChildContexts.push_back(pContext);
201 void XMLChartPlotAreaOOoTContext::ExportContent()
203 for( auto& rChildContext : m_aChildContexts )
205 rChildContext->Export();
208 m_aChildContexts.clear();
211 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */