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