Bump for 3.6-28
[LibreOffice.git] / xmloff / source / transform / ChartPlotAreaOOoTContext.cxx
blobd36cf0e2074a1829265d77cc9e633138625a0c33
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "ChartPlotAreaOOoTContext.hxx"
30 #include "TransformerBase.hxx"
31 #include <xmloff/nmspmap.hxx>
32 #include "xmloff/xmlnmspe.hxx"
33 #include <xmloff/xmltoken.hxx>
34 #include "DeepTContext.hxx"
35 #include "ActionMapTypesOOo.hxx"
36 #include "MutableAttrList.hxx"
38 using namespace ::com::sun::star;
39 using namespace ::xmloff::token;
41 using ::com::sun::star::uno::Reference;
42 using ::rtl::OUString;
44 class XMLAxisOOoContext : public XMLPersElemContentTContext
46 public:
47 TYPEINFO();
49 XMLAxisOOoContext( XMLTransformerBase& rTransformer,
50 const ::rtl::OUString& rQName );
51 ~XMLAxisOOoContext();
53 virtual void StartElement( const Reference< xml::sax::XAttributeList >& rAttrList );
55 bool IsCategoryAxis() const;
57 private:
58 bool m_bIsCategoryAxis;
61 TYPEINIT1( XMLAxisOOoContext, XMLPersElemContentTContext );
63 XMLAxisOOoContext::XMLAxisOOoContext(
64 XMLTransformerBase& rTransformer,
65 const ::rtl::OUString& rQName ) :
66 XMLPersElemContentTContext( rTransformer, rQName ),
67 m_bIsCategoryAxis( false )
70 XMLAxisOOoContext::~XMLAxisOOoContext()
73 void XMLAxisOOoContext::StartElement(
74 const Reference< xml::sax::XAttributeList >& rAttrList )
76 Reference< xml::sax::XAttributeList > xAttrList( rAttrList );
77 XMLMutableAttributeList *pMutableAttrList = 0;
78 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
79 for( sal_Int16 i=0; i < nAttrCount; i++ )
81 const OUString& rAttrName = xAttrList->getNameByIndex( i );
82 OUString aLocalName;
83 sal_uInt16 nPrefix =
84 GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName );
86 if( nPrefix == XML_NAMESPACE_CHART &&
87 IsXMLToken( aLocalName, XML_CLASS ) )
89 if( !pMutableAttrList )
91 pMutableAttrList = new XMLMutableAttributeList( xAttrList );
92 xAttrList = pMutableAttrList;
95 const OUString& rAttrValue = xAttrList->getValueByIndex( i );
96 XMLTokenEnum eToken = XML_TOKEN_INVALID;
97 if( IsXMLToken( rAttrValue, XML_DOMAIN ) ||
98 IsXMLToken( rAttrValue, XML_CATEGORY ))
100 eToken = XML_X;
101 if( IsXMLToken( rAttrValue, XML_CATEGORY ) )
102 m_bIsCategoryAxis = true;
104 else if( IsXMLToken( rAttrValue, XML_VALUE ))
106 eToken = XML_Y;
108 else if( IsXMLToken( rAttrValue, XML_SERIES ))
110 eToken = XML_Z;
112 else
114 OSL_FAIL( "ChartAxis: Invalid attribute value" );
117 if( eToken != XML_TOKEN_INVALID )
119 OUString aNewAttrQName(
120 GetTransformer().GetNamespaceMap().GetQNameByKey(
121 XML_NAMESPACE_CHART, GetXMLToken( XML_DIMENSION )));
122 pMutableAttrList->RenameAttributeByIndex( i, aNewAttrQName );
123 pMutableAttrList->SetValueByIndex( i, GetXMLToken( eToken ));
128 XMLPersElemContentTContext::StartElement( xAttrList );
131 bool XMLAxisOOoContext::IsCategoryAxis() const
133 return m_bIsCategoryAxis;
137 TYPEINIT1( XMLChartPlotAreaOOoTContext, XMLProcAttrTransformerContext )
139 XMLChartPlotAreaOOoTContext::XMLChartPlotAreaOOoTContext(
140 XMLTransformerBase & rTransformer, const ::rtl::OUString & rQName ) :
141 XMLProcAttrTransformerContext( rTransformer, rQName, OOO_SHAPE_ACTIONS )
145 XMLChartPlotAreaOOoTContext::~XMLChartPlotAreaOOoTContext()
148 XMLTransformerContext * XMLChartPlotAreaOOoTContext::CreateChildContext(
149 sal_uInt16 nPrefix,
150 const ::rtl::OUString& rLocalName,
151 const ::rtl::OUString& rQName,
152 const uno::Reference< xml::sax::XAttributeList >& xAttrList )
154 XMLTransformerContext *pContext = 0;
156 if( XML_NAMESPACE_CHART == nPrefix &&
157 IsXMLToken( rLocalName, XML_AXIS ) )
159 XMLAxisOOoContext * pAxisContext( new XMLAxisOOoContext( GetTransformer(), rQName ));
160 AddContent( pAxisContext );
161 pContext = pAxisContext;
163 else if( XML_NAMESPACE_CHART == nPrefix &&
164 IsXMLToken( rLocalName, XML_CATEGORIES ) )
166 pContext = new XMLPersAttrListTContext( GetTransformer(), rQName );
168 // put categories at correct axis
169 XMLAxisContextVector::iterator aIter = m_aChildContexts.begin();
170 bool bFound =false;
172 // iterate over axis elements
173 for( ; ! bFound && aIter != m_aChildContexts.end(); ++aIter )
175 XMLAxisOOoContext * pAxisContext = (*aIter).get();
176 if( pAxisContext != 0 )
178 // iterate over attributes to find category axis
179 Reference< xml::sax::XAttributeList > xNewAttrList( pAxisContext->GetAttrList());
180 sal_Int16 nAttrCount = xNewAttrList.is() ? xNewAttrList->getLength() : 0;
182 for( sal_Int16 i=0; i < nAttrCount; i++ )
184 const OUString & rAttrName = xNewAttrList->getNameByIndex( i );
185 OUString aLocalName;
186 sal_uInt16 nNewPrefix =
187 GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName,
188 &aLocalName );
189 if( nNewPrefix == XML_NAMESPACE_CHART &&
190 pAxisContext->IsCategoryAxis() &&
191 IsXMLToken( aLocalName, XML_DIMENSION ) )
193 // category axis found
194 pAxisContext->AddContent( pContext );
195 bFound = true;
196 break;
201 OSL_ENSURE( bFound, "No suitable axis for categories found." );
203 else
205 ExportContent();
206 pContext = XMLProcAttrTransformerContext::CreateChildContext(
207 nPrefix, rLocalName, rQName, xAttrList );
210 return pContext;
213 void XMLChartPlotAreaOOoTContext::EndElement()
215 ExportContent();
216 XMLProcAttrTransformerContext::EndElement();
219 void XMLChartPlotAreaOOoTContext::AddContent( XMLAxisOOoContext *pContext )
221 OSL_ENSURE( pContext && pContext->IsPersistent(),
222 "non-persistent context" );
223 XMLAxisContextVector::value_type aVal( pContext );
224 m_aChildContexts.push_back( aVal );
228 void XMLChartPlotAreaOOoTContext::ExportContent()
230 XMLAxisContextVector::iterator aIter = m_aChildContexts.begin();
232 for( ; aIter != m_aChildContexts.end(); ++aIter )
234 (*aIter)->Export();
237 m_aChildContexts.clear();
240 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */