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