LCOV - code coverage report
Current view: top level - libreoffice/xmloff/source/transform - ChartPlotAreaOOoTContext.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 92 0.0 %
Date: 2012-12-27 Functions: 0 22 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      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             : 
      29             : using namespace ::com::sun::star;
      30             : using namespace ::xmloff::token;
      31             : 
      32             : using ::com::sun::star::uno::Reference;
      33             : using ::rtl::OUString;
      34             : 
      35             : class XMLAxisOOoContext : public XMLPersElemContentTContext
      36             : {
      37             : public:
      38             :     TYPEINFO();
      39             : 
      40             :     XMLAxisOOoContext( XMLTransformerBase& rTransformer,
      41             :                        const ::rtl::OUString& rQName );
      42             :     ~XMLAxisOOoContext();
      43             : 
      44             :     virtual void StartElement( const Reference< xml::sax::XAttributeList >& rAttrList );
      45             : 
      46             :     bool IsCategoryAxis() const;
      47             : 
      48             : private:
      49             :     bool m_bIsCategoryAxis;
      50             : };
      51             : 
      52           0 : TYPEINIT1( XMLAxisOOoContext, XMLPersElemContentTContext );
      53             : 
      54           0 : XMLAxisOOoContext::XMLAxisOOoContext(
      55             :     XMLTransformerBase& rTransformer,
      56             :     const ::rtl::OUString& rQName ) :
      57             :         XMLPersElemContentTContext( rTransformer, rQName ),
      58           0 :         m_bIsCategoryAxis( false )
      59           0 : {}
      60             : 
      61           0 : XMLAxisOOoContext::~XMLAxisOOoContext()
      62           0 : {}
      63             : 
      64           0 : void XMLAxisOOoContext::StartElement(
      65             :     const Reference< xml::sax::XAttributeList >& rAttrList )
      66             : {
      67           0 :     Reference< xml::sax::XAttributeList > xAttrList( rAttrList );
      68           0 :     XMLMutableAttributeList *pMutableAttrList = 0;
      69           0 :     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
      70           0 :     for( sal_Int16 i=0; i < nAttrCount; i++ )
      71             :     {
      72           0 :         const OUString& rAttrName = xAttrList->getNameByIndex( i );
      73           0 :         OUString aLocalName;
      74             :         sal_uInt16 nPrefix =
      75           0 :             GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName );
      76             : 
      77           0 :         if( nPrefix == XML_NAMESPACE_CHART &&
      78           0 :             IsXMLToken( aLocalName, XML_CLASS ) )
      79             :         {
      80           0 :             if( !pMutableAttrList )
      81             :             {
      82           0 :                 pMutableAttrList = new XMLMutableAttributeList( xAttrList );
      83           0 :                 xAttrList = pMutableAttrList;
      84             :             }
      85             : 
      86           0 :             const OUString& rAttrValue = xAttrList->getValueByIndex( i );
      87           0 :             XMLTokenEnum eToken = XML_TOKEN_INVALID;
      88           0 :             if( IsXMLToken( rAttrValue, XML_DOMAIN ) ||
      89           0 :                 IsXMLToken( rAttrValue, XML_CATEGORY ))
      90             :             {
      91           0 :                 eToken = XML_X;
      92           0 :                 if( IsXMLToken( rAttrValue, XML_CATEGORY ) )
      93           0 :                     m_bIsCategoryAxis = true;
      94             :             }
      95           0 :             else if( IsXMLToken( rAttrValue, XML_VALUE ))
      96             :             {
      97           0 :                 eToken = XML_Y;
      98             :             }
      99           0 :             else if( IsXMLToken( rAttrValue, XML_SERIES ))
     100             :             {
     101           0 :                 eToken = XML_Z;
     102             :             }
     103             :             else
     104             :             {
     105             :                 OSL_FAIL( "ChartAxis: Invalid attribute value" );
     106             :             }
     107             : 
     108           0 :             if( eToken != XML_TOKEN_INVALID )
     109             :             {
     110             :                 OUString aNewAttrQName(
     111           0 :                     GetTransformer().GetNamespaceMap().GetQNameByKey(
     112           0 :                         XML_NAMESPACE_CHART, GetXMLToken( XML_DIMENSION )));
     113           0 :                 pMutableAttrList->RenameAttributeByIndex( i, aNewAttrQName );
     114           0 :                 pMutableAttrList->SetValueByIndex( i, GetXMLToken( eToken ));
     115           0 :             }
     116             :         }
     117           0 :     }
     118             : 
     119           0 :     XMLPersElemContentTContext::StartElement( xAttrList );
     120           0 : }
     121             : 
     122           0 : bool XMLAxisOOoContext::IsCategoryAxis() const
     123             : {
     124           0 :     return m_bIsCategoryAxis;
     125             : }
     126             : 
     127             : 
     128           0 : TYPEINIT1( XMLChartPlotAreaOOoTContext, XMLProcAttrTransformerContext )
     129             : 
     130           0 : XMLChartPlotAreaOOoTContext::XMLChartPlotAreaOOoTContext(
     131             :     XMLTransformerBase & rTransformer, const ::rtl::OUString & rQName ) :
     132           0 :         XMLProcAttrTransformerContext( rTransformer, rQName, OOO_SHAPE_ACTIONS )
     133             : {
     134           0 : }
     135             : 
     136           0 : XMLChartPlotAreaOOoTContext::~XMLChartPlotAreaOOoTContext()
     137           0 : {}
     138             : 
     139           0 : XMLTransformerContext * XMLChartPlotAreaOOoTContext::CreateChildContext(
     140             :     sal_uInt16 nPrefix,
     141             :     const ::rtl::OUString& rLocalName,
     142             :     const ::rtl::OUString& rQName,
     143             :     const uno::Reference< xml::sax::XAttributeList >& xAttrList )
     144             : {
     145           0 :     XMLTransformerContext *pContext = 0;
     146             : 
     147           0 :     if( XML_NAMESPACE_CHART == nPrefix &&
     148           0 :         IsXMLToken( rLocalName, XML_AXIS ) )
     149             :     {
     150           0 :         XMLAxisOOoContext * pAxisContext( new XMLAxisOOoContext( GetTransformer(), rQName ));
     151           0 :         AddContent( pAxisContext );
     152           0 :         pContext = pAxisContext;
     153             :     }
     154           0 :     else if( XML_NAMESPACE_CHART == nPrefix &&
     155           0 :              IsXMLToken( rLocalName, XML_CATEGORIES ) )
     156             :     {
     157           0 :         pContext = new XMLPersAttrListTContext( GetTransformer(), rQName );
     158             : 
     159             :         // put categories at correct axis
     160           0 :         XMLAxisContextVector::iterator aIter = m_aChildContexts.begin();
     161           0 :         bool bFound =false;
     162             : 
     163             :         // iterate over axis elements
     164           0 :         for( ; ! bFound && aIter != m_aChildContexts.end(); ++aIter )
     165             :         {
     166           0 :             XMLAxisOOoContext * pAxisContext = (*aIter).get();
     167           0 :             if( pAxisContext != 0 )
     168             :             {
     169             :                 // iterate over attributes to find category axis
     170           0 :                 Reference< xml::sax::XAttributeList > xNewAttrList( pAxisContext->GetAttrList());
     171           0 :                 sal_Int16 nAttrCount = xNewAttrList.is() ? xNewAttrList->getLength() : 0;
     172             : 
     173           0 :                 for( sal_Int16 i=0; i < nAttrCount; i++ )
     174             :                 {
     175           0 :                     const OUString & rAttrName = xNewAttrList->getNameByIndex( i );
     176           0 :                     OUString aLocalName;
     177             :                     sal_uInt16 nNewPrefix =
     178           0 :                         GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName,
     179           0 :                                                                              &aLocalName );
     180           0 :                     if( nNewPrefix == XML_NAMESPACE_CHART &&
     181           0 :                         pAxisContext->IsCategoryAxis() &&
     182           0 :                         IsXMLToken( aLocalName, XML_DIMENSION ) )
     183             :                     {
     184             :                         // category axis found
     185           0 :                         pAxisContext->AddContent( pContext );
     186           0 :                         bFound = true;
     187             :                         break;
     188             :                     }
     189           0 :                 }
     190             :             }
     191             :         }
     192             :         OSL_ENSURE( bFound, "No suitable axis for categories found." );
     193             :     }
     194             :     else
     195             :     {
     196           0 :         ExportContent();
     197             :         pContext =  XMLProcAttrTransformerContext::CreateChildContext(
     198           0 :             nPrefix, rLocalName, rQName, xAttrList );
     199             :     }
     200             : 
     201           0 :     return pContext;
     202             : }
     203             : 
     204           0 : void XMLChartPlotAreaOOoTContext::EndElement()
     205             : {
     206           0 :     ExportContent();
     207           0 :     XMLProcAttrTransformerContext::EndElement();
     208           0 : }
     209             : 
     210           0 : void XMLChartPlotAreaOOoTContext::AddContent( XMLAxisOOoContext *pContext )
     211             : {
     212             :     OSL_ENSURE( pContext && pContext->IsPersistent(),
     213             :                 "non-persistent context" );
     214           0 :     XMLAxisContextVector::value_type aVal( pContext );
     215           0 :     m_aChildContexts.push_back( aVal );
     216           0 : }
     217             : 
     218             : 
     219           0 : void XMLChartPlotAreaOOoTContext::ExportContent()
     220             : {
     221           0 :     XMLAxisContextVector::iterator aIter = m_aChildContexts.begin();
     222             : 
     223           0 :     for( ; aIter != m_aChildContexts.end(); ++aIter )
     224             :     {
     225           0 :         (*aIter)->Export();
     226             :     }
     227             : 
     228           0 :     m_aChildContexts.clear();
     229           0 : }
     230             : 
     231             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10