[Libreoffice-commits] core.git: sd/source

Noel Grandin (via logerrit) logerrit at kemper.freedesktop.org
Sat Oct 17 06:52:21 UTC 2020


 sd/source/filter/xml/sdxmlwrp.cxx |   33 ++++++++++++++++++++-------------
 1 file changed, 20 insertions(+), 13 deletions(-)

New commits:
commit 3059f556f6818b66b2fa988c69664f5a98f4c075
Author:     Noel Grandin <noelgrandin at gmail.com>
AuthorDate: Sat Oct 17 08:07:45 2020 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Sat Oct 17 08:51:41 2020 +0200

    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 at collabora.co.uk>

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)
     {


More information about the Libreoffice-commits mailing list