summaryrefslogtreecommitdiff
path: root/hwpfilter
diff options
context:
space:
mode:
authorNoel Grandin <noelgrandin@gmail.com>2020-07-13 19:03:55 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2020-07-14 10:26:53 +0200
commit332e805dad96c5a06b1b8aeea159d17f4abb302a (patch)
tree2c35074758457c2a8f2f8538e004dac8d492dba6 /hwpfilter
parent02add49081fc52838a8cff8746c647a0286544c1 (diff)
hwpfilter: create instances with uno constructors
See tdf#74608 for motivation. And move the code out of a header file into a .cxx file. Change-Id: I37b88e1d5173c9064f1b733b5d38fc40a463e2a8 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/98677 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'hwpfilter')
-rw-r--r--hwpfilter/source/hwp.component5
-rw-r--r--hwpfilter/source/hwpreader.cxx124
-rw-r--r--hwpfilter/source/hwpreader.hxx168
3 files changed, 128 insertions, 169 deletions
diff --git a/hwpfilter/source/hwp.component b/hwpfilter/source/hwp.component
index 4c82cb671e74..961d6b7d7f8c 100644
--- a/hwpfilter/source/hwp.component
+++ b/hwpfilter/source/hwp.component
@@ -18,8 +18,9 @@
-->
<component loader="com.sun.star.loader.SharedLibrary" environment="@CPPU_ENV@"
- prefix="hwp" xmlns="http://openoffice.org/2010/uno-components">
- <implementation name="com.sun.comp.hwpimport.HwpImportFilter">
+ xmlns="http://openoffice.org/2010/uno-components">
+ <implementation name="com.sun.comp.hwpimport.HwpImportFilter"
+ constructor="hwpfilter_HwpImportFilter_get_implementation">
<service name="com.sun.star.document.ImportFilter"/>
<service name="com.sun.star.document.ExtendedTypeDetection"/>
</implementation>
diff --git a/hwpfilter/source/hwpreader.cxx b/hwpfilter/source/hwpreader.cxx
index 4db88bcc732e..e647f3882d58 100644
--- a/hwpfilter/source/hwpreader.cxx
+++ b/hwpfilter/source/hwpreader.cxx
@@ -4816,4 +4816,128 @@ void HwpReader::parsePara(HWPPara * para)
}
}
+
+namespace
+{
+
+constexpr OUStringLiteral IMPLEMENTATION_NAME = "com.sun.comp.hwpimport.HwpImportFilter";
+constexpr OUStringLiteral SERVICE_NAME1 = "com.sun.star.document.ImportFilter";
+constexpr OUStringLiteral SERVICE_NAME2 = "com.sun.star.document.ExtendedTypeDetection";
+
+class HwpImportFilter : public WeakImplHelper< XFilter, XImporter, XServiceInfo, XExtendedFilterDetection >
+{
+public:
+ explicit HwpImportFilter(const Reference< XComponentContext >& );
+
+public:
+ // XFilter
+ virtual sal_Bool SAL_CALL filter( const Sequence< PropertyValue >& aDescriptor ) override;
+ virtual void SAL_CALL cancel() override;
+
+ // XImporter
+ virtual void SAL_CALL setTargetDocument( const Reference< XComponent >& xDoc) override;
+
+ // XServiceInfo
+ OUString SAL_CALL getImplementationName() override;
+ Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
+ sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override;
+
+ //XExtendedFilterDetection
+ virtual OUString SAL_CALL detect( css::uno::Sequence< css::beans::PropertyValue >& rDescriptor ) override;
+
+private:
+ Reference< XFilter > rFilter;
+ Reference< XImporter > rImporter;
+};
+
+
+HwpImportFilter::HwpImportFilter(const Reference< XComponentContext >& rxContext)
+{
+ try {
+ Reference< XDocumentHandler > xHandler( rxContext->getServiceManager()->createInstanceWithContext( WRITER_IMPORTER_NAME, rxContext ), UNO_QUERY );
+
+ HwpReader *p = new HwpReader;
+ p->setDocumentHandler( xHandler );
+
+ Reference< XImporter > xImporter( xHandler, UNO_QUERY );
+ rImporter = xImporter;
+ Reference< XFilter > xFilter( p );
+ rFilter = xFilter;
+ }
+ catch( Exception & )
+ {
+ printf(" fail to instantiate %s\n", WRITER_IMPORTER_NAME );
+ exit( 1 );
+ }
+}
+
+sal_Bool HwpImportFilter::filter( const Sequence< PropertyValue >& aDescriptor )
+{
+ // delegate to IchitaroImpoter
+ return rFilter->filter( aDescriptor );
+}
+
+void HwpImportFilter::cancel()
+{
+ rFilter->cancel();
+}
+
+void HwpImportFilter::setTargetDocument( const Reference< XComponent >& xDoc )
+{
+ // delegate
+ rImporter->setTargetDocument( xDoc );
+}
+
+OUString HwpImportFilter::getImplementationName()
+{
+ return IMPLEMENTATION_NAME;
+}
+
+sal_Bool HwpImportFilter::supportsService( const OUString& ServiceName )
+{
+ return cppu::supportsService(this, ServiceName);
+}
+
+//XExtendedFilterDetection
+OUString HwpImportFilter::detect( css::uno::Sequence< css::beans::PropertyValue >& rDescriptor )
+{
+ OUString sTypeName;
+
+ utl::MediaDescriptor aDescriptor(rDescriptor);
+ aDescriptor.addInputStream();
+
+ Reference< XInputStream > xInputStream(
+ aDescriptor[utl::MediaDescriptor::PROP_INPUTSTREAM()], UNO_QUERY);
+
+ if (xInputStream.is())
+ {
+ Sequence< sal_Int8 > aData;
+ sal_Int32 nLen = HWPIDLen;
+ if (
+ nLen == xInputStream->readBytes(aData, nLen) &&
+ detect_hwp_version(reinterpret_cast<const char*>(aData.getConstArray()))
+ )
+ {
+ sTypeName = "writer_MIZI_Hwp_97";
+ }
+ }
+
+ return sTypeName;
+}
+
+Sequence< OUString> HwpImportFilter::getSupportedServiceNames()
+{
+ return { SERVICE_NAME1, SERVICE_NAME2 };
+}
+
+}
+
+extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
+hwpfilter_HwpImportFilter_get_implementation(
+ css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const&)
+{
+ return cppu::acquire(new HwpImportFilter(context));
+}
+
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/hwpfilter/source/hwpreader.hxx b/hwpfilter/source/hwpreader.hxx
index 6d8d1b86fbaa..7642d9324981 100644
--- a/hwpfilter/source/hwpreader.hxx
+++ b/hwpfilter/source/hwpreader.hxx
@@ -27,12 +27,11 @@
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/lang/XComponent.hpp>
-#include <com/sun/star/lang/XSingleServiceFactory.hpp>
-#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/io/XInputStream.hpp>
#include <com/sun/star/document/XFilter.hpp>
#include <com/sun/star/document/XImporter.hpp>
#include <com/sun/star/xml/sax/XDocumentHandler.hpp>
+#include <com/sun/star/uno/XComponentContext.hpp>
#include <com/sun/star/io/XActiveDataSink.hpp>
#include <com/sun/star/io/XActiveDataControl.hpp>
@@ -66,9 +65,6 @@ using namespace ::com::sun::star::xml::sax;
#include "drawdef.h"
#include "attributes.hxx"
-#define IMPLEMENTATION_NAME "com.sun.comp.hwpimport.HwpImportFilter"
-#define SERVICE_NAME1 "com.sun.star.document.ImportFilter"
-#define SERVICE_NAME2 "com.sun.star.document.ExtendedTypeDetection"
#define WRITER_IMPORTER_NAME "com.sun.star.comp.Writer.XMLImporter"
struct HwpReaderPrivate;
@@ -152,168 +148,6 @@ private:
static char* getPStyleName(int, char *);
};
-class HwpImportFilter : public WeakImplHelper< XFilter, XImporter, XServiceInfo, XExtendedFilterDetection >
-{
-public:
- explicit HwpImportFilter(const Reference< XMultiServiceFactory >& rFact);
- virtual ~HwpImportFilter() override;
-
-public:
- static Sequence< OUString > getSupportedServiceNames_Static() throw();
- static OUString getImplementationName_Static() throw();
-
-public:
- // XFilter
- virtual sal_Bool SAL_CALL filter( const Sequence< PropertyValue >& aDescriptor ) override;
- virtual void SAL_CALL cancel() override;
-
- // XImporter
- virtual void SAL_CALL setTargetDocument( const Reference< XComponent >& xDoc) override;
-
- // XServiceInfo
- OUString SAL_CALL getImplementationName() override;
- Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
- sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override;
-
- //XExtendedFilterDetection
- virtual OUString SAL_CALL detect( css::uno::Sequence< css::beans::PropertyValue >& rDescriptor ) override;
-
-private:
- Reference< XFilter > rFilter;
- Reference< XImporter > rImporter;
-};
-
-/// @throws Exception
-Reference< XInterface > HwpImportFilter_CreateInstance(
- const Reference< XMultiServiceFactory >& rSMgr )
-{
- HwpImportFilter *p = new HwpImportFilter( rSMgr );
-
- return Reference< XInterface > ( static_cast<OWeakObject*>(p) );
-}
-
-Sequence< OUString > HwpImportFilter::getSupportedServiceNames_Static() throw ()
-{
- return { HwpImportFilter::getImplementationName_Static() };
-}
-
-HwpImportFilter::HwpImportFilter(const Reference< XMultiServiceFactory >& rFact)
-{
- try {
- Reference< XDocumentHandler > xHandler( rFact->createInstance( WRITER_IMPORTER_NAME ), UNO_QUERY );
-
- HwpReader *p = new HwpReader;
- p->setDocumentHandler( xHandler );
-
- Reference< XImporter > xImporter( xHandler, UNO_QUERY );
- rImporter = xImporter;
- Reference< XFilter > xFilter( p );
- rFilter = xFilter;
- }
- catch( Exception & )
- {
- printf(" fail to instantiate %s\n", WRITER_IMPORTER_NAME );
- exit( 1 );
- }
-}
-
-HwpImportFilter::~HwpImportFilter()
-{
-}
-
-sal_Bool HwpImportFilter::filter( const Sequence< PropertyValue >& aDescriptor )
-{
- // delegate to IchitaroImpoter
- return rFilter->filter( aDescriptor );
-}
-
-void HwpImportFilter::cancel()
-{
- rFilter->cancel();
-}
-
-void HwpImportFilter::setTargetDocument( const Reference< XComponent >& xDoc )
-{
- // delegate
- rImporter->setTargetDocument( xDoc );
-}
-
-OUString HwpImportFilter::getImplementationName_Static() throw()
-{
- return IMPLEMENTATION_NAME;
-}
-
-OUString HwpImportFilter::getImplementationName()
-{
- return IMPLEMENTATION_NAME;
-}
-
-sal_Bool HwpImportFilter::supportsService( const OUString& ServiceName )
-{
- return cppu::supportsService(this, ServiceName);
-}
-
-//XExtendedFilterDetection
-OUString HwpImportFilter::detect( css::uno::Sequence< css::beans::PropertyValue >& rDescriptor )
-{
- OUString sTypeName;
-
- utl::MediaDescriptor aDescriptor(rDescriptor);
- aDescriptor.addInputStream();
-
- Reference< XInputStream > xInputStream(
- aDescriptor[utl::MediaDescriptor::PROP_INPUTSTREAM()], UNO_QUERY);
-
- if (xInputStream.is())
- {
- Sequence< sal_Int8 > aData;
- sal_Int32 nLen = HWPIDLen;
- if (
- nLen == xInputStream->readBytes(aData, nLen) &&
- detect_hwp_version(reinterpret_cast<const char*>(aData.getConstArray()))
- )
- {
- sTypeName = "writer_MIZI_Hwp_97";
- }
- }
-
- return sTypeName;
-}
-
-Sequence< OUString> HwpImportFilter::getSupportedServiceNames()
-{
- return { SERVICE_NAME1, SERVICE_NAME2 };
-}
-
-extern "C"
-{
- SAL_DLLPUBLIC_EXPORT void * hwp_component_getFactory( const char * pImplName, void * pServiceManager, void * )
- {
- void * pRet = nullptr;
-
- if (pServiceManager )
- {
- Reference< XSingleServiceFactory > xRet;
- Reference< XMultiServiceFactory > xSMgr = static_cast< XMultiServiceFactory * > ( pServiceManager );
-
- OUString aImplementationName = OUString::createFromAscii( pImplName );
-
- if (aImplementationName == IMPLEMENTATION_NAME )
- {
- xRet = createSingleFactory( xSMgr, aImplementationName,
- HwpImportFilter_CreateInstance,
- HwpImportFilter::getSupportedServiceNames_Static() );
- }
- if (xRet.is())
- {
- xRet->acquire();
- pRet = xRet.get();
- }
- }
-
- return pRet;
- }
-}
#endif