convert XMLEventsImportContext to fastparser

for now, it supports both fast and non-fast methods, since it is
constructed by both contexts

Change-Id: I925c50be161b95ecebd951cb7038a938c848a15d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/88715
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
Noel Grandin
2020-02-14 13:27:23 +02:00
parent 2339b36033
commit 10e08b1d39
11 changed files with 94 additions and 46 deletions

View File

@@ -73,6 +73,10 @@ public:
const OUString& rLocalName,
const css::uno::Reference<css::document::XEventsSupplier> & xEventsSupplier);
XMLEventsImportContext(
SvXMLImport& rImport,
const css::uno::Reference<css::document::XEventsSupplier> & xEventsSupplier);
XMLEventsImportContext(
SvXMLImport& rImport,
sal_uInt16 nPrfx,
@@ -112,6 +116,14 @@ protected:
sal_uInt16 nPrefix,
const OUString& rLocalName,
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 >& ) override;
virtual void SAL_CALL endFastElement( sal_Int32 nElement ) 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;
};
#endif

View File

@@ -128,8 +128,6 @@ public:
virtual SvXMLImportContext* CreateContext(
SvXMLImport& rImport, /// import context
sal_uInt16 nPrefix, /// element: namespace prefix
const OUString& rLocalName, /// element: local name
const css::uno::Reference<css::xml::sax::XAttributeList> & xAttrList, /// attribute list
/// the context for the enclosing <script:events> element
XMLEventsImportContext* rEvents,

View File

@@ -38,11 +38,6 @@ public:
const css::uno::Reference< css::frame::XModel>& rDocModel );
virtual ~XMLScriptContext() override;
// Create child element.
virtual SvXMLImportContextRef CreateChildContext( sal_uInt16 nPrefix,
const OUString& rLocalName,
const css::uno::Reference< css::xml::sax::XAttributeList>& xAttrList ) 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;

View File

