LCOV - code coverage report
Current view: top level - sc/source/filter/xml - xmlnexpi.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 86 93 92.5 %
Date: 2012-08-25 Functions: 17 19 89.5 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 50 98 51.0 %

           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 <rtl/ustrbuf.hxx>
      30                 :            : 
      31                 :            : #include "xmlnexpi.hxx"
      32                 :            : #include "xmlimprt.hxx"
      33                 :            : #include "xmlcelli.hxx"
      34                 :            : #include "docuno.hxx"
      35                 :            : #include "document.hxx"
      36                 :            : 
      37                 :            : #include <xmloff/xmltkmap.hxx>
      38                 :            : #include <xmloff/nmspmap.hxx>
      39                 :            : 
      40                 :            : using namespace com::sun::star;
      41                 :            : 
      42                 :            : //------------------------------------------------------------------
      43                 :            : 
      44                 :         51 : ScXMLNamedExpressionsContext::GlobalInserter::GlobalInserter(ScXMLImport& rImport) : mrImport(rImport) {}
      45                 :            : 
      46                 :         56 : void ScXMLNamedExpressionsContext::GlobalInserter::insert(ScMyNamedExpression* pExp)
      47                 :            : {
      48         [ +  - ]:         56 :     if (pExp)
      49                 :         56 :         mrImport.AddNamedExpression(pExp);
      50                 :         56 : }
      51                 :            : 
      52                 :         12 : ScXMLNamedExpressionsContext::SheetLocalInserter::SheetLocalInserter(ScXMLImport& rImport, SCTAB nTab) :
      53                 :         12 :     mrImport(rImport), mnTab(nTab) {}
      54                 :            : 
      55                 :         18 : void ScXMLNamedExpressionsContext::SheetLocalInserter::insert(ScMyNamedExpression* pExp)
      56                 :            : {
      57                 :         18 :     mrImport.AddNamedExpression(mnTab, pExp);
      58                 :         18 : }
      59                 :            : 
      60                 :         63 : ScXMLNamedExpressionsContext::ScXMLNamedExpressionsContext(
      61                 :            :     ScXMLImport& rImport, sal_uInt16 nPrfx, const ::rtl::OUString& rLName,
      62                 :            :     const uno::Reference<xml::sax::XAttributeList>& /* xAttrList */,
      63                 :            :     Inserter* pInserter ) :
      64                 :            :     SvXMLImportContext( rImport, nPrfx, rLName ),
      65         [ +  - ]:         63 :     mpInserter(pInserter)
      66                 :            : {
      67         [ +  - ]:         63 :     rImport.LockSolarMutex();
      68                 :         63 : }
      69                 :            : 
      70         [ +  - ]:         63 : ScXMLNamedExpressionsContext::~ScXMLNamedExpressionsContext()
      71                 :            : {
      72         [ +  - ]:         63 :     GetScImport().UnlockSolarMutex();
      73         [ -  + ]:        126 : }
      74                 :            : 
      75                 :         74 : SvXMLImportContext *ScXMLNamedExpressionsContext::CreateChildContext( sal_uInt16 nPrefix,
      76                 :            :                                             const ::rtl::OUString& rLName,
      77                 :            :                                             const ::com::sun::star::uno::Reference<
      78                 :            :                                           ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
      79                 :            : {
      80                 :         74 :     SvXMLImportContext *pContext(0);
      81                 :            : 
      82                 :         74 :     const SvXMLTokenMap& rTokenMap(GetScImport().GetNamedExpressionsElemTokenMap());
      83      [ +  +  - ]:         74 :     switch( rTokenMap.Get( nPrefix, rLName ) )
      84                 :            :     {
      85                 :            :     case XML_TOK_NAMED_EXPRESSIONS_NAMED_RANGE:
      86                 :            :         pContext = new ScXMLNamedRangeContext(
      87         [ +  - ]:         68 :             GetScImport(), nPrefix, rLName, xAttrList, mpInserter.get() );
      88                 :         68 :         break;
      89                 :            :     case XML_TOK_NAMED_EXPRESSIONS_NAMED_EXPRESSION:
      90                 :            :         pContext = new ScXMLNamedExpressionContext(
      91         [ +  - ]:          6 :             GetScImport(), nPrefix, rLName, xAttrList, mpInserter.get() );
      92                 :          6 :         break;
      93                 :            :     }
      94                 :            : 
      95         [ -  + ]:         74 :     if( !pContext )
      96         [ #  # ]:          0 :         pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
      97                 :            : 
      98                 :         74 :     return pContext;
      99                 :            : }
     100                 :            : 
     101                 :         63 : void ScXMLNamedExpressionsContext::EndElement()
     102                 :            : {
     103                 :            :     // happends in ScXMLImport::EndDocument()
     104                 :            :     // because it has to be set after the Database Ranges
     105                 :         63 : }
     106                 :            : 
     107                 :         68 : ScXMLNamedRangeContext::ScXMLNamedRangeContext(
     108                 :            :     ScXMLImport& rImport,
     109                 :            :     sal_uInt16 nPrfx,
     110                 :            :     const ::rtl::OUString& rLName,
     111                 :            :     const uno::Reference<xml::sax::XAttributeList>& xAttrList,
     112                 :            :     ScXMLNamedExpressionsContext::Inserter* pInserter ) :
     113                 :            :     SvXMLImportContext( rImport, nPrfx, rLName ),
     114                 :         68 :     mpInserter(pInserter)
     115                 :            : {
     116         [ -  + ]:         68 :     if (!mpInserter)
     117                 :         68 :         return;
     118                 :            : 
     119         [ +  - ]:         68 :     ScMyNamedExpression* pNamedExpression(new ScMyNamedExpression);
     120                 :            :     // A simple table:cell-range-address is not a formula expression, stored
     121                 :            :     // without [] brackets but with dot, .A1
     122                 :            :     pNamedExpression->eGrammar = formula::FormulaGrammar::mergeToGrammar(
     123                 :         68 :             GetScImport().GetDocument()->GetStorageGrammar(),
     124                 :         68 :             formula::FormulaGrammar::CONV_OOO);
     125 [ +  - ][ +  - ]:         68 :     sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
                 [ +  - ]
     126         [ +  - ]:         68 :     const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetNamedRangeAttrTokenMap();
     127         [ +  + ]:        272 :     for( sal_Int16 i=0; i < nAttrCount; ++i )
     128                 :            :     {
     129 [ +  - ][ +  - ]:        204 :         const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
     130                 :        204 :         rtl::OUString aLocalName;
     131                 :        204 :         sal_uInt16 nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
     132         [ +  - ]:        204 :                                             sAttrName, &aLocalName ));
     133 [ +  - ][ +  - ]:        204 :         const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
     134                 :            : 
     135 [ +  - ][ +  +  :        204 :         switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
                +  -  - ]
     136                 :            :         {
     137                 :            :             case XML_TOK_NAMED_RANGE_ATTR_NAME :
     138                 :            :             {
     139                 :         68 :                 pNamedExpression->sName = sValue;
     140                 :            :             }
     141                 :         68 :             break;
     142                 :            :             case XML_TOK_NAMED_RANGE_ATTR_CELL_RANGE_ADDRESS :
     143                 :            :             {
     144                 :         68 :                 pNamedExpression->sContent = sValue;
     145                 :            :             }
     146                 :         68 :             break;
     147                 :            :             case XML_TOK_NAMED_RANGE_ATTR_BASE_CELL_ADDRESS :
     148                 :            :             {
     149                 :         68 :                 pNamedExpression->sBaseCellAddress = sValue;
     150                 :            :             }
     151                 :         68 :             break;
     152                 :            :             case XML_TOK_NAMED_RANGE_ATTR_RANGE_USABLE_AS :
     153                 :            :             {
     154                 :          0 :                 pNamedExpression->sRangeType = sValue;
     155                 :            :             }
     156                 :          0 :             break;
     157                 :            :         }
     158                 :        204 :     }
     159                 :         68 :     pNamedExpression->bIsExpression = sal_False;
     160         [ +  - ]:         68 :     mpInserter->insert(pNamedExpression);
     161                 :            : }
     162                 :            : 
     163                 :         68 : ScXMLNamedRangeContext::~ScXMLNamedRangeContext()
     164                 :            : {
     165         [ -  + ]:        136 : }
     166                 :            : 
     167                 :          0 : SvXMLImportContext *ScXMLNamedRangeContext::CreateChildContext( sal_uInt16 nPrefix,
     168                 :            :                                             const ::rtl::OUString& rLName,
     169                 :            :                                             const ::com::sun::star::uno::Reference<
     170                 :            :                                         ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ )
     171                 :            : {
     172         [ #  # ]:          0 :     return new SvXMLImportContext( GetImport(), nPrefix, rLName );
     173                 :            : }
     174                 :            : 
     175                 :         68 : void ScXMLNamedRangeContext::EndElement()
     176                 :            : {
     177                 :         68 : }
     178                 :            : 
     179                 :          6 : ScXMLNamedExpressionContext::ScXMLNamedExpressionContext(
     180                 :            :     ScXMLImport& rImport, sal_uInt16 nPrfx, const ::rtl::OUString& rLName,
     181                 :            :     const uno::Reference<xml::sax::XAttributeList>& xAttrList,
     182                 :            :     ScXMLNamedExpressionsContext::Inserter* pInserter ) :
     183                 :            :     SvXMLImportContext( rImport, nPrfx, rLName ),
     184                 :          6 :     mpInserter(pInserter)
     185                 :            : {
     186         [ -  + ]:          6 :     if (!mpInserter)
     187                 :          6 :         return;
     188                 :            : 
     189         [ +  - ]:          6 :     ScMyNamedExpression* pNamedExpression(new ScMyNamedExpression);
     190 [ +  - ][ +  - ]:          6 :     sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
                 [ +  - ]
     191         [ +  - ]:          6 :     const SvXMLTokenMap& rAttrTokenMap(GetScImport().GetNamedExpressionAttrTokenMap());
     192         [ +  + ]:         24 :     for( sal_Int16 i=0; i < nAttrCount; ++i )
     193                 :            :     {
     194 [ +  - ][ +  - ]:         18 :         const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
     195                 :         18 :         rtl::OUString aLocalName;
     196                 :         18 :         sal_uInt16 nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
     197         [ +  - ]:         18 :                                             sAttrName, &aLocalName ));
     198 [ +  - ][ +  - ]:         18 :         const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
     199                 :            : 
     200         [ +  - ]:         18 :         switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
           [ +  +  +  - ]
     201                 :            :         {
     202                 :            :             case XML_TOK_NAMED_EXPRESSION_ATTR_NAME :
     203                 :            :             {
     204                 :          6 :                 pNamedExpression->sName = sValue;
     205                 :            :             }
     206                 :          6 :             break;
     207                 :            :             case XML_TOK_NAMED_EXPRESSION_ATTR_EXPRESSION :
     208                 :            :             {
     209                 :          6 :                 GetScImport().ExtractFormulaNamespaceGrammar(
     210                 :            :                     pNamedExpression->sContent, pNamedExpression->sContentNmsp,
     211         [ +  - ]:          6 :                     pNamedExpression->eGrammar, sValue );
     212                 :            :             }
     213                 :          6 :             break;
     214                 :            :             case XML_TOK_NAMED_EXPRESSION_ATTR_BASE_CELL_ADDRESS :
     215                 :            :             {
     216                 :          6 :                 pNamedExpression->sBaseCellAddress = sValue;
     217                 :            :             }
     218                 :          6 :             break;
     219                 :            :         }
     220                 :         18 :     }
     221                 :          6 :     pNamedExpression->bIsExpression = true;
     222         [ +  - ]:          6 :     mpInserter->insert(pNamedExpression);
     223                 :            : }
     224                 :            : 
     225                 :          6 : ScXMLNamedExpressionContext::~ScXMLNamedExpressionContext()
     226                 :            : {
     227         [ -  + ]:         12 : }
     228                 :            : 
     229                 :          0 : SvXMLImportContext *ScXMLNamedExpressionContext::CreateChildContext( sal_uInt16 nPrefix,
     230                 :            :                                             const ::rtl::OUString& rLName,
     231                 :            :                                             const ::com::sun::star::uno::Reference<
     232                 :            :                                         ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ )
     233                 :            : {
     234         [ #  # ]:          0 :     return new SvXMLImportContext( GetImport(), nPrefix, rLName );;
     235                 :            : }
     236                 :            : 
     237                 :          6 : void ScXMLNamedExpressionContext::EndElement()
     238                 :            : {
     239                 :          6 : }
     240                 :            : 
     241                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10