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

Generated by: LCOV version 1.10