diff options
author | Noel Grandin <noelgrandin@gmail.com> | 2020-10-17 12:02:36 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-10-17 15:41:55 +0200 |
commit | f2502e72156be4c73760f95e5d59a7e5a64aa021 (patch) | |
tree | 670b872f93faf5a38751debd70d34e8df389de7e /starmath | |
parent | dd4670b976b00d643f335516fe5fd0c880d58025 (diff) |
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@collabora.co.uk>
Diffstat (limited to 'starmath')
-rw-r--r-- | starmath/source/mathmlimport.cxx | 34 |
1 files changed, 19 insertions, 15 deletions
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() ) |