summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2020-08-27 13:05:14 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2020-08-27 20:48:36 +0200
commitc995359be1b768d9848ebbeac57765e217f5acff (patch)
treebb4223767b5dc293dde9942972cf310024cde9bc /sc
parent2730ae520da2c47ac1cabaa3ddcc43359aae5875 (diff)
use fastparser in CreateHeaderFooterContext
Change-Id: Ic0a4e4911bb56fd9731e0e9d3850387b1f26b1d5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/101474 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sc')
-rw-r--r--sc/source/filter/xml/XMLTableHeaderFooterContext.cxx100
-rw-r--r--sc/source/filter/xml/XMLTableHeaderFooterContext.hxx20
-rw-r--r--sc/source/filter/xml/xmlstyli.cxx7
-rw-r--r--sc/source/filter/xml/xmlstyli.hxx5
4 files changed, 64 insertions, 68 deletions
diff --git a/sc/source/filter/xml/XMLTableHeaderFooterContext.cxx b/sc/source/filter/xml/XMLTableHeaderFooterContext.cxx
index e62dec99205c..1e04f85cbf53 100644
--- a/sc/source/filter/xml/XMLTableHeaderFooterContext.cxx
+++ b/sc/source/filter/xml/XMLTableHeaderFooterContext.cxx
@@ -26,6 +26,7 @@
#include "XMLTableHeaderFooterContext.hxx"
#include <xmloff/xmltoken.hxx>
#include <comphelper/extract.hxx>
+#include <sal/log.hxx>
#include <unonames.hxx>
@@ -37,13 +38,12 @@ using namespace ::com::sun::star::beans;
using namespace xmloff::token;
-XMLTableHeaderFooterContext::XMLTableHeaderFooterContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
- const OUString& rLName,
+XMLTableHeaderFooterContext::XMLTableHeaderFooterContext( SvXMLImport& rImport, sal_Int32 /*nElement*/,
const uno::Reference<
- xml::sax::XAttributeList > & xAttrList,
+ xml::sax::XFastAttributeList > & xAttrList,
const Reference < XPropertySet > & rPageStylePropSet,
bool bFooter, bool bLeft ) :
- SvXMLImportContext( rImport, nPrfx, rLName ),
+ SvXMLImportContext( rImport ),
xPropSet( rPageStylePropSet ),
bContainsLeft(false),
bContainsRight(false),
@@ -54,20 +54,12 @@ XMLTableHeaderFooterContext::XMLTableHeaderFooterContext( SvXMLImport& rImport,
OUString sContentLeft( bFooter ? OUString(SC_UNO_PAGE_LEFTFTRCONT) : OUString(SC_UNO_PAGE_LEFTHDRCONT) );
OUString sShareContent( bFooter ? OUString(SC_UNO_PAGE_FTRSHARED) : OUString(SC_UNO_PAGE_HDRSHARED) );
bool bDisplay( true );
- sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
- for( sal_Int16 i=0; i < nAttrCount; ++i )
+ for( auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ) )
{
- const OUString& rAttrName(xAttrList->getNameByIndex( i ));
- OUString aLName;
- sal_uInt16 nPrefix(GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLName ));
- const OUString& rValue(xAttrList->getValueByIndex( i ));
-
- // TODO: use a map here
- if( XML_NAMESPACE_STYLE == nPrefix )
- {
- if( IsXMLToken(aLName, XML_DISPLAY ) )
- bDisplay = IsXMLToken(rValue, XML_TRUE);
- }
+ if( aIter.getToken() == XML_ELEMENT(STYLE, XML_DISPLAY) )
+ bDisplay = IsXMLToken(aIter.toString(), XML_TRUE);
+ else
+ SAL_WARN("sc", "unknown attribute " << SvXMLImport::getPrefixAndNameFromToken(aIter.getToken()) << "=" << aIter.toString());
}
if( bLeft )
{
@@ -103,6 +95,39 @@ XMLTableHeaderFooterContext::~XMLTableHeaderFooterContext()
{
}
+css::uno::Reference< css::xml::sax::XFastContextHandler > XMLTableHeaderFooterContext::createFastChildContext(
+ sal_Int32 nElement,
+ const css::uno::Reference< css::xml::sax::XFastAttributeList >& /*xAttrList*/ )
+{
+ if (xHeaderFooterContent.is())
+ {
+ uno::Reference < text::XText > xText;
+ switch (nElement)
+ {
+ case XML_ELEMENT(STYLE, XML_REGION_LEFT):
+ xText.set(xHeaderFooterContent->getLeftText());
+ bContainsLeft = true;
+ break;
+ case XML_ELEMENT(STYLE, XML_REGION_CENTER):
+ xText.set(xHeaderFooterContent->getCenterText());
+ bContainsCenter = true;
+ break;
+ case XML_ELEMENT(STYLE, XML_REGION_RIGHT):
+ xText.set(xHeaderFooterContent->getRightText());
+ bContainsRight = true;
+ break;
+ default: break;
+ }
+ if (xText.is())
+ {
+ xText->setString("");
+ uno::Reference < text::XTextCursor > xTempTextCursor(xText->createTextCursor());
+ return new XMLHeaderFooterRegionContext( GetImport(), xTempTextCursor);
+ }
+ }
+ return nullptr;
+}
+
SvXMLImportContextRef XMLTableHeaderFooterContext::CreateChildContext(
sal_uInt16 nPrefix,
const OUString& rLocalName,
@@ -131,43 +156,11 @@ SvXMLImportContextRef XMLTableHeaderFooterContext::CreateChildContext(
rLocalName,
xAttrList);
}
- else
- {
- if (nPrefix == XML_NAMESPACE_STYLE)
- {
- if (xHeaderFooterContent.is())
- {
- uno::Reference < text::XText > xText;
- if (IsXMLToken(rLocalName, XML_REGION_LEFT ))
- {
- xText.set(xHeaderFooterContent->getLeftText());
- bContainsLeft = true;
- }
- else if (IsXMLToken(rLocalName, XML_REGION_CENTER ))
- {
- xText.set(xHeaderFooterContent->getCenterText());
- bContainsCenter = true;
- }
- else if (IsXMLToken(rLocalName, XML_REGION_RIGHT ))
- {
- xText.set(xHeaderFooterContent->getRightText());
- bContainsRight = true;
- }
- if (xText.is())
- {
- xText->setString("");
- //SvXMLImport aSvXMLImport( GetImport() );
- uno::Reference < text::XTextCursor > xTempTextCursor(xText->createTextCursor());
- pContext = new XMLHeaderFooterRegionContext( GetImport(), nPrefix, rLocalName, xTempTextCursor);
- }
- }
- }
- }
return pContext;
}
-void XMLTableHeaderFooterContext::EndElement()
+void XMLTableHeaderFooterContext::endFastElement(sal_Int32 )
{
if( GetImport().GetTextImport()->GetCursor().is() )
{
@@ -196,10 +189,9 @@ void XMLTableHeaderFooterContext::EndElement()
}
-XMLHeaderFooterRegionContext::XMLHeaderFooterRegionContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
- const OUString& rLName,
+XMLHeaderFooterRegionContext::XMLHeaderFooterRegionContext( SvXMLImport& rImport,
uno::Reference< text::XTextCursor >& xCursor ) :
- SvXMLImportContext( rImport, nPrfx, rLName ),
+ SvXMLImportContext( rImport ),
xTextCursor ( xCursor )
{
xOldTextCursor.set(GetImport().GetTextImport()->GetCursor());
@@ -230,7 +222,7 @@ SvXMLImportContextRef XMLHeaderFooterRegionContext::CreateChildContext(
return pContext;
}
-void XMLHeaderFooterRegionContext::EndElement()
+void XMLHeaderFooterRegionContext::endFastElement(sal_Int32 )
{
if( GetImport().GetTextImport()->GetCursor().is() )
{
diff --git a/sc/source/filter/xml/XMLTableHeaderFooterContext.hxx b/sc/source/filter/xml/XMLTableHeaderFooterContext.hxx
index a8021d55f00c..f9088ebe8f38 100644
--- a/sc/source/filter/xml/XMLTableHeaderFooterContext.hxx
+++ b/sc/source/filter/xml/XMLTableHeaderFooterContext.hxx
@@ -43,9 +43,8 @@ class XMLTableHeaderFooterContext: public SvXMLImportContext
public:
- XMLTableHeaderFooterContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
- const OUString& rLName,
- const css::uno::Reference< css::xml::sax::XAttributeList > & xAttrList,
+ XMLTableHeaderFooterContext( SvXMLImport& rImport, sal_Int32 nElement,
+ const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList,
const css::uno::Reference< css::beans::XPropertySet > & rPageStylePropSet,
bool bFooter, bool bLft );
@@ -56,7 +55,13 @@ public:
const OUString& rLocalName,
const css::uno::Reference< css::xml::sax::XAttributeList > & xAttrList ) override;
- virtual void EndElement() override;
+ virtual void SAL_CALL startFastElement( sal_Int32 /*nElement*/,
+ const css::uno::Reference< css::xml::sax::XFastAttributeList >& ) override {}
+
+ virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
+ sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) override;
+
+ virtual void SAL_CALL endFastElement(sal_Int32 nElement) override;
};
class XMLHeaderFooterRegionContext: public SvXMLImportContext
@@ -67,8 +72,7 @@ private:
public:
- XMLHeaderFooterRegionContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
- const OUString& rLName,
+ XMLHeaderFooterRegionContext( SvXMLImport& rImport,
css::uno::Reference< css::text::XTextCursor >& xCursor );
virtual ~XMLHeaderFooterRegionContext() override;
@@ -78,7 +82,9 @@ public:
const OUString& rLocalName,
const css::uno::Reference< css::xml::sax::XAttributeList > & xAttrList ) override;
- virtual void EndElement() override;
+ virtual void SAL_CALL startFastElement( sal_Int32 /*nElement*/,
+ const css::uno::Reference< css::xml::sax::XFastAttributeList >& ) override {}
+ virtual void SAL_CALL endFastElement(sal_Int32 nElement) override;
};
#endif
diff --git a/sc/source/filter/xml/xmlstyli.cxx b/sc/source/filter/xml/xmlstyli.cxx
index 80f9a207537e..9569fa52e417 100644
--- a/sc/source/filter/xml/xmlstyli.cxx
+++ b/sc/source/filter/xml/xmlstyli.cxx
@@ -955,9 +955,8 @@ ScMasterPageContext::~ScMasterPageContext()
}
SvXMLImportContext *ScMasterPageContext::CreateHeaderFooterContext(
- sal_uInt16 nPrefix,
- const OUString& rLocalName,
- const css::uno::Reference< css::xml::sax::XAttributeList > & xAttrList,
+ sal_Int32 nElement,
+ const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList,
const bool bFooter,
const bool bLeft,
const bool /*bFirst*/ )
@@ -972,7 +971,7 @@ SvXMLImportContext *ScMasterPageContext::CreateHeaderFooterContext(
if (!xPropSet.is())
xPropSet.set(GetStyle(), UNO_QUERY );
return new XMLTableHeaderFooterContext( GetImport(),
- nPrefix, rLocalName,
+ nElement,
xAttrList,
xPropSet,
bFooter, bLeft );
diff --git a/sc/source/filter/xml/xmlstyli.hxx b/sc/source/filter/xml/xmlstyli.hxx
index 29010ad2b507..0bbcefb18a0b 100644
--- a/sc/source/filter/xml/xmlstyli.hxx
+++ b/sc/source/filter/xml/xmlstyli.hxx
@@ -200,9 +200,8 @@ public:
virtual ~ScMasterPageContext() override;
virtual SvXMLImportContext *CreateHeaderFooterContext(
- sal_uInt16 nPrefix,
- const OUString& rLocalName,
- const css::uno::Reference< css::xml::sax::XAttributeList > & xAttrList,
+ sal_Int32 nElement,
+ const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList,
const bool bFooter,
const bool bLeft,
const bool bFirst ) override;