summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorNoel <noelgrandin@gmail.com>2020-10-16 13:25:17 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2020-10-16 17:44:57 +0200
commitf586c0c9257473d92936a91d632a4a408a36275e (patch)
tree00b9e6180ad22cff2f86bdb1e259bbc109f00043 /sw
parent90fa4426a1be8874baacd21eff8c7c46f8a4371a (diff)
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@collabora.co.uk>
Diffstat (limited to 'sw')
-rw-r--r--sw/source/filter/xml/swxml.cxx33
1 files changed, 20 insertions, 13 deletions
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)
{