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 <noel.grandin@collabora.co.uk>
This commit is contained in:
Noel 2020-10-16 09:14:52 +02:00 committed by Noel Grandin
parent 2df0e59909
commit 90fa4426a1
4 changed files with 35 additions and 18 deletions

View file

@ -32,6 +32,7 @@ $(eval $(call gb_CppunitTest_use_libraries,writerperfect_wpftimport,\
vcl \ vcl \
wpftqahelper \ wpftqahelper \
writerperfect \ writerperfect \
xo \
)) ))
$(eval $(call gb_CppunitTest_use_external,writerperfect_wpftimport,boost_headers)) $(eval $(call gb_CppunitTest_use_external,writerperfect_wpftimport,boost_headers))

View file

@ -18,7 +18,7 @@
#include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/uno/Reference.h> #include <com/sun/star/uno/Reference.h>
#include <com/sun/star/uno/XComponentContext.hpp> #include <com/sun/star/uno/XComponentContext.hpp>
#include <com/sun/star/xml/sax/XDocumentHandler.hpp> #include <com/sun/star/xml/sax/XFastDocumentHandler.hpp>
#include <osl/diagnose.h> #include <osl/diagnose.h>
#include <cppuhelper/implbase.hxx> #include <cppuhelper/implbase.hxx>
@ -26,6 +26,7 @@
#include <unotools/mediadescriptor.hxx> #include <unotools/mediadescriptor.hxx>
#include <vcl/svapp.hxx> #include <vcl/svapp.hxx>
#include <vcl/weld.hxx> #include <vcl/weld.hxx>
#include <xmloff/xmlimp.hxx>
#include "DocumentHandler.hxx" #include "DocumentHandler.hxx"
#include "WPXSvInputStream.hxx" #include "WPXSvInputStream.hxx"
@ -70,19 +71,24 @@ public:
aDescriptor["ParentWindow"] >>= xDialogParent; aDescriptor["ParentWindow"] >>= xDialogParent;
// An XML import service: what we push sax messages to... // An XML import service: what we push sax messages to...
css::uno::Reference<css::xml::sax::XDocumentHandler> xInternalHandler( css::uno::Reference<XInterface> xInternalFilter
mxContext->getServiceManager()->createInstanceWithContext( = mxContext->getServiceManager()->createInstanceWithContext(
DocumentHandlerFor<Generator>::name(), mxContext), DocumentHandlerFor<Generator>::name(), mxContext);
css::uno::UNO_QUERY_THROW); assert(xInternalFilter);
css::uno::Reference<css::xml::sax::XFastDocumentHandler> xInternalHandler(
xInternalFilter, css::uno::UNO_QUERY);
assert(xInternalHandler);
// The XImporter sets up an empty target document for XDocumentHandler to write to... // The XImporter sets up an empty target document for XDocumentHandler to write to...
css::uno::Reference<css::document::XImporter> xImporter(xInternalHandler, css::uno::Reference<css::document::XImporter> xImporter(xInternalHandler,
css::uno::UNO_QUERY); css::uno::UNO_QUERY);
assert(xImporter);
xImporter->setTargetDocument(mxDoc); xImporter->setTargetDocument(mxDoc);
// OO Graphics Handler: abstract class to handle document SAX messages, concrete implementation here // OO Graphics Handler: abstract class to handle document SAX messages, concrete implementation here
// writes to in-memory target doc // writes to in-memory target doc
DocumentHandler aHandler(xInternalHandler); DocumentHandler aHandler(
new SvXMLLegacyToFastDocHandler(dynamic_cast<SvXMLImport*>(xInternalHandler.get())));
WPXSvInputStream input(xInputStream); WPXSvInputStream input(xInputStream);

View file

