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

Generated by: LCOV version 1.10