[Libreoffice-commits] core.git: 3 commits - filter/source sc/Library_scd.mk sc/source sc/util

Kohei Yoshida kohei.yoshida at gmail.com
Mon Feb 4 22:24:26 PST 2013


 filter/source/config/fragments/types/calc_MS_Excel_40.xcu                   |    2 
 filter/source/config/fragments/types/calc_MS_Excel_40_VorlageTemplate.xcu   |    2 
 filter/source/config/fragments/types/calc_MS_Excel_5095.xcu                 |    2 
 filter/source/config/fragments/types/calc_MS_Excel_5095_VorlageTemplate.xcu |    2 
 filter/source/config/fragments/types/calc_MS_Excel_95.xcu                   |    2 
 filter/source/config/fragments/types/calc_MS_Excel_95_VorlageTemplate.xcu   |    2 
 filter/source/config/fragments/types/calc_MS_Excel_97.xcu                   |    2 
 filter/source/config/fragments/types/calc_MS_Excel_97_VorlageTemplate.xcu   |    2 
 sc/Library_scd.mk                                                           |    1 
 sc/source/ui/unoobj/detreg.cxx                                              |   66 +---
 sc/source/ui/unoobj/exceldetect.cxx                                         |  162 ++++++++++
 sc/source/ui/unoobj/exceldetect.hxx                                         |   46 ++
 sc/source/ui/unoobj/scdetect.cxx                                            |    7 
 sc/source/ui/unoobj/scdetect.hxx                                            |    7 
 sc/util/scd.component                                                       |    3 
 15 files changed, 253 insertions(+), 55 deletions(-)

New commits:
commit fed4f58030db4e9afd83044201b06d437345fc3f
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Tue Feb 5 01:21:45 2013 -0500

    Use the new excel format detector for all binary excel types.
    
    But I have yet to implement the detection of Excel 4.0...
    
    Separating detection services like this will make the overall type
    detection process a little more reliable. It's actually not a good
    idea to use a single type detection service for a multitude of file
    format types...
    
    Change-Id: I2914c179ac939a031b84e8d37de891a5043851e6

diff --git a/filter/source/config/fragments/types/calc_MS_Excel_40.xcu b/filter/source/config/fragments/types/calc_MS_Excel_40.xcu
index 1506f7e..b99cfc4 100644
--- a/filter/source/config/fragments/types/calc_MS_Excel_40.xcu
+++ b/filter/source/config/fragments/types/calc_MS_Excel_40.xcu
@@ -16,7 +16,7 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 -->
     <node oor:name="calc_MS_Excel_40" oor:op="replace" >
-        <prop oor:name="DetectService"><value>com.sun.star.comp.calc.FormatDetector</value></prop>
+        <prop oor:name="DetectService"><value>com.sun.star.comp.calc.ExcelBiffFormatDetector</value></prop>
         <prop oor:name="URLPattern"/>
         <prop oor:name="Extensions"><value>xls xlw xlc xlm</value></prop>
         <prop oor:name="MediaType"><value>application/vnd.ms-excel</value></prop>
diff --git a/filter/source/config/fragments/types/calc_MS_Excel_40_VorlageTemplate.xcu b/filter/source/config/fragments/types/calc_MS_Excel_40_VorlageTemplate.xcu
index ed9ccb2..69304a7 100644
--- a/filter/source/config/fragments/types/calc_MS_Excel_40_VorlageTemplate.xcu
+++ b/filter/source/config/fragments/types/calc_MS_Excel_40_VorlageTemplate.xcu
@@ -16,7 +16,7 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 -->
     <node oor:name="calc_MS_Excel_40_VorlageTemplate" oor:op="replace" >
-        <prop oor:name="DetectService"><value>com.sun.star.comp.calc.FormatDetector</value></prop>
+        <prop oor:name="DetectService"><value>com.sun.star.comp.calc.ExcelBiffFormatDetector</value></prop>
         <prop oor:name="URLPattern"/>
         <prop oor:name="Extensions"><value>xlt</value></prop>
         <prop oor:name="MediaType"><value>application/vnd.ms-excel</value></prop>
