1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_xmloff.hxx" 30*cdf0e10cSrcweir #include "ChartPlotAreaOOoTContext.hxx" 31*cdf0e10cSrcweir #include "TransformerBase.hxx" 32*cdf0e10cSrcweir #include <xmloff/nmspmap.hxx> 33*cdf0e10cSrcweir #include "xmloff/xmlnmspe.hxx" 34*cdf0e10cSrcweir #include <xmloff/xmltoken.hxx> 35*cdf0e10cSrcweir #include "DeepTContext.hxx" 36*cdf0e10cSrcweir #include "ActionMapTypesOOo.hxx" 37*cdf0e10cSrcweir #include "MutableAttrList.hxx" 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir using namespace ::com::sun::star; 40*cdf0e10cSrcweir using namespace ::xmloff::token; 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir using ::com::sun::star::uno::Reference; 43*cdf0e10cSrcweir using ::rtl::OUString; 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir class XMLAxisOOoContext : public XMLPersElemContentTContext 46*cdf0e10cSrcweir { 47*cdf0e10cSrcweir public: 48*cdf0e10cSrcweir TYPEINFO(); 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir XMLAxisOOoContext( XMLTransformerBase& rTransformer, 51*cdf0e10cSrcweir const ::rtl::OUString& rQName ); 52*cdf0e10cSrcweir ~XMLAxisOOoContext(); 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir virtual void StartElement( const Reference< xml::sax::XAttributeList >& rAttrList ); 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir bool IsCategoryAxis() const; 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir private: 59*cdf0e10cSrcweir bool m_bIsCategoryAxis; 60*cdf0e10cSrcweir }; 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir TYPEINIT1( XMLAxisOOoContext, XMLPersElemContentTContext ); 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir XMLAxisOOoContext::XMLAxisOOoContext( 65*cdf0e10cSrcweir XMLTransformerBase& rTransformer, 66*cdf0e10cSrcweir const ::rtl::OUString& rQName ) : 67*cdf0e10cSrcweir XMLPersElemContentTContext( rTransformer, rQName ), 68*cdf0e10cSrcweir m_bIsCategoryAxis( false ) 69*cdf0e10cSrcweir {} 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir XMLAxisOOoContext::~XMLAxisOOoContext() 72*cdf0e10cSrcweir {} 73*cdf0e10cSrcweir 74*cdf0e10cSrcweir void XMLAxisOOoContext::StartElement( 75*cdf0e10cSrcweir const Reference< xml::sax::XAttributeList >& rAttrList ) 76*cdf0e10cSrcweir { 77*cdf0e10cSrcweir OUString aLocation, aMacroName; 78*cdf0e10cSrcweir Reference< xml::sax::XAttributeList > xAttrList( rAttrList ); 79*cdf0e10cSrcweir XMLMutableAttributeList *pMutableAttrList = 0; 80*cdf0e10cSrcweir sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; 81*cdf0e10cSrcweir for( sal_Int16 i=0; i < nAttrCount; i++ ) 82*cdf0e10cSrcweir { 83*cdf0e10cSrcweir const OUString& rAttrName = xAttrList->getNameByIndex( i ); 84*cdf0e10cSrcweir OUString aLocalName; 85*cdf0e10cSrcweir sal_uInt16 nPrefix = 86*cdf0e10cSrcweir GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName ); 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir if( nPrefix == XML_NAMESPACE_CHART && 89*cdf0e10cSrcweir IsXMLToken( aLocalName, XML_CLASS ) ) 90*cdf0e10cSrcweir { 91*cdf0e10cSrcweir if( !pMutableAttrList ) 92*cdf0e10cSrcweir { 93*cdf0e10cSrcweir pMutableAttrList = new XMLMutableAttributeList( xAttrList ); 94*cdf0e10cSrcweir xAttrList = pMutableAttrList; 95*cdf0e10cSrcweir } 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir const OUString& rAttrValue = xAttrList->getValueByIndex( i ); 98*cdf0e10cSrcweir XMLTokenEnum eToken = XML_TOKEN_INVALID; 99*cdf0e10cSrcweir if( IsXMLToken( rAttrValue, XML_DOMAIN ) || 100*cdf0e10cSrcweir IsXMLToken( rAttrValue, XML_CATEGORY )) 101*cdf0e10cSrcweir { 102*cdf0e10cSrcweir eToken = XML_X; 103*cdf0e10cSrcweir if( IsXMLToken( rAttrValue, XML_CATEGORY ) ) 104*cdf0e10cSrcweir m_bIsCategoryAxis = true; 105*cdf0e10cSrcweir } 106*cdf0e10cSrcweir else if( IsXMLToken( rAttrValue, XML_VALUE )) 107*cdf0e10cSrcweir { 108*cdf0e10cSrcweir eToken = XML_Y; 109*cdf0e10cSrcweir } 110*cdf0e10cSrcweir else if( IsXMLToken( rAttrValue, XML_SERIES )) 111*cdf0e10cSrcweir { 112*cdf0e10cSrcweir eToken = XML_Z; 113*cdf0e10cSrcweir } 114*cdf0e10cSrcweir else 115*cdf0e10cSrcweir { 116*cdf0e10cSrcweir OSL_ENSURE( false, "ChartAxis: Invalid attribute value" ); 117*cdf0e10cSrcweir } 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir if( eToken != XML_TOKEN_INVALID ) 120*cdf0e10cSrcweir { 121*cdf0e10cSrcweir OUString aNewAttrQName( 122*cdf0e10cSrcweir GetTransformer().GetNamespaceMap().GetQNameByKey( 123*cdf0e10cSrcweir XML_NAMESPACE_CHART, GetXMLToken( XML_DIMENSION ))); 124*cdf0e10cSrcweir pMutableAttrList->RenameAttributeByIndex( i, aNewAttrQName ); 125*cdf0e10cSrcweir pMutableAttrList->SetValueByIndex( i, GetXMLToken( eToken )); 126*cdf0e10cSrcweir } 127*cdf0e10cSrcweir } 128*cdf0e10cSrcweir } 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir XMLPersElemContentTContext::StartElement( xAttrList ); 131*cdf0e10cSrcweir } 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir bool XMLAxisOOoContext::IsCategoryAxis() const 134*cdf0e10cSrcweir { 135*cdf0e10cSrcweir return m_bIsCategoryAxis; 136*cdf0e10cSrcweir } 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir 139*cdf0e10cSrcweir TYPEINIT1( XMLChartPlotAreaOOoTContext, XMLProcAttrTransformerContext ) 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir XMLChartPlotAreaOOoTContext::XMLChartPlotAreaOOoTContext( 142*cdf0e10cSrcweir XMLTransformerBase & rTransformer, const ::rtl::OUString & rQName ) : 143*cdf0e10cSrcweir XMLProcAttrTransformerContext( rTransformer, rQName, OOO_SHAPE_ACTIONS ) 144*cdf0e10cSrcweir { 145*cdf0e10cSrcweir } 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir XMLChartPlotAreaOOoTContext::~XMLChartPlotAreaOOoTContext() 148*cdf0e10cSrcweir {} 149*cdf0e10cSrcweir 150*cdf0e10cSrcweir XMLTransformerContext * XMLChartPlotAreaOOoTContext::CreateChildContext( 151*cdf0e10cSrcweir sal_uInt16 nPrefix, 152*cdf0e10cSrcweir const ::rtl::OUString& rLocalName, 153*cdf0e10cSrcweir const ::rtl::OUString& rQName, 154*cdf0e10cSrcweir const uno::Reference< xml::sax::XAttributeList >& xAttrList ) 155*cdf0e10cSrcweir { 156*cdf0e10cSrcweir XMLTransformerContext *pContext = 0; 157*cdf0e10cSrcweir 158*cdf0e10cSrcweir if( XML_NAMESPACE_CHART == nPrefix && 159*cdf0e10cSrcweir IsXMLToken( rLocalName, XML_AXIS ) ) 160*cdf0e10cSrcweir { 161*cdf0e10cSrcweir XMLAxisOOoContext * pAxisContext( new XMLAxisOOoContext( GetTransformer(), rQName )); 162*cdf0e10cSrcweir AddContent( pAxisContext ); 163*cdf0e10cSrcweir pContext = pAxisContext; 164*cdf0e10cSrcweir } 165*cdf0e10cSrcweir else if( XML_NAMESPACE_CHART == nPrefix && 166*cdf0e10cSrcweir IsXMLToken( rLocalName, XML_CATEGORIES ) ) 167*cdf0e10cSrcweir { 168*cdf0e10cSrcweir pContext = new XMLPersAttrListTContext( GetTransformer(), rQName ); 169*cdf0e10cSrcweir 170*cdf0e10cSrcweir // put categories at correct axis 171*cdf0e10cSrcweir XMLAxisContextVector::iterator aIter = m_aChildContexts.begin(); 172*cdf0e10cSrcweir bool bFound =false; 173*cdf0e10cSrcweir 174*cdf0e10cSrcweir // iterate over axis elements 175*cdf0e10cSrcweir for( ; ! bFound && aIter != m_aChildContexts.end(); ++aIter ) 176*cdf0e10cSrcweir { 177*cdf0e10cSrcweir XMLAxisOOoContext * pAxisContext = (*aIter).get(); 178*cdf0e10cSrcweir if( pAxisContext != 0 ) 179*cdf0e10cSrcweir { 180*cdf0e10cSrcweir // iterate over attributes to find category axis 181*cdf0e10cSrcweir Reference< xml::sax::XAttributeList > xNewAttrList( pAxisContext->GetAttrList()); 182*cdf0e10cSrcweir sal_Int16 nAttrCount = xNewAttrList.is() ? xNewAttrList->getLength() : 0; 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir for( sal_Int16 i=0; i < nAttrCount; i++ ) 185*cdf0e10cSrcweir { 186*cdf0e10cSrcweir const OUString & rAttrName = xNewAttrList->getNameByIndex( i ); 187*cdf0e10cSrcweir OUString aLocalName; 188*cdf0e10cSrcweir sal_uInt16 nNewPrefix = 189*cdf0e10cSrcweir GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName, 190*cdf0e10cSrcweir &aLocalName ); 191*cdf0e10cSrcweir if( nNewPrefix == XML_NAMESPACE_CHART && 192*cdf0e10cSrcweir pAxisContext->IsCategoryAxis() && 193*cdf0e10cSrcweir IsXMLToken( aLocalName, XML_DIMENSION ) ) 194*cdf0e10cSrcweir { 195*cdf0e10cSrcweir // category axis found 196*cdf0e10cSrcweir pAxisContext->AddContent( pContext ); 197*cdf0e10cSrcweir bFound = true; 198*cdf0e10cSrcweir break; 199*cdf0e10cSrcweir } 200*cdf0e10cSrcweir } 201*cdf0e10cSrcweir } 202*cdf0e10cSrcweir } 203*cdf0e10cSrcweir OSL_ENSURE( bFound, "No suitable axis for categories found." ); 204*cdf0e10cSrcweir } 205*cdf0e10cSrcweir else 206*cdf0e10cSrcweir { 207*cdf0e10cSrcweir ExportContent(); 208*cdf0e10cSrcweir pContext = XMLProcAttrTransformerContext::CreateChildContext( 209*cdf0e10cSrcweir nPrefix, rLocalName, rQName, xAttrList ); 210*cdf0e10cSrcweir } 211*cdf0e10cSrcweir 212*cdf0e10cSrcweir return pContext; 213*cdf0e10cSrcweir } 214*cdf0e10cSrcweir 215*cdf0e10cSrcweir void XMLChartPlotAreaOOoTContext::EndElement() 216*cdf0e10cSrcweir { 217*cdf0e10cSrcweir ExportContent(); 218*cdf0e10cSrcweir XMLProcAttrTransformerContext::EndElement(); 219*cdf0e10cSrcweir } 220*cdf0e10cSrcweir 221*cdf0e10cSrcweir void XMLChartPlotAreaOOoTContext::AddContent( XMLAxisOOoContext *pContext ) 222*cdf0e10cSrcweir { 223*cdf0e10cSrcweir OSL_ENSURE( pContext && pContext->IsPersistent(), 224*cdf0e10cSrcweir "non-persistent context" ); 225*cdf0e10cSrcweir XMLAxisContextVector::value_type aVal( pContext ); 226*cdf0e10cSrcweir m_aChildContexts.push_back( aVal ); 227*cdf0e10cSrcweir } 228*cdf0e10cSrcweir 229*cdf0e10cSrcweir 230*cdf0e10cSrcweir void XMLChartPlotAreaOOoTContext::ExportContent() 231*cdf0e10cSrcweir { 232*cdf0e10cSrcweir XMLAxisContextVector::iterator aIter = m_aChildContexts.begin(); 233*cdf0e10cSrcweir 234*cdf0e10cSrcweir for( ; aIter != m_aChildContexts.end(); ++aIter ) 235*cdf0e10cSrcweir { 236*cdf0e10cSrcweir (*aIter)->Export(); 237*cdf0e10cSrcweir } 238*cdf0e10cSrcweir 239*cdf0e10cSrcweir m_aChildContexts.clear(); 240*cdf0e10cSrcweir } 241