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

Generated by: LCOV version 1.10