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

Noel (via logerrit) logerrit at kemper.freedesktop.org
Fri Oct 16 15:45:42 UTC 2020


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

New commits:
commit f586c0c9257473d92936a91d632a4a408a36275e
Author:     Noel <noelgrandin at gmail.com>
AuthorDate: Fri Oct 16 13:25:17 2020 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Fri Oct 16 17:44:57 2020 +0200

    sw: use the fastparser API when possible
    
    part of the process of making SvXMLImport fastparser-only
    
    Change-Id: I240c92f8c1b06e1e17a836982d918e39719d2569
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104428
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/sw/source/filter/xml/swxml.cxx b/sw/source/filter/xml/swxml.cxx
index 4683b6ecb1c7..c3d9c50556da 100644
--- a/sw/source/filter/xml/swxml.cxx
+++ b/sw/source/filter/xml/swxml.cxx
@@ -150,34 +150,41 @@ ErrCode ReadThroughComponent(
     aParserInput.sSystemId = rName;
     aParserInput.aInputStream = xInputStream;
 
-    // get parser
-    uno::Reference< xml::sax::XParser > xParser = xml::sax::Parser::create(rxContext);
-    SAL_INFO( "sw.filter", "parser created" );
     // get filter
     const OUString aFilterName(OUString::createFromAscii(pFilterName));
-    uno::Reference< xml::sax::XDocumentHandler > xFilter(
-        rxContext->getServiceManager()->createInstanceWithArgumentsAndContext(aFilterName, rFilterArguments, rxContext),
-        UNO_QUERY);
+    uno::Reference< XInterface > xFilter =
+        rxContext->getServiceManager()->createInstanceWithArgumentsAndContext(aFilterName, rFilterArguments, rxContext);
     SAL_WARN_IF(!xFilter.is(), "sw.filter", "Can't instantiate filter component: " << aFilterName);
     if( !xFilter.is() )
         return ERR_SWG_READ_ERROR;
-    SAL_INFO( "sw.filter", "" << pFilterName << " created" );
-    // connect parser and filter
-    xParser->setDocumentHandler( xFilter );
+    // the underlying SvXMLImport implements XFastParser, XImporter, XFastDocumentHandler
+    uno::Reference< xml::sax::XFastParser > xFastParser(xFilter, UNO_QUERY);
+    uno::Reference< xml::sax::XDocumentHandler > xDocumentHandler;
+    if (!xFastParser)
+        xDocumentHandler.set(xFilter, UNO_QUERY);
+    if (!xDocumentHandler && !xFastParser)
+    {
+        SAL_WARN("sd", "service does not implement XFastParser or XDocumentHandler");
+        assert(false);
+        return ERR_SWG_READ_ERROR;
+    }
 
     // connect model and filter
     uno::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
+    // finally, parse the stream
     try
     {
-        if( xFastParser.is() )
+        if (xFastParser)
             xFastParser->parseStream( aParserInput );
         else
+        {
+            uno::Reference< xml::sax::XParser > xParser = xml::sax::Parser::create(rxContext);
+            // connect parser and filter
+            xParser->setDocumentHandler( xDocumentHandler );
             xParser->parseStream( aParserInput );
+        }
     }
     catch( xml::sax::SAXParseException& r)
     {


More information about the Libreoffice-commits mailing list