diff --git a/filter/source/config/fragments/types/calc_MS_Excel_5095.xcu b/filter/source/config/fragments/types/calc_MS_Excel_5095.xcu
index b1f7a87..c1e5371 100644
--- a/filter/source/config/fragments/types/calc_MS_Excel_5095.xcu
+++ b/filter/source/config/fragments/types/calc_MS_Excel_5095.xcu
@@ -16,7 +16,7 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 -->
     <node oor:name="calc_MS_Excel_5095" oor:op="replace" >
-        <prop oor:name="DetectService"><value>com.sun.star.comp.calc.FormatDetector</value></prop>
+        <prop oor:name="DetectService"><value>com.sun.star.comp.calc.ExcelBiffFormatDetector</value></prop>
         <prop oor:name="URLPattern"/>
         <prop oor:name="Extensions"><value>xls xlc xlm xlw</value></prop>
         <prop oor:name="MediaType"><value>application/vnd.ms-excel</value></prop>
diff --git a/filter/source/config/fragments/types/calc_MS_Excel_5095_VorlageTemplate.xcu b/filter/source/config/fragments/types/calc_MS_Excel_5095_VorlageTemplate.xcu
index b14111f..ead4b04 100644
--- a/filter/source/config/fragments/types/calc_MS_Excel_5095_VorlageTemplate.xcu
+++ b/filter/source/config/fragments/types/calc_MS_Excel_5095_VorlageTemplate.xcu
@@ -16,7 +16,7 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 -->
     <node oor:name="calc_MS_Excel_5095_VorlageTemplate" oor:op="replace" >
-        <prop oor:name="DetectService"><value>com.sun.star.comp.calc.FormatDetector</value></prop>
+        <prop oor:name="DetectService"><value>com.sun.star.comp.calc.ExcelBiffFormatDetector</value></prop>
         <prop oor:name="URLPattern"/>
         <prop oor:name="Extensions"><value>xlt</value></prop>
         <prop oor:name="MediaType"><value>application/vnd.ms-excel</value></prop>
diff --git a/filter/source/config/fragments/types/calc_MS_Excel_95.xcu b/filter/source/config/fragments/types/calc_MS_Excel_95.xcu
index 4e20ce8..25e1d33 100644
--- a/filter/source/config/fragments/types/calc_MS_Excel_95.xcu
+++ b/filter/source/config/fragments/types/calc_MS_Excel_95.xcu
@@ -16,7 +16,7 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 -->
     <node oor:name="calc_MS_Excel_95" oor:op="replace" >
-        <prop oor:name="DetectService"><value>com.sun.star.comp.calc.FormatDetector</value></prop>
+        <prop oor:name="DetectService"><value>com.sun.star.comp.calc.ExcelBiffFormatDetector</value></prop>
         <prop oor:name="URLPattern"/>
         <prop oor:name="Extensions"><value>xls xlc xlm xlw</value></prop>
         <prop oor:name="MediaType"><value>application/vnd.ms-excel</value></prop>
diff --git a/filter/source/config/fragments/types/calc_MS_Excel_95_VorlageTemplate.xcu b/filter/source/config/fragments/types/calc_MS_Excel_95_VorlageTemplate.xcu
index 4376a5e..fc3e68f 100644
--- a/filter/source/config/fragments/types/calc_MS_Excel_95_VorlageTemplate.xcu
+++ b/filter/source/config/fragments/types/calc_MS_Excel_95_VorlageTemplate.xcu
@@ -16,7 +16,7 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 -->
     <node oor:name="calc_MS_Excel_95_VorlageTemplate" oor:op="replace" >
-        <prop oor:name="DetectService"><value>com.sun.star.comp.calc.FormatDetector</value></prop>
+        <prop oor:name="DetectService"><value>com.sun.star.comp.calc.ExcelBiffFormatDetector</value></prop>
         <prop oor:name="URLPattern"/>
         <prop oor:name="Extensions"><value>xlt</value></prop>
         <prop oor:name="MediaType"><value>application/vnd.ms-excel</value></prop>
