LCOV - code coverage report
Current view: top level - xmloff/source/transform - ChartPlotAreaOOoTContext.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 88 92 95.7 %
Date: 2012-08-25 Functions: 12 22 54.5 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 86 160 53.8 %

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

Generated by: LCOV version 1.10