diff options
Diffstat (limited to 'unotools')
-rw-r--r-- | unotools/inc/unotools/charclass.hxx | 3 | ||||
-rw-r--r-- | unotools/source/i18n/calendarwrapper.cxx | 51 | ||||
-rw-r--r-- | unotools/source/i18n/charclass.cxx | 48 | ||||
-rw-r--r-- | unotools/source/i18n/collatorwrapper.cxx | 45 | ||||
-rw-r--r-- | unotools/source/i18n/instance.hxx | 64 | ||||
-rw-r--r-- | unotools/source/i18n/localedatawrapper.cxx | 55 | ||||
-rw-r--r-- | unotools/source/i18n/nativenumberwrapper.cxx | 46 | ||||
-rw-r--r-- | unotools/source/i18n/numberformatcodewrapper.cxx | 45 | ||||
-rw-r--r-- | unotools/source/i18n/transliterationwrapper.cxx | 45 |
9 files changed, 90 insertions, 312 deletions
diff --git a/unotools/inc/unotools/charclass.hxx b/unotools/inc/unotools/charclass.hxx index 8cd379f678dd..acb640d36825 100644 --- a/unotools/inc/unotools/charclass.hxx +++ b/unotools/inc/unotools/charclass.hxx @@ -85,9 +85,6 @@ class UNOTOOLS_DLLPUBLIC CharClass CharClass( const CharClass& ); CharClass& operator=( const CharClass& ); - // instantiate component somehow - void getComponentInstance(); - public: /// Preferred ctor with service manager specified CharClass( diff --git a/unotools/source/i18n/calendarwrapper.cxx b/unotools/source/i18n/calendarwrapper.cxx index 4510981a8bd2..bd79ab71ee01 100644 --- a/unotools/source/i18n/calendarwrapper.cxx +++ b/unotools/source/i18n/calendarwrapper.cxx @@ -32,16 +32,13 @@ #include <unotools/calendarwrapper.hxx> #include <tools/string.hxx> #include <tools/debug.hxx> - -#include <comphelper/componentfactory.hxx> +#include <instance.hxx> #include <com/sun/star/i18n/CalendarFieldIndex.hpp> #include <com/sun/star/i18n/XExtendedCalendar.hpp> -#include <com/sun/star/lang/XMultiServiceFactory.hpp> #define CALENDAR_LIBRARYNAME "i18n" #define CALENDAR_SERVICENAME "com.sun.star.i18n.LocaleCalendar" - using namespace ::com::sun::star; using namespace ::com::sun::star::i18n; using namespace ::com::sun::star::uno; @@ -57,53 +54,9 @@ CalendarWrapper::CalendarWrapper( xSMgr( xSF ), aEpochStart( Date( 1, 1, 1970 ) ) { - if ( xSMgr.is() ) - { - try - { - xC = Reference< XExtendedCalendar > ( xSMgr->createInstance( - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( CALENDAR_SERVICENAME ) ) ), - uno::UNO_QUERY ); - } - catch ( Exception& e ) - { -#ifdef DBG_UTIL - ByteString aMsg( "CalendarWrapper ctor: Exception caught\n" ); - aMsg += ByteString( String( e.Message ), RTL_TEXTENCODING_UTF8 ); - DBG_ERRORFILE( aMsg.GetBuffer() ); -#else - (void)e; -#endif - } - } - else - { // try to get an instance somehow - DBG_ERRORFILE( "CalendarWrapper: no service manager, trying own" ); - try - { - Reference< XInterface > xI = ::comphelper::getComponentInstance( - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( LLCF_LIBNAME( CALENDAR_LIBRARYNAME ) ) ), - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( CALENDAR_SERVICENAME ) ) ); - if ( xI.is() ) - { - Any x = xI->queryInterface( ::getCppuType((const Reference< XExtendedCalendar >*)0) ); - x >>= xC; - } - } - catch ( Exception& e ) - { -#ifdef DBG_UTIL - ByteString aMsg( "getComponentInstance: Exception caught\n" ); - aMsg += ByteString( String( e.Message ), RTL_TEXTENCODING_UTF8 ); - DBG_ERRORFILE( aMsg.GetBuffer() ); -#else - (void)e; -#endif - } - } + xC = Reference< XExtendedCalendar >( intl_createInstance( xSMgr, CALENDAR_SERVICENAME, "CalendarWrapper" ), uno::UNO_QUERY ); } - CalendarWrapper::~CalendarWrapper() { } diff --git a/unotools/source/i18n/charclass.cxx b/unotools/source/i18n/charclass.cxx index d4a9be17929a..a8343d98eec3 100644 --- a/unotools/source/i18n/charclass.cxx +++ b/unotools/source/i18n/charclass.cxx @@ -33,11 +33,8 @@ #include <tools/string.hxx> #include <tools/debug.hxx> -#include <comphelper/componentfactory.hxx> -#include <com/sun/star/uno/XInterface.hpp> -#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include "instance.hxx" -#define CHARCLASS_LIBRARYNAME "i18n" #define CHARCLASS_SERVICENAME "com.sun.star.i18n.CharacterClassification" using namespace ::com::sun::star; @@ -53,23 +50,7 @@ CharClass::CharClass( xSMgr( xSF ) { setLocale( rLocale ); - if ( xSMgr.is() ) - { - try - { - xCC = Reference< XCharacterClassification > ( xSMgr->createInstance( - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( CHARCLASS_SERVICENAME ) ) ), - uno::UNO_QUERY ); - } - catch ( const Exception& ) - { - DBG_ERRORFILE( "CharClass ctor: Exception caught!" ); - } - } - else - { // try to get an instance somehow - getComponentInstance(); - } + xCC = Reference< XCharacterClassification > ( intl_createInstance( xSMgr, CHARCLASS_SERVICENAME, "CharClass" ), uno::UNO_QUERY ); } @@ -77,7 +58,8 @@ CharClass::CharClass( const ::com::sun::star::lang::Locale& rLocale ) { setLocale( rLocale ); - getComponentInstance(); + Reference< lang::XMultiServiceFactory > xNil; + xCC = Reference< XCharacterClassification > ( intl_createInstance( xNil, CHARCLASS_SERVICENAME, "CharClass" ), uno::UNO_QUERY ); } @@ -86,28 +68,6 @@ CharClass::~CharClass() } -void CharClass::getComponentInstance() -{ - try - { - // CharClass may be needed by "small tools" like the Setup - // => maybe no service manager => loadLibComponentFactory - Reference < XInterface > xI = ::comphelper::getComponentInstance( - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( LLCF_LIBNAME( CHARCLASS_LIBRARYNAME ) ) ), - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( CHARCLASS_SERVICENAME ) ) ); - if ( xI.is() ) - { - Any x = xI->queryInterface( ::getCppuType((const Reference< XCharacterClassification >*)0) ); - x >>= xCC; - } - } - catch ( const Exception& ) - { - DBG_ERRORFILE( "getComponentInstance: Exception caught!" ); - } -} - - void CharClass::setLocale( const ::com::sun::star::lang::Locale& rLocale ) { ::osl::MutexGuard aGuard( aMutex ); diff --git a/unotools/source/i18n/collatorwrapper.cxx b/unotools/source/i18n/collatorwrapper.cxx index 58f0b1764914..e872b8271b59 100644 --- a/unotools/source/i18n/collatorwrapper.cxx +++ b/unotools/source/i18n/collatorwrapper.cxx @@ -31,9 +31,7 @@ #include <unotools/collatorwrapper.hxx> #include <tools/debug.hxx> -#include <comphelper/componentfactory.hxx> -#include <com/sun/star/uno/XInterface.hpp> -#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include "instance.hxx" using namespace ::com::sun::star; @@ -41,44 +39,9 @@ CollatorWrapper::CollatorWrapper ( const uno::Reference< lang::XMultiServiceFactory > &xServiceFactory) : mxServiceFactory (xServiceFactory) { - ::rtl::OUString aService (RTL_CONSTASCII_USTRINGPARAM("com.sun.star.i18n.Collator")); - - if (mxServiceFactory.is()) - { - try - { - mxInternationalCollator = uno::Reference< i18n::XCollator > ( - mxServiceFactory->createInstance(aService), uno::UNO_QUERY); - } - catch (uno::Exception& rException) - { - (void)rException; - DBG_ERRORFILE ("CollatorWrapper: failed to create instance"); - } - } - else - { - ::rtl::OUString aLibrary (RTL_CONSTASCII_USTRINGPARAM(LLCF_LIBNAME("i18n"))); - - try - { - uno::Reference< uno::XInterface > xInstance = - ::comphelper::getComponentInstance (aLibrary, aService); - - if (xInstance.is()) - { - uno::Any xInterface = xInstance->queryInterface ( - ::getCppuType((const uno::Reference< i18n::XCollator >*)0) ); - xInterface >>= mxInternationalCollator; - } - } - catch (uno::Exception& rException) - { - (void)rException; - DBG_ERRORFILE ("CollatorWrapper: failed to get component instance!"); - } - } - + mxInternationalCollator = uno::Reference< i18n::XCollator > ( + intl_createInstance( xServiceFactory, "com.sun.star.i18n.Collator", + "CollatorWrapper" ), uno::UNO_QUERY ); DBG_ASSERT (mxInternationalCollator.is(), "CollatorWrapper: no i18n collator"); } diff --git a/unotools/source/i18n/instance.hxx b/unotools/source/i18n/instance.hxx new file mode 100644 index 000000000000..34c64decb58a --- /dev/null +++ b/unotools/source/i18n/instance.hxx @@ -0,0 +1,64 @@ +/* + * Version: MPL 1.1 / GPLv3+ / LGPLv3+ + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License or as specified alternatively below. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * Major Contributor(s): + * Copyright (C) 2011 Novell, Inc <michael.meeks@novell.com> (initial developer) + * + * All Rights Reserved. + * + * For minor contributions see the git repository. + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 3 or later (the "GPLv3+"), or + * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"), + * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable + * instead of those above. + */ +#ifndef _INTL_INSTANCE_HXX +#define INTL_INSTANCE_HXX + +#include <comphelper/processfactory.hxx> +#include <comphelper/componentfactory.hxx> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> + +// ugly but so is this namespacing evil. +#define css ::com::sun::star + +// Helper to share code between activators with a fallback MSF. +// Potentially this may also needs to find the library the component +// is implemented inside, but at least centralises this. +inline css::uno::Reference<css::uno::XInterface> + intl_createInstance( const css::uno::Reference< css::lang::XMultiServiceFactory > & xOptSF, + const char *serviceName, const char *context ) +{ + css::uno::Reference<css::uno::XInterface> xRet; + css::uno::Reference<css::lang::XMultiServiceFactory > xSMgr( xOptSF ); + try { + if (!xSMgr.is()) + xSMgr = ::comphelper::getProcessServiceFactory(); + xRet = xSMgr->createInstance( rtl::OUString::createFromAscii( serviceName ) ); + } catch (css::uno::Exception &e) { +#ifdef DBG_UTIL + ByteString aMsg( context ); + aMsg += "ctor: Exception caught\n"; + aMsg += ByteString( String( e.Message ), RTL_TEXTENCODING_UTF8 ); + DBG_ERRORFILE( aMsg.GetBuffer() ); +#else + (void)e; (void)context; +#endif + xRet = css::uno::Reference<css::uno::XInterface>(); + } + return xRet; +} + +#endif // _INTL_INSTANCE_HXX diff --git a/unotools/source/i18n/localedatawrapper.cxx b/unotools/source/i18n/localedatawrapper.cxx index a8e1dccf0727..6bb166fdc7a4 100644 --- a/unotools/source/i18n/localedatawrapper.cxx +++ b/unotools/source/i18n/localedatawrapper.cxx @@ -40,10 +40,7 @@ #include <tools/debug.hxx> #include <i18npool/mslangid.hxx> -#include <comphelper/componentfactory.hxx> -#include <unotools/processfactory.hxx> -#include <com/sun/star/uno/XInterface.hpp> -#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include "instance.hxx" #include <com/sun/star/i18n/KNumberFormatUsage.hpp> #include <com/sun/star/i18n/KNumberFormatType.hpp> #include <com/sun/star/i18n/CalendarFieldIndex.hpp> @@ -54,9 +51,6 @@ #include <rtl/ustrbuf.hxx> #include <sal/macros.h> -#define LOCALEDATA_LIBRARYNAME "i18npool" -#define LOCALEDATA_SERVICENAME "com.sun.star.i18n.LocaleData" - static const int nDateFormatInvalid = -1; static const sal_uInt16 nCurrFormatInvalid = 0xffff; static const sal_uInt16 nCurrFormatDefault = 0; @@ -90,50 +84,9 @@ LocaleDataWrapper::LocaleDataWrapper( bReservedWordValid( sal_False ) { setLocale( rLocale ); - if ( xSMgr.is() ) - { - try - { - xLD = Reference< XLocaleData2 > ( xSMgr->createInstance( - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( LOCALEDATA_SERVICENAME ) ) ), - uno::UNO_QUERY ); - } - catch ( Exception& e ) - { -#ifdef DBG_UTIL - ByteString aMsg( "LocaleDataWrapper ctor: Exception caught\n" ); - aMsg += ByteString( String( e.Message ), RTL_TEXTENCODING_UTF8 ); - DBG_ERRORFILE( aMsg.GetBuffer() ); -#else - (void)e; -#endif - } - } - else - { // try to get an instance somehow - DBG_ERRORFILE( "LocaleDataWrapper: no service manager, trying own" ); - try - { - Reference< XInterface > xI = ::comphelper::getComponentInstance( - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( LLCF_LIBNAME( LOCALEDATA_LIBRARYNAME ) ) ), - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( LOCALEDATA_SERVICENAME ) ) ); - if ( xI.is() ) - { - Any x = xI->queryInterface( ::getCppuType((const Reference< XLocaleData2 >*)0) ); - x >>= xLD; - } - } - catch ( Exception& e ) - { -#ifdef DBG_UTIL - ByteString aMsg( "getComponentInstance: Exception caught\n" ); - aMsg += ByteString( String( e.Message ), RTL_TEXTENCODING_UTF8 ); - DBG_ERRORFILE( aMsg.GetBuffer() ); -#else - (void)e; -#endif - } - } + xLD = Reference< XLocaleData2 > ( + intl_createInstance( xSMgr, "com.sun.star.i18n.LocaleData", + "LocaleDataWrapper" ), uno::UNO_QUERY ); } diff --git a/unotools/source/i18n/nativenumberwrapper.cxx b/unotools/source/i18n/nativenumberwrapper.cxx index 71e74fd0c249..b1a8c8c7591b 100644 --- a/unotools/source/i18n/nativenumberwrapper.cxx +++ b/unotools/source/i18n/nativenumberwrapper.cxx @@ -31,57 +31,19 @@ #include <unotools/nativenumberwrapper.hxx> #include <tools/debug.hxx> - -#include <comphelper/componentfactory.hxx> -#include <com/sun/star/uno/XInterface.hpp> -#include <com/sun/star/lang/XMultiServiceFactory.hpp> - -#define LOCALEDATA_LIBRARYNAME "i18npool" -#define LOCALEDATA_SERVICENAME "com.sun.star.i18n.NativeNumberSupplier" +#include "instance.hxx" using namespace ::com::sun::star; - NativeNumberWrapper::NativeNumberWrapper( const uno::Reference< lang::XMultiServiceFactory > & xSF ) : xSMgr( xSF ) { - if ( xSMgr.is() ) - { - try - { - xNNS = uno::Reference< i18n::XNativeNumberSupplier > ( xSMgr->createInstance( - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( LOCALEDATA_SERVICENAME ) ) ), - uno::UNO_QUERY ); - } - catch ( uno::Exception& e ) - { - (void)e; - DBG_ERRORFILE( "NativeNumberWrapper ctor: Exception caught!" ); - } - } - else - { // try to get an instance somehow - DBG_ERRORFILE( "NativeNumberWrapper: no service manager, trying own" ); - try - { - uno::Reference< uno::XInterface > xI = ::comphelper::getComponentInstance( - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( LLCF_LIBNAME( LOCALEDATA_LIBRARYNAME ) ) ), - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( LOCALEDATA_SERVICENAME ) ) ); - if ( xI.is() ) - { - uno::Any x = xI->queryInterface( ::getCppuType((const uno::Reference< i18n::XNativeNumberSupplier >*)0) ); - x >>= xNNS; - } - } - catch ( uno::Exception& e ) - { - (void)e; - DBG_ERRORFILE( "getComponentInstance: Exception caught!" ); - } - } + xNNS = uno::Reference< i18n::XNativeNumberSupplier > ( + intl_createInstance( xSMgr, "com.sun.star.i18n.NativeNumberSupplier", + "NativeNumberWrapper"), uno::UNO_QUERY ); DBG_ASSERT( xNNS.is(), "NativeNumberWrapper: no NativeNumberSupplier" ); } diff --git a/unotools/source/i18n/numberformatcodewrapper.cxx b/unotools/source/i18n/numberformatcodewrapper.cxx index 116c64f9fc70..430adbefdea9 100644 --- a/unotools/source/i18n/numberformatcodewrapper.cxx +++ b/unotools/source/i18n/numberformatcodewrapper.cxx @@ -31,13 +31,7 @@ #include <unotools/numberformatcodewrapper.hxx> #include <tools/debug.hxx> - -#include <comphelper/componentfactory.hxx> -#include <com/sun/star/uno/XInterface.hpp> -#include <com/sun/star/lang/XMultiServiceFactory.hpp> - -#define LOCALEDATA_LIBRARYNAME "i18npool" -#define LOCALEDATA_SERVICENAME "com.sun.star.i18n.NumberFormatMapper" +#include "instance.hxx" using namespace ::com::sun::star; using namespace ::com::sun::star::i18n; @@ -52,40 +46,9 @@ NumberFormatCodeWrapper::NumberFormatCodeWrapper( xSMgr( xSF ) { setLocale( rLocale ); - if ( xSMgr.is() ) - { - try - { - xNFC = Reference< XNumberFormatCode > ( xSMgr->createInstance( - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( LOCALEDATA_SERVICENAME ) ) ), - uno::UNO_QUERY ); - } - catch ( Exception& e ) - { - (void)e; - DBG_ERRORFILE( "NumberFormatCodeWrapper ctor: Exception caught!" ); - } - } - else - { // try to get an instance somehow - DBG_ERRORFILE( "NumberFormatCodeWrapper: no service manager, trying own" ); - try - { - Reference< XInterface > xI = ::comphelper::getComponentInstance( - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( LLCF_LIBNAME( LOCALEDATA_LIBRARYNAME ) ) ), - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( LOCALEDATA_SERVICENAME ) ) ); - if ( xI.is() ) - { - Any x = xI->queryInterface( ::getCppuType((const Reference< XNumberFormatCode >*)0) ); - x >>= xNFC; - } - } - catch ( Exception& e ) - { - (void)e; - DBG_ERRORFILE( "getComponentInstance: Exception caught!" ); - } - } + xNFC = Reference< XNumberFormatCode > ( + intl_createInstance( xSMgr, "com.sun.star.i18n.NumberFormatMapper", + "NumberFormatCodeWrapper" ), uno::UNO_QUERY ); DBG_ASSERT( xNFC.is(), "NumberFormatCodeWrapper: no NumberFormatMapper" ); } diff --git a/unotools/source/i18n/transliterationwrapper.cxx b/unotools/source/i18n/transliterationwrapper.cxx index 82b8492f80ce..fdeff1c90e9f 100644 --- a/unotools/source/i18n/transliterationwrapper.cxx +++ b/unotools/source/i18n/transliterationwrapper.cxx @@ -34,14 +34,9 @@ #include <i18npool/mslangid.hxx> #include <comphelper/componentfactory.hxx> -#include <com/sun/star/uno/XInterface.hpp> -#include <com/sun/star/lang/XMultiServiceFactory.hpp> -#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include "instance.hxx" #include <com/sun/star/i18n/TransliterationModulesExtra.hpp> -#define TRANSLIT_LIBRARYNAME "i18n" -#define TRANSLIT_SERVICENAME "com.sun.star.i18n.Transliteration" - using namespace ::com::sun::star::lang; using namespace ::com::sun::star::i18n; using namespace ::com::sun::star::uno; @@ -52,41 +47,9 @@ TransliterationWrapper::TransliterationWrapper( sal_uInt32 nTyp ) : xSMgr( xSF ), nType( nTyp ), nLanguage( 0 ), bFirstCall( sal_True ) { - if( xSMgr.is() ) - { - try { - xTrans = Reference< XExtendedTransliteration > ( - xSMgr->createInstance( ::rtl::OUString( - RTL_CONSTASCII_USTRINGPARAM( - TRANSLIT_SERVICENAME))), UNO_QUERY ); - } - catch ( Exception& ) - { - DBG_ERRORFILE( "TransliterationWrapper: Exception caught!" ); - } - } - else - { // try to get an instance somehow - DBG_ERRORFILE( "TransliterationWrapper: no service manager, trying own" ); - try - { - Reference< XInterface > xI = ::comphelper::getComponentInstance( - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( LLCF_LIBNAME( - TRANSLIT_LIBRARYNAME ))), - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( - TRANSLIT_SERVICENAME))); - if ( xI.is() ) - { - Any x = xI->queryInterface( - ::getCppuType((const Reference< XExtendedTransliteration>*)0) ); - x >>= xTrans ; - } - } - catch ( Exception& ) - { - DBG_ERRORFILE( "getComponentInstance: Exception caught!" ); - } - } + xTrans = Reference< XExtendedTransliteration > ( + intl_createInstance( xSMgr, "com.sun.star.i18n.Transliteration", + "TransliterationWrapper" ), UNO_QUERY ); DBG_ASSERT( xTrans.is(), "TransliterationWrapper: no Transliteraion available" ); } |