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:
@@ -73,6 +73,10 @@ public:
|
|||||||
const OUString& rLocalName,
|
const OUString& rLocalName,
|
||||||
const css::uno::Reference<css::document::XEventsSupplier> & xEventsSupplier);
|
const css::uno::Reference<css::document::XEventsSupplier> & xEventsSupplier);
|
||||||
|
|
||||||
|
XMLEventsImportContext(
|
||||||
|
SvXMLImport& rImport,
|
||||||
|
const css::uno::Reference<css::document::XEventsSupplier> & xEventsSupplier);
|
||||||
|
|
||||||
XMLEventsImportContext(
|
XMLEventsImportContext(
|
||||||
SvXMLImport& rImport,
|
SvXMLImport& rImport,
|
||||||
sal_uInt16 nPrfx,
|
sal_uInt16 nPrfx,
|
||||||
@@ -112,6 +116,14 @@ protected:
|
|||||||
sal_uInt16 nPrefix,
|
sal_uInt16 nPrefix,
|
||||||
const OUString& rLocalName,
|
const OUString& rLocalName,
|
||||||
const css::uno::Reference<css::xml::sax::XAttributeList> & xAttrList ) override;
|
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
|
#endif
|
||||||
|
@@ -128,8 +128,6 @@ public:
|
|||||||
|
|
||||||
virtual SvXMLImportContext* CreateContext(
|
virtual SvXMLImportContext* CreateContext(
|
||||||
SvXMLImport& rImport, /// import context
|
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
|
const css::uno::Reference<css::xml::sax::XAttributeList> & xAttrList, /// attribute list
|
||||||
/// the context for the enclosing <script:events> element
|
/// the context for the enclosing <script:events> element
|
||||||
XMLEventsImportContext* rEvents,
|
XMLEventsImportContext* rEvents,
|
||||||
|
@@ -38,11 +38,6 @@ public:
|
|||||||
const css::uno::Reference< css::frame::XModel>& rDocModel );
|
const css::uno::Reference< css::frame::XModel>& rDocModel );
|
||||||
virtual ~XMLScriptContext() override;
|
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(
|
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
|
||||||
sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) override;
|
sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) override;
|
||||||
|
|
||||||
|
@@ -84,8 +84,6 @@ public:
|
|||||||
/// create an appropriate import context for a particular event
|
/// create an appropriate import context for a particular event
|
||||||
SvXMLImportContext* CreateContext(
|
SvXMLImportContext* CreateContext(
|
||||||
SvXMLImport& rImport,
|
SvXMLImport& rImport,
|
||||||
sal_uInt16 nPrefix,
|
|
||||||
const OUString& rLocalName,
|
|
||||||
const css::uno::Reference< css::xml::sax::XAttributeList> & xAttrList,
|
const css::uno::Reference< css::xml::sax::XAttributeList> & xAttrList,
|
||||||
XMLEventsImportContext* rEvents,
|
XMLEventsImportContext* rEvents,
|
||||||
const OUString& rXmlEventName,
|
const OUString& rXmlEventName,
|
||||||
|
@@ -38,8 +38,6 @@ public:
|
|||||||
|
|
||||||
virtual SvXMLImportContext *
|
virtual SvXMLImportContext *
|
||||||
CreateContext(SvXMLImport & rImport, /// import context
|
CreateContext(SvXMLImport & rImport, /// import context
|
||||||
sal_uInt16 nPrefix, /// element: namespace prefix
|
|
||||||
const OUString & rLocalName, /// element: local name
|
|
||||||
/// attribute list
|
/// attribute list
|
||||||
const css::uno::Reference< css::xml::sax::XAttributeList> & xAttrList,
|
const css::uno::Reference< css::xml::sax::XAttributeList> & xAttrList,
|
||||||
/// the context for the enclosing <script:events> element
|
/// the context for the enclosing <script:events> element
|
||||||
|
@@ -39,8 +39,6 @@ public:
|
|||||||
|
|
||||||
virtual SvXMLImportContext* CreateContext(
|
virtual SvXMLImportContext* CreateContext(
|
||||||
SvXMLImport& rImport, /// import context
|
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
|
const css::uno::Reference<css::xml::sax::XAttributeList> & xAttrList,/// attribute list
|
||||||
/// the context for the enclosing <script:events> element
|
/// the context for the enclosing <script:events> element
|
||||||
XMLEventsImportContext* rEvents,
|
XMLEventsImportContext* rEvents,
|
||||||
|
@@ -99,8 +99,6 @@ void XMLEventImportHelper::PopTranslationTable()
|
|||||||
|
|
||||||
SvXMLImportContext* XMLEventImportHelper::CreateContext(
|
SvXMLImportContext* XMLEventImportHelper::CreateContext(
|
||||||
SvXMLImport& rImport,
|
SvXMLImport& rImport,
|
||||||
sal_uInt16 nPrefix,
|
|
||||||
const OUString& rLocalName,
|
|
||||||
const Reference<XAttributeList> & xAttrList,
|
const Reference<XAttributeList> & xAttrList,
|
||||||
XMLEventsImportContext* rEvents,
|
XMLEventsImportContext* rEvents,
|
||||||
const OUString& rXmlEventName,
|
const OUString& rXmlEventName,
|
||||||
@@ -132,7 +130,7 @@ SvXMLImportContext* XMLEventImportHelper::CreateContext(
|
|||||||
{
|
{
|
||||||
// delegate to factory
|
// delegate to factory
|
||||||
pContext = aFactoryIterator->second->CreateContext(
|
pContext = aFactoryIterator->second->CreateContext(
|
||||||
rImport, nPrefix, rLocalName, xAttrList,
|
rImport, xAttrList,
|
||||||
rEvents, aNameIter->second);
|
rEvents, aNameIter->second);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -140,7 +138,7 @@ SvXMLImportContext* XMLEventImportHelper::CreateContext(
|
|||||||
// default context (if no context was created above)
|
// default context (if no context was created above)
|
||||||
if( nullptr == pContext )
|
if( nullptr == pContext )
|
||||||
{
|
{
|
||||||
pContext = new SvXMLImportContext(rImport, nPrefix, rLocalName);
|
pContext = new SvXMLImportContext(rImport);
|
||||||
|
|
||||||
Sequence<OUString> aMsgParams(2);
|
Sequence<OUString> aMsgParams(2);
|
||||||
|
|
||||||
|
@@ -22,6 +22,7 @@
|
|||||||
#include <XMLEventImportHelper.hxx>
|
#include <XMLEventImportHelper.hxx>
|
||||||
|
|
||||||
#include <com/sun/star/document/XEventsSupplier.hpp>
|
#include <com/sun/star/document/XEventsSupplier.hpp>
|
||||||
|
#include <comphelper/attributelist.hxx>
|
||||||
#include <xmloff/xmlimp.hxx>
|
#include <xmloff/xmlimp.hxx>
|
||||||
#include <xmloff/nmspmap.hxx>
|
#include <xmloff/nmspmap.hxx>
|
||||||
#include <xmloff/xmlnmspe.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(
|
XMLEventsImportContext::XMLEventsImportContext(
|
||||||
SvXMLImport& rImport,
|
SvXMLImport& rImport,
|
||||||
@@ -87,8 +96,8 @@ void XMLEventsImportContext::EndElement()
|
|||||||
}
|
}
|
||||||
|
|
||||||
SvXMLImportContextRef XMLEventsImportContext::CreateChildContext(
|
SvXMLImportContextRef XMLEventsImportContext::CreateChildContext(
|
||||||
sal_uInt16 p_nPrefix,
|
sal_uInt16 /*p_nPrefix*/,
|
||||||
const OUString& rLocalName,
|
const OUString& /*rLocalName*/,
|
||||||
const Reference<XAttributeList> & xAttrList )
|
const Reference<XAttributeList> & xAttrList )
|
||||||
{
|
{
|
||||||
// a) search for script:language and script:event-name attribute
|
// a) search for script:language and script:event-name attribute
|
||||||
@@ -124,8 +133,67 @@ SvXMLImportContextRef XMLEventsImportContext::CreateChildContext(
|
|||||||
|
|
||||||
// b) delegate to factory
|
// b) delegate to factory
|
||||||
return GetImport().GetEventImport().CreateContext(
|
return GetImport().GetEventImport().CreateContext(
|
||||||
GetImport(), p_nPrefix, rLocalName, xAttrList,
|
GetImport(), xAttrList, this, sEventName, sLanguage);
|
||||||
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(
|
void XMLEventsImportContext::SetEvents(
|
||||||
|
@@ -46,8 +46,6 @@ XMLScriptContextFactory::~XMLScriptContextFactory()
|
|||||||
|
|
||||||
SvXMLImportContext * XMLScriptContextFactory::CreateContext
|
SvXMLImportContext * XMLScriptContextFactory::CreateContext
|
||||||
(SvXMLImport & rImport,
|
(SvXMLImport & rImport,
|
||||||
sal_uInt16 p_nPrefix,
|
|
||||||
const OUString & rLocalName,
|
|
||||||
const Reference<XAttributeList> & xAttrList,
|
const Reference<XAttributeList> & xAttrList,
|
||||||
XMLEventsImportContext * rEvents,
|
XMLEventsImportContext * rEvents,
|
||||||
const OUString & rApiEventName)
|
const OUString & rApiEventName)
|
||||||
@@ -84,7 +82,7 @@ SvXMLImportContext * XMLScriptContextFactory::CreateContext
|
|||||||
rEvents->AddEventValues(rApiEventName, aValues);
|
rEvents->AddEventValues(rApiEventName, aValues);
|
||||||
|
|
||||||
// return dummy context
|
// return dummy context
|
||||||
return new SvXMLImportContext(rImport, p_nPrefix, rLocalName);
|
return new SvXMLImportContext(rImport);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -48,8 +48,6 @@ XMLStarBasicContextFactory::~XMLStarBasicContextFactory()
|
|||||||
|
|
||||||
SvXMLImportContext* XMLStarBasicContextFactory::CreateContext(
|
SvXMLImportContext* XMLStarBasicContextFactory::CreateContext(
|
||||||
SvXMLImport& rImport,
|
SvXMLImport& rImport,
|
||||||
sal_uInt16 p_nPrefix,
|
|
||||||
const OUString& rLocalName,
|
|
||||||
const Reference<XAttributeList> & xAttrList,
|
const Reference<XAttributeList> & xAttrList,
|
||||||
XMLEventsImportContext* rEvents,
|
XMLEventsImportContext* rEvents,
|
||||||
const OUString& rApiEventName)
|
const OUString& rApiEventName)
|
||||||
@@ -110,7 +108,7 @@ SvXMLImportContext* XMLStarBasicContextFactory::CreateContext(
|
|||||||
rEvents->AddEventValues(rApiEventName, aValues);
|
rEvents->AddEventValues(rApiEventName, aValues);
|
||||||
|
|
||||||
// return dummy context
|
// return dummy context
|
||||||
return new SvXMLImportContext(rImport, p_nPrefix, rLocalName);
|
return new SvXMLImportContext(rImport);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||||
|
@@ -122,26 +122,13 @@ css::uno::Reference< css::xml::sax::XFastContextHandler > XMLScriptContext::crea
|
|||||||
return new XMLScriptChildContext( GetImport(), m_xModel, aLanguage );
|
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;
|
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: */
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||||
|
Reference in New Issue
Block a user