update dev300-m58
[ooovba.git] / unotools / source / i18n / nativenumberwrapper.cxx
blob73ebcab654cc81978e1d29fa96d3cc50ed410e56
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: nativenumberwrapper.cxx,v $
10 * $Revision: 1.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_unotools.hxx"
34 #include <unotools/nativenumberwrapper.hxx>
35 #include <tools/debug.hxx>
37 #ifndef _COMPHELPER_COMPONENTFACTORY_HXX_
38 #include <comphelper/componentfactory.hxx>
39 #endif
40 #include <com/sun/star/uno/XInterface.hpp>
41 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
43 #define LOCALEDATA_LIBRARYNAME "i18npool"
44 #define LOCALEDATA_SERVICENAME "com.sun.star.i18n.NativeNumberSupplier"
46 using namespace ::com::sun::star;
49 NativeNumberWrapper::NativeNumberWrapper(
50 const uno::Reference< lang::XMultiServiceFactory > & xSF
53 xSMgr( xSF )
55 if ( xSMgr.is() )
57 try
59 xNNS = uno::Reference< i18n::XNativeNumberSupplier > ( xSMgr->createInstance(
60 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( LOCALEDATA_SERVICENAME ) ) ),
61 uno::UNO_QUERY );
63 catch ( uno::Exception& e )
65 (void)e;
66 DBG_ERRORFILE( "NativeNumberWrapper ctor: Exception caught!" );
69 else
70 { // try to get an instance somehow
71 DBG_ERRORFILE( "NativeNumberWrapper: no service manager, trying own" );
72 try
74 uno::Reference< uno::XInterface > xI = ::comphelper::getComponentInstance(
75 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( LLCF_LIBNAME( LOCALEDATA_LIBRARYNAME ) ) ),
76 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( LOCALEDATA_SERVICENAME ) ) );
77 if ( xI.is() )
79 uno::Any x = xI->queryInterface( ::getCppuType((const uno::Reference< i18n::XNativeNumberSupplier >*)0) );
80 x >>= xNNS;
83 catch ( uno::Exception& e )
85 (void)e;
86 DBG_ERRORFILE( "getComponentInstance: Exception caught!" );
89 DBG_ASSERT( xNNS.is(), "NativeNumberWrapper: no NativeNumberSupplier" );
93 NativeNumberWrapper::~NativeNumberWrapper()
98 ::rtl::OUString
99 NativeNumberWrapper::getNativeNumberString(
100 const ::rtl::OUString& rNumberString,
101 const ::com::sun::star::lang::Locale& rLocale,
102 sal_Int16 nNativeNumberMode ) const
106 if ( xNNS.is() )
107 return xNNS->getNativeNumberString( rNumberString, rLocale, nNativeNumberMode );
109 catch ( uno::Exception& e )
111 (void)e;
112 DBG_ERRORFILE( "getNativeNumberString: Exception caught!" );
114 return ::rtl::OUString();
118 sal_Bool
119 NativeNumberWrapper::isValidNatNum(
120 const ::com::sun::star::lang::Locale& rLocale,
121 sal_Int16 nNativeNumberMode ) const
125 if ( xNNS.is() )
126 return xNNS->isValidNatNum( rLocale, nNativeNumberMode );
128 catch ( uno::Exception& e )
130 (void)e;
131 DBG_ERRORFILE( "isValidNatNum: Exception caught!" );
133 return sal_False;
137 i18n::NativeNumberXmlAttributes
138 NativeNumberWrapper::convertToXmlAttributes(
139 const ::com::sun::star::lang::Locale& rLocale,
140 sal_Int16 nNativeNumberMode ) const
144 if ( xNNS.is() )
145 return xNNS->convertToXmlAttributes( rLocale, nNativeNumberMode );
147 catch ( uno::Exception& e )
149 (void)e;
150 DBG_ERRORFILE( "convertToXmlAttributes: Exception caught!" );
152 return i18n::NativeNumberXmlAttributes();
156 sal_Int16
157 NativeNumberWrapper::convertFromXmlAttributes(
158 const i18n::NativeNumberXmlAttributes& rAttr ) const
162 if ( xNNS.is() )
163 return xNNS->convertFromXmlAttributes( rAttr );
165 catch ( uno::Exception& e )
167 (void)e;
168 DBG_ERRORFILE( "convertFromXmlAttributes: Exception caught!" );
170 return 0;