From f2502e72156be4c73760f95e5d59a7e5a64aa021 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Sat, 17 Oct 2020 12:02:36 +0200 Subject: 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 --- starmath/source/mathmlimport.cxx | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) (limited to 'starmath') 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 #include -#include +#include #include #include #include @@ -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 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 xFastParser(xFilter, UNO_QUERY); + Reference xFastDocHandler(xFilter, UNO_QUERY); + if (xFastParser) xFastParser->parseStream( aParserInput ); + else if (xFastDocHandler) + { + Reference xParser = css::xml::sax::FastParser::create(rxContext); + xParser->setFastDocumentHandler(xFastDocHandler); + xParser->parseStream( aParserInput ); + } else + { + Reference xDocHandler(xFilter, UNO_QUERY); + assert(xDocHandler); + Reference xParser = css::xml::sax::Parser::create(rxContext); + xParser->setDocumentHandler(xDocHandler); xParser->parseStream( aParserInput ); + } auto pFilter = comphelper::getUnoTunnelImplementation(xFilter); if ( pFilter && pFilter->GetSuccess() ) -- cgit