@@ -84,8 +84,6 @@ public:
/// create an appropriate import context for a particular event
SvXMLImportContext* CreateContext(
SvXMLImport& rImport,
sal_uInt16 nPrefix,
const OUString& rLocalName,
const css::uno::Reference< css::xml::sax::XAttributeList> & xAttrList,
XMLEventsImportContext* rEvents,
const OUString& rXmlEventName,

View File

@@ -38,8 +38,6 @@ public:
virtual SvXMLImportContext *
CreateContext(SvXMLImport & rImport, /// import context
sal_uInt16 nPrefix, /// element: namespace prefix
const OUString & rLocalName, /// element: local name
/// attribute list
const css::uno::Reference< css::xml::sax::XAttributeList> & xAttrList,
/// the context for the enclosing <script:events> element

View File

@@ -39,8 +39,6 @@ public:
virtual SvXMLImportContext* CreateContext(
SvXMLImport& rImport, /// import context
sal_uInt16 nPrefix, /// element: namespace prefix
const OUString& rLocalName, /// element: local name
const css::uno::Reference<css::xml::sax::XAttributeList> & xAttrList,/// attribute list
/// the context for the enclosing <script:events> element
XMLEventsImportContext* rEvents,

View File

@@ -99,8 +99,6 @@ void XMLEventImportHelper::PopTranslationTable()
SvXMLImportContext* XMLEventImportHelper::CreateContext(
SvXMLImport& rImport,
sal_uInt16 nPrefix,
const OUString& rLocalName,
const Reference<XAttributeList> & xAttrList,
XMLEventsImportContext* rEvents,
const OUString& rXmlEventName,
@@ -132,7 +130,7 @@ SvXMLImportContext* XMLEventImportHelper::CreateContext(
{
// delegate to factory
pContext = aFactoryIterator->second->CreateContext(
rImport, nPrefix, rLocalName, xAttrList,
rImport, xAttrList,
rEvents, aNameIter->second);
}
}
@@ -140,7 +138,7 @@ SvXMLImportContext* XMLEventImportHelper::CreateContext(
// default context (if no context was created above)
if( nullptr == pContext )
{
pContext = new SvXMLImportContext(rImport, nPrefix, rLocalName);
pContext = new SvXMLImportContext(rImport);
Sequence<OUString> aMsgParams(2);

View File

@@ -22,6 +22,7 @@
#include <XMLEventImportHelper.hxx>
#include <com/sun/star/document/XEventsSupplier.hpp>
#include <comphelper/attributelist.hxx>
#include <xmloff/xmlimp.hxx>
#include <xmloff/nmspmap.hxx>
#include <xmloff/xmlnmspe.hxx>
@@ -57,6 +58,14 @@ XMLEventsImportContext::XMLEventsImportContext(
{
}
XMLEventsImportContext::XMLEventsImportContext(
SvXMLImport& rImport,
const Reference<XEventsSupplier> & xEventsSupplier) :
SvXMLImportContext(rImport),
xEvents(xEventsSupplier->getEvents())
{
}
XMLEventsImportContext::XMLEventsImportContext(
SvXMLImport& rImport,
@@ -87,8 +96,8 @@ void XMLEventsImportContext::EndElement()
}
SvXMLImportContextRef XMLEventsImportContext::CreateChildContext(
sal_uInt16 p_nPrefix,
const OUString& rLocalName,
sal_uInt16 /*p_nPrefix*/,
const OUString& /*rLocalName*/,
const Reference<XAttributeList> & xAttrList )
{
// a) search for script:language and script:event-name attribute
@@ -124,8 +133,67 @@ SvXMLImportContextRef XMLEventsImportContext::CreateChildContext(
// b) delegate to factory
return GetImport().GetEventImport().CreateContext(
GetImport(), p_nPrefix, rLocalName, xAttrList,
this, sEventName, sLanguage);
GetImport(), xAttrList, this, sEventName, sLanguage);
}
void XMLEventsImportContext::startFastElement(sal_Int32 /*nElement*/,
const css::uno::Reference< css::xml::sax::XFastAttributeList >&)
{
// nothing to be done
}
void XMLEventsImportContext::endFastElement(sal_Int32 /*nElement*/)
{
// nothing to be done
}
css::uno::Reference< css::xml::sax::XFastContextHandler > XMLEventsImportContext::createFastChildContext(
sal_Int32 /*nElement*/,
const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
{
// a) search for script:language and script:event-name attribute
// b) delegate to factory. The factory will:
// 1) translate XML event name into API event name
// 2) get proper event context factory from import
// 3) instantiate context
// a) search for script:language and script:event-name attribute
OUString sLanguage;
OUString sEventName;
sax_fastparser::FastAttributeList *pAttribList =
sax_fastparser::FastAttributeList::castToFastAttributeList( xAttrList );
for (auto &aIter : *pAttribList)
{
OUString sValue = aIter.toString();
if (aIter.getToken() == XML_ELEMENT(SCRIPT, XML_EVENT_NAME))
{
sEventName = sValue;
}
else if (aIter.getToken() == XML_ELEMENT(SCRIPT, XML_EVENT_NAME))
{
sLanguage = sValue;
// else: ignore -> let child context handle this
}
// else: ignore -> let child context handle this
}
rtl::Reference < comphelper::AttributeList > rAttrList = new comphelper::AttributeList;
const Sequence< css::xml::FastAttribute > fastAttribs = xAttrList->getFastAttributes();
for (const auto& rAttr : fastAttribs)
{
const OUString& rAttrValue = rAttr.Value;
sal_Int32 nToken = rAttr.Token;
const OUString& rAttrNamespacePrefix = SvXMLImport::getNamespacePrefixFromToken( nToken, nullptr );
OUString sAttrName = SvXMLImport::getNameFromToken( nToken );
if ( !rAttrNamespacePrefix.isEmpty() )
sAttrName = rAttrNamespacePrefix + ":" + sAttrName;
rAttrList->AddAttribute( sAttrName, "CDATA", rAttrValue );
}
// b) delegate to factory
return GetImport().GetEventImport().CreateContext(
GetImport(), rAttrList.get(), this, sEventName, sLanguage);
}
void XMLEventsImportContext::SetEvents(

View File

@@ -46,8 +46,6 @@ XMLScriptContextFactory::~XMLScriptContextFactory()
SvXMLImportContext * XMLScriptContextFactory::CreateContext
(SvXMLImport & rImport,
sal_uInt16 p_nPrefix,
const OUString & rLocalName,
const Reference<XAttributeList> & xAttrList,
XMLEventsImportContext * rEvents,
const OUString & rApiEventName)
@@ -84,7 +82,7 @@ SvXMLImportContext * XMLScriptContextFactory::CreateContext
rEvents->AddEventValues(rApiEventName, aValues);
// return dummy context
return new SvXMLImportContext(rImport, p_nPrefix, rLocalName);
return new SvXMLImportContext(rImport);
}

View File

@@ -48,8 +48,6 @@ XMLStarBasicContextFactory::~XMLStarBasicContextFactory()
SvXMLImportContext* XMLStarBasicContextFactory::CreateContext(
SvXMLImport& rImport,
sal_uInt16 p_nPrefix,
const OUString& rLocalName,
const Reference<XAttributeList> & xAttrList,
XMLEventsImportContext* rEvents,
const OUString& rApiEventName)
@@ -110,7 +108,7 @@ SvXMLImportContext* XMLStarBasicContextFactory::CreateContext(
rEvents->AddEventValues(rApiEventName, aValues);
// return dummy context
return new SvXMLImportContext(rImport, p_nPrefix, rLocalName);
return new SvXMLImportContext(rImport);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@@ -122,26 +122,13 @@ css::uno::Reference< css::xml::sax::XFastContextHandler > XMLScriptContext::crea
return new XMLScriptChildContext( GetImport(), m_xModel, aLanguage );
}
}
else if ( nElement == XML_ELEMENT(OFFICE, XML_EVENT_LISTENERS) )
{
Reference< XEventsSupplier> xSupplier( GetImport().GetModel(), UNO_QUERY );
return new XMLEventsImportContext( GetImport(), xSupplier );
}
return nullptr;
}
SvXMLImportContextRef XMLScriptContext::CreateChildContext(
sal_uInt16 nPrefix, const OUString& rLName,
const Reference<XAttributeList>& /*xAttrList*/ )
{
SvXMLImportContextRef xContext;
if ( nPrefix == XML_NAMESPACE_OFFICE )
{
if ( IsXMLToken( rLName, XML_EVENT_LISTENERS ) )
{
Reference< XEventsSupplier> xSupplier( GetImport().GetModel(), UNO_QUERY );
xContext = new XMLEventsImportContext( GetImport(), nPrefix, rLName, xSupplier );
}
}
return xContext;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */