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

Generated by: LCOV version 1.10