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/nativenumberwrapper.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.NativeNumberSupplier"
38cdf0e10cSrcweir 
39cdf0e10cSrcweir using namespace ::com::sun::star;
40cdf0e10cSrcweir 
41cdf0e10cSrcweir 
NativeNumberWrapper(const uno::Reference<lang::XMultiServiceFactory> & xSF)42cdf0e10cSrcweir NativeNumberWrapper::NativeNumberWrapper(
43cdf0e10cSrcweir             const uno::Reference< lang::XMultiServiceFactory > & xSF
44cdf0e10cSrcweir             )
45cdf0e10cSrcweir         :
46cdf0e10cSrcweir         xSMgr( xSF )
47cdf0e10cSrcweir {
48cdf0e10cSrcweir     if ( xSMgr.is() )
49cdf0e10cSrcweir     {
50cdf0e10cSrcweir         try
51cdf0e10cSrcweir         {
52cdf0e10cSrcweir             xNNS = uno::Reference< i18n::XNativeNumberSupplier > ( xSMgr->createInstance(
53cdf0e10cSrcweir                 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( LOCALEDATA_SERVICENAME ) ) ),
54cdf0e10cSrcweir                 uno::UNO_QUERY );
55cdf0e10cSrcweir         }
56cdf0e10cSrcweir         catch ( uno::Exception& e )
57cdf0e10cSrcweir         {
58cdf0e10cSrcweir             (void)e;
59cdf0e10cSrcweir             DBG_ERRORFILE( "NativeNumberWrapper ctor: Exception caught!" );
60cdf0e10cSrcweir         }
61cdf0e10cSrcweir     }
62cdf0e10cSrcweir     else
63cdf0e10cSrcweir     {   // try to get an instance somehow
64cdf0e10cSrcweir         DBG_ERRORFILE( "NativeNumberWrapper: no service manager, trying own" );
65cdf0e10cSrcweir         try
66cdf0e10cSrcweir         {
67cdf0e10cSrcweir             uno::Reference< uno::XInterface > xI = ::comphelper::getComponentInstance(
68cdf0e10cSrcweir                 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( LLCF_LIBNAME( LOCALEDATA_LIBRARYNAME ) ) ),
69cdf0e10cSrcweir                 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( LOCALEDATA_SERVICENAME ) ) );
70cdf0e10cSrcweir             if ( xI.is() )
71cdf0e10cSrcweir             {
72cdf0e10cSrcweir                 uno::Any x = xI->queryInterface( ::getCppuType((const uno::Reference< i18n::XNativeNumberSupplier >*)0) );
73cdf0e10cSrcweir                 x >>= xNNS;
74cdf0e10cSrcweir             }
75cdf0e10cSrcweir         }
76cdf0e10cSrcweir         catch ( uno::Exception& e )
77cdf0e10cSrcweir         {
78cdf0e10cSrcweir             (void)e;
79cdf0e10cSrcweir             DBG_ERRORFILE( "getComponentInstance: Exception caught!" );
80cdf0e10cSrcweir         }
81cdf0e10cSrcweir     }
82cdf0e10cSrcweir     DBG_ASSERT( xNNS.is(), "NativeNumberWrapper: no NativeNumberSupplier" );
83cdf0e10cSrcweir }
84cdf0e10cSrcweir 
85cdf0e10cSrcweir 
~NativeNumberWrapper()86cdf0e10cSrcweir NativeNumberWrapper::~NativeNumberWrapper()
87cdf0e10cSrcweir {
88cdf0e10cSrcweir }
89cdf0e10cSrcweir 
90cdf0e10cSrcweir 
91cdf0e10cSrcweir ::rtl::OUString
getNativeNumberString(const::rtl::OUString & rNumberString,const::com::sun::star::lang::Locale & rLocale,sal_Int16 nNativeNumberMode) const92cdf0e10cSrcweir NativeNumberWrapper::getNativeNumberString(
93cdf0e10cSrcweir                     const ::rtl::OUString& rNumberString,
94cdf0e10cSrcweir                     const ::com::sun::star::lang::Locale& rLocale,
95cdf0e10cSrcweir                     sal_Int16 nNativeNumberMode ) const
96cdf0e10cSrcweir {
97cdf0e10cSrcweir     try
98cdf0e10cSrcweir     {
99cdf0e10cSrcweir         if ( xNNS.is() )
100cdf0e10cSrcweir             return xNNS->getNativeNumberString( rNumberString, rLocale, nNativeNumberMode );
101cdf0e10cSrcweir     }
102cdf0e10cSrcweir     catch ( uno::Exception& e )
103cdf0e10cSrcweir     {
104cdf0e10cSrcweir         (void)e;
105cdf0e10cSrcweir         DBG_ERRORFILE( "getNativeNumberString: Exception caught!" );
106cdf0e10cSrcweir     }
107cdf0e10cSrcweir     return ::rtl::OUString();
108cdf0e10cSrcweir }
109cdf0e10cSrcweir 
110cdf0e10cSrcweir 
111cdf0e10cSrcweir sal_Bool
isValidNatNum(const::com::sun::star::lang::Locale & rLocale,sal_Int16 nNativeNumberMode) const112cdf0e10cSrcweir NativeNumberWrapper::isValidNatNum(
113cdf0e10cSrcweir                     const ::com::sun::star::lang::Locale& rLocale,
114cdf0e10cSrcweir                     sal_Int16 nNativeNumberMode ) const
115cdf0e10cSrcweir {
116cdf0e10cSrcweir     try
117cdf0e10cSrcweir     {
118cdf0e10cSrcweir         if ( xNNS.is() )
119cdf0e10cSrcweir             return xNNS->isValidNatNum( rLocale, nNativeNumberMode );
120cdf0e10cSrcweir     }
121cdf0e10cSrcweir     catch ( uno::Exception& e )
122cdf0e10cSrcweir     {
123cdf0e10cSrcweir         (void)e;
124cdf0e10cSrcweir         DBG_ERRORFILE( "isValidNatNum: Exception caught!" );
125cdf0e10cSrcweir     }
126cdf0e10cSrcweir     return sal_False;
127cdf0e10cSrcweir }
128cdf0e10cSrcweir 
129cdf0e10cSrcweir 
130cdf0e10cSrcweir i18n::NativeNumberXmlAttributes
convertToXmlAttributes(const::com::sun::star::lang::Locale & rLocale,sal_Int16 nNativeNumberMode) const131cdf0e10cSrcweir NativeNumberWrapper::convertToXmlAttributes(
132cdf0e10cSrcweir                     const ::com::sun::star::lang::Locale& rLocale,
133cdf0e10cSrcweir                     sal_Int16 nNativeNumberMode ) const
134cdf0e10cSrcweir {
135cdf0e10cSrcweir     try
136cdf0e10cSrcweir     {
137cdf0e10cSrcweir         if ( xNNS.is() )
138cdf0e10cSrcweir             return xNNS->convertToXmlAttributes( rLocale, nNativeNumberMode );
139cdf0e10cSrcweir     }
140cdf0e10cSrcweir     catch ( uno::Exception& e )
141cdf0e10cSrcweir     {
142cdf0e10cSrcweir         (void)e;
143cdf0e10cSrcweir         DBG_ERRORFILE( "convertToXmlAttributes: Exception caught!" );
144cdf0e10cSrcweir     }
145cdf0e10cSrcweir     return i18n::NativeNumberXmlAttributes();
146cdf0e10cSrcweir }
147cdf0e10cSrcweir 
148cdf0e10cSrcweir 
149cdf0e10cSrcweir sal_Int16
convertFromXmlAttributes(const i18n::NativeNumberXmlAttributes & rAttr) const150cdf0e10cSrcweir NativeNumberWrapper::convertFromXmlAttributes(
151cdf0e10cSrcweir                     const i18n::NativeNumberXmlAttributes& rAttr ) const
152cdf0e10cSrcweir {
153cdf0e10cSrcweir     try
154cdf0e10cSrcweir     {
155cdf0e10cSrcweir         if ( xNNS.is() )
156cdf0e10cSrcweir             return xNNS->convertFromXmlAttributes( rAttr );
157cdf0e10cSrcweir     }
158cdf0e10cSrcweir     catch ( uno::Exception& e )
159cdf0e10cSrcweir     {
160cdf0e10cSrcweir         (void)e;
161cdf0e10cSrcweir         DBG_ERRORFILE( "convertFromXmlAttributes: Exception caught!" );
162cdf0e10cSrcweir     }
163cdf0e10cSrcweir     return 0;
164cdf0e10cSrcweir }
165cdf0e10cSrcweir 
166cdf0e10cSrcweir 
167