diff --git a/filter/source/config/fragments/types/calc_MS_Excel_97.xcu b/filter/source/config/fragments/types/calc_MS_Excel_97.xcu
index da3fd39..6df277a 100644
--- a/filter/source/config/fragments/types/calc_MS_Excel_97.xcu
+++ b/filter/source/config/fragments/types/calc_MS_Excel_97.xcu
@@ -16,7 +16,7 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 -->
     <node oor:name="calc_MS_Excel_97" oor:op="replace" >
-        <prop oor:name="DetectService"><value>com.sun.star.comp.calc.FormatDetector</value></prop>
+        <prop oor:name="DetectService"><value>com.sun.star.comp.calc.ExcelBiffFormatDetector</value></prop>
         <prop oor:name="URLPattern"/>
         <prop oor:name="Extensions"><value>xls xlc xlm xlw xlk</value></prop>
         <prop oor:name="MediaType"><value>application/vnd.ms-excel</value></prop>
diff --git a/filter/source/config/fragments/types/calc_MS_Excel_97_VorlageTemplate.xcu b/filter/source/config/fragments/types/calc_MS_Excel_97_VorlageTemplate.xcu
index 587a9bd..0dff79b 100644
--- a/filter/source/config/fragments/types/calc_MS_Excel_97_VorlageTemplate.xcu
+++ b/filter/source/config/fragments/types/calc_MS_Excel_97_VorlageTemplate.xcu
@@ -16,7 +16,7 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 -->
     <node oor:name="calc_MS_Excel_97_VorlageTemplate" oor:op="replace" >
-        <prop oor:name="DetectService"><value>com.sun.star.comp.calc.FormatDetector</value></prop>
+        <prop oor:name="DetectService"><value>com.sun.star.comp.calc.ExcelBiffFormatDetector</value></prop>
         <prop oor:name="URLPattern"/>
         <prop oor:name="Extensions"><value>xlt</value></prop>
         <prop oor:name="MediaType"><value>application/vnd.ms-excel</value></prop>
diff --git a/sc/source/ui/unoobj/exceldetect.cxx b/sc/source/ui/unoobj/exceldetect.cxx
index f11cf17..2e0eae2 100644
--- a/sc/source/ui/unoobj/exceldetect.cxx
+++ b/sc/source/ui/unoobj/exceldetect.cxx
@@ -9,7 +9,19 @@
 
 #include "exceldetect.hxx"
 
+#include <com/sun/star/io/XInputStream.hpp>
+#include <com/sun/star/ucb/XContent.hpp>
+
+#include "svl/itemset.hxx"
+#include "svl/eitem.hxx"
+#include "sfx2/app.hxx"
+#include "sfx2/docfile.hxx"
+#include "sfx2/sfxsids.hrc"
+#include "comphelper/mediadescriptor.hxx"
+#include "sot/storage.hxx"
+
 using namespace com::sun::star;
+using comphelper::MediaDescriptor;
 
 ScExcelBiffDetect::ScExcelBiffDetect( const uno::Reference<uno::XComponentContext>& /*xContext*/ ) {}
 ScExcelBiffDetect::~ScExcelBiffDetect() {}
@@ -36,9 +48,95 @@ uno::Sequence<OUString> ScExcelBiffDetect::getSupportedServiceNames() throw (uno
     return impl_getStaticSupportedServiceNames();
 }
 
