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

Generated by: LCOV version 1.10