summaryrefslogtreecommitdiff
path: root/chart2
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2020-01-12 20:12:10 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2020-01-13 14:35:06 +0100
commit029044bd5b5989e4b1a965f89e6ba79bf9717bc2 (patch)
treeec3f84c8b74805d0bc76163c1a4c03b755213d53 /chart2
parentbfb7fef85f63b82b54832c755e111b90f701e8dc (diff)
use FastParser in chart2
Change-Id: I98e8649bdfd2ceb556621a8b2c3c3a29bfaf7498 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/86677 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'chart2')
-rw-r--r--chart2/source/model/filter/XMLFilter.cxx50
-rw-r--r--chart2/source/model/inc/XMLFilter.hxx3
2 files changed, 31 insertions, 22 deletions
diff --git a/chart2/source/model/filter/XMLFilter.cxx b/chart2/source/model/filter/XMLFilter.cxx
index 0c608efcdd0e..467afe8038a2 100644
--- a/chart2/source/model/filter/XMLFilter.cxx
+++ b/chart2/source/model/filter/XMLFilter.cxx
@@ -24,6 +24,7 @@
#include <unotools/saveopt.hxx>
#include <comphelper/genericpropertyset.hxx>
#include <comphelper/propertysetinfo.hxx>
+#include <comphelper/propertysequence.hxx>
#include <comphelper/documentconstants.hxx>
#include <cppuhelper/supportsservice.hxx>
#include <comphelper/sequence.hxx>
@@ -34,6 +35,7 @@
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/xml/sax/InputSource.hpp>
#include <com/sun/star/xml/sax/Writer.hpp>
+#include <com/sun/star/xml/sax/FastToken.hpp>
#include <com/sun/star/lang/XMultiComponentFactory.hpp>
#include <com/sun/star/lang/XSingleServiceFactory.hpp>
#include <com/sun/star/embed/ElementModes.hpp>
@@ -41,13 +43,15 @@
#include <com/sun/star/embed/StorageFactory.hpp>
#include <com/sun/star/embed/XTransactedObject.hpp>
#include <com/sun/star/frame/XModel.hpp>
-#include <com/sun/star/xml/sax/XDocumentHandler.hpp>
#include <com/sun/star/xml/sax/Parser.hpp>
#include <com/sun/star/xml/sax/SAXParseException.hpp>
+#include <com/sun/star/xml/sax/XDocumentHandler.hpp>
+#include <com/sun/star/xml/sax/XFastParser.hpp>
#include <com/sun/star/packages/zip/ZipIOException.hpp>
#include <com/sun/star/document/GraphicStorageHandler.hpp>
#include <tools/diagnose_ex.h>
#include <sal/log.hxx>
+#include <xmloff/xmlnmspe.hxx>
using namespace ::com::sun::star;
@@ -289,9 +293,6 @@ ErrCode XMLFilter::impl_Import(
if( ! xFactory.is())
return ERRCODE_SFX_GENERAL;
- // create a sax parser
- Reference< xml::sax::XParser > xSaxParser = xml::sax::Parser::create(m_xContext);
-
bool bOasis = true;
isOasisFormat( rMediaDescriptor, bOasis );
Reference< embed::XStorage > xStorage( lcl_getReadStorage( rMediaDescriptor, m_xContext));
@@ -362,7 +363,7 @@ ErrCode XMLFilter::impl_Import(
nWarning = impl_ImportStream(
sXML_metaStreamName,
"com.sun.star.comp.Chart.XMLOasisMetaImporter",
- xStorage, xSaxParser, xFactory, xGraphicStorageHandler, xImportInfo );
+ xStorage, xFactory, xGraphicStorageHandler, xImportInfo );
// import styles
ErrCode nTmpErr = impl_ImportStream(
@@ -370,7 +371,7 @@ ErrCode XMLFilter::impl_Import(
bOasis
? OUString("com.sun.star.comp.Chart.XMLOasisStylesImporter")
: OUString("com.sun.star.comp.Chart.XMLStylesImporter"),
- xStorage, xSaxParser, xFactory, xGraphicStorageHandler, xImportInfo );
+ xStorage, xFactory, xGraphicStorageHandler, xImportInfo );
nWarning = nWarning != ERRCODE_NONE ? nWarning : nTmpErr;
// import content
@@ -379,7 +380,7 @@ ErrCode XMLFilter::impl_Import(
bOasis
? OUString("com.sun.star.comp.Chart.XMLOasisContentImporter")
: OUString("com.sun.star.comp.Chart.XMLContentImporter"),
- xStorage, xSaxParser, xFactory, xGraphicStorageHandler, xImportInfo );
+ xStorage, xFactory, xGraphicStorageHandler, xImportInfo );
nWarning = nWarning != ERRCODE_NONE ? nWarning : nContentWarning;
// import of "content.xml" didn't work - try old "Content.xml" stream
@@ -388,7 +389,7 @@ ErrCode XMLFilter::impl_Import(
nWarning = impl_ImportStream(
"Content.xml", // old content stream name
"com.sun.star.office.sax.importer.Chart",
- xStorage, xSaxParser, xFactory, xGraphicStorageHandler, xImportInfo );
+ xStorage, xFactory, xGraphicStorageHandler, xImportInfo );
}
}
catch (const uno::Exception&)
@@ -406,7 +407,6 @@ ErrCode XMLFilter::impl_ImportStream(
const OUString & rStreamName,
const OUString & rServiceName,
const Reference< embed::XStorage > & xStorage,
- const Reference< xml::sax::XParser > & xParser,
const Reference< lang::XMultiComponentFactory > & xFactory,
const Reference< document::XGraphicStorageHandler > & xGraphicStorageHandler,
uno::Reference< beans::XPropertySet > const & xImportInfo )
@@ -425,16 +425,14 @@ ErrCode XMLFilter::impl_ImportStream(
{
try
{
- xml::sax::InputSource aParserInput;
- aParserInput.aInputStream.set(
+ auto xInputStream =
xStorage->openStreamElement(
rStreamName,
- embed::ElementModes::READ | embed::ElementModes::NOCREATE ),
- uno::UNO_QUERY );
+ embed::ElementModes::READ | embed::ElementModes::NOCREATE );
// todo: encryption
- if( aParserInput.aInputStream.is())
+ if( xInputStream.is())
{
sal_Int32 nArgs = 0;
if( xGraphicStorageHandler.is())
@@ -450,7 +448,8 @@ ErrCode XMLFilter::impl_ImportStream(
if( xImportInfo.is())
aFilterCompArgs[ nArgs++ ] <<= xImportInfo;
- Reference< xml::sax::XDocumentHandler > xDocHandler(
+ // the underlying SvXMLImport implements XFastParser, XImporter, XFastDocumentHandler
+ Reference< xml::sax::XDocumentHandler > xDocHandler(
xFactory->createInstanceWithArgumentsAndContext( rServiceName, aFilterCompArgs, m_xContext ),
uno::UNO_QUERY_THROW );
@@ -470,16 +469,26 @@ ErrCode XMLFilter::impl_ImportStream(
aValue.Value <<= m_xTargetDoc;
aArgs[1] <<= aValue;
- xDocHandler.set(xFactory->createInstanceWithArgumentsAndContext(m_sDocumentHandler,aArgs,m_xContext), uno::UNO_QUERY );
- xImporter.set(xDocHandler,uno::UNO_QUERY);
+ xDocHandler.set(xFactory->createInstanceWithArgumentsAndContext(m_sDocumentHandler,aArgs,m_xContext), uno::UNO_QUERY_THROW );
}
catch (const uno::Exception&)
{
- OSL_FAIL("Exception caught!");
+ TOOLS_WARN_EXCEPTION("chart2", "");
}
}
- xParser->setDocumentHandler( xDocHandler );
- xParser->parseStream( aParserInput );
+ xml::sax::InputSource aParserInput;
+ aParserInput.aInputStream.set(xInputStream, uno::UNO_QUERY_THROW);
+
+ // the underlying SvXMLImport implements XFastParser, XImporter, XFastDocumentHandler
+ Reference< xml::sax::XFastParser > xFastParser(xDocHandler, uno::UNO_QUERY);
+ if (xFastParser.is())
+ xFastParser->parseStream(aParserInput);
+ else
+ {
+ Reference<xml::sax::XParser> xParser = xml::sax::Parser::create(m_xContext);
+ xParser->setDocumentHandler( xDocHandler );
+ xParser->parseStream(aParserInput);
+ }
}
// load was successful
@@ -499,6 +508,7 @@ ErrCode XMLFilter::impl_ImportStream(
}
catch (const io::IOException&)
{
+ TOOLS_WARN_EXCEPTION("chart2", "");
}
catch (const uno::Exception&)
{
diff --git a/chart2/source/model/inc/XMLFilter.hxx b/chart2/source/model/inc/XMLFilter.hxx
index 22b5a40a8077..2b79999eff40 100644
--- a/chart2/source/model/inc/XMLFilter.hxx
+++ b/chart2/source/model/inc/XMLFilter.hxx
@@ -41,7 +41,7 @@ namespace embed
}
namespace xml { namespace sax
{
- class XParser;
+ class XFastParser;
}}
namespace document
{
@@ -104,7 +104,6 @@ private:
const OUString & rStreamName,
const OUString & rServiceName,
const css::uno::Reference< css::embed::XStorage > & xStorage,
- const css::uno::Reference< css::xml::sax::XParser > & xParser,
const css::uno::Reference< css::lang::XMultiComponentFactory > & xFactory,
const css::uno::Reference<css::document::XGraphicStorageHandler> & xGraphicStorageHandler,
css::uno::Reference< css::beans::XPropertySet > const & xPropSet );