[Libreoffice-commits] core.git: xmloff/source
Noel Grandin (via logerrit)
logerrit at kemper.freedesktop.org
Thu Apr 30 08:33:22 UTC 2020
xmloff/source/forms/elementimport.cxx | 80 +++++++++++++++++++---
xmloff/source/forms/elementimport.hxx | 121 +++++-----------------------------
2 files changed, 89 insertions(+), 112 deletions(-)
New commits:
commit 7e4463db510fe7faa15e4f5ad3394aa0abf52b66
Author: Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Thu Apr 30 09:53:49 2020 +0200
Commit: Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Thu Apr 30 10:32:42 2020 +0200
expand out OContainerImport template
to make the logic easier to follow, and to make it possible to convert
this to fast-parser APIs
Change-Id: I48921c3cd84b45f56ff943060f2d9c8e4882d051
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/93193
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
diff --git a/xmloff/source/forms/elementimport.cxx b/xmloff/source/forms/elementimport.cxx
index 25824d8e08c6..8693cc355bf1 100644
--- a/xmloff/source/forms/elementimport.cxx
+++ b/xmloff/source/forms/elementimport.cxx
@@ -1836,20 +1836,62 @@ namespace xmloff
OGridImport::OGridImport(OFormLayerXMLImport_Impl& _rImport, IEventAttacherManager& _rEventManager, sal_uInt16 _nPrefix, const OUString& _rName,
const Reference< XNameContainer >& _rxParentContainer,
OControlElement::ElementType _eType)
- :OGridImport_Base(_rImport, _rEventManager, _nPrefix, _rName, _rxParentContainer, "column")
+ :OControlImport(_rImport, _rEventManager, _nPrefix, _rName, _rxParentContainer)
{
setElementType(_eType);
}
- SvXMLImportContext* OGridImport::implCreateControlWrapper(sal_uInt16 _nPrefix, const OUString& _rLocalName)
+ SvXMLImportContextRef OGridImport::CreateChildContext(
+ sal_uInt16 _nPrefix, const OUString& _rLocalName,
+ const css::uno::Reference< css::xml::sax::XAttributeList >& _rxAttrList)
+ {
+ // maybe it's a sub control
+ if (_rLocalName == "column")
+ {
+ if (m_xMeAsContainer.is())
+ return new OColumnWrapperImport(m_rFormImport, *this, _nPrefix, _rLocalName, m_xMeAsContainer);
+ else
+ {
+ OSL_FAIL("OGridImport::CreateChildContext: don't have an element!");
+ return nullptr;
+ }
+ }
+
+ return OControlImport::CreateChildContext(_nPrefix, _rLocalName, _rxAttrList);
+ }
+
+ void OGridImport::EndElement()
+ {
+ OControlImport::EndElement();
+
+ // now that we have all children, attach the events
+ css::uno::Reference< css::container::XIndexAccess > xIndexContainer(m_xMeAsContainer, css::uno::UNO_QUERY);
+ if (xIndexContainer.is())
+ ODefaultEventAttacherManager::setEvents(xIndexContainer);
+ }
+
+ css::uno::Reference< css::beans::XPropertySet > OGridImport::createElement()
{
- return new OColumnWrapperImport(m_rFormImport, *this, _nPrefix, _rLocalName, m_xMeAsContainer);
+ // let the base class create the object
+ css::uno::Reference< css::beans::XPropertySet > xReturn = OControlImport::createElement();
+ if (!xReturn.is())
+ return xReturn;
+
+ // ensure that the object is a XNameContainer (we strongly need this for inserting child elements)
+ m_xMeAsContainer.set(xReturn, css::uno::UNO_QUERY);
+ if (!m_xMeAsContainer.is())
+ {
+ OSL_FAIL("OContainerImport::createElement: invalid element (no XNameContainer) created!");
+ xReturn.clear();
+ }
+
+ return xReturn;
}
//= OFormImport
OFormImport::OFormImport(OFormLayerXMLImport_Impl& _rImport, IEventAttacherManager& _rEventManager, sal_uInt16 _nPrefix, const OUString& _rName,
const Reference< XNameContainer >& _rxParentContainer)
- :OFormImport_Base(_rImport, _rEventManager, _nPrefix, _rName, _rxParentContainer, "control")
+ :OElementImport(_rImport, _rEventManager, _nPrefix, _rName, _rxParentContainer)
{
enableTrackAttributes();
}
@@ -1875,7 +1917,7 @@ namespace xmloff
void OFormImport::StartElement(const Reference< XAttributeList >& _rxAttrList)
{
m_rFormImport.enterEventContext();
- OFormImport_Base::StartElement(_rxAttrList);
+ OElementImport::StartElement(_rxAttrList);
// handle the target-frame attribute
simulateDefaultedAttribute(OAttributeMetaData::getCommonControlAttributeName(CCAFlags::TargetFrame), PROPERTY_TARGETFRAME, "_blank");
@@ -1883,14 +1925,32 @@ namespace xmloff
void OFormImport::EndElement()
{
- OFormImport_Base::EndElement();
+ OElementImport::EndElement();
+
+ // now that we have all children, attach the events
+ css::uno::Reference< css::container::XIndexAccess > xIndexContainer(m_xMeAsContainer, css::uno::UNO_QUERY);
+ if (xIndexContainer.is())
+ ODefaultEventAttacherManager::setEvents(xIndexContainer);
+
m_rFormImport.leaveEventContext();
}
- SvXMLImportContext* OFormImport::implCreateControlWrapper(sal_uInt16 _nPrefix, const OUString& _rLocalName)
+ css::uno::Reference< css::beans::XPropertySet > OFormImport::createElement()
{
- OSL_ENSURE( false, "illegal call to OFormImport::implCreateControlWrapper" );
- return new SvXMLImportContext(GetImport(), _nPrefix, _rLocalName );
+ // let the base class create the object
+ css::uno::Reference< css::beans::XPropertySet > xReturn = OElementImport::createElement();
+ if (!xReturn.is())
+ return xReturn;
+
+ // ensure that the object is a XNameContainer (we strongly need this for inserting child elements)
+ m_xMeAsContainer.set(xReturn, css::uno::UNO_QUERY);
+ if (!m_xMeAsContainer.is())
+ {
+ OSL_FAIL("OContainerImport::createElement: invalid element (no XNameContainer) created!");
+ xReturn.clear();
+ }
+
+ return xReturn;
}
bool OFormImport::handleAttribute(sal_uInt16 _nNamespaceKey, const OUString& _rLocalName, const OUString& _rValue)
@@ -1911,7 +1971,7 @@ namespace xmloff
return true;
}
- return OFormImport_Base::handleAttribute(_nNamespaceKey, _rLocalName, _rValue);
+ return OElementImport::handleAttribute(_nNamespaceKey, _rLocalName, _rValue);
}
void OFormImport::implTranslateStringListProperty(const OUString& _rPropertyName, const OUString& _rValue)
diff --git a/xmloff/source/forms/elementimport.hxx b/xmloff/source/forms/elementimport.hxx
index b0e8f3ce1407..a33993213443 100644
--- a/xmloff/source/forms/elementimport.hxx
+++ b/xmloff/source/forms/elementimport.hxx
@@ -549,42 +549,6 @@ namespace xmloff
const css::uno::Reference< css::xml::sax::XAttributeList >& _rxAttrList) override;
};
- //= OContainerImport
- // BASE must be a derivee of OElementImport
- template <class BASE>
- class OContainerImport
- :public BASE
- ,public ODefaultEventAttacherManager
- {
- protected:
- css::uno::Reference< css::container::XNameContainer >
- m_xMeAsContainer;
- OUString m_sWrapperElementName;
-
- protected:
- OContainerImport(OFormLayerXMLImport_Impl& _rImport, IEventAttacherManager& _rEventManager, sal_uInt16 _nPrefix, const OUString& _rName,
- const css::uno::Reference< css::container::XNameContainer >& _rxParentContainer,
- const char* _pWrapperElementName)
- :BASE(_rImport, _rEventManager, _nPrefix, _rName, _rxParentContainer)
- ,m_sWrapperElementName(OUString::createFromAscii(_pWrapperElementName))
- {
- }
-
- // SvXMLImportContext overridables
- virtual SvXMLImportContextRef CreateChildContext(
- sal_uInt16 _nPrefix, const OUString& _rLocalName,
- const css::uno::Reference< css::xml::sax::XAttributeList >& _rxAttrList) override;
- virtual void EndElement() override;
-
- protected:
- // OElementImport overridables
- virtual css::uno::Reference< css::beans::XPropertySet >
- createElement() override;
-
- // create the child context for the given control type
- virtual SvXMLImportContext* implCreateControlWrapper(
- sal_uInt16 _nPrefix, const OUString& _rLocalName) = 0;
- };
//= OColumnImport
/** helper class importing a single grid column (without the <form:column> element wrapping
@@ -635,11 +599,9 @@ namespace xmloff
OControlElement::ElementType _eType);
};
- //= OGridImport
- typedef OContainerImport< OControlImport > OGridImport_Base;
/** helper class importing a single <form:grid> element
*/
- class OGridImport : public OGridImport_Base
+ class OGridImport : public OControlImport, public ODefaultEventAttacherManager
{
public:
OGridImport(
@@ -647,17 +609,22 @@ namespace xmloff
const css::uno::Reference< css::container::XNameContainer >& _rxParentContainer,
OControlElement::ElementType _eType);
- protected:
- // OContainerImport overridables
- virtual SvXMLImportContext* implCreateControlWrapper(
- sal_uInt16 _nPrefix, const OUString& _rLocalName) override;
+ // SvXMLImportContext overridables
+ virtual SvXMLImportContextRef CreateChildContext(
+ sal_uInt16 _nPrefix, const OUString& _rLocalName,
+ const css::uno::Reference< css::xml::sax::XAttributeList >& _rxAttrList) override;
+ virtual void EndElement() override;
+
+ private:
+ // OElementImport overridables
+ virtual css::uno::Reference< css::beans::XPropertySet > createElement() override;
+
+ css::uno::Reference< css::container::XNameContainer > m_xMeAsContainer;
};
- //= OFormImport
- typedef OContainerImport< OElementImport > OFormImport_Base;
/** helper class importing a single <form:form> element
*/
- class OFormImport : public OFormImport_Base
+ class OFormImport : public OElementImport, public ODefaultEventAttacherManager
{
public:
OFormImport(
@@ -674,21 +641,23 @@ namespace xmloff
const css::uno::Reference< css::xml::sax::XAttributeList >& _rxAttrList) override;
virtual void EndElement() override;
- // OContainerImport overridables
- virtual SvXMLImportContext* implCreateControlWrapper(
- sal_uInt16 _nPrefix, const OUString& _rLocalName) override;
-
// OPropertyImport overridables
virtual bool handleAttribute(sal_uInt16 _nNamespaceKey,
const OUString& _rLocalName,
const OUString& _rValue) override;
+ // OElementImport overridables
+ virtual css::uno::Reference< css::beans::XPropertySet >
+ createElement() override;
+
OControlImport* implCreateChildContext(
sal_uInt16 _nPrefix, const OUString& _rLocalName,
OControlElement::ElementType _eType );
virtual OUString determineDefaultServiceName() const override;
void implTranslateStringListProperty(const OUString& _rPropertyName, const OUString& _rValue);
+
+ css::uno::Reference< css::container::XNameContainer > m_xMeAsContainer;
};
//= OXMLDataSourceImport
@@ -702,58 +671,6 @@ namespace xmloff
,const css::uno::Reference< css::beans::XPropertySet >& _xElement);
};
- //= OContainerImport
- template <class BASE>
- inline SvXMLImportContextRef OContainerImport< BASE >::CreateChildContext(
- sal_uInt16 _nPrefix, const OUString& _rLocalName,
- const css::uno::Reference< css::xml::sax::XAttributeList >& _rxAttrList)
- {
- // maybe it's a sub control
- if (_rLocalName == m_sWrapperElementName)
- {
- if (m_xMeAsContainer.is())
- return implCreateControlWrapper(_nPrefix, _rLocalName);
- else
- {
- OSL_FAIL("OContainerImport::CreateChildContext: don't have an element!");
- return nullptr;
- }
- }
-
- return BASE::CreateChildContext(_nPrefix, _rLocalName, _rxAttrList);
- }
-
- template <class BASE>
- inline css::uno::Reference< css::beans::XPropertySet >
- OContainerImport< BASE >::createElement()
- {
- // let the base class create the object
- css::uno::Reference< css::beans::XPropertySet > xReturn = BASE::createElement();
- if (!xReturn.is())
- return xReturn;
-
- // ensure that the object is a XNameContainer (we strongly need this for inserting child elements)
- m_xMeAsContainer.set(xReturn, css::uno::UNO_QUERY);
- if (!m_xMeAsContainer.is())
- {
- OSL_FAIL("OContainerImport::createElement: invalid element (no XNameContainer) created!");
- xReturn.clear();
- }
-
- return xReturn;
- }
-
- template <class BASE>
- inline void OContainerImport< BASE >::EndElement()
- {
- BASE::EndElement();
-
- // now that we have all children, attach the events
- css::uno::Reference< css::container::XIndexAccess > xIndexContainer(m_xMeAsContainer, css::uno::UNO_QUERY);
- if (xIndexContainer.is())
- ODefaultEventAttacherManager::setEvents(xIndexContainer);
- }
-
//= OColumnImport
template <class BASE>
OColumnImport< BASE >::OColumnImport(OFormLayerXMLImport_Impl& _rImport, IEventAttacherManager& _rEventManager, sal_uInt16 _nPrefix, const OUString& _rName,
More information about the Libreoffice-commits
mailing list