summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2019-11-06 11:19:12 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2019-11-06 13:38:29 +0100
commit2b77d9dba51e1c3841428f3343e9186ca9c446ae (patch)
tree2b839547070996ec17d3f22694bb3588a3dc4991
parent5e73b07c36ec1e40337075b93207c438d49ca565 (diff)
convert SwXMLSectionList to FastParser
Change-Id: I6bffd6891a4a90f986513a5385ef30c38f1a48c4 Reviewed-on: https://gerrit.libreoffice.org/82127 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r--sw/inc/SwXMLSectionList.hxx11
-rw-r--r--sw/source/core/swg/SwXMLSectionList.cxx100
-rw-r--r--sw/source/filter/xml/swxml.cxx8
3 files changed, 50 insertions, 69 deletions
diff --git a/sw/inc/SwXMLSectionList.hxx b/sw/inc/SwXMLSectionList.hxx
index af8c8cb20831..99255b85df6c 100644
--- a/sw/inc/SwXMLSectionList.hxx
+++ b/sw/inc/SwXMLSectionList.hxx
@@ -23,10 +23,6 @@
class SwXMLSectionList final : public SvXMLImport
{
- virtual SvXMLImportContext *CreateDocumentContext( sal_uInt16 nPrefix,
- const OUString& rLocalName,
- const css::uno::Reference< css::xml::sax::XAttributeList > & xAttrList ) override;
-
public:
std::vector<OUString> & m_rSectionList;
@@ -34,8 +30,11 @@ public:
const css::uno::Reference< css::uno::XComponentContext >& rContext,
std::vector<OUString> & rNewSectionList);
- virtual ~SwXMLSectionList ( )
- throw() override;
+ virtual ~SwXMLSectionList ( ) throw() override;
+
+private:
+ virtual SvXMLImportContext *CreateFastContext( sal_Int32 Element,
+ const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList ) override;
};
#endif
diff --git a/sw/source/core/swg/SwXMLSectionList.cxx b/sw/source/core/swg/SwXMLSectionList.cxx
index 1ac8c1d083f1..1940ebfea478 100644
--- a/sw/source/core/swg/SwXMLSectionList.cxx
+++ b/sw/source/core/swg/SwXMLSectionList.cxx
@@ -32,13 +32,11 @@ private:
SwXMLSectionList & m_rImport;
public:
- SvXMLSectionListContext(SwXMLSectionList& rImport,
- sal_uInt16 nPrefix,
- const OUString& rLocalName,
- const uno::Reference<xml::sax::XAttributeList> & xAttrList);
- virtual SvXMLImportContextRef CreateChildContext(sal_uInt16 nPrefix,
- const OUString& rLocalName,
- const uno::Reference<xml::sax::XAttributeList> & xAttrList) override;
+ SvXMLSectionListContext(SwXMLSectionList& rImport);
+
+ virtual css::uno::Reference<css::xml::sax::XFastContextHandler> SAL_CALL createFastChildContext(
+ sal_Int32 Element,
+ const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList ) override;
};
class SwXMLParentContext : public SvXMLImportContext
@@ -47,43 +45,37 @@ private:
SwXMLSectionList & m_rImport;
public:
- SwXMLParentContext(SwXMLSectionList& rImport,
- sal_uInt16 nPrefix,
- const OUString& rLocalName)
- : SvXMLImportContext(rImport, nPrefix, rLocalName)
+ SwXMLParentContext(SwXMLSectionList& rImport)
+ : SvXMLImportContext(rImport)
, m_rImport(rImport)
{
}
- virtual SvXMLImportContextRef CreateChildContext(sal_uInt16 nPrefix,
- const OUString& rLocalName,
- const uno::Reference<xml::sax::XAttributeList> & xAttrList) override
+ virtual css::uno::Reference<XFastContextHandler> SAL_CALL createFastChildContext(
+ sal_Int32 Element, const css::uno::Reference< css::xml::sax::XFastAttributeList > & /*xAttrList*/ ) override
{
- if ((nPrefix == XML_NAMESPACE_OFFICE && IsXMLToken(rLocalName, XML_BODY)) ||
- (nPrefix == XML_NAMESPACE_TEXT &&
- ( IsXMLToken(rLocalName, XML_P)
- || IsXMLToken(rLocalName, XML_H)
- || IsXMLToken(rLocalName, XML_A)
- || IsXMLToken(rLocalName, XML_SPAN)
- || IsXMLToken(rLocalName, XML_SECTION)
- || IsXMLToken(rLocalName, XML_INDEX_BODY)
- || IsXMLToken(rLocalName, XML_INDEX_TITLE)
- || IsXMLToken(rLocalName, XML_INSERTION)
- || IsXMLToken(rLocalName, XML_DELETION))))
+ if (Element == XML_ELEMENT(OFFICE, XML_BODY) ||
+ Element == XML_ELEMENT(TEXT, XML_P) ||
+ Element == XML_ELEMENT(TEXT, XML_H) ||
+ Element == XML_ELEMENT(TEXT, XML_A) ||
+ Element == XML_ELEMENT(TEXT, XML_SPAN) ||
+ Element == XML_ELEMENT(TEXT, XML_SECTION) ||
+ Element == XML_ELEMENT(TEXT, XML_INDEX_BODY) ||
+ Element == XML_ELEMENT(TEXT, XML_INDEX_TITLE) ||
+ Element == XML_ELEMENT(TEXT, XML_INSERTION) ||
+ Element == XML_ELEMENT(TEXT, XML_DELETION))
{
- return new SvXMLSectionListContext(m_rImport, nPrefix, rLocalName, xAttrList);
+ return new SvXMLSectionListContext(m_rImport);
}
else
{
- return new SwXMLParentContext(m_rImport, nPrefix, rLocalName);
+ return new SwXMLParentContext(m_rImport);
}
}
};
-SwXMLSectionList::SwXMLSectionList(
- const uno::Reference< uno::XComponentContext >& rContext,
- std::vector<OUString> &rNewSectionList)
+SwXMLSectionList::SwXMLSectionList(const css::uno::Reference< css::uno::XComponentContext >& rContext, std::vector<OUString> &rNewSectionList)
: SvXMLImport(rContext, "")
, m_rSectionList(rNewSectionList)
{
@@ -102,50 +94,40 @@ SwXMLSectionList::~SwXMLSectionList()
{
}
-SvXMLImportContext *SwXMLSectionList::CreateDocumentContext(
- sal_uInt16 nPrefix,
- const OUString& rLocalName,
- const uno::Reference<xml::sax::XAttributeList> & )
+SvXMLImportContext * SwXMLSectionList::CreateFastContext(
+ sal_Int32 /*Element*/,
+ const css::uno::Reference< css::xml::sax::XFastAttributeList > & /*xAttrList*/ )
{
- return new SwXMLParentContext(*this, nPrefix, rLocalName);
+ return new SwXMLParentContext(*this);
}
-SvXMLSectionListContext::SvXMLSectionListContext(
- SwXMLSectionList& rImport,
- sal_uInt16 nPrefix,
- const OUString& rLocalName,
- const uno::Reference< xml::sax::XAttributeList > & ) :
- SvXMLImportContext ( rImport, nPrefix, rLocalName ),
- m_rImport(rImport)
+SvXMLSectionListContext::SvXMLSectionListContext( SwXMLSectionList& rImport )
+ : SvXMLImportContext ( rImport ),
+ m_rImport(rImport)
{
}
-SvXMLImportContextRef SvXMLSectionListContext::CreateChildContext(
- sal_uInt16 nPrefix,
- const OUString& rLocalName,
- const uno::Reference< xml::sax::XAttributeList > & xAttrList )
+css::uno::Reference<css::xml::sax::XFastContextHandler> SvXMLSectionListContext::createFastChildContext(
+ sal_Int32 Element,
+ const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList )
{
SvXMLImportContext *pContext = nullptr;
- if (nPrefix == XML_NAMESPACE_TEXT && ( IsXMLToken ( rLocalName, XML_SECTION ) ||
- IsXMLToken ( rLocalName, XML_BOOKMARK) ) )
+ if (Element == XML_ELEMENT(TEXT, XML_SECTION ) ||
+ Element == XML_ELEMENT(TEXT, XML_BOOKMARK) )
{
- OUString sName;
- sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
+ sax_fastparser::FastAttributeList *pAttribList =
+ sax_fastparser::FastAttributeList::castToFastAttributeList( xAttrList );
- for (sal_Int16 i=0; i < nAttrCount; i++)
- {
- const OUString& rAttrName = xAttrList->getNameByIndex( i );
- OUString aLocalName;
- sal_uInt16 nPrefx = m_rImport.GetNamespaceMap().GetKeyByAttrName(rAttrName, &aLocalName);
- if (XML_NAMESPACE_TEXT == nPrefx && IsXMLToken ( aLocalName, XML_NAME ) )
- sName = xAttrList->getValueByIndex( i );
- }
+ OUString sName;
+ for (auto &aIter : *pAttribList)
+ if (aIter.getToken() == (XML_NAMESPACE_TEXT | XML_NAME))
+ sName = aIter.toString();
if ( !sName.isEmpty() )
m_rImport.m_rSectionList.push_back(sName);
}
- pContext = new SvXMLSectionListContext(m_rImport, nPrefix, rLocalName, xAttrList);
+ pContext = new SvXMLSectionListContext(m_rImport);
return pContext;
}
diff --git a/sw/source/filter/xml/swxml.cxx b/sw/source/filter/xml/swxml.cxx
index 4f0c6a206f52..1b671c834d32 100644
--- a/sw/source/filter/xml/swxml.cxx
+++ b/sw/source/filter/xml/swxml.cxx
@@ -35,7 +35,7 @@
#include <com/sun/star/packages/zip/ZipIOException.hpp>
#include <com/sun/star/packages/WrongPasswordException.hpp>
#include <com/sun/star/ucb/InteractiveAugmentedIOException.hpp>
-#include <com/sun/star/xml/sax/XFastParser.hpp>
+#include <com/sun/star/xml/sax/FastParser.hpp>
#include <com/sun/star/task/XStatusIndicator.hpp>
#include <com/sun/star/frame/XModel.hpp>
#include <officecfg/Office/Common.hxx>
@@ -1003,11 +1003,11 @@ size_t XMLReader::GetSectionList( SfxMedium& rMedium,
aParserInput.aInputStream = xStm->getInputStream();
// get filter
- uno::Reference< xml::sax::XDocumentHandler > xFilter = new SwXMLSectionList( xContext, rStrings );
+ uno::Reference< xml::sax::XFastDocumentHandler > xFilter = new SwXMLSectionList( xContext, rStrings );
// connect parser and filter
- uno::Reference< xml::sax::XParser > xParser = xml::sax::Parser::create(xContext);
- xParser->setDocumentHandler( xFilter );
+ uno::Reference< xml::sax::XFastParser > xParser = xml::sax::FastParser::create(xContext);
+ xParser->setFastDocumentHandler( xFilter );
// parse
xParser->parseStream( aParserInput );