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

Generated by: LCOV version 1.11