+namespace {
+
+bool hasStream(const uno::Reference<io::XInputStream>& xInStream, const OUString& rName)
+{
+    SfxMedium aMedium;
+    aMedium.UseInteractionHandler(true);
+    aMedium.setStreamToLoadFrom(xInStream, true);
+    SvStream* pStream = aMedium.GetInStream();
+    if (!pStream)
+        return false;
+
+    pStream->Seek(STREAM_SEEK_TO_END);
+    sal_Size nSize = pStream->Tell();
+    pStream->Seek(0);
+
+    if (!nSize)
+        // 0-size stream.  Failed.
+        return false;
+
+    SotStorageRef xStorage = new SotStorage(pStream, false);
+    if (!xStorage.Is() || xStorage->GetError())
+        return false;
+
+    return xStorage->IsStream(rName);
+}
+
+bool isTemplate(const OUString& rType)
+{
+    return rType.indexOf("_VorlageTemplate") != -1;
+}
+
+}
+
 OUString ScExcelBiffDetect::detect( uno::Sequence<beans::PropertyValue>& lDescriptor )
     throw (uno::RuntimeException)
 {
+    MediaDescriptor aMediaDesc(lDescriptor);
+    OUString aType;
+    aMediaDesc[MediaDescriptor::PROP_TYPENAME()] >>= aType;
+    if (aType.isEmpty())
+        // Type is not given.  We can't proceed.
+        return OUString();
+
+    aMediaDesc.addInputStream();
+    uno::Reference<io::XInputStream> xInStream(aMediaDesc[MediaDescriptor::PROP_INPUTSTREAM()], uno::UNO_QUERY);
+    if (!xInStream.is())
+        // No input stream.
+        return OUString();
+
+    if (aType == "calc_MS_Excel_97" || aType == "calc_MS_Excel_97_VorlageTemplate")
+    {
+        // See if this stream is a Excel 97/XP/2003 (BIFF8) stream.
+        if (!hasStream(xInStream, "Workbook"))
+            // BIFF8 is expected to contain a stream named "Workbook".
+            return OUString();
+
+        aMediaDesc[MediaDescriptor::PROP_FILTERNAME()] <<= isTemplate(aType) ? OUString("MS Excel 97 Vorlage/Template") : OUString("MS Excel 97");
+        return aType;
+    }
+
+    if (aType == "calc_MS_Excel_95" || aType == "calc_MS_Excel_95_VorlageTemplate")
+    {
+        // See if this stream is a Excel 95 (BIFF5) stream.
+        if (!hasStream(xInStream, "Book"))
+            return OUString();
+
+        aMediaDesc[MediaDescriptor::PROP_FILTERNAME()] <<= isTemplate(aType) ? OUString("MS Excel 95 Vorlage/Template") : OUString("MS Excel 95");
+        return aType;
+    }
+
+    if (aType == "calc_MS_Excel_5095" || aType == "calc_MS_Excel_5095_VorlageTemplate")
+    {
+        // See if this stream is a Excel 5.0/95 stream.
+        if (!hasStream(xInStream, "Book"))
+            return OUString();
+
+        aMediaDesc[MediaDescriptor::PROP_FILTERNAME()] <<= isTemplate(aType) ? OUString("MS Excel 5.0/95 Vorlage/Template") : OUString("MS Excel 5.0/95");
+        return aType;
+    }
+
+    if (aType == "calc_MS_Excel_40" || aType == "calc_MS_Excel_40_VorlageTemplate")
+    {
+        // See if this stream is a Excel 4.0 stream.
+
+        // TODO: Implement this.
+        return OUString();
+    }
+
+    // failed!
     return OUString();
 }
 
commit ff59007adbaadddcf7411e15d9c24eaad32c985f
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Mon Feb 4 22:45:24 2013 -0500

    Skeleton for new excel biff format detector service.
    
    Not used yet.
    
    Change-Id: I1d3c28c46ec3b1830b8d0c656717e95677df9508