@ -317,18 +317,23 @@ MSWorksCalcImportFilter::filter(const css::uno::Sequence<css::beans::PropertyVal
} }
// An XML import service: what we push sax messages to... // An XML import service: what we push sax messages to...
css::uno::Reference<css::xml::sax::XDocumentHandler> xInternalHandler( css::uno::Reference<XInterface> xInternalFilter
getXContext()->getServiceManager()->createInstanceWithContext( = getXContext()->getServiceManager()->createInstanceWithContext(
writerperfect::DocumentHandlerFor<OdsGenerator>::name(), getXContext()), writerperfect::DocumentHandlerFor<OdsGenerator>::name(), getXContext());
css::uno::UNO_QUERY_THROW); assert(xInternalFilter);
css::uno::Reference<css::xml::sax::XFastDocumentHandler> xInternalHandler(xInternalFilter,
css::uno::UNO_QUERY);
assert(xInternalHandler);
// The XImporter sets up an empty target document for XDocumentHandler to write to... // The XImporter sets up an empty target document for XDocumentHandler to write to...
css::uno::Reference<css::document::XImporter> xImporter(xInternalHandler, css::uno::UNO_QUERY); css::uno::Reference<css::document::XImporter> xImporter(xInternalHandler, css::uno::UNO_QUERY);
assert(xImporter);
xImporter->setTargetDocument(getTargetDocument()); xImporter->setTargetDocument(getTargetDocument());
// OO Graphics Handler: abstract class to handle document SAX messages, concrete implementation here // OO Graphics Handler: abstract class to handle document SAX messages, concrete implementation here
// writes to in-memory target doc // writes to in-memory target doc
writerperfect::DocumentHandler aHandler(xInternalHandler); writerperfect::DocumentHandler aHandler(
new SvXMLLegacyToFastDocHandler(dynamic_cast<SvXMLImport*>(xInternalHandler.get())));
writerperfect::WPXSvInputStream input(xInputStream); writerperfect::WPXSvInputStream input(xInputStream);
OdsGenerator exporter; OdsGenerator exporter;

View file

@ -12,7 +12,7 @@
#include <com/sun/star/awt/XWindow.hpp> #include <com/sun/star/awt/XWindow.hpp>
#include <com/sun/star/io/XInputStream.hpp> #include <com/sun/star/io/XInputStream.hpp>
#include <com/sun/star/xml/sax/XDocumentHandler.hpp> #include <com/sun/star/xml/sax/XFastDocumentHandler.hpp>
#include <com/sun/star/uno/Reference.h> #include <com/sun/star/uno/Reference.h>
#include <cppuhelper/supportsservice.hxx> #include <cppuhelper/supportsservice.hxx>
@ -22,6 +22,7 @@
#include <sfx2/passwd.hxx> #include <sfx2/passwd.hxx>
#include <ucbhelper/content.hxx> #include <ucbhelper/content.hxx>
#include <vcl/svapp.hxx> #include <vcl/svapp.hxx>
#include <xmloff/xmlimp.hxx>
#include <libwpd/libwpd.h> #include <libwpd/libwpd.h>
#include <libwpg/libwpg.h> #include <libwpg/libwpg.h>
@ -33,7 +34,7 @@ using com::sun::star::uno::Reference;
using com::sun::star::awt::XWindow; using com::sun::star::awt::XWindow;
using com::sun::star::document::XImporter; using com::sun::star::document::XImporter;
using com::sun::star::io::XInputStream; 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::DocumentHandler;
using writerperfect::WPXSvInputStream; using writerperfect::WPXSvInputStream;
@ -122,10 +123,13 @@ bool WordPerfectImportFilter::importImpl(
} }
// An XML import service: what we push sax messages to. // An XML import service: what we push sax messages to.
Reference<XDocumentHandler> xInternalHandler( Reference<XInterface> xInternalFilter
mxContext->getServiceManager()->createInstanceWithContext( = mxContext->getServiceManager()->createInstanceWithContext(
"com.sun.star.comp.Writer.XMLOasisImporter", mxContext), "com.sun.star.comp.Writer.XMLOasisImporter", mxContext);
css::uno::UNO_QUERY_THROW); assert(xInternalFilter);
css::uno::Reference<css::xml::sax::XFastDocumentHandler> xInternalHandler(xInternalFilter,
css::uno::UNO_QUERY);
assert(xInternalHandler);
// The XImporter sets up an empty target document for XDocumentHandler to write to. // The XImporter sets up an empty target document for XDocumentHandler to write to.
Reference<XImporter> xImporter(xInternalHandler, css::uno::UNO_QUERY); Reference<XImporter> 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 // OO Document Handler: abstract class to handle document SAX messages, concrete implementation here
// writes to in-memory target doc // writes to in-memory target doc
DocumentHandler aHandler(xInternalHandler); DocumentHandler aHandler(
new SvXMLLegacyToFastDocHandler(dynamic_cast<SvXMLImport*>(xInternalHandler.get())));
OdtGenerator collector; OdtGenerator collector;
collector.addDocumentHandler(&aHandler, ODF_FLAT_XML); collector.addDocumentHandler(&aHandler, ODF_FLAT_XML);