[Libreoffice-commits] .: 3 commits - desktop/source solenv/bin unotools/inc unotools/source

Michael Meeks michael at kemper.freedesktop.org
Fri Aug 19 04:29:55 PDT 2011


 desktop/source/app/app.cxx                       |   19 ++++--
 solenv/bin/linkoo                                |   19 ++++++
 unotools/inc/unotools/charclass.hxx              |    3 -
 unotools/source/i18n/calendarwrapper.cxx         |   51 ------------------
 unotools/source/i18n/charclass.cxx               |   48 +----------------
 unotools/source/i18n/collatorwrapper.cxx         |   45 +---------------
 unotools/source/i18n/instance.hxx                |   64 +++++++++++++++++++++++
 unotools/source/i18n/localedatawrapper.cxx       |   55 +------------------
 unotools/source/i18n/nativenumberwrapper.cxx     |   46 +---------------
 unotools/source/i18n/numberformatcodewrapper.cxx |   45 +---------------
 unotools/source/i18n/transliterationwrapper.cxx  |   45 +---------------
 11 files changed, 119 insertions(+), 321 deletions(-)

New commits:
commit a36485c82a964b71156f8e4d38f38abe6dd93868
Author: Michael Meeks <michael.meeks at novell.com>
Date:   Fri Aug 19 12:22:27 2011 +0100

    fix linkoo issue with preferring old libraries to new gnumake ones

diff --git a/solenv/bin/linkoo b/solenv/bin/linkoo
index ae6a7f2..5e06459 100755
--- a/solenv/bin/linkoo
+++ b/solenv/bin/linkoo
@@ -199,9 +199,24 @@ sub do_link($$$$@)
 sub scan_one_dir($$$$)
 {
     my ($installed_files, $build_files, $path, $solver) = @_;
+    my $dirh_module;
+
+    if (!$solver) {
+	if (opendir ($dirh_module, "$path/..")) {
+	    while (my $file = readdir ($dirh_module)) {
+		if ($file =~ /Library_.*\.mk/) {
+		    if (-d $path) {
+			print STDERR "gnu-makeified module contains stale output dir '$path', renaming it away\n";
+			rename ($path, "$path.obsolete"); # if it fails, nevermind ...
+		    }
+		    return;
+		}
+	    }
+	    closedir ($dirh_module);
+	}
+    }
 
     for my $elem (@search_dirs) {
-	my $dirh_module;
 	my $module_path = "$path/$elem";
 	if (opendir ($dirh_module, $module_path)) {
 	    while (my $file = readdir ($dirh_module)) {
@@ -214,7 +229,7 @@ sub scan_one_dir($$$$)
 			    }
 			}
 			if (!$known && !$solver) {
-			    print STDERR "\nlinkoo:: Unknown duplicate file '$file' in: '" . 
+			    print STDERR "\nlinkoo:: Unknown duplicate file '$file' in: '" .
 				$build_files->{$file} . "' vs '" .
 				$module_path . "' in module $path\n";
 			    exit (1);
commit 9950fc4f657ebc389185006137143e9782deccfc
Author: Michael Meeks <michael.meeks at novell.com>
Date:   Fri Aug 19 11:58:47 2011 +0100

    print fatal UNO exceptions' text in a friendly way from OpenClients failures

diff --git a/desktop/source/app/app.cxx b/desktop/source/app/app.cxx
index 4a02c28..786ca4d 100644
--- a/desktop/source/app/app.cxx
+++ b/desktop/source/app/app.cxx
@@ -2199,16 +2199,21 @@ IMPL_LINK( Desktop, OpenClients_Impl, void*, EMPTYARG )
 {
     RTL_LOGFILE_PRODUCT_CONTEXT( aLog, "PERFORMANCE - DesktopOpenClients_Impl()" );
 
-    OpenClients();
+    try {
+        OpenClients();
 
-    OfficeIPCThread::SetReady();
+        OfficeIPCThread::SetReady();
 
-    CloseSplashScreen();
-    CheckFirstRun( );
-    EnableOleAutomation();
+        CloseSplashScreen();
+        CheckFirstRun( );
+        EnableOleAutomation();
 
-    if (getenv ("OOO_EXIT_POST_STARTUP"))
-        new ExitTimer();
+        if (getenv ("OOO_EXIT_POST_STARTUP"))
+            new ExitTimer();
+    } catch (const ::com::sun::star::uno::Exception &e) {
+        String a( RTL_CONSTASCII_USTRINGPARAM( "UNO exception during client open:\n" ) );
+        Application::Abort( a + e.Message );
+    }
     return 0;
 }
 
commit d27d1489770666fe1d44f832882b67ac507033cd
Author: Michael Meeks <michael.meeks at novell.com>
Date:   Fri Aug 19 10:28:42 2011 +0100

    remove legacy explicit library loading fallbacks, and clean
    
    centralise cut/paste coding designed to explicitly load i18n and
    i18npool libraries if UNO is not bootstrapped. Instead fallback to
    the process service manager, and require this to be initialized,
    even for small tools.

diff --git a/unotools/inc/unotools/charclass.hxx b/unotools/inc/unotools/charclass.hxx
index 8cd379f..acb640d 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 4510981..bd79ab7 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 d4a9be1..a8343d9 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 58f0b17..e872b82 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 0000000..34c64de
--- /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 at 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 a8e1dcc..6bb166f 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 71e74fd..b1a8c8c 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 116c64f..430adbe 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 82b8492..fdeff1c 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" );
 }
 


More information about the Libreoffice-commits mailing list