diff options
author | Noel Grandin <noelgrandin@gmail.com> | 2020-10-17 08:07:45 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-10-17 08:51:41 +0200 |
commit | 3059f556f6818b66b2fa988c69664f5a98f4c075 (patch) | |
tree | 283e98bb7dc62360f657c72537887e0f974f9898 /sd | |
parent | 17cbc559be6936777904e5cf8a517cac89045264 (diff) |
sd: use the fastparser API when possible
part of the process of making SvXMLImport fastparser-only
Change-Id: I34b9781ff905094b2231940bb69eb68b18faeb22
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104452
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sd')
-rw-r--r-- | sd/source/filter/xml/sdxmlwrp.cxx | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/sd/source/filter/xml/sdxmlwrp.cxx b/sd/source/filter/xml/sdxmlwrp.cxx index 7186ef911c24..2425a5fd4de4 100644 --- a/sd/source/filter/xml/sdxmlwrp.cxx +++ b/sd/source/filter/xml/sdxmlwrp.cxx @@ -42,6 +42,7 @@ #include <sdxmlwrp.hxx> #include <svx/xmleohlp.hxx> +#include <com/sun/star/xml/sax/Parser.hpp> #include <com/sun/star/xml/sax/XDocumentHandler.hpp> #include <com/sun/star/xml/sax/XFastParser.hpp> #include <com/sun/star/document/XFilter.hpp> @@ -55,7 +56,7 @@ #include <com/sun/star/packages/zip/ZipIOException.hpp> #include <com/sun/star/xml/sax/InputSource.hpp> -#include <com/sun/star/xml/sax/Parser.hpp> +#include <com/sun/star/xml/sax/FastParser.hpp> #include <com/sun/star/xml/sax/Writer.hpp> #include <comphelper/genericpropertyset.hxx> #include <comphelper/propertysetinfo.hxx> @@ -189,38 +190,44 @@ ErrCode ReadThroughComponent( aParserInput.sSystemId = rName; aParserInput.aInputStream = xInputStream; - // get parser - Reference< xml::sax::XParser > xParser = xml::sax::Parser::create(rxContext); - SAL_INFO( "sd.filter", "parser created" ); - // get filter OUString aFilterName(OUString::createFromAscii(pFilterName)); - Reference< xml::sax::XDocumentHandler > xFilter( + // the underlying SvXMLImport implements XFastParser, XImporter, XFastDocumentHandler + Reference< XInterface > xFilter( rxContext->getServiceManager()->createInstanceWithArgumentsAndContext(aFilterName, rFilterArguments, rxContext), UNO_QUERY ); SAL_WARN_IF(!xFilter.is(), "sd.filter", "Can't instantiate filter component: " << aFilterName); if( !xFilter.is() ) return SD_XML_READERROR; + Reference< xml::sax::XFastParser > xFastParser(xFilter, UNO_QUERY); + Reference< xml::sax::XDocumentHandler > xDocumentHandler; + if (!xFastParser) + xDocumentHandler.set(xFilter, UNO_QUERY); + if (!xFastParser && !xDocumentHandler) + { + SAL_WARN("sd", "service does not implement XFastParser or XDocumentHandler"); + assert(false); + return SD_XML_READERROR; + } SAL_INFO( "sd.filter", "" << pFilterName << " created" ); - // connect parser and filter - xParser->setDocumentHandler( xFilter ); - // connect model and filter Reference < XImporter > xImporter( xFilter, UNO_QUERY ); xImporter->setTargetDocument( xModelComponent ); - uno::Reference< xml::sax::XFastParser > xFastParser = dynamic_cast< - xml::sax::XFastParser* >( xFilter.get() ); - // finally, parser the stream SAL_INFO( "sd.filter", "parsing stream" ); try { - if( xFastParser.is() ) + if (xFastParser) xFastParser->parseStream( aParserInput ); else + { + Reference< xml::sax::XParser > xParser = xml::sax::Parser::create(rxContext); + // connect parser and filter + xParser->setDocumentHandler( xDocumentHandler ); xParser->parseStream( aParserInput ); + } } catch (const xml::sax::SAXParseException& r) { |