diff options
author | Noel Grandin <noelgrandin@gmail.com> | 2020-07-13 19:03:55 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-07-14 10:26:53 +0200 |
commit | 332e805dad96c5a06b1b8aeea159d17f4abb302a (patch) | |
tree | 2c35074758457c2a8f2f8538e004dac8d492dba6 /hwpfilter/source/hwpreader.cxx | |
parent | 02add49081fc52838a8cff8746c647a0286544c1 (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/source/hwpreader.cxx')
-rw-r--r-- | hwpfilter/source/hwpreader.cxx | 124 |
1 files changed, 124 insertions, 0 deletions
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: */ |