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

Noel Grandin (via logerrit) logerrit at kemper.freedesktop.org
Sat Oct 17 13:42:35 UTC 2020


 starmath/source/mathmlimport.cxx |   34 +++++++++++++++++++---------------
 1 file changed, 19 insertions(+), 15 deletions(-)

New commits:
commit f2502e72156be4c73760f95e5d59a7e5a64aa021
Author:     Noel Grandin <noelgrandin at gmail.com>
AuthorDate: Sat Oct 17 12:02:36 2020 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Sat Oct 17 15:41:55 2020 +0200

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

diff --git a/starmath/source/mathmlimport.cxx b/starmath/source/mathmlimport.cxx
index 76b82a5d519b..be223003bfb7 100644
--- a/starmath/source/mathmlimport.cxx
+++ b/starmath/source/mathmlimport.cxx
@@ -24,7 +24,7 @@ one go*/
 
 #include <com/sun/star/xml/sax/InputSource.hpp>
 #include <com/sun/star/xml/sax/FastParser.hpp>
-#include <com/sun/star/xml/sax/XFastParser.hpp>
+#include <com/sun/star/xml/sax/Parser.hpp>
 #include <com/sun/star/xml/sax/SAXParseException.hpp>
 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
 #include <com/sun/star/packages/WrongPasswordException.hpp>
@@ -264,38 +264,42 @@ ErrCode SmXMLImportWrapper::ReadThroughComponent(
     xml::sax::InputSource aParserInput;
     aParserInput.aInputStream = xInputStream;
 
-    // get parser
-    Reference< xml::sax::XFastParser > xParser = xml::sax::FastParser::create(rxContext);
-
     Sequence<Any> aArgs( 1 );
     aArgs[0] <<= rPropSet;
 
     // get filter
-    Reference< xml::sax::XFastDocumentHandler > xFilter(
+    Reference< XInterface > xFilter =
         rxContext->getServiceManager()->createInstanceWithArgumentsAndContext(
-            OUString::createFromAscii(pFilterName), aArgs, rxContext),
-        UNO_QUERY );
-    OSL_ENSURE( xFilter.is(), "Can't instantiate filter component." );
+            OUString::createFromAscii(pFilterName), aArgs, rxContext);
+    SAL_WARN_IF( !xFilter, "starmath", "Can't instantiate filter component " << pFilterName );
     if ( !xFilter.is() )
         return nError;
 
-    // connect parser and filter
-    xParser->setFastDocumentHandler( 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
     try
     {
-        if( xFastParser.is() )
+        Reference<css::xml::sax::XFastParser> xFastParser(xFilter, UNO_QUERY);
+        Reference<css::xml::sax::XFastDocumentHandler> xFastDocHandler(xFilter, UNO_QUERY);
+        if (xFastParser)
             xFastParser->parseStream( aParserInput );
+        else if (xFastDocHandler)
+        {
+            Reference<css::xml::sax::XFastParser> xParser = css::xml::sax::FastParser::create(rxContext);
+            xParser->setFastDocumentHandler(xFastDocHandler);
+            xParser->parseStream( aParserInput );
+        }
         else
+        {
+            Reference<css::xml::sax::XDocumentHandler> xDocHandler(xFilter, UNO_QUERY);
+            assert(xDocHandler);
+            Reference<css::xml::sax::XParser> xParser = css::xml::sax::Parser::create(rxContext);
+            xParser->setDocumentHandler(xDocHandler);
             xParser->parseStream( aParserInput );
+        }
 
         auto pFilter = comphelper::getUnoTunnelImplementation<SmXMLImport>(xFilter);
         if ( pFilter && pFilter->GetSuccess() )


More information about the Libreoffice-commits mailing list