diff --git a/sc/Library_scd.mk b/sc/Library_scd.mk
index 815ce7d..93fe6b7 100644
--- a/sc/Library_scd.mk
+++ b/sc/Library_scd.mk
@@ -51,6 +51,7 @@ $(eval $(call gb_Library_use_libraries,scd,\
 $(eval $(call gb_Library_add_exception_objects,scd,\
 	sc/source/ui/unoobj/detreg \
 	sc/source/ui/unoobj/scdetect \
+	sc/source/ui/unoobj/exceldetect \
 ))
 
 # vim: set noet sw=4 ts=4:
diff --git a/sc/source/ui/unoobj/detreg.cxx b/sc/source/ui/unoobj/detreg.cxx
index 8d7ad31..6edc743 100644
--- a/sc/source/ui/unoobj/detreg.cxx
+++ b/sc/source/ui/unoobj/detreg.cxx
@@ -19,6 +19,7 @@
 
 
 #include "scdetect.hxx"
+#include "exceldetect.hxx"
 #include <cppuhelper/implementationentry.hxx>
 
 namespace {
@@ -33,6 +34,14 @@ static const cppu::ImplementationEntry spServices[] =
         0, 0
     },
 
+    {
+        ScExcelBiffDetect::impl_createInstance,
+        ScExcelBiffDetect::impl_getStaticImplementationName,
+        ScExcelBiffDetect::impl_getStaticSupportedServiceNames,
+        cppu::createSingleComponentFactory,
+        0, 0
+    },
+
     { 0, 0, 0, 0, 0, 0 }
 };
 
diff --git a/sc/source/ui/unoobj/exceldetect.cxx b/sc/source/ui/unoobj/exceldetect.cxx
new file mode 100644
index 0000000..f11cf17
--- /dev/null
+++ b/sc/source/ui/unoobj/exceldetect.cxx
@@ -0,0 +1,64 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include "exceldetect.hxx"
+
+using namespace com::sun::star;
+
+ScExcelBiffDetect::ScExcelBiffDetect( const uno::Reference<uno::XComponentContext>& /*xContext*/ ) {}
+ScExcelBiffDetect::~ScExcelBiffDetect() {}
+
+OUString ScExcelBiffDetect::getImplementationName() throw (uno::RuntimeException)
+{
+    return impl_getStaticImplementationName();
+}
+
+sal_Bool ScExcelBiffDetect::supportsService( const OUString& aName ) throw (uno::RuntimeException)
+{
+    uno::Sequence<OUString> aSrvNames = getSupportedServiceNames();
+    const OUString* pArray = aSrvNames.getConstArray();
+    for (sal_Int32 i = 0; i < aSrvNames.getLength(); ++i, ++pArray)
+    {
+        if (*pArray == aName)
+            return true;
+    }
+    return false;
+}
+
+uno::Sequence<OUString> ScExcelBiffDetect::getSupportedServiceNames() throw (uno::RuntimeException)
+{
+    return impl_getStaticSupportedServiceNames();
+}
+
+OUString ScExcelBiffDetect::detect( uno::Sequence<beans::PropertyValue>& lDescriptor )
+    throw (uno::RuntimeException)
+{
+    return OUString();
+}
+
+uno::Sequence<OUString> ScExcelBiffDetect::impl_getStaticSupportedServiceNames()
+{
+    uno::Sequence<OUString> aNames(1);
+    aNames[0] = "com.sun.star.frame.ExtendedTypeDetection";
+    return aNames;
+}
+
+OUString ScExcelBiffDetect::impl_getStaticImplementationName()
+{
+    return OUString("com.sun.star.comp.calc.ExcelBiffFormatDetector");
+}
+
+uno::Reference<uno::XInterface> ScExcelBiffDetect::impl_createInstance(
+    const uno::Reference<uno::XComponentContext>& xContext )
+        throw (com::sun::star::uno::Exception)
+{
+    return static_cast<cppu::OWeakObject*>(new ScExcelBiffDetect(xContext));
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/unoobj/exceldetect.hxx b/sc/source/ui/unoobj/exceldetect.hxx
new file mode 100644
index 0000000..d47d016
--- /dev/null
+++ b/sc/source/ui/unoobj/exceldetect.hxx
@@ -0,0 +1,46 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef __SC_EXCELDETECT_HXX__
+#define __SC_EXCELDETECT_HXX__
+
+#include <cppuhelper/implbase2.hxx>
+
+#include <com/sun/star/lang/XServiceInfo.hpp>
+#include <com/sun/star/document/XExtendedFilterDetection.hpp>
+
+namespace com { namespace sun { namespace star { namespace uno {
+    class XComponentContext;
+}}}}
+
+class ScExcelBiffDetect : public cppu::WeakImplHelper2<com::sun::star::document::XExtendedFilterDetection, com::sun::star::lang::XServiceInfo>
+{
+public:
+    ScExcelBiffDetect( const com::sun::star::uno::Reference<com::sun::star::uno::XComponentContext>& xContext );
+    virtual ~ScExcelBiffDetect();
+
+    // XServiceInfo
+    virtual OUString SAL_CALL getImplementationName() throw( com::sun::star::uno::RuntimeException );
+    virtual sal_Bool SAL_CALL supportsService( const OUString& aName ) throw( com::sun::star::uno::RuntimeException );
+    virtual com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames() throw( com::sun::star::uno::RuntimeException );
+
+    // XExtendedFilterDetection
+    virtual ::rtl::OUString SAL_CALL detect( com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue>& lDescriptor )
+        throw (com::sun::star::uno::RuntimeException);
+
+    static com::sun::star::uno::Sequence<OUString> impl_getStaticSupportedServiceNames();
+    static OUString impl_getStaticImplementationName();
+    static com::sun::star::uno::Reference< com::sun::star::uno::XInterface >
+        impl_createInstance( const com::sun::star::uno::Reference<com::sun::star::uno::XComponentContext>& xContext )
+            throw (com::sun::star::uno::Exception);
+};
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/unoobj/scdetect.hxx b/sc/source/ui/unoobj/scdetect.hxx
index a248f06..63702f8 100644
--- a/sc/source/ui/unoobj/scdetect.hxx
+++ b/sc/source/ui/unoobj/scdetect.hxx
@@ -53,7 +53,7 @@ public:
     static OUString impl_getStaticImplementationName();
 
     /* Helper for registry */
-    static com::sun::star::uno::Reference< com::sun::star::uno::XInterface > SAL_CALL
+    static com::sun::star::uno::Reference< com::sun::star::uno::XInterface >
         impl_createInstance( const com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >& xContext )
             throw (com::sun::star::uno::Exception);
 
diff --git a/sc/util/scd.component b/sc/util/scd.component
index 4ed0996..767429a 100644
--- a/sc/util/scd.component
+++ b/sc/util/scd.component
@@ -22,4 +22,7 @@
   <implementation name="com.sun.star.comp.calc.FormatDetector">
     <service name="com.sun.star.frame.ExtendedTypeDetection"/>
   </implementation>
+  <implementation name="com.sun.star.comp.calc.ExcelBiffFormatDetector">
+    <service name="com.sun.star.frame.ExtendedTypeDetection"/>
+  </implementation>
 </component>
commit 3405eb11dded8dc6c7e2463dfd83873d62528fbd
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Mon Feb 4 22:20:53 2013 -0500

    Simplify_component_getFactory using the helper code from cppu.
    
    Change-Id: I9d26b3523d4c6c22e0b26442ab3dfc479534f5bc

diff --git a/sc/source/ui/unoobj/detreg.cxx b/sc/source/ui/unoobj/detreg.cxx
index 34e8b33..8d7ad31 100644
--- a/sc/source/ui/unoobj/detreg.cxx
+++ b/sc/source/ui/unoobj/detreg.cxx
@@ -19,54 +19,33 @@
 
 
 #include "scdetect.hxx"
-#include <com/sun/star/lang/XServiceInfo.hpp>
-#include <com/sun/star/registry/XRegistryKey.hpp>
-#include <com/sun/star/uno/Sequence.h>
-#include <sal/types.h>
-#include <rtl/ustring.hxx>
+#include <cppuhelper/implementationentry.hxx>
 
-using ::rtl::OUString;
-using namespace ::com::sun::star;
-using namespace ::com::sun::star::uno;
-using namespace ::com::sun::star::lang;
+namespace {
 
-extern "C" {
-
-SAL_DLLPUBLIC_EXPORT void* SAL_CALL scd_component_getFactory( const sal_Char* pImplementationName,
-                                     void* pServiceManager,
-                                     void* /* pRegistryKey */ )
+static const cppu::ImplementationEntry spServices[] =
 {
-    // Set default return value for this operation - if it failed.
-    void* pReturn = NULL ;
-
-    if  (
-            ( pImplementationName   !=  NULL ) &&
-            ( pServiceManager       !=  NULL )
-        )
     {
-        // Define variables which are used in following macros.
-        Reference< XSingleServiceFactory >   xFactory                                                                                                ;
-        Reference< XMultiServiceFactory >    xServiceManager( reinterpret_cast< XMultiServiceFactory* >( pServiceManager ) ) ;
+        ScFilterDetect::impl_createInstance,
+        ScFilterDetect::impl_getStaticImplementationName,
+        ScFilterDetect::impl_getStaticSupportedServiceNames,
+        cppu::createSingleComponentFactory,
+        0, 0
+    },
+
+    { 0, 0, 0, 0, 0, 0 }
+};
 
-        if( ScFilterDetect::impl_getStaticImplementationName().equalsAscii( pImplementationName ) )
-        {
-            xFactory.set(::cppu::createSingleFactory( xServiceManager,
-            ScFilterDetect::impl_getStaticImplementationName(),
-            ScFilterDetect::impl_createInstance,
-            ScFilterDetect::impl_getStaticSupportedServiceNames() ));
-        }
+}
 
-        // Factory is valid - service was found.
-        if ( xFactory.is() )
-        {
-            xFactory->acquire();
-            pReturn = xFactory.get();
-        }
-    }
+extern "C" {
 
-    // Return with result of this operation.
-    return pReturn ;
+SAL_DLLPUBLIC_EXPORT void* SAL_CALL scd_component_getFactory(
+    const char* pImplName, void* pServiceManager, void* pRegistryKey )
+{
+    return ::cppu::component_getFactoryHelper(pImplName, pServiceManager, pRegistryKey, spServices);
 }
+
 } // extern "C"
 
 
diff --git a/sc/source/ui/unoobj/scdetect.cxx b/sc/source/ui/unoobj/scdetect.cxx
index a871e51..6bacac2 100644
--- a/sc/source/ui/unoobj/scdetect.cxx
+++ b/sc/source/ui/unoobj/scdetect.cxx
@@ -74,7 +74,7 @@ using namespace ::com::sun::star::lang;
 using namespace ::com::sun::star::ucb;
 using ::rtl::OUString;
 
-ScFilterDetect::ScFilterDetect( const uno::Reference<lang::XMultiServiceFactory>& /*xFactory*/ )
+ScFilterDetect::ScFilterDetect( const uno::Reference<uno::XComponentContext>& /*xContext*/ )
 {
 }
 
@@ -932,10 +932,9 @@ OUString ScFilterDetect::impl_getStaticImplementationName()
 }
 
 uno::Reference<uno::XInterface> ScFilterDetect::impl_createInstance(
-    const uno::Reference<lang::XMultiServiceFactory>& xServiceManager ) throw (uno::Exception)
+    const uno::Reference<uno::XComponentContext>& xContext ) throw (uno::Exception)
 {
-    return static_cast< cppu::OWeakObject * >(
-        new ScFilterDetect( xServiceManager ) );
+    return static_cast<cppu::OWeakObject*>(new ScFilterDetect(xContext));
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/unoobj/scdetect.hxx b/sc/source/ui/unoobj/scdetect.hxx
index 8faeef7..a248f06 100644
--- a/sc/source/ui/unoobj/scdetect.hxx
+++ b/sc/source/ui/unoobj/scdetect.hxx
@@ -33,7 +33,6 @@
 #include <sfx2/sfxuno.hxx>
 
 namespace com { namespace sun { namespace star {
-    namespace lang { class XMultiServiceFactory; }
     namespace beans { struct PropertyValue; }
 }}}
 
@@ -41,7 +40,7 @@ namespace com { namespace sun { namespace star {
 class ScFilterDetect : public ::cppu::WeakImplHelper2< ::com::sun::star::document::XExtendedFilterDetection, ::com::sun::star::lang::XServiceInfo >
 {
 public:
-    ScFilterDetect( const com::sun::star::uno::Reference<com::sun::star::lang::XMultiServiceFactory>& xFactory );
+    ScFilterDetect( const com::sun::star::uno::Reference<com::sun::star::uno::XComponentContext>& xContext );
     virtual ~ScFilterDetect();
 
     /* XServiceInfo */
@@ -55,7 +54,7 @@ public:
 
     /* Helper for registry */
     static com::sun::star::uno::Reference< com::sun::star::uno::XInterface > SAL_CALL
-        impl_createInstance( const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& xServiceManager )
+        impl_createInstance( const com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >& xContext )
             throw (com::sun::star::uno::Exception);
 
     //----------------------------------------------------------------------------------


More information about the Libreoffice-commits mailing list