LCOV - code coverage report
Current view: top level - xmloff/source/style - numehelp.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 45 229 19.7 %
Date: 2012-08-25 Functions: 5 14 35.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 40 374 10.7 %

           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                 :            : 
      30                 :            : #include "xmloff/numehelp.hxx"
      31                 :            : 
      32                 :            : #include <xmloff/nmspmap.hxx>
      33                 :            : #include "xmloff/xmlnmspe.hxx"
      34                 :            : #include <xmloff/xmluconv.hxx>
      35                 :            : #include <xmloff/xmltoken.hxx>
      36                 :            : #include <xmloff/xmlexp.hxx>
      37                 :            : #include <com/sun/star/uno/Reference.h>
      38                 :            : #include <rtl/ustring.hxx>
      39                 :            : #include <svl/zforlist.hxx>
      40                 :            : #include <com/sun/star/util/NumberFormat.hpp>
      41                 :            : #include <sax/tools/converter.hxx>
      42                 :            : #include <rtl/math.hxx>
      43                 :            : #include <rtl/ustrbuf.hxx>
      44                 :            : 
      45                 :            : using namespace com::sun::star;
      46                 :            : using namespace xmloff::token;
      47                 :            : 
      48                 :            : #define XML_TYPE "Type"
      49                 :            : #define XML_CURRENCYSYMBOL "CurrencySymbol"
      50                 :            : #define XML_CURRENCYABBREVIATION "CurrencyAbbreviation"
      51                 :            : #define XML_STANDARDFORMAT "StandardFormat"
      52                 :            : 
      53                 :         55 : XMLNumberFormatAttributesExportHelper::XMLNumberFormatAttributesExportHelper(
      54                 :            :             ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatsSupplier >& xTempNumberFormatsSupplier)
      55                 :        110 :     : xNumberFormats(xTempNumberFormatsSupplier.is() ? xTempNumberFormatsSupplier->getNumberFormats() : ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormats > ()),
      56                 :            :     pExport(NULL),
      57                 :            :     sStandardFormat(RTL_CONSTASCII_USTRINGPARAM(XML_STANDARDFORMAT)),
      58                 :            :     sType(RTL_CONSTASCII_USTRINGPARAM(XML_TYPE)),
      59                 :            :     msCurrencySymbol(RTL_CONSTASCII_USTRINGPARAM(XML_CURRENCYSYMBOL)),
      60                 :            :     msCurrencyAbbreviation(RTL_CONSTASCII_USTRINGPARAM(XML_CURRENCYABBREVIATION)),
      61 [ +  - ][ +  - ]:        110 :     aNumberFormats()
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
      62                 :            : {
      63                 :         55 : }
      64                 :            : 
      65                 :          0 : XMLNumberFormatAttributesExportHelper::XMLNumberFormatAttributesExportHelper(
      66                 :            :             ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatsSupplier >& xTempNumberFormatsSupplier,
      67                 :            :             SvXMLExport& rTempExport )
      68                 :          0 : :   xNumberFormats(xTempNumberFormatsSupplier.is() ? xTempNumberFormatsSupplier->getNumberFormats() : ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormats > ()),
      69                 :            :     pExport(&rTempExport),
      70                 :            :     sStandardFormat(RTL_CONSTASCII_USTRINGPARAM(XML_STANDARDFORMAT)),
      71                 :            :     sType(RTL_CONSTASCII_USTRINGPARAM(XML_TYPE)),
      72         [ #  # ]:          0 :     sAttrValueType(rTempExport.GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_OFFICE, GetXMLToken(XML_VALUE_TYPE))),
      73         [ #  # ]:          0 :     sAttrValue(rTempExport.GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_OFFICE, GetXMLToken(XML_VALUE))),
      74         [ #  # ]:          0 :     sAttrDateValue(rTempExport.GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_OFFICE, GetXMLToken(XML_DATE_VALUE))),
      75         [ #  # ]:          0 :     sAttrTimeValue(rTempExport.GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_OFFICE, GetXMLToken(XML_TIME_VALUE))),
      76         [ #  # ]:          0 :     sAttrBooleanValue(rTempExport.GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_OFFICE, GetXMLToken(XML_BOOLEAN_VALUE))),
      77         [ #  # ]:          0 :     sAttrStringValue(rTempExport.GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_OFFICE, GetXMLToken(XML_STRING_VALUE))),
      78         [ #  # ]:          0 :     sAttrCurrency(rTempExport.GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_OFFICE, GetXMLToken(XML_CURRENCY))),
      79                 :            :     msCurrencySymbol(RTL_CONSTASCII_USTRINGPARAM(XML_CURRENCYSYMBOL)),
      80                 :            :     msCurrencyAbbreviation(RTL_CONSTASCII_USTRINGPARAM(XML_CURRENCYABBREVIATION)),
      81 [ #  # ][ #  #  :          0 :     aNumberFormats()
          #  #  #  #  #  
          #  #  #  #  #  
             #  #  #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      82                 :            : {
      83                 :          0 : }
      84                 :            : 
      85                 :         55 : XMLNumberFormatAttributesExportHelper::~XMLNumberFormatAttributesExportHelper()
      86                 :            : {
      87                 :         55 : }
      88                 :            : 
      89                 :        228 : sal_Int16 XMLNumberFormatAttributesExportHelper::GetCellType(const sal_Int32 nNumberFormat, rtl::OUString& sCurrency, bool& bIsStandard)
      90                 :            : {
      91                 :        228 :     XMLNumberFormat aFormat(sEmpty, nNumberFormat, 0);
      92         [ +  - ]:        228 :     XMLNumberFormatSet::iterator aItr(aNumberFormats.find(aFormat));
      93                 :        228 :     XMLNumberFormatSet::iterator aEndItr(aNumberFormats.end());
      94         [ +  + ]:        228 :     if (aItr != aEndItr)
      95                 :            :     {
      96                 :        131 :         bIsStandard = aItr->bIsStandard;
      97                 :        131 :         sCurrency = aItr->sCurrency;
      98                 :        131 :         return aItr->nType;
      99                 :            :     }
     100                 :            :     else
     101                 :            :     {
     102         [ +  - ]:         97 :         aFormat.nType = GetCellType(nNumberFormat, bIsStandard);
     103                 :         97 :         aFormat.bIsStandard = bIsStandard;
     104         [ +  + ]:         97 :         if ((aFormat.nType & ~util::NumberFormat::DEFINED) == util::NumberFormat::CURRENCY)
     105 [ +  - ][ +  - ]:          3 :             if (GetCurrencySymbol(nNumberFormat, aFormat.sCurrency))
     106                 :          3 :                 sCurrency = aFormat.sCurrency;
     107         [ +  - ]:         97 :         aNumberFormats.insert(aFormat);
     108                 :         97 :         return aFormat.nType;
     109                 :        228 :     }
     110                 :            : }
     111                 :            : 
     112                 :          0 : void XMLNumberFormatAttributesExportHelper::WriteAttributes(SvXMLExport& rXMLExport,
     113                 :            :                                 const sal_Int16 nTypeKey,
     114                 :            :                                 const double& rValue,
     115                 :            :                                 const rtl::OUString& rCurrency,
     116                 :            :                                 sal_Bool bExportValue)
     117                 :            : {
     118                 :          0 :     sal_Bool bWasSetTypeAttribute = sal_False;
     119   [ #  #  #  #  :          0 :     switch(nTypeKey & ~util::NumberFormat::DEFINED)
             #  #  #  # ]
     120                 :            :     {
     121                 :            :     case 0:
     122                 :            :     case util::NumberFormat::NUMBER:
     123                 :            :     case util::NumberFormat::SCIENTIFIC:
     124                 :            :     case util::NumberFormat::FRACTION:
     125                 :            :         {
     126         [ #  # ]:          0 :             if (!bWasSetTypeAttribute)
     127                 :            :             {
     128                 :          0 :                 rXMLExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_VALUE_TYPE, XML_FLOAT);
     129                 :          0 :                 bWasSetTypeAttribute = sal_True;
     130                 :            :             }
     131                 :            :         }       // No Break
     132                 :            :     case util::NumberFormat::PERCENT:
     133                 :            :         {
     134         [ #  # ]:          0 :             if (!bWasSetTypeAttribute)
     135                 :            :             {
     136                 :          0 :                 rXMLExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_VALUE_TYPE, XML_PERCENTAGE);
     137                 :          0 :                 bWasSetTypeAttribute = sal_True;
     138                 :            :             }
     139                 :            :         }       // No Break
     140                 :            :     case util::NumberFormat::CURRENCY:
     141                 :            :         {
     142         [ #  # ]:          0 :             if (!bWasSetTypeAttribute)
     143                 :            :             {
     144                 :          0 :                 rXMLExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_VALUE_TYPE, XML_CURRENCY);
     145         [ #  # ]:          0 :                 if (!rCurrency.isEmpty())
     146                 :          0 :                     rXMLExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_CURRENCY, rCurrency);
     147                 :          0 :                 bWasSetTypeAttribute = sal_True;
     148                 :            :             }
     149                 :            : 
     150         [ #  # ]:          0 :             if (bExportValue)
     151                 :            :             {
     152                 :            :                 rtl::OUString sValue( ::rtl::math::doubleToUString( rValue,
     153                 :            :                             rtl_math_StringFormat_Automatic,
     154                 :          0 :                             rtl_math_DecimalPlaces_Max, '.', sal_True));
     155         [ #  # ]:          0 :                 rXMLExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_VALUE, sValue);
     156                 :            :             }
     157                 :            :         }
     158                 :          0 :         break;
     159                 :            :     case util::NumberFormat::DATE:
     160                 :            :     case util::NumberFormat::DATETIME:
     161                 :            :         {
     162         [ #  # ]:          0 :             if (!bWasSetTypeAttribute)
     163                 :            :             {
     164                 :          0 :                 rXMLExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_VALUE_TYPE, XML_DATE);
     165                 :          0 :                 bWasSetTypeAttribute = sal_True;
     166                 :            :             }
     167         [ #  # ]:          0 :             if (bExportValue)
     168                 :            :             {
     169         [ #  # ]:          0 :                 if ( rXMLExport.SetNullDateOnUnitConverter() )
     170                 :            :                 {
     171                 :          0 :                     rtl::OUStringBuffer sBuffer;
     172         [ #  # ]:          0 :                     rXMLExport.GetMM100UnitConverter().convertDateTime(sBuffer, rValue);
     173 [ #  # ][ #  # ]:          0 :                     rXMLExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_DATE_VALUE, sBuffer.makeStringAndClear());
     174                 :            :                 }
     175                 :            :             }
     176                 :            :         }
     177                 :          0 :         break;
     178                 :            :     case util::NumberFormat::TIME:
     179                 :            :         {
     180         [ #  # ]:          0 :             if (!bWasSetTypeAttribute)
     181                 :            :             {
     182                 :          0 :                 rXMLExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_VALUE_TYPE, XML_TIME);
     183                 :          0 :                 bWasSetTypeAttribute = sal_True;
     184                 :            :             }
     185         [ #  # ]:          0 :             if (bExportValue)
     186                 :            :             {
     187                 :          0 :                 rtl::OUStringBuffer sBuffer;
     188         [ #  # ]:          0 :                 ::sax::Converter::convertDuration(sBuffer, rValue);
     189 [ #  # ][ #  # ]:          0 :                 rXMLExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_TIME_VALUE, sBuffer.makeStringAndClear());
     190                 :            :             }
     191                 :            :         }
     192                 :          0 :         break;
     193                 :            :     case util::NumberFormat::LOGICAL:
     194                 :            :         {
     195         [ #  # ]:          0 :             if (!bWasSetTypeAttribute)
     196                 :            :             {
     197                 :          0 :                 rXMLExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_VALUE_TYPE, XML_BOOLEAN);
     198                 :          0 :                 bWasSetTypeAttribute = sal_True;
     199                 :            :             }
     200         [ #  # ]:          0 :             if (bExportValue)
     201                 :            :             {
     202                 :          0 :                 double fTempValue = rValue;
     203         [ #  # ]:          0 :                 if (::rtl::math::approxEqual( fTempValue, 1.0 ))
     204                 :            :                 {
     205                 :          0 :                     rXMLExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_BOOLEAN_VALUE, XML_TRUE);
     206                 :            :                 }
     207                 :            :                 else
     208                 :            :                 {
     209         [ #  # ]:          0 :                     if (::rtl::math::approxEqual( rValue, 0.0 ))
     210                 :            :                     {
     211                 :          0 :                         rXMLExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_BOOLEAN_VALUE, XML_FALSE);
     212                 :            :                     }
     213                 :            :                     else
     214                 :            :                     {
     215                 :            :                         rtl::OUString sValue( ::rtl::math::doubleToUString(
     216                 :            :                                     fTempValue,
     217                 :            :                                     rtl_math_StringFormat_Automatic,
     218                 :            :                                     rtl_math_DecimalPlaces_Max, '.',
     219                 :          0 :                                     sal_True));
     220         [ #  # ]:          0 :                         rXMLExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_BOOLEAN_VALUE, sValue);
     221                 :            :                     }
     222                 :            :                 }
     223                 :            :             }
     224                 :            :         }
     225                 :          0 :         break;
     226                 :            :     case util::NumberFormat::TEXT:
     227                 :            :         {
     228         [ #  # ]:          0 :             if (!bWasSetTypeAttribute)
     229                 :            :             {
     230                 :          0 :                 rXMLExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_VALUE_TYPE, XML_FLOAT);
     231                 :          0 :                 bWasSetTypeAttribute = sal_True;
     232         [ #  # ]:          0 :                 if (bExportValue)
     233                 :            :                 {
     234                 :            :                     rtl::OUString sValue( ::rtl::math::doubleToUString( rValue,
     235                 :            :                                 rtl_math_StringFormat_Automatic,
     236                 :          0 :                                 rtl_math_DecimalPlaces_Max, '.', sal_True));
     237         [ #  # ]:          0 :                     rXMLExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_VALUE, sValue);
     238                 :            :                 }
     239                 :            :             }
     240                 :            :         }
     241                 :          0 :         break;
     242                 :            :     }
     243                 :          0 : }
     244                 :            : 
     245                 :          0 : sal_Bool XMLNumberFormatAttributesExportHelper::GetCurrencySymbol(const sal_Int32 nNumberFormat, rtl::OUString& sCurrencySymbol,
     246                 :            :     uno::Reference <util::XNumberFormatsSupplier>& xNumberFormatsSupplier)
     247                 :            : {
     248         [ #  # ]:          0 :     if (xNumberFormatsSupplier.is())
     249                 :            :     {
     250 [ #  # ][ #  # ]:          0 :         uno::Reference <util::XNumberFormats> xNumberFormats(xNumberFormatsSupplier->getNumberFormats());
     251         [ #  # ]:          0 :         if (xNumberFormats.is())
     252                 :            :         {
     253                 :            :             try
     254                 :            :             {
     255 [ #  # ][ #  # ]:          0 :                 uno::Reference <beans::XPropertySet> xNumberPropertySet(xNumberFormats->getByKey(nNumberFormat));
     256 [ #  # ][ #  # ]:          0 :                 if ( xNumberPropertySet->getPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(XML_CURRENCYSYMBOL))) >>= sCurrencySymbol)
         [ #  # ][ #  # ]
     257                 :            :                 {
     258                 :          0 :                     rtl::OUString sCurrencyAbbreviation;
     259 [ #  # ][ #  # ]:          0 :                     if ( xNumberPropertySet->getPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(XML_CURRENCYABBREVIATION))) >>= sCurrencyAbbreviation)
         [ #  # ][ #  # ]
     260                 :            :                     {
     261         [ #  # ]:          0 :                         if ( !sCurrencyAbbreviation.isEmpty())
     262                 :          0 :                             sCurrencySymbol = sCurrencyAbbreviation;
     263                 :            :                         else
     264                 :            :                         {
     265 [ #  # ][ #  # ]:          0 :                             if ( sCurrencySymbol.getLength() == 1 && sCurrencySymbol.toChar() == NfCurrencyEntry::GetEuroSymbol() )
                 [ #  # ]
     266         [ #  # ]:          0 :                                 sCurrencySymbol = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("EUR"));
     267                 :            :                         }
     268                 :            :                     }
     269                 :          0 :                     return sal_True;
     270 [ #  # ][ #  # ]:          0 :                 }
     271                 :            :             }
     272         [ #  # ]:          0 :             catch ( uno::Exception& )
     273                 :            :             {
     274                 :            :                 OSL_FAIL("Numberformat not found");
     275                 :            :             }
     276         [ #  # ]:          0 :         }
     277                 :            :     }
     278                 :          0 :     return sal_False;
     279                 :            : }
     280                 :            : 
     281                 :            : 
     282                 :          0 : sal_Int16 XMLNumberFormatAttributesExportHelper::GetCellType(const sal_Int32 nNumberFormat, sal_Bool& bIsStandard,
     283                 :            :     uno::Reference <util::XNumberFormatsSupplier>& xNumberFormatsSupplier)
     284                 :            : {
     285         [ #  # ]:          0 :     if (xNumberFormatsSupplier.is())
     286                 :            :     {
     287 [ #  # ][ #  # ]:          0 :         uno::Reference <util::XNumberFormats> xNumberFormats(xNumberFormatsSupplier->getNumberFormats());
     288         [ #  # ]:          0 :         if (xNumberFormats.is())
     289                 :            :         {
     290                 :            :             try
     291                 :            :             {
     292 [ #  # ][ #  # ]:          0 :                 uno::Reference <beans::XPropertySet> xNumberPropertySet(xNumberFormats->getByKey(nNumberFormat));
     293 [ #  # ][ #  # ]:          0 :                 xNumberPropertySet->getPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(XML_STANDARDFORMAT))) >>= bIsStandard;
                 [ #  # ]
     294                 :          0 :                 sal_Int16 nNumberType = sal_Int16();
     295 [ #  # ][ #  # ]:          0 :                 if ( xNumberPropertySet->getPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(XML_TYPE))) >>= nNumberType )
         [ #  # ][ #  # ]
     296                 :            :                 {
     297                 :          0 :                     return nNumberType;
     298 [ #  # ][ #  # ]:          0 :                 }
     299                 :            :             }
     300         [ #  # ]:          0 :             catch ( uno::Exception& )
     301                 :            :             {
     302                 :            :                 OSL_FAIL("Numberformat not found");
     303                 :            :             }
     304         [ #  # ]:          0 :         }
     305                 :            :     }
     306                 :          0 :     return 0;
     307                 :            : }
     308                 :            : 
     309                 :          0 : void XMLNumberFormatAttributesExportHelper::SetNumberFormatAttributes(SvXMLExport& rXMLExport,
     310                 :            :     const sal_Int32 nNumberFormat, const double& rValue, sal_Bool bExportValue)
     311                 :            : {
     312                 :            :     sal_Bool bIsStandard;
     313         [ #  # ]:          0 :     sal_Int16 nTypeKey = GetCellType(nNumberFormat, bIsStandard, rXMLExport.GetNumberFormatsSupplier());
     314                 :          0 :     rtl::OUString sCurrency;
     315         [ #  # ]:          0 :     if ((nTypeKey & ~util::NumberFormat::DEFINED) == util::NumberFormat::CURRENCY)
     316         [ #  # ]:          0 :         GetCurrencySymbol(nNumberFormat, sCurrency, rXMLExport.GetNumberFormatsSupplier());
     317         [ #  # ]:          0 :     WriteAttributes(rXMLExport, nTypeKey, rValue, sCurrency, bExportValue);
     318                 :          0 : }
     319                 :            : 
     320                 :          0 : void XMLNumberFormatAttributesExportHelper::SetNumberFormatAttributes(SvXMLExport& rXMLExport,
     321                 :            :     const rtl::OUString& rValue, const rtl::OUString& rCharacters,
     322                 :            :     sal_Bool bExportValue, sal_Bool bExportTypeAttribute)
     323                 :            : {
     324         [ #  # ]:          0 :     if (bExportTypeAttribute)
     325                 :          0 :         rXMLExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_VALUE_TYPE, XML_STRING);
     326 [ #  # ][ #  # ]:          0 :     if (bExportValue && !rValue.isEmpty() && (rValue != rCharacters))
         [ #  # ][ #  # ]
     327                 :          0 :         rXMLExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_STRING_VALUE, rValue);
     328                 :          0 : }
     329                 :            : 
     330                 :          3 : sal_Bool XMLNumberFormatAttributesExportHelper::GetCurrencySymbol(const sal_Int32 nNumberFormat, rtl::OUString& rCurrencySymbol)
     331                 :            : {
     332 [ -  + ][ #  # ]:          3 :     if (!xNumberFormats.is() && pExport && pExport->GetNumberFormatsSupplier().is())
         [ #  # ][ -  + ]
     333         [ #  # ]:          0 :         xNumberFormats.set(pExport->GetNumberFormatsSupplier()->getNumberFormats());
     334                 :            : 
     335         [ +  - ]:          3 :     if (xNumberFormats.is())
     336                 :            :     {
     337                 :            :         try
     338                 :            :         {
     339 [ +  - ][ +  - ]:          3 :             uno::Reference <beans::XPropertySet> xNumberPropertySet(xNumberFormats->getByKey(nNumberFormat));
     340 [ +  - ][ +  - ]:          3 :             if ( xNumberPropertySet->getPropertyValue(msCurrencySymbol) >>= rCurrencySymbol)
                 [ +  - ]
     341                 :            :             {
     342                 :          3 :                 rtl::OUString sCurrencyAbbreviation;
     343 [ +  - ][ +  - ]:          3 :                 if ( xNumberPropertySet->getPropertyValue(msCurrencyAbbreviation) >>= sCurrencyAbbreviation)
                 [ +  - ]
     344                 :            :                 {
     345         [ +  - ]:          3 :                     if ( !sCurrencyAbbreviation.isEmpty())
     346                 :          3 :                         rCurrencySymbol = sCurrencyAbbreviation;
     347                 :            :                     else
     348                 :            :                     {
     349 [ #  # ][ #  # ]:          0 :                         if ( rCurrencySymbol.getLength() == 1 && rCurrencySymbol.toChar() == NfCurrencyEntry::GetEuroSymbol() )
                 [ #  # ]
     350         [ #  # ]:          0 :                             rCurrencySymbol = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("EUR"));
     351                 :            :                     }
     352                 :            :                 }
     353                 :          3 :                 return sal_True;
     354 [ -  + ][ #  # ]:          3 :             }
     355                 :            :         }
     356                 :          0 :         catch ( uno::Exception& )
     357                 :            :         {
     358                 :            :             OSL_FAIL("Numberformat not found");
     359                 :            :         }
     360                 :            :     }
     361                 :          3 :     return sal_False;
     362                 :            : }
     363                 :            : 
     364                 :         97 : sal_Int16 XMLNumberFormatAttributesExportHelper::GetCellType(const sal_Int32 nNumberFormat, bool& bIsStandard)
     365                 :            : {
     366 [ -  + ][ #  # ]:         97 :     if (!xNumberFormats.is() && pExport && pExport->GetNumberFormatsSupplier().is())
         [ #  # ][ -  + ]
     367         [ #  # ]:          0 :         xNumberFormats.set(pExport->GetNumberFormatsSupplier()->getNumberFormats());
     368                 :            : 
     369         [ +  - ]:         97 :     if (xNumberFormats.is())
     370                 :            :     {
     371                 :            :         try
     372                 :            :         {
     373 [ +  - ][ +  - ]:         97 :             uno::Reference <beans::XPropertySet> xNumberPropertySet(xNumberFormats->getByKey(nNumberFormat));
     374         [ +  - ]:         97 :             if (xNumberPropertySet.is())
     375                 :            :             {
     376 [ +  - ][ +  - ]:         97 :                 xNumberPropertySet->getPropertyValue(sStandardFormat) >>= bIsStandard;
     377                 :         97 :                 sal_Int16 nNumberType = sal_Int16();
     378 [ +  - ][ +  - ]:         97 :                 if ( xNumberPropertySet->getPropertyValue(sType) >>= nNumberType )
                 [ +  - ]
     379                 :            :                 {
     380                 :         97 :                     return nNumberType;
     381                 :            :                 }
     382 [ -  + ][ #  # ]:         97 :             }
     383                 :            :         }
     384                 :          0 :         catch ( uno::Exception& )
     385                 :            :         {
     386                 :            :             OSL_FAIL("Numberformat not found");
     387                 :            :         }
     388                 :            :     }
     389                 :         97 :     return 0;
     390                 :            : }
     391                 :            : 
     392                 :          0 : void XMLNumberFormatAttributesExportHelper::WriteAttributes(
     393                 :            :                                 const sal_Int16 nTypeKey,
     394                 :            :                                 const double& rValue,
     395                 :            :                                 const rtl::OUString& rCurrency,
     396                 :            :                                 sal_Bool bExportValue)
     397                 :            : {
     398         [ #  # ]:          0 :     if (!pExport)
     399                 :          0 :         return;
     400                 :            : 
     401                 :          0 :     sal_Bool bWasSetTypeAttribute = sal_False;
     402   [ #  #  #  #  :          0 :     switch(nTypeKey & ~util::NumberFormat::DEFINED)
             #  #  #  # ]
     403                 :            :     {
     404                 :            :     case 0:
     405                 :            :     case util::NumberFormat::NUMBER:
     406                 :            :     case util::NumberFormat::SCIENTIFIC:
     407                 :            :     case util::NumberFormat::FRACTION:
     408                 :            :         {
     409         [ #  # ]:          0 :             if (!bWasSetTypeAttribute)
     410                 :            :             {
     411                 :          0 :                 pExport->AddAttribute(sAttrValueType, XML_FLOAT);
     412                 :          0 :                 bWasSetTypeAttribute = sal_True;
     413                 :            :             }
     414                 :            :         }       // No Break
     415                 :            :     case util::NumberFormat::PERCENT:
     416                 :            :         {
     417         [ #  # ]:          0 :             if (!bWasSetTypeAttribute)
     418                 :            :             {
     419                 :          0 :                 pExport->AddAttribute(sAttrValueType, XML_PERCENTAGE);
     420                 :          0 :                 bWasSetTypeAttribute = sal_True;
     421                 :            :             }
     422                 :            :         }       // No Break
     423                 :            :     case util::NumberFormat::CURRENCY:
     424                 :            :         {
     425         [ #  # ]:          0 :             if (!bWasSetTypeAttribute)
     426                 :            :             {
     427                 :          0 :                 pExport->AddAttribute(sAttrValueType, XML_CURRENCY);
     428         [ #  # ]:          0 :                 if (!rCurrency.isEmpty())
     429                 :          0 :                     pExport->AddAttribute(sAttrCurrency, rCurrency);
     430                 :          0 :                 bWasSetTypeAttribute = sal_True;
     431                 :            :             }
     432                 :            : 
     433         [ #  # ]:          0 :             if (bExportValue)
     434                 :            :             {
     435                 :            :                 rtl::OUString sValue( ::rtl::math::doubleToUString( rValue,
     436                 :            :                             rtl_math_StringFormat_Automatic,
     437                 :          0 :                             rtl_math_DecimalPlaces_Max, '.', sal_True));
     438         [ #  # ]:          0 :                 pExport->AddAttribute(sAttrValue, sValue);
     439                 :            :             }
     440                 :            :         }
     441                 :          0 :         break;
     442                 :            :     case util::NumberFormat::DATE:
     443                 :            :     case util::NumberFormat::DATETIME:
     444                 :            :         {
     445         [ #  # ]:          0 :             if (!bWasSetTypeAttribute)
     446                 :            :             {
     447                 :          0 :                 pExport->AddAttribute(sAttrValueType, XML_DATE);
     448                 :          0 :                 bWasSetTypeAttribute = sal_True;
     449                 :            :             }
     450         [ #  # ]:          0 :             if (bExportValue)
     451                 :            :             {
     452         [ #  # ]:          0 :                 if ( pExport->SetNullDateOnUnitConverter() )
     453                 :            :                 {
     454                 :          0 :                     rtl::OUStringBuffer sBuffer;
     455         [ #  # ]:          0 :                     pExport->GetMM100UnitConverter().convertDateTime(sBuffer, rValue);
     456 [ #  # ][ #  # ]:          0 :                     pExport->AddAttribute(sAttrDateValue, sBuffer.makeStringAndClear());
     457                 :            :                 }
     458                 :            :             }
     459                 :            :         }
     460                 :          0 :         break;
     461                 :            :     case util::NumberFormat::TIME:
     462                 :            :         {
     463         [ #  # ]:          0 :             if (!bWasSetTypeAttribute)
     464                 :            :             {
     465                 :          0 :                 pExport->AddAttribute(sAttrValueType, XML_TIME);
     466                 :          0 :                 bWasSetTypeAttribute = sal_True;
     467                 :            :             }
     468         [ #  # ]:          0 :             if (bExportValue)
     469                 :            :             {
     470                 :          0 :                 rtl::OUStringBuffer sBuffer;
     471         [ #  # ]:          0 :                 ::sax::Converter::convertDuration(sBuffer, rValue);
     472 [ #  # ][ #  # ]:          0 :                 pExport->AddAttribute(sAttrTimeValue, sBuffer.makeStringAndClear());
     473                 :            :             }
     474                 :            :         }
     475                 :          0 :         break;
     476                 :            :     case util::NumberFormat::LOGICAL:
     477                 :            :         {
     478         [ #  # ]:          0 :             if (!bWasSetTypeAttribute)
     479                 :            :             {
     480                 :          0 :                 pExport->AddAttribute(sAttrValueType, XML_BOOLEAN);
     481                 :          0 :                 bWasSetTypeAttribute = sal_True;
     482                 :            :             }
     483         [ #  # ]:          0 :             if (bExportValue)
     484                 :            :             {
     485                 :          0 :                 double fTempValue = rValue;
     486         [ #  # ]:          0 :                 if (::rtl::math::approxEqual( fTempValue, 1.0 ))
     487                 :            :                 {
     488                 :          0 :                     pExport->AddAttribute(sAttrBooleanValue, XML_TRUE);
     489                 :            :                 }
     490                 :            :                 else
     491                 :            :                 {
     492         [ #  # ]:          0 :                     if (::rtl::math::approxEqual( rValue, 0.0 ))
     493                 :            :                     {
     494                 :          0 :                         pExport->AddAttribute(sAttrBooleanValue, XML_FALSE);
     495                 :            :                     }
     496                 :            :                     else
     497                 :            :                     {
     498                 :            :                         rtl::OUString sValue( ::rtl::math::doubleToUString(
     499                 :            :                                     fTempValue,
     500                 :            :                                     rtl_math_StringFormat_Automatic,
     501                 :            :                                     rtl_math_DecimalPlaces_Max, '.',
     502                 :          0 :                                     sal_True));
     503         [ #  # ]:          0 :                         pExport->AddAttribute(sAttrBooleanValue, sValue);
     504                 :            :                     }
     505                 :            :                 }
     506                 :            :             }
     507                 :            :         }
     508                 :          0 :         break;
     509                 :            :     case util::NumberFormat::TEXT:
     510                 :            :         {
     511         [ #  # ]:          0 :             if (!bWasSetTypeAttribute)
     512                 :            :             {
     513                 :          0 :                 pExport->AddAttribute(sAttrValueType, XML_FLOAT);
     514                 :          0 :                 bWasSetTypeAttribute = sal_True;
     515         [ #  # ]:          0 :                 if (bExportValue)
     516                 :            :                 {
     517                 :            :                     rtl::OUString sValue( ::rtl::math::doubleToUString( rValue,
     518                 :            :                                 rtl_math_StringFormat_Automatic,
     519                 :          0 :                                 rtl_math_DecimalPlaces_Max, '.', sal_True));
     520         [ #  # ]:          0 :                     pExport->AddAttribute(sAttrValue, sValue);
     521                 :            :                 }
     522                 :            :             }
     523                 :            :         }
     524                 :          0 :         break;
     525                 :            :     }
     526                 :            : }
     527                 :            : 
     528                 :          0 : void XMLNumberFormatAttributesExportHelper::SetNumberFormatAttributes(
     529                 :            :     const sal_Int32 nNumberFormat, const double& rValue, sal_Bool bExportValue)
     530                 :            : {
     531         [ #  # ]:          0 :     if (pExport)
     532                 :            :     {
     533                 :            :         bool bIsStandard;
     534                 :          0 :         rtl::OUString sCurrency;
     535         [ #  # ]:          0 :         sal_Int16 nTypeKey = GetCellType(nNumberFormat, sCurrency, bIsStandard);
     536         [ #  # ]:          0 :         WriteAttributes(nTypeKey, rValue, sCurrency, bExportValue);
     537                 :            :     }
     538                 :            :     else {
     539                 :            :         OSL_FAIL("no SvXMLExport given");
     540                 :            :     }
     541                 :          0 : }
     542                 :            : 
     543                 :          0 : void XMLNumberFormatAttributesExportHelper::SetNumberFormatAttributes(
     544                 :            :     const rtl::OUString& rValue, const rtl::OUString& rCharacters,
     545                 :            :     sal_Bool bExportValue, sal_Bool bExportTypeAttribute)
     546                 :            : {
     547         [ #  # ]:          0 :     if (pExport)
     548                 :            :     {
     549         [ #  # ]:          0 :         if (bExportTypeAttribute)
     550                 :          0 :             pExport->AddAttribute(sAttrValueType, XML_STRING);
     551 [ #  # ][ #  # ]:          0 :         if (bExportValue && !rValue.isEmpty() && (rValue != rCharacters))
         [ #  # ][ #  # ]
     552                 :          0 :             pExport->AddAttribute(sAttrStringValue, rValue);
     553                 :            :     }
     554                 :            :     else {
     555                 :            :         OSL_FAIL("no SvXMLExport given");
     556                 :            :     }
     557                 :          0 : }
     558                 :            : 
     559                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10