summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoel Grandin <noelgrandin@gmail.com>2020-11-30 20:37:44 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2020-12-01 08:22:57 +0100
commit5a6350c4e02092e97faa4593acfcd4a3f07de3ef (patch)
treebd72b543c9b0a2fcd64c83a7c15dddacbebc3d89
parent445d56983863a739797dfb940483c209c764e8d6 (diff)
fastparser in XMLSectionImportContext
Change-Id: I536214f532c39de7319ec66d357ee84e53c97c59 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/106914 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r--xmloff/source/text/XMLSectionImportContext.cxx53
-rw-r--r--xmloff/source/text/XMLSectionImportContext.hxx14
-rw-r--r--xmloff/source/text/txtimp.cxx2
3 files changed, 30 insertions, 39 deletions
diff --git a/xmloff/source/text/XMLSectionImportContext.cxx b/xmloff/source/text/XMLSectionImportContext.cxx
index 2ed3f5b23a9a..11716281bd7e 100644
--- a/xmloff/source/text/XMLSectionImportContext.cxx
+++ b/xmloff/source/text/XMLSectionImportContext.cxx
@@ -28,6 +28,7 @@
#include <xmloff/xmlnamespace.hxx>
#include <xmloff/xmltoken.hxx>
#include <xmloff/prstylei.hxx>
+#include <sal/log.hxx>
#include <sax/tools/converter.hxx>
#include <com/sun/star/container/XNamed.hpp>
#include <com/sun/star/frame/XModel.hpp>
@@ -41,6 +42,7 @@
using ::com::sun::star::beans::XPropertySet;
using ::com::sun::star::uno::Reference;
using ::com::sun::star::xml::sax::XAttributeList;
+using ::com::sun::star::xml::sax::XFastAttributeList;
using ::com::sun::star::lang::XMultiServiceFactory;
using ::com::sun::star::container::XNamed;
@@ -85,11 +87,8 @@ const SvXMLTokenMapEntry aSectionTokenMap[] =
// insert a section within another section, you can't move the cursor
// between the ends of the inner and the enclosing section. To avoid
// these problems, additional markers are first inserted and later deleted.
-XMLSectionImportContext::XMLSectionImportContext(
- SvXMLImport& rImport,
- sal_uInt16 nPrfx,
- const OUString& rLocalName )
-: SvXMLImportContext(rImport, nPrfx, rLocalName)
+XMLSectionImportContext::XMLSectionImportContext( SvXMLImport& rImport )
+: SvXMLImportContext(rImport)
, bProtect(false)
, bCondOK(false)
, bIsVisible(true)
@@ -105,14 +104,14 @@ XMLSectionImportContext::~XMLSectionImportContext()
{
}
-void XMLSectionImportContext::StartElement(
- const Reference<XAttributeList> & xAttrList)
+void XMLSectionImportContext::startFastElement( sal_Int32 nElement,
+ const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
{
// process attributes
ProcessAttributes(xAttrList);
// process index headers:
- bool bIsIndexHeader = IsXMLToken( GetLocalName(), XML_INDEX_TITLE );
+ bool bIsIndexHeader = (nElement & TOKEN_MASK) == XML_INDEX_TITLE;
if (bIsIndexHeader)
{
bValid = true;
@@ -178,7 +177,7 @@ void XMLSectionImportContext::StartElement(
// password (only for regular sections)
if ( bSequenceOK &&
- IsXMLToken(GetLocalName(), XML_SECTION) )
+ (nElement & TOKEN_MASK) == XML_SECTION )
{
xPropSet->setPropertyValue("ProtectionKey", Any(aSequence));
}
@@ -226,32 +225,25 @@ void XMLSectionImportContext::StartElement(
}
void XMLSectionImportContext::ProcessAttributes(
- const Reference<XAttributeList> & xAttrList )
+ const Reference<XFastAttributeList> & xAttrList )
{
- static const SvXMLTokenMap aTokenMap(aSectionTokenMap);
-
- sal_Int16 nLength = xAttrList->getLength();
- for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
+ for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) )
{
- OUString sLocalName;
- sal_uInt16 nNamePrefix = GetImport().GetNamespaceMap().
- GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
- &sLocalName );
- OUString sAttr = xAttrList->getValueByIndex(nAttr);
+ OUString sAttr = aIter.toString();
- switch (aTokenMap.Get(nNamePrefix, sLocalName))
+ switch (aIter.getToken())
{
- case XML_TOK_SECTION_XMLID:
+ case XML_ELEMENT(XML, XML_ID):
sXmlId = sAttr;
break;
- case XML_TOK_SECTION_STYLE_NAME:
+ case XML_ELEMENT(TEXT, XML_STYLE_NAME):
sStyleName = sAttr;
break;
- case XML_TOK_SECTION_NAME:
+ case XML_ELEMENT(TEXT, XML_NAME):
sName = sAttr;
bValid = true;
break;
- case XML_TOK_SECTION_CONDITION:
+ case XML_ELEMENT(TEXT, XML_CONDITION):
{
OUString sTmp;
sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
@@ -265,7 +257,7 @@ void XMLSectionImportContext::ProcessAttributes(
sCond = sAttr;
}
break;
- case XML_TOK_SECTION_DISPLAY:
+ case XML_ELEMENT(TEXT, XML_DISPLAY):
if (IsXMLToken(sAttr, XML_TRUE))
{
bIsVisible = true;
@@ -277,7 +269,7 @@ void XMLSectionImportContext::ProcessAttributes(
}
// else: ignore
break;
- case XML_TOK_SECTION_IS_HIDDEN:
+ case XML_ELEMENT(TEXT, XML_IS_HIDDEN):
{
bool bTmp(false);
if (::sax::Converter::convertBool(bTmp, sAttr))
@@ -287,11 +279,13 @@ void XMLSectionImportContext::ProcessAttributes(
}
}
break;
- case XML_TOK_SECTION_PROTECTION_KEY:
+ case XML_ELEMENT(TEXT, XML_PROTECTION_KEY):
::comphelper::Base64::decode(aSequence, sAttr);
bSequenceOK = true;
break;
- case XML_TOK_SECTION_PROTECT:
+ case XML_ELEMENT(TEXT, XML_PROTECTED):
+ // compatibility with SRC629 (or earlier) versions
+ case XML_ELEMENT(TEXT, XML_PROTECT):
{
bool bTmp(false);
if (::sax::Converter::convertBool(bTmp, sAttr))
@@ -301,7 +295,8 @@ void XMLSectionImportContext::ProcessAttributes(
break;
}
default:
- ; // ignore
+ // ignore
+ XMLOFF_WARN_UNKNOWN("xmloff", aIter);
break;
}
}
diff --git a/xmloff/source/text/XMLSectionImportContext.hxx b/xmloff/source/text/XMLSectionImportContext.hxx
index b593237d74af..38f8c536684e 100644
--- a/xmloff/source/text/XMLSectionImportContext.hxx
+++ b/xmloff/source/text/XMLSectionImportContext.hxx
@@ -37,7 +37,7 @@ namespace com::sun::star {
* This context may *also* be used for index header sections. The
* differentiates its behaviour based on GetLocalName().
*/
-class XMLSectionImportContext : public SvXMLImportContext
+class XMLSectionImportContext final : public SvXMLImportContext
{
/// TextSection (as XPropertySet) for passing down to data source elements
css::uno::Reference<css::beans::XPropertySet> xSectionPropertySet;
@@ -59,18 +59,14 @@ class XMLSectionImportContext : public SvXMLImportContext
public:
-
- XMLSectionImportContext(
- SvXMLImport& rImport,
- sal_uInt16 nPrfx,
- const OUString& rLocalName );
+ XMLSectionImportContext( SvXMLImport& rImport );
virtual ~XMLSectionImportContext() override;
private:
- virtual void StartElement(
- const css::uno::Reference<css::xml::sax::XAttributeList> & xAttrList) override;
+ virtual void SAL_CALL startFastElement( sal_Int32 nElement,
+ const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override;
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override;
@@ -80,7 +76,7 @@ private:
const css::uno::Reference<css::xml::sax::XAttributeList> & xAttrList ) override;
void ProcessAttributes(
- const css::uno::Reference<css::xml::sax::XAttributeList> & xAttrList );
+ const css::uno::Reference<css::xml::sax::XFastAttributeList> & xAttrList );
};
#endif
diff --git a/xmloff/source/text/txtimp.cxx b/xmloff/source/text/txtimp.cxx
index e5942678447c..f37e571ab51b 100644
--- a/xmloff/source/text/txtimp.cxx
+++ b/xmloff/source/text/txtimp.cxx
@@ -2249,7 +2249,7 @@ SvXMLImportContext *XMLTextImportHelper::CreateTextChildContext(
case XML_TOK_TEXT_INDEX_TITLE:
case XML_TOK_TEXT_SECTION:
- pContext = new XMLSectionImportContext( rImport, nPrefix, rLocalName );
+ pContext = new XMLSectionImportContext( rImport );
break;
case XML_TOK_TEXT_TOC: