LCOV - code coverage report
Current view: top level - svl/source/numbers - supservs.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 52 62 83.9 %
Date: 2015-06-13 12:38:46 Functions: 12 13 92.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 "supservs.hxx"
      21             : #include <com/sun/star/lang/Locale.hpp>
      22             : #include <comphelper/sharedmutex.hxx>
      23             : #include <cppuhelper/supportsservice.hxx>
      24             : #include <cppuhelper/queryinterface.hxx>
      25             : #include <cppuhelper/weak.hxx>
      26             : #include <i18nlangtag/mslangid.hxx>
      27             : #include <tools/debug.hxx>
      28             : #include <osl/mutex.hxx>
      29             : #include <osl/diagnose.h>
      30             : #include <tools/stream.hxx>
      31             : #include <svl/instrm.hxx>
      32             : 
      33             : #include <strmadpt.hxx>
      34             : 
      35             : using namespace ::com::sun::star::uno;
      36             : using namespace ::com::sun::star::lang;
      37             : using namespace ::com::sun::star::io;
      38             : using namespace ::com::sun::star::beans;
      39             : using namespace ::com::sun::star::util;
      40             : using namespace ::utl;
      41             : 
      42             : 
      43         133 : SvNumberFormatsSupplierServiceObject::SvNumberFormatsSupplierServiceObject(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxORB)
      44             :     :m_pOwnFormatter(NULL)
      45         133 :     ,m_xORB(_rxORB)
      46             : {
      47         133 : }
      48             : 
      49         396 : SvNumberFormatsSupplierServiceObject::~SvNumberFormatsSupplierServiceObject()
      50             : {
      51         132 :     if (m_pOwnFormatter)
      52             :     {
      53         132 :         delete m_pOwnFormatter;
      54         132 :         m_pOwnFormatter = NULL;
      55             :     }
      56         264 : }
      57             : 
      58         806 : Any SAL_CALL SvNumberFormatsSupplierServiceObject::queryAggregation( const Type& _rType ) throw (RuntimeException, std::exception)
      59             : {
      60             :     Any aReturn = ::cppu::queryInterface(_rType,
      61             :         static_cast< XInitialization* >(this),
      62             :         static_cast< XServiceInfo* >(this)
      63         806 :     );
      64             : 
      65         806 :     if (!aReturn.hasValue())
      66         672 :         aReturn = SvNumberFormatsSupplierObj::queryAggregation(_rType);
      67             : 
      68         806 :     return aReturn;
      69             : }
      70             : 
      71         133 : void SAL_CALL SvNumberFormatsSupplierServiceObject::initialize( const Sequence< Any >& _rArguments ) throw(Exception, RuntimeException, std::exception)
      72             : {
      73         133 :     ::osl::MutexGuard aGuard( getSharedMutex() );
      74             : 
      75             :     DBG_ASSERT(m_pOwnFormatter == NULL,
      76             :         "SvNumberFormatsSupplierServiceObject::initialize : already initialized !");
      77             :         // maybe you already called a method which needed the formatter
      78             :         // you should use XMultiServiceFactory::createInstanceWithArguments to avoid that
      79         133 :     if (m_pOwnFormatter)
      80             :     {   // !!! this is only a emergency handling, normally this should not occur !!!
      81           0 :         delete m_pOwnFormatter;
      82           0 :         m_pOwnFormatter = NULL;
      83           0 :         SetNumberFormatter(m_pOwnFormatter);
      84             :     }
      85             : 
      86         266 :     Type aExpectedArgType = ::cppu::UnoType<css::lang::Locale>::get();
      87         133 :     LanguageType eNewFormatterLanguage = LANGUAGE_ENGLISH_US;
      88             :         // the default
      89             : 
      90         133 :     const Any* pArgs = _rArguments.getConstArray();
      91         264 :     for (sal_Int32 i=0; i<_rArguments.getLength(); ++i, ++pArgs)
      92             :     {
      93         131 :         if (pArgs->getValueType().equals(aExpectedArgType))
      94             :         {
      95         131 :             css::lang::Locale aLocale;
      96         131 :             *pArgs >>= aLocale;
      97         131 :             eNewFormatterLanguage = LanguageTag::convertToLanguageType( aLocale, false);
      98             :         }
      99             : #ifdef DBG_UTIL
     100             :         else
     101             :         {
     102             :             OSL_FAIL("SvNumberFormatsSupplierServiceObject::initialize : unknown argument !");
     103             :         }
     104             : #endif
     105             :     }
     106             : 
     107         133 :     m_pOwnFormatter = new SvNumberFormatter( m_xORB, eNewFormatterLanguage);
     108         133 :     m_pOwnFormatter->SetEvalDateFormat( NF_EVALDATEFORMAT_FORMAT_INTL );
     109         266 :     SetNumberFormatter(m_pOwnFormatter);
     110         133 : }
     111             : 
     112           1 : OUString SAL_CALL SvNumberFormatsSupplierServiceObject::getImplementationName(  ) throw(RuntimeException, std::exception)
     113             : {
     114           1 :     return OUString("com.sun.star.uno.util.numbers.SvNumberFormatsSupplierServiceObject");
     115             : }
     116             : 
     117           0 : sal_Bool SAL_CALL SvNumberFormatsSupplierServiceObject::supportsService( const OUString& _rServiceName ) throw(RuntimeException, std::exception)
     118             : {
     119           0 :     return cppu::supportsService(this, _rServiceName);
     120             : }
     121             : 
     122           1 : Sequence< OUString > SAL_CALL SvNumberFormatsSupplierServiceObject::getSupportedServiceNames(  ) throw(RuntimeException, std::exception)
     123             : {
     124           1 :     Sequence< OUString > aSupported(1);
     125           1 :     aSupported.getArray()[0] = "com.sun.star.util.NumberFormatsSupplier";
     126           1 :     return aSupported;
     127             : }
     128             : 
     129         151 : Reference< XPropertySet > SAL_CALL SvNumberFormatsSupplierServiceObject::getNumberFormatSettings() throw(RuntimeException, std::exception)
     130             : {
     131         151 :     ::osl::MutexGuard aGuard( getSharedMutex() );
     132         151 :     implEnsureFormatter();
     133         151 :     return SvNumberFormatsSupplierObj::getNumberFormatSettings();
     134             : }
     135             : 
     136         871 : Reference< XNumberFormats > SAL_CALL SvNumberFormatsSupplierServiceObject::getNumberFormats() throw(RuntimeException, std::exception)
     137             : {
     138         871 :     ::osl::MutexGuard aGuard( getSharedMutex() );
     139         871 :     implEnsureFormatter();
     140         871 :     return SvNumberFormatsSupplierObj::getNumberFormats();
     141             : }
     142             : 
     143         265 : sal_Int64 SAL_CALL SvNumberFormatsSupplierServiceObject::getSomething( const Sequence< sal_Int8 >& aIdentifier ) throw (RuntimeException, std::exception)
     144             : {
     145         265 :     sal_Int64 nReturn = SvNumberFormatsSupplierObj::getSomething( aIdentifier );
     146         265 :     if ( nReturn )
     147             :         // if somebody accesses internals then we should have the formatter
     148         265 :         implEnsureFormatter();
     149         265 :     return nReturn;
     150             : }
     151             : 
     152        1287 : void SvNumberFormatsSupplierServiceObject::implEnsureFormatter()
     153             : {
     154        1287 :     if (!m_pOwnFormatter)
     155             :     {
     156             :         // get the office's UI locale
     157           0 :         SvtSysLocale aSysLocale;
     158           0 :         css::lang::Locale aOfficeLocale = aSysLocale.GetLocaleData().getLanguageTag().getLocale();
     159             : 
     160             :         // initi with this locale
     161           0 :         Sequence< Any > aFakedInitProps( 1 );
     162           0 :         aFakedInitProps[0] <<= aOfficeLocale;
     163             : 
     164           0 :         initialize( aFakedInitProps );
     165             :     }
     166        1287 : }
     167             : 
     168             : 
     169             : extern "C" SAL_DLLPUBLIC_EXPORT ::com::sun::star::uno::XInterface* SAL_CALL
     170         133 : com_sun_star_uno_util_numbers_SvNumberFormatsSupplierServiceObject_get_implementation(::com::sun::star::uno::XComponentContext* context,
     171             :                                                                     ::com::sun::star::uno::Sequence<css::uno::Any> const &)
     172             : {
     173         133 :     return cppu::acquire(new SvNumberFormatsSupplierServiceObject(context));
     174             : }
     175             : 
     176             : 
     177             : 
     178             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11