bump product version to 5.0.4.1
[LibreOffice.git] / svl / source / numbers / supservs.cxx
blob416ddef688aef93ba1244328b6528e72ef645bd1
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
33 #include <strmadpt.hxx>
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;
43 SvNumberFormatsSupplierServiceObject::SvNumberFormatsSupplierServiceObject(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxORB)
44 :m_pOwnFormatter(NULL)
45 ,m_xORB(_rxORB)
49 SvNumberFormatsSupplierServiceObject::~SvNumberFormatsSupplierServiceObject()
51 if (m_pOwnFormatter)
53 delete m_pOwnFormatter;
54 m_pOwnFormatter = NULL;
58 Any SAL_CALL SvNumberFormatsSupplierServiceObject::queryAggregation( const Type& _rType ) throw (RuntimeException, std::exception)
60 Any aReturn = ::cppu::queryInterface(_rType,
61 static_cast< XInitialization* >(this),
62 static_cast< XServiceInfo* >(this)
65 if (!aReturn.hasValue())
66 aReturn = SvNumberFormatsSupplierObj::queryAggregation(_rType);
68 return aReturn;
71 void SAL_CALL SvNumberFormatsSupplierServiceObject::initialize( const Sequence< Any >& _rArguments ) throw(Exception, RuntimeException, std::exception)
73 ::osl::MutexGuard aGuard( getSharedMutex() );
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 if (m_pOwnFormatter)
80 { // !!! this is only a emergency handling, normally this should not occur !!!
81 delete m_pOwnFormatter;
82 m_pOwnFormatter = NULL;
83 SetNumberFormatter(m_pOwnFormatter);
86 Type aExpectedArgType = ::cppu::UnoType<css::lang::Locale>::get();
87 LanguageType eNewFormatterLanguage = LANGUAGE_ENGLISH_US;
88 // the default
90 const Any* pArgs = _rArguments.getConstArray();
91 for (sal_Int32 i=0; i<_rArguments.getLength(); ++i, ++pArgs)
93 if (pArgs->getValueType().equals(aExpectedArgType))
95 css::lang::Locale aLocale;
96 *pArgs >>= aLocale;
97 eNewFormatterLanguage = LanguageTag::convertToLanguageType( aLocale, false);
99 #ifdef DBG_UTIL
100 else
102 OSL_FAIL("SvNumberFormatsSupplierServiceObject::initialize : unknown argument !");
104 #endif
107 m_pOwnFormatter = new SvNumberFormatter( m_xORB, eNewFormatterLanguage);
108 m_pOwnFormatter->SetEvalDateFormat( NF_EVALDATEFORMAT_FORMAT_INTL );
109 SetNumberFormatter(m_pOwnFormatter);
112 OUString SAL_CALL SvNumberFormatsSupplierServiceObject::getImplementationName( ) throw(RuntimeException, std::exception)
114 return OUString("com.sun.star.uno.util.numbers.SvNumberFormatsSupplierServiceObject");
117 sal_Bool SAL_CALL SvNumberFormatsSupplierServiceObject::supportsService( const OUString& _rServiceName ) throw(RuntimeException, std::exception)
119 return cppu::supportsService(this, _rServiceName);
122 Sequence< OUString > SAL_CALL SvNumberFormatsSupplierServiceObject::getSupportedServiceNames( ) throw(RuntimeException, std::exception)
124 Sequence< OUString > aSupported(1);
125 aSupported.getArray()[0] = "com.sun.star.util.NumberFormatsSupplier";
126 return aSupported;
129 Reference< XPropertySet > SAL_CALL SvNumberFormatsSupplierServiceObject::getNumberFormatSettings() throw(RuntimeException, std::exception)
131 ::osl::MutexGuard aGuard( getSharedMutex() );
132 implEnsureFormatter();
133 return SvNumberFormatsSupplierObj::getNumberFormatSettings();
136 Reference< XNumberFormats > SAL_CALL SvNumberFormatsSupplierServiceObject::getNumberFormats() throw(RuntimeException, std::exception)
138 ::osl::MutexGuard aGuard( getSharedMutex() );
139 implEnsureFormatter();
140 return SvNumberFormatsSupplierObj::getNumberFormats();
143 sal_Int64 SAL_CALL SvNumberFormatsSupplierServiceObject::getSomething( const Sequence< sal_Int8 >& aIdentifier ) throw (RuntimeException, std::exception)
145 sal_Int64 nReturn = SvNumberFormatsSupplierObj::getSomething( aIdentifier );
146 if ( nReturn )
147 // if somebody accesses internals then we should have the formatter
148 implEnsureFormatter();
149 return nReturn;
152 void SvNumberFormatsSupplierServiceObject::implEnsureFormatter()
154 if (!m_pOwnFormatter)
156 // get the office's UI locale
157 SvtSysLocale aSysLocale;
158 css::lang::Locale aOfficeLocale = aSysLocale.GetLocaleData().getLanguageTag().getLocale();
160 // initi with this locale
161 Sequence< Any > aFakedInitProps( 1 );
162 aFakedInitProps[0] <<= aOfficeLocale;
164 initialize( aFakedInitProps );
169 extern "C" SAL_DLLPUBLIC_EXPORT ::com::sun::star::uno::XInterface* SAL_CALL
170 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 &)
173 return cppu::acquire(new SvNumberFormatsSupplierServiceObject(context));
178 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */