LCOV - code coverage report
Current view: top level - svl/source/numbers - supservs.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 46 79 58.2 %
Date: 2014-11-03 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         254 : Reference< XInterface > SAL_CALL SvNumberFormatsSupplierServiceObject_CreateInstance(const Reference< XMultiServiceFactory >& _rxFactory)
      43             : {
      44         254 :     return static_cast< ::cppu::OWeakObject* >(new SvNumberFormatsSupplierServiceObject( comphelper::getComponentContext(_rxFactory) ));
      45             : }
      46             : 
      47         254 : SvNumberFormatsSupplierServiceObject::SvNumberFormatsSupplierServiceObject(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxORB)
      48             :     :m_pOwnFormatter(NULL)
      49         254 :     ,m_xORB(_rxORB)
      50             : {
      51         254 : }
      52             : 
      53         756 : SvNumberFormatsSupplierServiceObject::~SvNumberFormatsSupplierServiceObject()
      54             : {
      55         252 :     if (m_pOwnFormatter)
      56             :     {
      57         252 :         delete m_pOwnFormatter;
      58         252 :         m_pOwnFormatter = NULL;
      59             :     }
      60         504 : }
      61             : 
      62        1541 : 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        1541 :     );
      69             : 
      70        1541 :     if (!aReturn.hasValue())
      71        1287 :         aReturn = SvNumberFormatsSupplierObj::queryAggregation(_rType);
      72             : 
      73        1541 :     return aReturn;
      74             : }
      75             : 
      76         254 : void SAL_CALL SvNumberFormatsSupplierServiceObject::initialize( const Sequence< Any >& _rArguments ) throw(Exception, RuntimeException, std::exception)
      77             : {
      78         254 :     ::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         254 :     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         508 :     Type aExpectedArgType = ::cppu::UnoType<Locale>::get();
      92         254 :     LanguageType eNewFormatterLanguage = LANGUAGE_ENGLISH_US;
      93             :         // the default
      94             : 
      95         254 :     const Any* pArgs = _rArguments.getConstArray();
      96         504 :     for (sal_Int32 i=0; i<_rArguments.getLength(); ++i, ++pArgs)
      97             :     {
      98         250 :         if (pArgs->getValueType().equals(aExpectedArgType))
      99             :         {
     100         250 :             Locale aLocale;
     101         250 :             *pArgs >>= aLocale;
     102         250 :             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         254 :     m_pOwnFormatter = new SvNumberFormatter( m_xORB, eNewFormatterLanguage);
     113         254 :     m_pOwnFormatter->SetEvalDateFormat( NF_EVALDATEFORMAT_FORMAT_INTL );
     114         508 :     SetNumberFormatter(m_pOwnFormatter);
     115         254 : }
     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         160 : Reference< XPropertySet > SAL_CALL SvNumberFormatsSupplierServiceObject::getNumberFormatSettings() throw(RuntimeException, std::exception)
     163             : {
     164         160 :     ::osl::MutexGuard aGuard( getSharedMutex() );
     165         160 :     implEnsureFormatter();
     166         160 :     return SvNumberFormatsSupplierObj::getNumberFormatSettings();
     167             : }
     168             : 
     169         338 : Reference< XNumberFormats > SAL_CALL SvNumberFormatsSupplierServiceObject::getNumberFormats() throw(RuntimeException, std::exception)
     170             : {
     171         338 :     ::osl::MutexGuard aGuard( getSharedMutex() );
     172         338 :     implEnsureFormatter();
     173         338 :     return SvNumberFormatsSupplierObj::getNumberFormats();
     174             : }
     175             : 
     176         504 : sal_Int64 SAL_CALL SvNumberFormatsSupplierServiceObject::getSomething( const Sequence< sal_Int8 >& aIdentifier ) throw (RuntimeException, std::exception)
     177             : {
     178         504 :     sal_Int64 nReturn = SvNumberFormatsSupplierObj::getSomething( aIdentifier );
     179         504 :     if ( nReturn )
     180             :         // if somebody accesses internals then we should have the formatter
     181         504 :         implEnsureFormatter();
     182         504 :     return nReturn;
     183             : }
     184             : 
     185        1002 : void SvNumberFormatsSupplierServiceObject::implEnsureFormatter()
     186             : {
     187        1002 :     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        1002 : }
     200             : 
     201             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10