Resolves: tdf#117162 ImportDocumentHandler expects data provider to exist

already in its ctor

which changed since...

commit 9009663deb8f0862f419fd99bf0b761c7f923eff
Date:   Sun Feb 26 22:48:06 2017 +0100

    tdf#83257 [API-CHANGE] Pivot chart implementation

which defers it, take a probably safely backportable approach here to
fix it.

Change-Id: I1863791af7ae737f337993833a9cf1429a3a8028
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132286
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
diff --git a/chart2/Library_chartcore.mk b/chart2/Library_chartcore.mk
index a9a2315..1b2a4b7 100644
--- a/chart2/Library_chartcore.mk
+++ b/chart2/Library_chartcore.mk
@@ -56,6 +56,7 @@ $(eval $(call gb_Library_use_libraries,chartcore,\
    ucbhelper \
    utl \
    vcl \
    xo \
))

$(eval $(call gb_Library_set_componentfile,chartcore,chart2/source/chartcore,services))
diff --git a/chart2/source/model/filter/XMLFilter.cxx b/chart2/source/model/filter/XMLFilter.cxx
index 0f061c66..145d4e4 100644
--- a/chart2/source/model/filter/XMLFilter.cxx
+++ b/chart2/source/model/filter/XMLFilter.cxx
@@ -32,6 +32,7 @@
#include <com/sun/star/beans/NamedValue.hpp>
#include <com/sun/star/beans/PropertyAttribute.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/chart2/XChartDocument.hpp>
#include <com/sun/star/xml/sax/InputSource.hpp>
#include <com/sun/star/xml/sax/Writer.hpp>
#include <com/sun/star/lang/XMultiComponentFactory.hpp>
@@ -49,6 +50,7 @@
#include <com/sun/star/document/GraphicStorageHandler.hpp>
#include <tools/diagnose_ex.h>
#include <sal/log.hxx>
#include <xmloff/SchXMLImportHelper.hxx>

using namespace ::com::sun::star;

@@ -448,6 +450,14 @@ ErrCode XMLFilter::impl_ImportStream(
                {
                    try
                    {
                        // tdf#117162 reportbuilder expects setDataProvider to be called before ctor
                        if (m_sDocumentHandler == "com.sun.star.comp.report.ImportDocumentHandler")
                        {
                            css::uno::Reference<css::chart2::XChartDocument> xChart(m_xTargetDoc, uno::UNO_QUERY);
                            if (xChart)
                                setDataProvider(xChart, OUString());
                        }

                        uno::Sequence< uno::Any > aArgs{
                            uno::Any(beans::NamedValue("DocumentHandler", uno::Any(xFilter))),
                            uno::Any(beans::NamedValue("Model", uno::Any(m_xTargetDoc)))
diff --git a/include/xmloff/SchXMLImportHelper.hxx b/include/xmloff/SchXMLImportHelper.hxx
index bec8167..446b073 100644
--- a/include/xmloff/SchXMLImportHelper.hxx
+++ b/include/xmloff/SchXMLImportHelper.hxx
@@ -21,6 +21,7 @@

#include <com/sun/star/uno/Reference.hxx>
#include <salhelper/simplereferenceobject.hxx>
#include <xmloff/dllapi.h>
#include <xmloff/families.hxx>

namespace com::sun::star::chart { class XChartDocument; }
@@ -107,6 +108,8 @@ public:
                    const css::uno::Reference< css::chart2::XChartDocument > & xDoc );
};

XMLOFF_DLLPUBLIC void setDataProvider(css::uno::Reference<css::chart2::XChartDocument> const & xChartDoc, OUString const & sDataPilotSource);

#endif // INCLUDED_XMLOFF_SCHXMLIMPORTHELPER_HXX

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/xmloff/source/chart/SchXMLChartContext.cxx b/xmloff/source/chart/SchXMLChartContext.cxx
index 51a7e1f..331a928 100644
--- a/xmloff/source/chart/SchXMLChartContext.cxx
+++ b/xmloff/source/chart/SchXMLChartContext.cxx
@@ -244,7 +244,7 @@ static bool lcl_hasServiceName(Reference<lang::XMultiServiceFactory> const & xFa
    return std::find(aServiceNames.begin(), aServiceNames.end(), rServiceName) != aServiceNames.end();
}

static void lcl_setDataProvider(uno::Reference<chart2::XChartDocument> const & xChartDoc, OUString const & sDataPilotSource)
void setDataProvider(uno::Reference<chart2::XChartDocument> const & xChartDoc, OUString const & sDataPilotSource)
{
    if (!xChartDoc.is())
        return;
@@ -392,7 +392,7 @@ void SchXMLChartContext::startFastElement( sal_Int32 /*nElement*/,
    uno::Reference<chart::XChartDocument> xDoc = mrImportHelper.GetChartDocument();
    uno::Reference<chart2::XChartDocument> xNewDoc(xDoc, uno::UNO_QUERY);

    lcl_setDataProvider(xNewDoc, msDataPilotSource);
    setDataProvider(xNewDoc, msDataPilotSource);

    if( aOldChartTypeName.isEmpty() )
    {