From 90fa4426a1be8874baacd21eff8c7c46f8a4371a Mon Sep 17 00:00:00 2001 From: Noel Date: Fri, 16 Oct 2020 09:14:52 +0200 Subject: [PATCH] writerfilter: use the fastparser API when possible part of the process of making SvXMLImport fastparser-only Change-Id: I9bb2d337954354be63984892e1fc4a7950ca3628 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104411 Tested-by: Jenkins Reviewed-by: Noel Grandin --- .../CppunitTest_writerperfect_wpftimport.mk | 1 + writerperfect/inc/ImportFilter.hxx | 18 ++++++++++++------ .../source/calc/MSWorksCalcImportFilter.cxx | 15 ++++++++++----- .../source/writer/WordPerfectImportFilter.cxx | 19 ++++++++++++------- 4 files changed, 35 insertions(+), 18 deletions(-) diff --git a/writerperfect/CppunitTest_writerperfect_wpftimport.mk b/writerperfect/CppunitTest_writerperfect_wpftimport.mk index 101908aadeb4..b43836d45e7e 100644 --- a/writerperfect/CppunitTest_writerperfect_wpftimport.mk +++ b/writerperfect/CppunitTest_writerperfect_wpftimport.mk @@ -32,6 +32,7 @@ $(eval $(call gb_CppunitTest_use_libraries,writerperfect_wpftimport,\ vcl \ wpftqahelper \ writerperfect \ + xo \ )) $(eval $(call gb_CppunitTest_use_external,writerperfect_wpftimport,boost_headers)) diff --git a/writerperfect/inc/ImportFilter.hxx b/writerperfect/inc/ImportFilter.hxx index 4328b902181c..56f352556c73 100644 --- a/writerperfect/inc/ImportFilter.hxx +++ b/writerperfect/inc/ImportFilter.hxx @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include #include @@ -26,6 +26,7 @@ #include #include #include +#include #include "DocumentHandler.hxx" #include "WPXSvInputStream.hxx" @@ -70,19 +71,24 @@ public: aDescriptor["ParentWindow"] >>= xDialogParent; // An XML import service: what we push sax messages to... - css::uno::Reference xInternalHandler( - mxContext->getServiceManager()->createInstanceWithContext( - DocumentHandlerFor::name(), mxContext), - css::uno::UNO_QUERY_THROW); + css::uno::Reference xInternalFilter + = mxContext->getServiceManager()->createInstanceWithContext( + DocumentHandlerFor::name(), mxContext); + assert(xInternalFilter); + css::uno::Reference xInternalHandler( + xInternalFilter, css::uno::UNO_QUERY); + assert(xInternalHandler); // The XImporter sets up an empty target document for XDocumentHandler to write to... css::uno::Reference xImporter(xInternalHandler, css::uno::UNO_QUERY); + assert(xImporter); xImporter->setTargetDocument(mxDoc); // OO Graphics Handler: abstract class to handle document SAX messages, concrete implementation here // writes to in-memory target doc - DocumentHandler aHandler(xInternalHandler); + DocumentHandler aHandler( + new SvXMLLegacyToFastDocHandler(dynamic_cast(xInternalHandler.get()))); WPXSvInputStream input(xInputStream); diff --git a/writerperfect/source/calc/MSWorksCalcImportFilter.cxx b/writerperfect/source/calc/MSWorksCalcImportFilter.cxx index 521b7c0dbf5d..83035d8b9926 100644 --- a/writerperfect/source/calc/MSWorksCalcImportFilter.cxx +++ b/writerperfect/source/calc/MSWorksCalcImportFilter.cxx @@ -317,18 +317,23 @@ MSWorksCalcImportFilter::filter(const css::uno::Sequence xInternalHandler( - getXContext()->getServiceManager()->createInstanceWithContext( - writerperfect::DocumentHandlerFor::name(), getXContext()), - css::uno::UNO_QUERY_THROW); + css::uno::Reference xInternalFilter + = getXContext()->getServiceManager()->createInstanceWithContext( + writerperfect::DocumentHandlerFor::name(), getXContext()); + assert(xInternalFilter); + css::uno::Reference xInternalHandler(xInternalFilter, + css::uno::UNO_QUERY); + assert(xInternalHandler); // The XImporter sets up an empty target document for XDocumentHandler to write to... css::uno::Reference xImporter(xInternalHandler, css::uno::UNO_QUERY); + assert(xImporter); xImporter->setTargetDocument(getTargetDocument()); // OO Graphics Handler: abstract class to handle document SAX messages, concrete implementation here // writes to in-memory target doc - writerperfect::DocumentHandler aHandler(xInternalHandler); + writerperfect::DocumentHandler aHandler( + new SvXMLLegacyToFastDocHandler(dynamic_cast(xInternalHandler.get()))); writerperfect::WPXSvInputStream input(xInputStream); OdsGenerator exporter; diff --git a/writerperfect/source/writer/WordPerfectImportFilter.cxx b/writerperfect/source/writer/WordPerfectImportFilter.cxx index ca27d5fbc1ec..8888134e2ebf 100644 --- a/writerperfect/source/writer/WordPerfectImportFilter.cxx +++ b/writerperfect/source/writer/WordPerfectImportFilter.cxx @@ -12,7 +12,7 @@ #include #include -#include +#include #include #include @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -33,7 +34,7 @@ using com::sun::star::uno::Reference; using com::sun::star::awt::XWindow; using com::sun::star::document::XImporter; using com::sun::star::io::XInputStream; -using com::sun::star::xml::sax::XDocumentHandler; +using com::sun::star::xml::sax::XFastDocumentHandler; using writerperfect::DocumentHandler; using writerperfect::WPXSvInputStream; @@ -122,10 +123,13 @@ bool WordPerfectImportFilter::importImpl( } // An XML import service: what we push sax messages to. - Reference xInternalHandler( - mxContext->getServiceManager()->createInstanceWithContext( - "com.sun.star.comp.Writer.XMLOasisImporter", mxContext), - css::uno::UNO_QUERY_THROW); + Reference xInternalFilter + = mxContext->getServiceManager()->createInstanceWithContext( + "com.sun.star.comp.Writer.XMLOasisImporter", mxContext); + assert(xInternalFilter); + css::uno::Reference xInternalHandler(xInternalFilter, + css::uno::UNO_QUERY); + assert(xInternalHandler); // The XImporter sets up an empty target document for XDocumentHandler to write to. Reference xImporter(xInternalHandler, css::uno::UNO_QUERY); @@ -133,7 +137,8 @@ bool WordPerfectImportFilter::importImpl( // OO Document Handler: abstract class to handle document SAX messages, concrete implementation here // writes to in-memory target doc - DocumentHandler aHandler(xInternalHandler); + DocumentHandler aHandler( + new SvXMLLegacyToFastDocHandler(dynamic_cast(xInternalHandler.get()))); OdtGenerator collector; collector.addDocumentHandler(&aHandler, ODF_FLAT_XML);