LCOV - code coverage report
Current view: top level - svl/source/numbers - supservs.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 51 84 60.7 %
Date: 2012-08-25 Functions: 10 16 62.5 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 46 148 31.1 %

           Branch data     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 "supservs.hxx"
      21                 :            : #include <com/sun/star/lang/Locale.hpp>
      22                 :            : #include <comphelper/sharedmutex.hxx>
      23                 :            : #include <i18npool/mslangid.hxx>
      24                 :            : #include <tools/debug.hxx>
      25                 :            : #include <osl/mutex.hxx>
      26                 :            : #include <tools/stream.hxx>
      27                 :            : #include <svl/strmadpt.hxx>
      28                 :            : #include <svl/instrm.hxx>
      29                 :            : 
      30                 :            : using namespace ::com::sun::star::uno;
      31                 :            : using namespace ::com::sun::star::lang;
      32                 :            : using namespace ::com::sun::star::io;
      33                 :            : using namespace ::com::sun::star::beans;
      34                 :            : using namespace ::com::sun::star::util;
      35                 :            : using namespace ::utl;
      36                 :            : 
      37                 :            : #define PERSISTENT_SERVICE_NAME     ::rtl::OUString("com.sun.star.util.NumberFormatsSupplier");
      38                 :            : 
      39                 :            : //-------------------------------------------------------------------------
      40                 :        197 : Reference< XInterface > SAL_CALL SvNumberFormatsSupplierServiceObject_CreateInstance(const Reference< XMultiServiceFactory >& _rxFactory)
      41                 :            : {
      42         [ +  - ]:        197 :     return static_cast< ::cppu::OWeakObject* >(new SvNumberFormatsSupplierServiceObject(_rxFactory));
      43                 :            : }
      44                 :            : 
      45                 :            : //-------------------------------------------------------------------------
      46                 :        197 : SvNumberFormatsSupplierServiceObject::SvNumberFormatsSupplierServiceObject(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB)
      47                 :            :     :m_pOwnFormatter(NULL)
      48                 :        197 :     ,m_xORB(_rxORB)
      49                 :            : {
      50                 :        197 : }
      51                 :            : 
      52                 :            : //-------------------------------------------------------------------------
      53                 :        197 : SvNumberFormatsSupplierServiceObject::~SvNumberFormatsSupplierServiceObject()
      54                 :            : {
      55         [ +  - ]:        197 :     if (m_pOwnFormatter)
      56                 :            :     {
      57 [ +  - ][ +  - ]:        197 :         delete m_pOwnFormatter;
      58                 :        197 :         m_pOwnFormatter = NULL;
      59                 :            :     }
      60         [ -  + ]:        394 : }
      61                 :            : 
      62                 :            : //-------------------------------------------------------------------------
      63                 :       1291 : Any SAL_CALL SvNumberFormatsSupplierServiceObject::queryAggregation( const Type& _rType ) throw (RuntimeException)
      64                 :            : {
      65                 :            :     Any aReturn = ::cppu::queryInterface(_rType,
      66                 :            :         static_cast< XInitialization* >(this),
      67                 :            :         static_cast< XPersistObject* >(this),
      68                 :            :         static_cast< XServiceInfo* >(this)
      69                 :       1291 :     );
      70                 :            : 
      71         [ +  + ]:       1291 :     if (!aReturn.hasValue())
      72         [ +  - ]:       1096 :         aReturn = SvNumberFormatsSupplierObj::queryAggregation(_rType);
      73                 :            : 
      74                 :       1291 :     return aReturn;
      75                 :            : }
      76                 :            : 
      77                 :            : //-------------------------------------------------------------------------
      78                 :        197 : void SAL_CALL SvNumberFormatsSupplierServiceObject::initialize( const Sequence< Any >& _rArguments ) throw(Exception, RuntimeException)
      79                 :            : {
      80 [ +  - ][ +  - ]:        197 :     ::osl::MutexGuard aGuard( getSharedMutex() );
                 [ +  - ]
      81                 :            : 
      82                 :            :     DBG_ASSERT(m_pOwnFormatter == NULL,
      83                 :            :         "SvNumberFormatsSupplierServiceObject::initialize : already initialized !");
      84                 :            :         // maybe you already called a method which needed the formatter
      85                 :            :         // you should use XMultiServiceFactory::createInstanceWithArguments to avoid that
      86         [ -  + ]:        197 :     if (m_pOwnFormatter)
      87                 :            :     {   // !!! this is only a emergency handling, normally this should not occur !!!
      88 [ #  # ][ #  # ]:          0 :         delete m_pOwnFormatter;
      89                 :          0 :         m_pOwnFormatter = NULL;
      90         [ #  # ]:          0 :         SetNumberFormatter(m_pOwnFormatter);
      91                 :            :     }
      92                 :            : 
      93         [ +  - ]:        197 :     Type aExpectedArgType = ::getCppuType(static_cast<Locale*>(NULL));
      94                 :        197 :     LanguageType eNewFormatterLanguage = LANGUAGE_ENGLISH_US;
      95                 :            :         // the default
      96                 :            : 
      97                 :        197 :     const Any* pArgs = _rArguments.getConstArray();
      98         [ +  + ]:        394 :     for (sal_Int32 i=0; i<_rArguments.getLength(); ++i, ++pArgs)
      99                 :            :     {
     100         [ +  - ]:        197 :         if (pArgs->getValueType().equals(aExpectedArgType))
     101                 :            :         {
     102                 :        197 :             Locale aLocale;
     103         [ +  - ]:        197 :             *pArgs >>= aLocale;
     104         [ +  - ]:        197 :             eNewFormatterLanguage = MsLangId::convertLocaleToLanguage( aLocale);
     105                 :            :         }
     106                 :            : #ifdef DBG_UTIL
     107                 :            :         else
     108                 :            :         {
     109                 :            :             OSL_FAIL("SvNumberFormatsSupplierServiceObject::initialize : unknown argument !");
     110                 :            :         }
     111                 :            : #endif
     112                 :            :     }
     113                 :            : 
     114 [ +  - ][ +  - ]:        197 :     m_pOwnFormatter = new SvNumberFormatter(m_xORB, eNewFormatterLanguage);
     115                 :        197 :     m_pOwnFormatter->SetEvalDateFormat( NF_EVALDATEFORMAT_FORMAT_INTL );
     116 [ +  - ][ +  - ]:        197 :     SetNumberFormatter(m_pOwnFormatter);
     117                 :        197 : }
     118                 :            : 
     119                 :            : //-------------------------------------------------------------------------
     120                 :          0 : ::rtl::OUString SAL_CALL SvNumberFormatsSupplierServiceObject::getImplementationName(  ) throw(RuntimeException)
     121                 :            : {
     122                 :          0 :     return ::rtl::OUString("com.sun.star.uno.util.numbers.SvNumberFormatsSupplierServiceObject");
     123                 :            : }
     124                 :            : 
     125                 :            : //-------------------------------------------------------------------------
     126                 :          0 : sal_Bool SAL_CALL SvNumberFormatsSupplierServiceObject::supportsService( const ::rtl::OUString& _rServiceName ) throw(RuntimeException)
     127                 :            : {
     128         [ #  # ]:          0 :     Sequence< ::rtl::OUString > aServices = getSupportedServiceNames();
     129                 :          0 :     const ::rtl::OUString* pServices = aServices.getConstArray();
     130         [ #  # ]:          0 :     for (sal_Int32 i=0; i<aServices.getLength(); ++i, ++pServices)
     131         [ #  # ]:          0 :         if (pServices->equals(_rServiceName))
     132                 :          0 :             return sal_True;
     133                 :            : 
     134         [ #  # ]:          0 :     return sal_False;
     135                 :            : }
     136                 :            : 
     137                 :            : //-------------------------------------------------------------------------
     138                 :          0 : Sequence< ::rtl::OUString > SAL_CALL SvNumberFormatsSupplierServiceObject::getSupportedServiceNames(  ) throw(RuntimeException)
     139                 :            : {
     140                 :          0 :     Sequence< ::rtl::OUString > aSupported(1);
     141         [ #  # ]:          0 :     aSupported.getArray()[0] = PERSISTENT_SERVICE_NAME;
     142                 :          0 :     return aSupported;
     143                 :            : }
     144                 :            : 
     145                 :            : //-------------------------------------------------------------------------
     146                 :          0 : ::rtl::OUString SAL_CALL SvNumberFormatsSupplierServiceObject::getServiceName(  ) throw(RuntimeException)
     147                 :            : {
     148                 :          0 :     return PERSISTENT_SERVICE_NAME;
     149                 :            : }
     150                 :            : 
     151                 :            : //-------------------------------------------------------------------------
     152                 :          0 : void SAL_CALL SvNumberFormatsSupplierServiceObject::write( const Reference< XObjectOutputStream >& _rxOutStream ) throw(IOException, RuntimeException)
     153                 :            : {
     154 [ #  # ][ #  # ]:          0 :     ::osl::MutexGuard aGuard( getSharedMutex() );
                 [ #  # ]
     155         [ #  # ]:          0 :     implEnsureFormatter();
     156                 :            : 
     157 [ #  # ][ #  # ]:          0 :     Reference< XOutputStream > xStream(_rxOutStream.get());
     158 [ #  # ][ #  # ]:          0 :     SvLockBytesRef aLockBytes = new SvOutputStreamOpenLockBytes(xStream);
     159         [ #  # ]:          0 :     SvStream aSvOutputSteam(aLockBytes);
     160                 :            : 
     161 [ #  # ][ #  # ]:          0 :     m_pOwnFormatter->Save(aSvOutputSteam);
         [ #  # ][ #  # ]
     162                 :          0 : }
     163                 :            : 
     164                 :            : //-------------------------------------------------------------------------
     165                 :          0 : void SAL_CALL SvNumberFormatsSupplierServiceObject::read( const Reference< XObjectInputStream >& _rxInStream ) throw(IOException, RuntimeException)
     166                 :            : {
     167 [ #  # ][ #  # ]:          0 :     ::osl::MutexGuard aGuard( getSharedMutex() );
                 [ #  # ]
     168         [ #  # ]:          0 :     implEnsureFormatter();
     169                 :            : 
     170 [ #  # ][ #  # ]:          0 :     Reference< XInputStream > xStream(_rxInStream.get());
     171         [ #  # ]:          0 :     SvInputStream aSvInputSteam(xStream);
     172                 :            : 
     173 [ #  # ][ #  # ]:          0 :     m_pOwnFormatter->Load(aSvInputSteam);
                 [ #  # ]
     174                 :          0 : }
     175                 :            : 
     176                 :            : //-------------------------------------------------------------------------
     177                 :         92 : Reference< XPropertySet > SAL_CALL SvNumberFormatsSupplierServiceObject::getNumberFormatSettings() throw(RuntimeException)
     178                 :            : {
     179 [ +  - ][ +  - ]:         92 :     ::osl::MutexGuard aGuard( getSharedMutex() );
                 [ +  - ]
     180         [ +  - ]:         92 :     implEnsureFormatter();
     181 [ +  - ][ +  - ]:         92 :     return SvNumberFormatsSupplierObj::getNumberFormatSettings();
     182                 :            : }
     183                 :            : 
     184                 :            : //-------------------------------------------------------------------------
     185                 :        276 : Reference< XNumberFormats > SAL_CALL SvNumberFormatsSupplierServiceObject::getNumberFormats() throw(RuntimeException)
     186                 :            : {
     187 [ +  - ][ +  - ]:        276 :     ::osl::MutexGuard aGuard( getSharedMutex() );
                 [ +  - ]
     188         [ +  - ]:        276 :     implEnsureFormatter();
     189 [ +  - ][ +  - ]:        276 :     return SvNumberFormatsSupplierObj::getNumberFormats();
     190                 :            : }
     191                 :            : 
     192                 :            : //-------------------------------------------------------------------------
     193                 :        472 : sal_Int64 SAL_CALL SvNumberFormatsSupplierServiceObject::getSomething( const Sequence< sal_Int8 >& aIdentifier ) throw (RuntimeException)
     194                 :            : {
     195                 :        472 :     sal_Int64 nReturn = SvNumberFormatsSupplierObj::getSomething( aIdentifier );
     196         [ +  - ]:        472 :     if ( nReturn )
     197                 :            :         // if somebody accesses internals then we should have the formatter
     198                 :        472 :         implEnsureFormatter();
     199                 :        472 :     return nReturn;
     200                 :            : }
     201                 :            : 
     202                 :            : //-------------------------------------------------------------------------
     203                 :        840 : void SvNumberFormatsSupplierServiceObject::implEnsureFormatter()
     204                 :            : {
     205         [ +  + ]:        840 :     if (!m_pOwnFormatter)
     206                 :            :     {
     207                 :            :         // get the office's UI locale
     208         [ +  - ]:          2 :         SvtSysLocale aSysLocale;
     209 [ +  - ][ +  - ]:          2 :         Locale aOfficeLocale = aSysLocale.GetLocaleData().getLocale();
     210                 :            : 
     211                 :            :         // initi with this locale
     212         [ +  - ]:          2 :         Sequence< Any > aFakedInitProps( 1 );
     213 [ +  - ][ +  - ]:          2 :         aFakedInitProps[0] <<= aOfficeLocale;
     214                 :            : 
     215 [ +  - ][ +  - ]:          2 :         initialize( aFakedInitProps );
                 [ +  - ]
     216                 :            :     }
     217                 :        840 : }
     218                 :            : 
     219                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10