tdf#148361: docx sdt: cleanup databinding data after inserting

Databinding data is used only for current sdt block. It should
be clean up after usage to avoid impact on next sdt blocks.

Change-Id: I53f47dd655ed027d40eb518784dcae69813e612f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132524
Tested-by: Jenkins
Tested-by: Xisco Fauli <xiscofauli@libreoffice.org>
Reviewed-by: Vasily Melenchuk <vasily.melenchuk@cib.de>
(cherry picked from commit fafadd7aee8c384af210008f693b5007a9f5ea48)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132595
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
diff --git a/sw/qa/extras/ooxmlexport/data/tdf148361.docx b/sw/qa/extras/ooxmlexport/data/tdf148361.docx
new file mode 100644
index 0000000..ecf9a5f
--- /dev/null
+++ b/sw/qa/extras/ooxmlexport/data/tdf148361.docx
Binary files differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx
index 370989a..51f0d9f 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx
@@ -143,6 +143,22 @@ DECLARE_OOXMLEXPORT_TEST(testTdf123642_BookmarkAtDocEnd, "tdf123642.docx")
    CPPUNIT_ASSERT_EQUAL(OUString("Bookmark1"), getXPath(pXmlDoc, "/w:document/w:body/w:p[2]/w:bookmarkStart[1]", "name"));
}

DECLARE_OOXMLEXPORT_TEST(testTdf148361, "tdf148361.docx")
{
    // Refresh fields and ensure cross-reference to numbered para is okay
    uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY);
    uno::Reference<container::XEnumerationAccess> xFieldsAccess(xTextFieldsSupplier->getTextFields());

    uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration());
    CPPUNIT_ASSERT(xFields->hasMoreElements());

    uno::Reference<text::XTextField> xTextField1(xFields->nextElement(), uno::UNO_QUERY);
    CPPUNIT_ASSERT_EQUAL(OUString("itadmin"), xTextField1->getPresentation(false));

    uno::Reference<text::XTextField> xTextField2(xFields->nextElement(), uno::UNO_QUERY);
    CPPUNIT_ASSERT_EQUAL(OUString("[Type text]"), xTextField2->getPresentation(false));
}

DECLARE_OOXMLEXPORT_TEST(testTdf142407, "tdf142407.docx")
{
    uno::Reference<container::XNameAccess> xPageStyles = getStyles("PageStyles");
diff --git a/writerfilter/source/dmapper/SdtHelper.cxx b/writerfilter/source/dmapper/SdtHelper.cxx
index 576d63d..f4b02fa 100644
--- a/writerfilter/source/dmapper/SdtHelper.cxx
+++ b/writerfilter/source/dmapper/SdtHelper.cxx
@@ -264,8 +264,7 @@ void SdtHelper::createDropDownControl()
    }

    // clean up
    m_aDropDownItems.clear();
    setControlType(SdtControlType::unknown);
    clear();
}

void SdtHelper::createPlainTextControl()
@@ -296,8 +295,7 @@ void SdtHelper::createPlainTextControl()
                                   uno::makeAny(getInteropGrabBagAndClear()));

    // clean up
    m_aDropDownItems.clear();
    setControlType(SdtControlType::unknown);
    clear();
}

void SdtHelper::createDateContentControl()
@@ -372,11 +370,11 @@ void SdtHelper::createDateContentControl()
                                                    uno::UNO_QUERY);
    xRefreshable->refresh();

    setControlType(SdtControlType::unknown);

    // Store all unused sdt parameters from grabbag
    xNameCont->insertByName(UNO_NAME_MISC_OBJ_INTEROPGRABBAG,
                            uno::makeAny(getInteropGrabBagAndClear()));

    clear();
}

void SdtHelper::createControlShape(awt::Size aSize,
@@ -423,6 +421,16 @@ bool SdtHelper::containedInInteropGrabBag(const OUString& rValueName)
        [&rValueName](const beans::PropertyValue& i) { return i.Name == rValueName; });
}

void SdtHelper::clear()
{
    m_aDropDownItems.clear();
    setControlType(SdtControlType::unknown);
    m_sDataBindingPrefixMapping.clear();
    m_sDataBindingXPath.clear();
    m_sDataBindingStoreItemID.clear();
    m_aGrabBag.clear();
}

} // namespace writerfilter::dmapper

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerfilter/source/dmapper/SdtHelper.hxx b/writerfilter/source/dmapper/SdtHelper.hxx
index e58d731..d9a6115 100644
--- a/writerfilter/source/dmapper/SdtHelper.hxx
+++ b/writerfilter/source/dmapper/SdtHelper.hxx
@@ -102,6 +102,9 @@ class SdtHelper final : public virtual SvRefBase

    void loadPropertiesXMLs();

    /// Clear all collected attributes for futher reuse
    void clear();

public:
    explicit SdtHelper(DomainMapper_Impl& rDM_Impl,
                       css::uno::Reference<css::uno::XComponentContext> const& xContext);