LCOV - code coverage report
Current view: top level - svl/source/numbers - supservs.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 46 79 58.2 %
Date: 2014-04-11 Functions: 10 16 62.5 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "supservs.hxx"
      21             : #include <com/sun/star/lang/Locale.hpp>
      22             : #include <comphelper/sharedmutex.hxx>
      23             : #include <cppuhelper/supportsservice.hxx>
      24             : #include <i18nlangtag/mslangid.hxx>
      25             : #include <tools/debug.hxx>
      26             : #include <osl/mutex.hxx>
      27             : #include <tools/stream.hxx>
      28             : #include <svl/strmadpt.hxx>
      29             : #include <svl/instrm.hxx>
      30             : 
      31             : #include <registerservices.hxx>
      32             : 
      33             : using namespace ::com::sun::star::uno;
      34             : using namespace ::com::sun::star::lang;
      35             : using namespace ::com::sun::star::io;
      36             : using namespace ::com::sun::star::beans;
      37             : using namespace ::com::sun::star::util;
      38             : using namespace ::utl;
      39             : 
      40             : #define PERSISTENT_SERVICE_NAME     OUString("com.sun.star.util.NumberFormatsSupplier");
      41             : 
      42         117 : Reference< XInterface > SAL_CALL SvNumberFormatsSupplierServiceObject_CreateInstance(const Reference< XMultiServiceFactory >& _rxFactory)
      43             : {
      44         117 :     return static_cast< ::cppu::OWeakObject* >(new SvNumberFormatsSupplierServiceObject( comphelper::getComponentContext(_rxFactory) ));
      45             : }
      46             : 
      47         117 : SvNumberFormatsSupplierServiceObject::SvNumberFormatsSupplierServiceObject(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxORB)
      48             :     :m_pOwnFormatter(NULL)
      49         117 :     ,m_xORB(_rxORB)
      50             : {
      51         117 : }
      52             : 
      53         345 : SvNumberFormatsSupplierServiceObject::~SvNumberFormatsSupplierServiceObject()
      54             : {
      55         115 :     if (m_pOwnFormatter)
      56             :     {
      57         115 :         delete m_pOwnFormatter;
      58         115 :         m_pOwnFormatter = NULL;
      59             :     }
      60         230 : }
      61             : 
      62         722 : Any SAL_CALL SvNumberFormatsSupplierServiceObject::queryAggregation( const Type& _rType ) throw (RuntimeException, std::exception)
      63             : {
      64             :     Any aReturn = ::cppu::queryInterface(_rType,
      65             :         static_cast< XInitialization* >(this),
      66             :         static_cast< XPersistObject* >(this),
      67             :         static_cast< XServiceInfo* >(this)
      68         722 :     );
      69             : 
      70         722 :     if (!aReturn.hasValue())
      71         605 :         aReturn = SvNumberFormatsSupplierObj::queryAggregation(_rType);
      72             : 
      73         722 :     return aReturn;
      74             : }
      75             : 
      76         117 : void SAL_CALL SvNumberFormatsSupplierServiceObject::initialize( const Sequence< Any >& _rArguments ) throw(Exception, RuntimeException, std::exception)
      77             : {
      78         117 :     ::osl::MutexGuard aGuard( getSharedMutex() );
      79             : 
      80             :     DBG_ASSERT(m_pOwnFormatter == NULL,
      81             :         "SvNumberFormatsSupplierServiceObject::initialize : already initialized !");
      82             :         // maybe you already called a method which needed the formatter
      83             :         // you should use XMultiServiceFactory::createInstanceWithArguments to avoid that
      84         117 :     if (m_pOwnFormatter)
      85             :     {   // !!! this is only a emergency handling, normally this should not occur !!!
      86           0 :         delete m_pOwnFormatter;
      87           0 :         m_pOwnFormatter = NULL;
      88           0 :         SetNumberFormatter(m_pOwnFormatter);
      89             :     }
      90             : 
      91         234 :     Type aExpectedArgType = ::getCppuType(static_cast<Locale*>(NULL));
      92         117 :     LanguageType eNewFormatterLanguage = LANGUAGE_ENGLISH_US;
      93             :         // the default
      94             : 
      95         117 :     const Any* pArgs = _rArguments.getConstArray();
      96         232 :     for (sal_Int32 i=0; i<_rArguments.getLength(); ++i, ++pArgs)
      97             :     {
      98         115 :         if (pArgs->getValueType().equals(aExpectedArgType))
      99             :         {
     100         115 :             Locale aLocale;
     101         115 :             *pArgs >>= aLocale;
     102         115 :             eNewFormatterLanguage = LanguageTag::convertToLanguageType( aLocale, false);
     103             :         }
     104             : #ifdef DBG_UTIL
     105             :         else
     106             :         {
     107             :             OSL_FAIL("SvNumberFormatsSupplierServiceObject::initialize : unknown argument !");
     108             :         }
     109             : #endif
     110             :     }
     111             : 
     112         117 :     m_pOwnFormatter = new SvNumberFormatter( m_xORB, eNewFormatterLanguage);
     113         117 :     m_pOwnFormatter->SetEvalDateFormat( NF_EVALDATEFORMAT_FORMAT_INTL );
     114         234 :     SetNumberFormatter(m_pOwnFormatter);
     115         117 : }
     116             : 
     117           0 : OUString SAL_CALL SvNumberFormatsSupplierServiceObject::getImplementationName(  ) throw(RuntimeException, std::exception)
     118             : {
     119           0 :     return OUString("com.sun.star.uno.util.numbers.SvNumberFormatsSupplierServiceObject");
     120             : }
     121             : 
     122           0 : sal_Bool SAL_CALL SvNumberFormatsSupplierServiceObject::supportsService( const OUString& _rServiceName ) throw(RuntimeException, std::exception)
     123             : {
     124           0 :     return cppu::supportsService(this, _rServiceName);
     125             : }
     126             : 
     127           0 : Sequence< OUString > SAL_CALL SvNumberFormatsSupplierServiceObject::getSupportedServiceNames(  ) throw(RuntimeException, std::exception)
     128             : {
     129           0 :     Sequence< OUString > aSupported(1);
     130           0 :     aSupported.getArray()[0] = PERSISTENT_SERVICE_NAME;
     131           0 :     return aSupported;
     132             : }
     133             : 
     134           0 : OUString SAL_CALL SvNumberFormatsSupplierServiceObject::getServiceName(  ) throw(RuntimeException, std::exception)
     135             : {
     136           0 :     return PERSISTENT_SERVICE_NAME;
     137             : }
     138             : 
     139           0 : void SAL_CALL SvNumberFormatsSupplierServiceObject::write( const Reference< XObjectOutputStream >& _rxOutStream ) throw(IOException, RuntimeException, std::exception)
     140             : {
     141           0 :     ::osl::MutexGuard aGuard( getSharedMutex() );
     142           0 :     implEnsureFormatter();
     143             : 
     144           0 :     Reference< XOutputStream > xStream(_rxOutStream.get());
     145           0 :     SvLockBytesRef aLockBytes = new SvOutputStreamOpenLockBytes(xStream);
     146           0 :     SvStream aSvOutputSteam(aLockBytes);
     147             : 
     148           0 :     m_pOwnFormatter->Save(aSvOutputSteam);
     149           0 : }
     150             : 
     151           0 : void SAL_CALL SvNumberFormatsSupplierServiceObject::read( const Reference< XObjectInputStream >& _rxInStream ) throw(IOException, RuntimeException, std::exception)
     152             : {
     153           0 :     ::osl::MutexGuard aGuard( getSharedMutex() );
     154           0 :     implEnsureFormatter();
     155             : 
     156           0 :     Reference< XInputStream > xStream(_rxInStream.get());
     157           0 :     SvInputStream aSvInputSteam(xStream);
     158             : 
     159           0 :     m_pOwnFormatter->Load(aSvInputSteam);
     160           0 : }
     161             : 
     162          47 : Reference< XPropertySet > SAL_CALL SvNumberFormatsSupplierServiceObject::getNumberFormatSettings() throw(RuntimeException, std::exception)
     163             : {
     164          47 :     ::osl::MutexGuard aGuard( getSharedMutex() );
     165          47 :     implEnsureFormatter();
     166          47 :     return SvNumberFormatsSupplierObj::getNumberFormatSettings();
     167             : }
     168             : 
     169         148 : Reference< XNumberFormats > SAL_CALL SvNumberFormatsSupplierServiceObject::getNumberFormats() throw(RuntimeException, std::exception)
     170             : {
     171         148 :     ::osl::MutexGuard aGuard( getSharedMutex() );
     172         148 :     implEnsureFormatter();
     173         148 :     return SvNumberFormatsSupplierObj::getNumberFormats();
     174             : }
     175             : 
     176         242 : sal_Int64 SAL_CALL SvNumberFormatsSupplierServiceObject::getSomething( const Sequence< sal_Int8 >& aIdentifier ) throw (RuntimeException, std::exception)
     177             : {
     178         242 :     sal_Int64 nReturn = SvNumberFormatsSupplierObj::getSomething( aIdentifier );
     179         242 :     if ( nReturn )
     180             :         // if somebody accesses internals then we should have the formatter
     181         242 :         implEnsureFormatter();
     182         242 :     return nReturn;
     183             : }
     184             : 
     185         437 : void SvNumberFormatsSupplierServiceObject::implEnsureFormatter()
     186             : {
     187         437 :     if (!m_pOwnFormatter)
     188             :     {
     189             :         // get the office's UI locale
     190           0 :         SvtSysLocale aSysLocale;
     191           0 :         Locale aOfficeLocale = aSysLocale.GetLocaleData().getLanguageTag().getLocale();
     192             : 
     193             :         // initi with this locale
     194           0 :         Sequence< Any > aFakedInitProps( 1 );
     195           0 :         aFakedInitProps[0] <<= aOfficeLocale;
     196             : 
     197           0 :         initialize( aFakedInitProps );
     198             :     }
     199         437 : }
     200             : 
     201             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10