merge the formfield patch from ooo-build
[ooovba.git] / xmloff / source / transform / ChartPlotAreaOOoTContext.cxx
blob03fd9429c97d13184b030752edadebc37f59141e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ChartPlotAreaOOoTContext.cxx,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
33 #include "ChartPlotAreaOOoTContext.hxx"
34 #include "TransformerBase.hxx"
35 #include <xmloff/nmspmap.hxx>
36 #include "xmlnmspe.hxx"
37 #include <xmloff/xmltoken.hxx>
38 #include "DeepTContext.hxx"
39 #include "ActionMapTypesOOo.hxx"
40 #include "MutableAttrList.hxx"
42 using namespace ::com::sun::star;
43 using namespace ::xmloff::token;
45 using ::com::sun::star::uno::Reference;
46 using ::rtl::OUString;
48 class XMLAxisOOoContext : public XMLPersElemContentTContext
50 public:
51 TYPEINFO();
53 XMLAxisOOoContext( XMLTransformerBase& rTransformer,
54 const ::rtl::OUString& rQName );
55 ~XMLAxisOOoContext();
57 virtual void StartElement( const Reference< xml::sax::XAttributeList >& rAttrList );
59 bool IsCategoryAxis() const;
61 private:
62 bool m_bIsCategoryAxis;
65 TYPEINIT1( XMLAxisOOoContext, XMLPersElemContentTContext );
67 XMLAxisOOoContext::XMLAxisOOoContext(
68 XMLTransformerBase& rTransformer,
69 const ::rtl::OUString& rQName ) :
70 XMLPersElemContentTContext( rTransformer, rQName ),
71 m_bIsCategoryAxis( false )
74 XMLAxisOOoContext::~XMLAxisOOoContext()
77 void XMLAxisOOoContext::StartElement(
78 const Reference< xml::sax::XAttributeList >& rAttrList )
80 OUString aLocation, aMacroName;
81 Reference< xml::sax::XAttributeList > xAttrList( rAttrList );
82 XMLMutableAttributeList *pMutableAttrList = 0;
83 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
84 for( sal_Int16 i=0; i < nAttrCount; i++ )
86 const OUString& rAttrName = xAttrList->getNameByIndex( i );
87 OUString aLocalName;
88 sal_uInt16 nPrefix =
89 GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName );
91 if( nPrefix == XML_NAMESPACE_CHART &&
92 IsXMLToken( aLocalName, XML_CLASS ) )
94 if( !pMutableAttrList )
96 pMutableAttrList = new XMLMutableAttributeList( xAttrList );
97 xAttrList = pMutableAttrList;
100 const OUString& rAttrValue = xAttrList->getValueByIndex( i );
101 XMLTokenEnum eToken = XML_TOKEN_INVALID;
102 if( IsXMLToken( rAttrValue, XML_DOMAIN ) ||
103 IsXMLToken( rAttrValue, XML_CATEGORY ))
105 eToken = XML_X;
106 if( IsXMLToken( rAttrValue, XML_CATEGORY ) )
107 m_bIsCategoryAxis = true;
109 else if( IsXMLToken( rAttrValue, XML_VALUE ))
111 eToken = XML_Y;
113 else if( IsXMLToken( rAttrValue, XML_SERIES ))
115 eToken = XML_Z;
117 else
119 OSL_ENSURE( false, "ChartAxis: Invalid attribute value" );
122 if( eToken != XML_TOKEN_INVALID )
124 OUString aNewAttrQName(
125 GetTransformer().GetNamespaceMap().GetQNameByKey(
126 XML_NAMESPACE_CHART, GetXMLToken( XML_DIMENSION )));
127 pMutableAttrList->RenameAttributeByIndex( i, aNewAttrQName );
128 pMutableAttrList->SetValueByIndex( i, GetXMLToken( eToken ));
133 XMLPersElemContentTContext::StartElement( xAttrList );
136 bool XMLAxisOOoContext::IsCategoryAxis() const
138 return m_bIsCategoryAxis;
142 TYPEINIT1( XMLChartPlotAreaOOoTContext, XMLProcAttrTransformerContext )
144 XMLChartPlotAreaOOoTContext::XMLChartPlotAreaOOoTContext(
145 XMLTransformerBase & rTransformer, const ::rtl::OUString & rQName ) :
146 XMLProcAttrTransformerContext( rTransformer, rQName, OOO_SHAPE_ACTIONS )
150 XMLChartPlotAreaOOoTContext::~XMLChartPlotAreaOOoTContext()
153 XMLTransformerContext * XMLChartPlotAreaOOoTContext::CreateChildContext(
154 sal_uInt16 nPrefix,
155 const ::rtl::OUString& rLocalName,
156 const ::rtl::OUString& rQName,
157 const uno::Reference< xml::sax::XAttributeList >& xAttrList )
159 XMLTransformerContext *pContext = 0;
161 if( XML_NAMESPACE_CHART == nPrefix &&
162 IsXMLToken( rLocalName, XML_AXIS ) )
164 XMLAxisOOoContext * pAxisContext( new XMLAxisOOoContext( GetTransformer(), rQName ));
165 AddContent( pAxisContext );
166 pContext = pAxisContext;
168 else if( XML_NAMESPACE_CHART == nPrefix &&
169 IsXMLToken( rLocalName, XML_CATEGORIES ) )
171 pContext = new XMLPersAttrListTContext( GetTransformer(), rQName );
173 // put categories at correct axis
174 XMLAxisContextVector::iterator aIter = m_aChildContexts.begin();
175 bool bFound =false;
177 // iterate over axis elements
178 for( ; ! bFound && aIter != m_aChildContexts.end(); ++aIter )
180 XMLAxisOOoContext * pAxisContext = (*aIter).get();
181 if( pAxisContext != 0 )
183 // iterate over attributes to find category axis
184 Reference< xml::sax::XAttributeList > xNewAttrList( pAxisContext->GetAttrList());
185 sal_Int16 nAttrCount = xNewAttrList.is() ? xNewAttrList->getLength() : 0;
187 for( sal_Int16 i=0; i < nAttrCount; i++ )
189 const OUString & rAttrName = xNewAttrList->getNameByIndex( i );
190 OUString aLocalName;
191 sal_uInt16 nNewPrefix =
192 GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName,
193 &aLocalName );
194 if( nNewPrefix == XML_NAMESPACE_CHART &&
195 pAxisContext->IsCategoryAxis() &&
196 IsXMLToken( aLocalName, XML_DIMENSION ) )
198 // category axis found
199 pAxisContext->AddContent( pContext );
200 bFound = true;
201 break;
206 OSL_ENSURE( bFound, "No suitable axis for categories found." );
208 else
210 ExportContent();
211 pContext = XMLProcAttrTransformerContext::CreateChildContext(
212 nPrefix, rLocalName, rQName, xAttrList );
215 return pContext;
218 void XMLChartPlotAreaOOoTContext::EndElement()
220 ExportContent();
221 XMLProcAttrTransformerContext::EndElement();
224 void XMLChartPlotAreaOOoTContext::AddContent( XMLAxisOOoContext *pContext )
226 OSL_ENSURE( pContext && pContext->IsPersistent(),
227 "non-persistent context" );
228 XMLAxisContextVector::value_type aVal( pContext );
229 m_aChildContexts.push_back( aVal );
233 void XMLChartPlotAreaOOoTContext::ExportContent()
235 XMLAxisContextVector::iterator aIter = m_aChildContexts.begin();
237 for( ; aIter != m_aChildContexts.end(); ++aIter )
239 (*aIter)->Export();
242 m_aChildContexts.clear();