LCOV - code coverage report
Current view: top level - sc/source/filter/xml - XMLCalculationSettingsContext.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 106 119 89.1 %
Date: 2014-04-11 Functions: 13 15 86.7 %
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 "XMLCalculationSettingsContext.hxx"
      21             : #include "xmlimprt.hxx"
      22             : #include "unonames.hxx"
      23             : #include "docoptio.hxx"
      24             : #include "document.hxx"
      25             : #include <xmloff/xmltoken.hxx>
      26             : #include <xmloff/xmlnmspe.hxx>
      27             : #include <xmloff/nmspmap.hxx>
      28             : #include <sax/tools/converter.hxx>
      29             : #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
      30             : #include <comphelper/extract.hxx>
      31             : 
      32             : using namespace com::sun::star;
      33             : using namespace xmloff::token;
      34             : 
      35         107 : ScXMLCalculationSettingsContext::ScXMLCalculationSettingsContext( ScXMLImport& rImport,
      36             :                                       sal_uInt16 nPrfx,
      37             :                                       const OUString& rLName,
      38             :                                       const ::com::sun::star::uno::Reference<
      39             :                                       ::com::sun::star::xml::sax::XAttributeList>& xAttrList) :
      40             :     SvXMLImportContext( rImport, nPrfx, rLName ),
      41             :     fIterationEpsilon(0.001),
      42             :     nIterationCount(100),
      43             :     nYear2000(1930),
      44             :     bIsIterationEnabled(false),
      45             :     bCalcAsShown(false),
      46             :     bIgnoreCase(false),
      47             :     bLookUpLabels(true),
      48             :     bMatchWholeCell(true),
      49         107 :     bUseRegularExpressions(true)
      50             : {
      51         107 :     aNullDate.Day = 30;
      52         107 :     aNullDate.Month = 12;
      53         107 :     aNullDate.Year = 1899;
      54         107 :     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
      55         135 :     for( sal_Int16 i=0; i < nAttrCount; ++i )
      56             :     {
      57          28 :         const OUString& sAttrName(xAttrList->getNameByIndex( i ));
      58          56 :         OUString aLocalName;
      59          28 :         sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
      60          28 :                                             sAttrName, &aLocalName );
      61          56 :         const OUString& sValue(xAttrList->getValueByIndex( i ));
      62             : 
      63          28 :         if (nPrefix == XML_NAMESPACE_TABLE)
      64             :         {
      65          28 :             if (IsXMLToken(aLocalName, XML_CASE_SENSITIVE))
      66             :             {
      67          10 :                 if (IsXMLToken(sValue, XML_FALSE))
      68          10 :                     bIgnoreCase = true;
      69             :             }
      70          18 :             else if (IsXMLToken(aLocalName, XML_PRECISION_AS_SHOWN))
      71             :             {
      72           0 :                 if (IsXMLToken(sValue, XML_TRUE))
      73           0 :                     bCalcAsShown = true;
      74             :             }
      75          18 :             else if (IsXMLToken(aLocalName, XML_SEARCH_CRITERIA_MUST_APPLY_TO_WHOLE_CELL))
      76             :             {
      77           0 :                 if (IsXMLToken(sValue, XML_FALSE))
      78           0 :                     bMatchWholeCell = false;
      79             :             }
      80          18 :             else if (IsXMLToken(aLocalName, XML_AUTOMATIC_FIND_LABELS))
      81             :             {
      82           8 :                 if (IsXMLToken(sValue, XML_FALSE))
      83           8 :                     bLookUpLabels = false;
      84             :             }
      85          10 :             else if (IsXMLToken(aLocalName, XML_NULL_YEAR))
      86             :             {
      87             :                 sal_Int32 nTemp;
      88           0 :                 ::sax::Converter::convertNumber(nTemp, sValue);
      89           0 :                 nYear2000 = static_cast<sal_uInt16>(nTemp);
      90             :             }
      91          10 :             else if (IsXMLToken(aLocalName, XML_USE_REGULAR_EXPRESSIONS))
      92             :             {
      93          10 :                 if (IsXMLToken(sValue, XML_FALSE))
      94          10 :                     bUseRegularExpressions = false;
      95             :             }
      96             :         }
      97          28 :     }
      98         107 : }
      99             : 
     100          34 : ScXMLCalculationSettingsContext::~ScXMLCalculationSettingsContext()
     101             : {
     102          34 : }
     103             : 
     104          13 : SvXMLImportContext *ScXMLCalculationSettingsContext::CreateChildContext( sal_uInt16 nPrefix,
     105             :                                             const OUString& rLName,
     106             :                                             const ::com::sun::star::uno::Reference<
     107             :                                           ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
     108             : {
     109          13 :     SvXMLImportContext *pContext = 0;
     110             : 
     111          13 :     if (nPrefix == XML_NAMESPACE_TABLE)
     112             :     {
     113          13 :         if (IsXMLToken(rLName, XML_NULL_DATE))
     114           7 :             pContext = new ScXMLNullDateContext(GetScImport(), nPrefix, rLName, xAttrList, this);
     115           6 :         else if (IsXMLToken(rLName, XML_ITERATION))
     116           6 :             pContext = new ScXMLIterationContext(GetScImport(), nPrefix, rLName, xAttrList, this);
     117             :     }
     118             : 
     119          13 :     if( !pContext )
     120           0 :         pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
     121             : 
     122          13 :     return pContext;
     123             : }
     124             : 
     125         107 : void ScXMLCalculationSettingsContext::EndElement()
     126             : {
     127         107 :     if (GetScImport().GetModel().is())
     128             :     {
     129         107 :         uno::Reference <beans::XPropertySet> xPropertySet (GetScImport().GetModel(), uno::UNO_QUERY);
     130         107 :         if (xPropertySet.is())
     131             :         {
     132         107 :             xPropertySet->setPropertyValue(OUString(SC_UNO_CALCASSHOWN), uno::makeAny(bCalcAsShown) );
     133         107 :             xPropertySet->setPropertyValue(OUString(SC_UNO_IGNORECASE), uno::makeAny(bIgnoreCase) );
     134         107 :             xPropertySet->setPropertyValue(OUString(SC_UNO_LOOKUPLABELS), uno::makeAny(bLookUpLabels) );
     135         107 :             xPropertySet->setPropertyValue(OUString(SC_UNO_MATCHWHOLE), uno::makeAny(bMatchWholeCell) );
     136         107 :             xPropertySet->setPropertyValue(OUString(SC_UNO_REGEXENABLED), uno::makeAny(bUseRegularExpressions) );
     137         107 :             xPropertySet->setPropertyValue(OUString(SC_UNO_ITERENABLED), uno::makeAny(bIsIterationEnabled) );
     138         107 :             xPropertySet->setPropertyValue( OUString(SC_UNO_ITERCOUNT), uno::makeAny(nIterationCount) );
     139         107 :             xPropertySet->setPropertyValue( OUString(SC_UNO_ITEREPSILON), uno::makeAny(fIterationEpsilon) );
     140         107 :             xPropertySet->setPropertyValue( OUString(SC_UNO_NULLDATE), uno::makeAny(aNullDate) );
     141         107 :             if (GetScImport().GetDocument())
     142             :             {
     143         107 :                 ScXMLImport::MutexGuard aGuard(GetScImport());
     144         214 :                 ScDocOptions aDocOptions (GetScImport().GetDocument()->GetDocOptions());
     145         107 :                 aDocOptions.SetYear2000(nYear2000);
     146         214 :                 GetScImport().GetDocument()->SetDocOptions(aDocOptions);
     147             :             }
     148         107 :         }
     149             :     }
     150         107 : }
     151             : 
     152           7 : ScXMLNullDateContext::ScXMLNullDateContext( ScXMLImport& rImport,
     153             :                                       sal_uInt16 nPrfx,
     154             :                                       const OUString& rLName,
     155             :                                       const ::com::sun::star::uno::Reference<
     156             :                                       ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
     157             :                                       ScXMLCalculationSettingsContext* pCalcSet) :
     158           7 :     SvXMLImportContext( rImport, nPrfx, rLName )
     159             : {
     160           7 :     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
     161          14 :     for( sal_Int16 i=0; i < nAttrCount; ++i )
     162             :     {
     163           7 :         const OUString& sAttrName(xAttrList->getNameByIndex( i ));
     164          14 :         OUString aLocalName;
     165           7 :         sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
     166           7 :                                             sAttrName, &aLocalName );
     167          14 :         const OUString& sValue(xAttrList->getValueByIndex( i ));
     168             : 
     169           7 :         if (nPrefix == XML_NAMESPACE_TABLE && IsXMLToken(aLocalName, XML_DATE_VALUE))
     170             :         {
     171           7 :             util::DateTime aDateTime;
     172           7 :             ::sax::Converter::parseDateTime(aDateTime, 0, sValue);
     173           7 :             util::Date aDate;
     174           7 :             aDate.Day = aDateTime.Day;
     175           7 :             aDate.Month = aDateTime.Month;
     176           7 :             aDate.Year = aDateTime.Year;
     177           7 :             pCalcSet->SetNullDate(aDate);
     178             :         }
     179           7 :     }
     180           7 : }
     181             : 
     182          14 : ScXMLNullDateContext::~ScXMLNullDateContext()
     183             : {
     184          14 : }
     185             : 
     186           0 : SvXMLImportContext *ScXMLNullDateContext::CreateChildContext( sal_uInt16 nPrefix,
     187             :                                             const OUString& rLName,
     188             :                                             const ::com::sun::star::uno::Reference<
     189             :                                         ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ )
     190             : {
     191           0 :     SvXMLImportContext *pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
     192             : 
     193           0 :     return pContext;
     194             : }
     195             : 
     196           7 : void ScXMLNullDateContext::EndElement()
     197             : {
     198           7 : }
     199             : 
     200           6 : ScXMLIterationContext::ScXMLIterationContext( ScXMLImport& rImport,
     201             :                                       sal_uInt16 nPrfx,
     202             :                                       const OUString& rLName,
     203             :                                       const ::com::sun::star::uno::Reference<
     204             :                                       ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
     205             :                                       ScXMLCalculationSettingsContext* pCalcSet) :
     206           6 :     SvXMLImportContext( rImport, nPrfx, rLName )
     207             : {
     208           6 :     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
     209          16 :     for( sal_Int16 i=0; i < nAttrCount; ++i )
     210             :     {
     211          10 :         const OUString& sAttrName(xAttrList->getNameByIndex( i ));
     212          20 :         OUString aLocalName;
     213          10 :         sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
     214          10 :                                             sAttrName, &aLocalName );
     215          20 :         const OUString& sValue(xAttrList->getValueByIndex( i ));
     216             : 
     217          10 :         if (nPrefix == XML_NAMESPACE_TABLE)
     218             :         {
     219          10 :             if (IsXMLToken(aLocalName, XML_STATUS))
     220             :             {
     221           3 :                 if (IsXMLToken(sValue, XML_ENABLE))
     222           3 :                     pCalcSet->SetIterationStatus(true);
     223             :             }
     224           7 :             else if (IsXMLToken(aLocalName, XML_STEPS))
     225             :             {
     226             :                 sal_Int32 nSteps;
     227           3 :                 ::sax::Converter::convertNumber(nSteps, sValue);
     228           3 :                 pCalcSet->SetIterationCount(nSteps);
     229             :             }
     230           4 :             else if (IsXMLToken(aLocalName, XML_MAXIMUM_DIFFERENCE))
     231             :             {
     232             :                 double fDif;
     233           4 :                 ::sax::Converter::convertDouble(fDif, sValue);
     234           4 :                 pCalcSet->SetIterationEpsilon(fDif);
     235             :             }
     236             :         }
     237          10 :     }
     238           6 : }
     239             : 
     240          12 : ScXMLIterationContext::~ScXMLIterationContext()
     241             : {
     242          12 : }
     243             : 
     244           0 : SvXMLImportContext *ScXMLIterationContext::CreateChildContext( sal_uInt16 nPrefix,
     245             :                                             const OUString& rLName,
     246             :                                             const ::com::sun::star::uno::Reference<
     247             :                                         ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ )
     248             : {
     249           0 :     SvXMLImportContext *pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
     250             : 
     251           0 :     return pContext;
     252             : }
     253             : 
     254           6 : void ScXMLIterationContext::EndElement()
     255             : {
     256           6 : }
     257             : 
     258             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10