1*b5088357SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*b5088357SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*b5088357SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*b5088357SAndrew Rist  * distributed with this work for additional information
6*b5088357SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*b5088357SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*b5088357SAndrew Rist  * "License"); you may not use this file except in compliance
9*b5088357SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*b5088357SAndrew Rist  *
11*b5088357SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*b5088357SAndrew Rist  *
13*b5088357SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*b5088357SAndrew Rist  * software distributed under the License is distributed on an
15*b5088357SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b5088357SAndrew Rist  * KIND, either express or implied.  See the License for the
17*b5088357SAndrew Rist  * specific language governing permissions and limitations
18*b5088357SAndrew Rist  * under the License.
19*b5088357SAndrew Rist  *
20*b5088357SAndrew Rist  *************************************************************/
21*b5088357SAndrew Rist 
22*b5088357SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_unotools.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <unotools/numberformatcodewrapper.hxx>
28cdf0e10cSrcweir #include <tools/debug.hxx>
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #ifndef _COMPHELPER_COMPONENTFACTORY_HXX_
31cdf0e10cSrcweir #include <comphelper/componentfactory.hxx>
32cdf0e10cSrcweir #endif
33cdf0e10cSrcweir #include <com/sun/star/uno/XInterface.hpp>
34cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #define LOCALEDATA_LIBRARYNAME "i18npool"
37cdf0e10cSrcweir #define LOCALEDATA_SERVICENAME "com.sun.star.i18n.NumberFormatMapper"
38cdf0e10cSrcweir 
39cdf0e10cSrcweir using namespace ::com::sun::star;
40cdf0e10cSrcweir using namespace ::com::sun::star::i18n;
41cdf0e10cSrcweir using namespace ::com::sun::star::uno;
42cdf0e10cSrcweir 
43cdf0e10cSrcweir 
NumberFormatCodeWrapper(const Reference<lang::XMultiServiceFactory> & xSF,const lang::Locale & rLocale)44cdf0e10cSrcweir NumberFormatCodeWrapper::NumberFormatCodeWrapper(
45cdf0e10cSrcweir 			const Reference< lang::XMultiServiceFactory > & xSF,
46cdf0e10cSrcweir 			const lang::Locale& rLocale
47cdf0e10cSrcweir 			)
48cdf0e10cSrcweir 		:
49cdf0e10cSrcweir 		xSMgr( xSF )
50cdf0e10cSrcweir {
51cdf0e10cSrcweir 	setLocale( rLocale );
52cdf0e10cSrcweir 	if ( xSMgr.is() )
53cdf0e10cSrcweir 	{
54cdf0e10cSrcweir 		try
55cdf0e10cSrcweir 		{
56cdf0e10cSrcweir 			xNFC = Reference< XNumberFormatCode > ( xSMgr->createInstance(
57cdf0e10cSrcweir 				::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( LOCALEDATA_SERVICENAME ) ) ),
58cdf0e10cSrcweir 				uno::UNO_QUERY );
59cdf0e10cSrcweir 		}
60cdf0e10cSrcweir 		catch ( Exception& e )
61cdf0e10cSrcweir 		{
62cdf0e10cSrcweir             (void)e;
63cdf0e10cSrcweir 			DBG_ERRORFILE( "NumberFormatCodeWrapper ctor: Exception caught!" );
64cdf0e10cSrcweir 		}
65cdf0e10cSrcweir 	}
66cdf0e10cSrcweir 	else
67cdf0e10cSrcweir 	{	// try to get an instance somehow
68cdf0e10cSrcweir 		DBG_ERRORFILE( "NumberFormatCodeWrapper: no service manager, trying own" );
69cdf0e10cSrcweir 		try
70cdf0e10cSrcweir 		{
71cdf0e10cSrcweir 			Reference< XInterface > xI = ::comphelper::getComponentInstance(
72cdf0e10cSrcweir 				::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( LLCF_LIBNAME( LOCALEDATA_LIBRARYNAME ) ) ),
73cdf0e10cSrcweir 				::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( LOCALEDATA_SERVICENAME ) ) );
74cdf0e10cSrcweir 			if ( xI.is() )
75cdf0e10cSrcweir 			{
76cdf0e10cSrcweir 				Any x = xI->queryInterface( ::getCppuType((const Reference< XNumberFormatCode >*)0) );
77cdf0e10cSrcweir 				x >>= xNFC;
78cdf0e10cSrcweir 			}
79cdf0e10cSrcweir 		}
80cdf0e10cSrcweir 		catch ( Exception& e )
81cdf0e10cSrcweir 		{
82cdf0e10cSrcweir             (void)e;
83cdf0e10cSrcweir 			DBG_ERRORFILE( "getComponentInstance: Exception caught!" );
84cdf0e10cSrcweir 		}
85cdf0e10cSrcweir 	}
86cdf0e10cSrcweir 	DBG_ASSERT( xNFC.is(), "NumberFormatCodeWrapper: no NumberFormatMapper" );
87cdf0e10cSrcweir }
88cdf0e10cSrcweir 
89cdf0e10cSrcweir 
~NumberFormatCodeWrapper()90cdf0e10cSrcweir NumberFormatCodeWrapper::~NumberFormatCodeWrapper()
91cdf0e10cSrcweir {
92cdf0e10cSrcweir }
93cdf0e10cSrcweir 
94cdf0e10cSrcweir 
setLocale(const::com::sun::star::lang::Locale & rLocale)95cdf0e10cSrcweir void NumberFormatCodeWrapper::setLocale( const ::com::sun::star::lang::Locale& rLocale )
96cdf0e10cSrcweir {
97cdf0e10cSrcweir 	aLocale = rLocale;
98cdf0e10cSrcweir }
99cdf0e10cSrcweir 
100cdf0e10cSrcweir 
101cdf0e10cSrcweir ::com::sun::star::i18n::NumberFormatCode
getDefault(sal_Int16 formatType,sal_Int16 formatUsage) const102cdf0e10cSrcweir NumberFormatCodeWrapper::getDefault( sal_Int16 formatType, sal_Int16 formatUsage ) const
103cdf0e10cSrcweir {
104cdf0e10cSrcweir 	try
105cdf0e10cSrcweir 	{
106cdf0e10cSrcweir 		if ( xNFC.is() )
107cdf0e10cSrcweir 			return xNFC->getDefault( formatType, formatUsage, aLocale );
108cdf0e10cSrcweir 	}
109cdf0e10cSrcweir 	catch ( Exception& e )
110cdf0e10cSrcweir 	{
111cdf0e10cSrcweir         (void)e;
112cdf0e10cSrcweir 		DBG_ERRORFILE( "getDefault: Exception caught!" );
113cdf0e10cSrcweir 	}
114cdf0e10cSrcweir 	return ::com::sun::star::i18n::NumberFormatCode();
115cdf0e10cSrcweir }
116cdf0e10cSrcweir 
117cdf0e10cSrcweir 
118cdf0e10cSrcweir ::com::sun::star::i18n::NumberFormatCode
getFormatCode(sal_Int16 formatIndex) const119cdf0e10cSrcweir NumberFormatCodeWrapper::getFormatCode( sal_Int16 formatIndex ) const
120cdf0e10cSrcweir {
121cdf0e10cSrcweir 	try
122cdf0e10cSrcweir 	{
123cdf0e10cSrcweir 		if ( xNFC.is() )
124cdf0e10cSrcweir 			return xNFC->getFormatCode( formatIndex, aLocale );
125cdf0e10cSrcweir 	}
126cdf0e10cSrcweir 	catch ( Exception& e )
127cdf0e10cSrcweir 	{
128cdf0e10cSrcweir         (void)e;
129cdf0e10cSrcweir 		DBG_ERRORFILE( "getFormatCode: Exception caught!" );
130cdf0e10cSrcweir 	}
131cdf0e10cSrcweir 	return ::com::sun::star::i18n::NumberFormatCode();
132cdf0e10cSrcweir }
133cdf0e10cSrcweir 
134cdf0e10cSrcweir 
135cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::com::sun::star::i18n::NumberFormatCode >
getAllFormatCode(sal_Int16 formatUsage) const136cdf0e10cSrcweir NumberFormatCodeWrapper::getAllFormatCode( sal_Int16 formatUsage ) const
137cdf0e10cSrcweir {
138cdf0e10cSrcweir 	try
139cdf0e10cSrcweir 	{
140cdf0e10cSrcweir 		if ( xNFC.is() )
141cdf0e10cSrcweir 			return xNFC->getAllFormatCode( formatUsage, aLocale );
142cdf0e10cSrcweir 	}
143cdf0e10cSrcweir 	catch ( Exception& e )
144cdf0e10cSrcweir 	{
145cdf0e10cSrcweir         (void)e;
146cdf0e10cSrcweir 		DBG_ERRORFILE( "getAllFormatCode: Exception caught!" );
147cdf0e10cSrcweir 	}
148cdf0e10cSrcweir 	return ::com::sun::star::uno::Sequence< ::com::sun::star::i18n::NumberFormatCode > (0);
149cdf0e10cSrcweir }
150cdf0e10cSrcweir 
151cdf0e10cSrcweir 
152cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::com::sun::star::i18n::NumberFormatCode >
getAllFormatCodes() const153cdf0e10cSrcweir NumberFormatCodeWrapper::getAllFormatCodes() const
154cdf0e10cSrcweir {
155cdf0e10cSrcweir 	try
156cdf0e10cSrcweir 	{
157cdf0e10cSrcweir 		if ( xNFC.is() )
158cdf0e10cSrcweir 			return xNFC->getAllFormatCodes( aLocale );
159cdf0e10cSrcweir 	}
160cdf0e10cSrcweir 	catch ( Exception& e )
161cdf0e10cSrcweir 	{
162cdf0e10cSrcweir         (void)e;
163cdf0e10cSrcweir 		DBG_ERRORFILE( "getAllFormatCodes: Exception caught!" );
164cdf0e10cSrcweir 	}
165cdf0e10cSrcweir 	return ::com::sun::star::uno::Sequence< ::com::sun::star::i18n::NumberFormatCode > (0);
166cdf0e10cSrcweir }
167