[Libreoffice-commits] core.git: 12 commits - embeddedobj/source include/oox oox/source sal/osl sfx2/source sw/source writerfilter/source

Michael Stahl mstahl at redhat.com
Sat Dec 19 15:58:54 PST 2015


 embeddedobj/source/msole/oleembed.cxx      |   11 
 include/oox/export/shapes.hxx              |   16 
 include/oox/export/utils.hxx               |    3 
 include/oox/ole/oleobjecthelper.hxx        |   10 
 oox/source/core/filterbase.cxx             |    2 
 oox/source/export/shapes.cxx               |  509 +++++++++++++++++++++--------
 oox/source/ole/oleobjecthelper.cxx         |   58 +++
 sal/osl/w32/procimpl.cxx                   |    3 
 sfx2/source/doc/objstor.cxx                |    3 
 sw/source/filter/ww8/docxexport.cxx        |  240 +------------
 sw/source/filter/ww8/docxexport.hxx        |    1 
 writerfilter/source/dmapper/OLEHandler.cxx |   44 --
 writerfilter/source/dmapper/OLEHandler.hxx |    5 
 13 files changed, 481 insertions(+), 424 deletions(-)

New commits:
commit e2eae56bd31a1f39d5ba76ee1bf350d0059ce7cd
Author: Michael Stahl <mstahl at redhat.com>
Date:   Sun Dec 20 00:38:37 2015 +0100

    sal: replace a list with vector
    
    std::stable_sort requires random access iterators, which std::list does
    not provide, so this is not actually supposed to work, but strangely
    does.  But there's no reason why this couldn't be a vector.
    
    Change-Id: I98ec5c28204d01a7352d15ed783748fc17bd8105

diff --git a/sal/osl/w32/procimpl.cxx b/sal/osl/w32/procimpl.cxx
index c0d5673..f7b66ca 100644
--- a/sal/osl/w32/procimpl.cxx
+++ b/sal/osl/w32/procimpl.cxx
@@ -38,7 +38,6 @@
 #include "secimpl.h"
 #include <osl/file.hxx>
 
-#include <list>
 #include <vector>
 #include <algorithm>
 #include <string>
@@ -53,7 +52,7 @@ const rtl::OUString QUOTE("\"");
 
 namespace /* private */
 {
-    typedef std::list<rtl::OUString> string_container_t;
+    typedef std::vector<rtl::OUString> string_container_t;
     typedef string_container_t::iterator string_container_iterator_t;
     typedef string_container_t::const_iterator string_container_const_iterator_t;
     typedef std::pair<string_container_iterator_t, string_container_iterator_t> iterator_pair_t;
commit e564f58b789139c7609facd0bea88f0b651b5153
Author: Michael Stahl <mstahl at redhat.com>
Date:   Sat Dec 19 00:11:28 2015 +0100

    sw: remove that silly lcl_CopyStream
    
    Change-Id: I0a357d5c4a2ff46e5203ba045b9550285e33943e

diff --git a/sw/source/filter/ww8/docxexport.cxx b/sw/source/filter/ww8/docxexport.cxx
index f0a931c..2c04e3f 100644
--- a/sw/source/filter/ww8/docxexport.cxx
+++ b/sw/source/filter/ww8/docxexport.cxx
@@ -70,6 +70,7 @@
 #include "ww8par.hxx"
 #include "ww8scan.hxx"
 #include <oox/token/properties.hxx>
+#include <comphelper/storagehelper.hxx>
 #include <comphelper/string.hxx>
 #include <rtl/ustrbuf.hxx>
 #include <vcl/font.hxx>
@@ -393,41 +394,26 @@ OString DocxExport::WriteOLEObject(SwOLEObj& rObject, OUString & io_rProgID)
         GetFilter().openFragmentStream("word/" + sFileName, sMediaType);
     assert(xOutStream.is()); // no reason why that could fail
 
-    bool const isExported = lcl_CopyStream(xInStream, xOutStream);
-
-    OUString sId;
-    if (isExported)
+    try
+    {
+        ::comphelper::OStorageHelper::CopyInputToOutput(xInStream, xOutStream);
+    }
+    catch (uno::Exception const& e)
     {
-        sId = m_pFilter->addRelation( GetFS()->getOutputStream(),
+        SAL_WARN("sw.ww8", "DocxExport::WriteOLEObject: exception: " << e.Message);
+        return OString();
+    }
+
+    OUString const sId = m_pFilter->addRelation( GetFS()->getOutputStream(),
                 sRelationType, sFileName );
-        if (pProgID)
-        {
-            io_rProgID = OUString::createFromAscii(pProgID);
-        }
+    if (pProgID)
+    {
+        io_rProgID = OUString::createFromAscii(pProgID);
     }
 
     return OUStringToOString( sId, RTL_TEXTENCODING_UTF8 );
 }
 
-// function copied from embeddedobj/source/msole/oleembed.cxx
-bool DocxExport::lcl_CopyStream( uno::Reference<io::XInputStream> xIn, uno::Reference<io::XOutputStream> xOut )
-{
-    if( !xIn.is() || !xOut.is() )
-        return false;
-
-    const sal_Int32 nChunkSize = 4096;
-    uno::Sequence< sal_Int8 > aData(nChunkSize);
-    sal_Int32 nTotalRead = 0;
-    sal_Int32 nRead = 0;
-    do
-    {
-        nRead = xIn->readBytes(aData, nChunkSize);
-        nTotalRead += nRead;
-        xOut->writeBytes(aData);
-    } while (nRead == nChunkSize);
-    return nTotalRead != 0;
-}
-
 void DocxExport::OutputDML(uno::Reference<drawing::XShape>& xShape)
 {
     uno::Reference<lang::XServiceInfo> xServiceInfo(xShape, uno::UNO_QUERY_THROW);
diff --git a/sw/source/filter/ww8/docxexport.hxx b/sw/source/filter/ww8/docxexport.hxx
index cc1854d..124b626 100644
--- a/sw/source/filter/ww8/docxexport.hxx
+++ b/sw/source/filter/ww8/docxexport.hxx
@@ -171,7 +171,6 @@ public:
     /// Returns the relationd id
     OString OutputChart( css::uno::Reference< css::frame::XModel >& xModel, sal_Int32 nCount, ::sax_fastparser::FSHelperPtr m_pSerializer );
     OString WriteOLEObject(SwOLEObj& rObject, OUString & io_rProgID);
-    static bool lcl_CopyStream( css::uno::Reference< css::io::XInputStream> xIn, css::uno::Reference< css::io::XOutputStream > xOut );
 
     /// Writes the shape using drawingML syntax.
     void OutputDML( css::uno::Reference< css::drawing::XShape >& xShape );
commit 89e85e5d2ec337aaccfa74bd7017898df42529b4
Author: Michael Stahl <mstahl at redhat.com>
Date:   Sun Dec 20 00:28:28 2015 +0100

    oox: fix indentation of ShapeExport::WriteOLE2Shape
    
    Change-Id: I9057cd9d574d545929a9f43f40f49164179a6dcc

diff --git a/oox/source/export/shapes.cxx b/oox/source/export/shapes.cxx
index db6ec66..e602533 100644
--- a/oox/source/export/shapes.cxx
+++ b/oox/source/export/shapes.cxx
@@ -1584,174 +1584,173 @@ ShapeExport& ShapeExport::WriteTextShape( Reference< XShape > xShape )
 ShapeExport& ShapeExport::WriteOLE2Shape( Reference< XShape > xShape )
 {
     Reference< XPropertySet > xPropSet( xShape, UNO_QUERY );
-    if( xPropSet.is() ) {
-        OUString clsid;
-        xPropSet->getPropertyValue("CLSID") >>= clsid;
-        assert(!clsid.isEmpty());
-        SvGlobalName aClassID;
-        bool const isValid(aClassID.MakeId(clsid));
-        assert(isValid); (void)isValid;
+    if (!xPropSet.is())
+        return *this;
 
-        {
-            if (SotExchange::IsChart(aClassID))
-            {
-                Reference< XChartDocument > xChartDoc;
-                xPropSet->getPropertyValue("Model") >>= xChartDoc;
-                assert(xChartDoc.is());
-                //export the chart
-                Reference< XModel > xModel( xChartDoc, UNO_QUERY );
-                ChartExport aChartExport( mnXmlNamespace, GetFS(), xModel, GetFB(), GetDocumentType() );
-                static sal_Int32 nChartCount = 0;
-                aChartExport.WriteChartObj( xShape, ++nChartCount );
-            }
-            else
-            {
-                uno::Reference<embed::XEmbeddedObject> const xObj(
-                    xPropSet->getPropertyValue("EmbeddedObject"), uno::UNO_QUERY);
+    OUString clsid;
+    xPropSet->getPropertyValue("CLSID") >>= clsid;
+    assert(!clsid.isEmpty());
+    SvGlobalName aClassID;
+    bool const isValid(aClassID.MakeId(clsid));
+    assert(isValid); (void)isValid;
 
-                uno::Reference<beans::XPropertySet> const xParent(
-                    uno::Reference<container::XChild>(xObj, uno::UNO_QUERY)->getParent(),
-                    uno::UNO_QUERY);
+    if (SotExchange::IsChart(aClassID))
+    {
+        Reference< XChartDocument > xChartDoc;
+        xPropSet->getPropertyValue("Model") >>= xChartDoc;
+        assert(xChartDoc.is());
+        //export the chart
+        Reference< XModel > xModel( xChartDoc, UNO_QUERY );
+        ChartExport aChartExport( mnXmlNamespace, GetFS(), xModel, GetFB(), GetDocumentType() );
+        static sal_Int32 nChartCount = 0;
+        aChartExport.WriteChartObj( xShape, ++nChartCount );
+    }
+    else
+    {
+        uno::Reference<embed::XEmbeddedObject> const xObj(
+            xPropSet->getPropertyValue("EmbeddedObject"), uno::UNO_QUERY);
+
+        uno::Reference<beans::XPropertySet> const xParent(
+            uno::Reference<container::XChild>(xObj, uno::UNO_QUERY)->getParent(),
+            uno::UNO_QUERY);
 
-                uno::Sequence<beans::PropertyValue> grabBag;
-                xParent->getPropertyValue("InteropGrabBag") >>= grabBag;
+        uno::Sequence<beans::PropertyValue> grabBag;
+        xParent->getPropertyValue("InteropGrabBag") >>= grabBag;
 
-                OUString const entryName(
-                    uno::Reference<embed::XEmbedPersist>(xObj, uno::UNO_QUERY)->getEntryName());
-                OUString progID;
+        OUString const entryName(
+            uno::Reference<embed::XEmbedPersist>(xObj, uno::UNO_QUERY)->getEntryName());
+        OUString progID;
 
-                for (auto const& it : grabBag)
+        for (auto const& it : grabBag)
+        {
+            if (it.Name == "EmbeddedObjects")
+            {
+                uno::Sequence<beans::PropertyValue> objects;
+                it.Value >>= objects;
+                for (auto const& object : objects)
                 {
-                    if (it.Name == "EmbeddedObjects")
+                    if (object.Name == entryName)
                     {
-                        uno::Sequence<beans::PropertyValue> objects;
-                        it.Value >>= objects;
-                        for (auto const& object : objects)
+                        uno::Sequence<beans::PropertyValue> props;
+                        object.Value >>= props;
+                        for (auto const& prop : props)
                         {
-                            if (object.Name == entryName)
+                            if (prop.Name == "ProgID")
                             {
-                                uno::Sequence<beans::PropertyValue> props;
-                                object.Value >>= props;
-                                for (auto const& prop : props)
-                                {
-                                    if (prop.Name == "ProgID")
-                                    {
-                                        prop.Value >>= progID;
-                                        break;
-                                    }
-                                }
+                                prop.Value >>= progID;
                                 break;
                             }
                         }
                         break;
                     }
                 }
+                break;
+            }
+        }
 
-                OUString sMediaType;
-                OUString sRelationType;
-                OUString sSuffix;
-                const char * pProgID(nullptr);
+        OUString sMediaType;
+        OUString sRelationType;
+        OUString sSuffix;
+        const char * pProgID(nullptr);
 
-                uno::Reference<io::XInputStream> const xInStream =
-                    oox::GetOLEObjectStream(
-                        mpFB->getComponentContext(), xObj, progID,
-                        sMediaType, sRelationType, sSuffix, pProgID);
+        uno::Reference<io::XInputStream> const xInStream =
+            oox::GetOLEObjectStream(
+                mpFB->getComponentContext(), xObj, progID,
+                sMediaType, sRelationType, sSuffix, pProgID);
 
-                if (!xInStream.is())
-                {
-                    return *this;
-                }
+        if (!xInStream.is())
+        {
+            return *this;
+        }
 
-                OString anotherProgID;
-                if (!pProgID && !progID.isEmpty())
-                {
-                    anotherProgID = OUStringToOString(progID, RTL_TEXTENCODING_UTF8);
-                    pProgID = anotherProgID.getStr();
-                }
+        OString anotherProgID;
+        if (!pProgID && !progID.isEmpty())
+        {
+            anotherProgID = OUStringToOString(progID, RTL_TEXTENCODING_UTF8);
+            pProgID = anotherProgID.getStr();
+        }
 
-                assert(!sMediaType.isEmpty());
-                assert(!sRelationType.isEmpty());
-                assert(!sSuffix.isEmpty());
-
-                OUString sFileName = "embeddings/oleObject" + OUString::number(mnEmbeddeDocumentCounter++) + "." + sSuffix;
-                uno::Reference<io::XOutputStream> const xOutStream(
-                    mpFB->openFragmentStream(
-                        OUString::createFromAscii(GetComponentDir()) + "/" + sFileName,
-                        sMediaType));
-                assert(xOutStream.is()); // no reason why that could fail
-
-                try {
-                    ::comphelper::OStorageHelper::CopyInputToOutput(xInStream, xOutStream);
-                } catch (uno::Exception const& e) {
-                    SAL_WARN("oox", "ShapeExport::WriteOLEObject: exception: " << e.Message);
-                }
+        assert(!sMediaType.isEmpty());
+        assert(!sRelationType.isEmpty());
+        assert(!sSuffix.isEmpty());
+
+        OUString sFileName = "embeddings/oleObject" + OUString::number(mnEmbeddeDocumentCounter++) + "." + sSuffix;
+        uno::Reference<io::XOutputStream> const xOutStream(
+            mpFB->openFragmentStream(
+                OUString::createFromAscii(GetComponentDir()) + "/" + sFileName,
+                sMediaType));
+        assert(xOutStream.is()); // no reason why that could fail
+
+        try {
+            ::comphelper::OStorageHelper::CopyInputToOutput(xInStream, xOutStream);
+        } catch (uno::Exception const& e) {
+            SAL_WARN("oox", "ShapeExport::WriteOLEObject: exception: " << e.Message);
+        }
 
-                OUString const sRelId = mpFB->addRelation(
-                    mpFS->getOutputStream(), sRelationType,
-                    OUString::createFromAscii(GetRelationCompPrefix()) + sFileName);
+        OUString const sRelId = mpFB->addRelation(
+            mpFS->getOutputStream(), sRelationType,
+            OUString::createFromAscii(GetRelationCompPrefix()) + sFileName);
 
-                        mpFS->startElementNS( mnXmlNamespace, XML_graphicFrame, FSEND );
+        mpFS->startElementNS( mnXmlNamespace, XML_graphicFrame, FSEND );
 
-                        mpFS->startElementNS( mnXmlNamespace, XML_nvGraphicFramePr, FSEND );
+        mpFS->startElementNS( mnXmlNamespace, XML_nvGraphicFramePr, FSEND );
 
-                        mpFS->singleElementNS( mnXmlNamespace, XML_cNvPr,
-                                               XML_id,     I32S( GetNewShapeID( xShape ) ),
-                                               XML_name,   IDS(Object),
-                                               FSEND );
+        mpFS->singleElementNS( mnXmlNamespace, XML_cNvPr,
+                               XML_id,     I32S( GetNewShapeID( xShape ) ),
+                               XML_name,   IDS(Object),
+                               FSEND );
 
-                        mpFS->singleElementNS( mnXmlNamespace, XML_cNvGraphicFramePr,
-                                               FSEND );
+        mpFS->singleElementNS( mnXmlNamespace, XML_cNvGraphicFramePr,
+                               FSEND );
 
-                        if( GetDocumentType() == DOCUMENT_PPTX )
-                            mpFS->singleElementNS( mnXmlNamespace, XML_nvPr,
-                                                   FSEND );
-                        mpFS->endElementNS( mnXmlNamespace, XML_nvGraphicFramePr );
+        if (GetDocumentType() == DOCUMENT_PPTX)
+            mpFS->singleElementNS( mnXmlNamespace, XML_nvPr,
+                                   FSEND );
+        mpFS->endElementNS( mnXmlNamespace, XML_nvGraphicFramePr );
 
-                        WriteShapeTransformation( xShape, mnXmlNamespace );
+        WriteShapeTransformation( xShape, mnXmlNamespace );
 
-                        mpFS->startElementNS( XML_a, XML_graphic, FSEND );
-                        mpFS->startElementNS( XML_a, XML_graphicData,
-                                              XML_uri, "http://schemas.openxmlformats.org/presentationml/2006/ole",
-                                              FSEND );
-                        if (pProgID)
-                        {
-                            mpFS->startElementNS( mnXmlNamespace, XML_oleObj,
-                                              XML_progId, pProgID,
-                                              FSNS(XML_r, XML_id), USS( sRelId ),
-                                              XML_spid, "",
-                                              FSEND );
-                        }
-                        else
-                        {
-                            mpFS->startElementNS( mnXmlNamespace, XML_oleObj,
+        mpFS->startElementNS( XML_a, XML_graphic, FSEND );
+        mpFS->startElementNS( XML_a, XML_graphicData,
+                              XML_uri, "http://schemas.openxmlformats.org/presentationml/2006/ole",
+                              FSEND );
+        if (pProgID)
+        {
+            mpFS->startElementNS( mnXmlNamespace, XML_oleObj,
+                              XML_progId, pProgID,
+                              FSNS(XML_r, XML_id), USS( sRelId ),
+                              XML_spid, "",
+                              FSEND );
+        }
+        else
+        {
+            mpFS->startElementNS( mnXmlNamespace, XML_oleObj,
 //?                                              XML_name, "Document",
-                                              FSNS(XML_r, XML_id), USS( sRelId ),
-                                              // The spec says that this is a required attribute, but PowerPoint can only handle an empty value.
-                                              XML_spid, "",
-                                              FSEND );
-                        }
+                              FSNS(XML_r, XML_id), USS( sRelId ),
+                              // The spec says that this is a required attribute, but PowerPoint can only handle an empty value.
+                              XML_spid, "",
+                              FSEND );
+        }
 
-                        mpFS->singleElementNS( mnXmlNamespace, XML_embed, FSEND );
+        mpFS->singleElementNS( mnXmlNamespace, XML_embed, FSEND );
 
-                        // pic element
-                        SdrObject* pSdrOLE2( GetSdrObjectFromXShape( xShape ) );
-                        // The spec doesn't allow <p:pic> here, but PowerPoint requires it.
-                        bool bEcma = mpFB->getVersion() == oox::core::ECMA_DIALECT;
-                        if ( pSdrOLE2 && dynamic_cast<const SdrOle2Obj*>( pSdrOLE2) != nullptr && bEcma)
-                        {
-                            const Graphic* pGraphic = static_cast<SdrOle2Obj*>(pSdrOLE2)->GetGraphic();
-                            if ( pGraphic )
-                                WriteGraphicObjectShapePart( xShape, pGraphic );
-                        }
+        // pic element
+        SdrObject* pSdrOLE2( GetSdrObjectFromXShape( xShape ) );
+        // The spec doesn't allow <p:pic> here, but PowerPoint requires it.
+        bool bEcma = mpFB->getVersion() == oox::core::ECMA_DIALECT;
+        if (pSdrOLE2 && dynamic_cast<const SdrOle2Obj*>( pSdrOLE2) != nullptr && bEcma)
+        {
+            const Graphic* pGraphic = static_cast<SdrOle2Obj*>(pSdrOLE2)->GetGraphic();
+            if (pGraphic)
+                WriteGraphicObjectShapePart( xShape, pGraphic );
+        }
 
-                        mpFS->endElementNS( mnXmlNamespace, XML_oleObj );
+        mpFS->endElementNS( mnXmlNamespace, XML_oleObj );
 
-                        mpFS->endElementNS( XML_a, XML_graphicData );
-                        mpFS->endElementNS( XML_a, XML_graphic );
+        mpFS->endElementNS( XML_a, XML_graphicData );
+        mpFS->endElementNS( XML_a, XML_graphic );
 
-                        mpFS->endElementNS( mnXmlNamespace, XML_graphicFrame );
-            }
-        }
+        mpFS->endElementNS( mnXmlNamespace, XML_graphicFrame );
     }
     return *this;
 }
commit d60398ff5b42ff77a4002dcd13b7fb8c9a73eade
Author: Michael Stahl <mstahl at redhat.com>
Date:   Sat Dec 19 23:55:34 2015 +0100

    oox: save ProgId on import, and use it in ShapeExport::WriteOLE2Shape()
    
    Uses the same approach as DOCX import to preserve the ProgID; it would
    be much better if the MediaType of the stream were preserved instead and
    the other things derived from that, but this here was rather quick to do...
    
    This makes the round-tripping of OOXML OLEs in PPTX work again, which
    was broken by an earlier commit.
    
    Change-Id: Ic7d0362f0c14bf0e522185713666bcd58db2cf64

diff --git a/include/oox/ole/oleobjecthelper.hxx b/include/oox/ole/oleobjecthelper.hxx
index febd097..35e16b0 100644
--- a/include/oox/ole/oleobjecthelper.hxx
+++ b/include/oox/ole/oleobjecthelper.hxx
@@ -57,7 +57,8 @@ class OleObjectHelper
 {
 public:
     explicit            OleObjectHelper(
-                            const css::uno::Reference< css::lang::XMultiServiceFactory >& rxModelFactory );
+                            const css::uno::Reference<css::lang::XMultiServiceFactory>& rxModelFactory,
+                            const css::uno::Reference<css::frame::XModel>& xModel);
                         ~OleObjectHelper();
 
     bool                importOleObject(
@@ -66,6 +67,7 @@ public:
                             const css::awt::Size& rObjSize );
 
 private:
+    css::uno::Reference<css::frame::XModel> m_xModel;
     css::uno::Reference< css::document::XEmbeddedObjectResolver > mxResolver;
     const OUString                                                maEmbeddedObjScheme;
     sal_Int32                                                     mnObjectId;
diff --git a/oox/source/core/filterbase.cxx b/oox/source/core/filterbase.cxx
index 9c7383a..3fefcc0 100644
--- a/oox/source/core/filterbase.cxx
+++ b/oox/source/core/filterbase.cxx
@@ -366,7 +366,7 @@ ModelObjectHelper& FilterBase::getModelObjectHelper() const
 OleObjectHelper& FilterBase::getOleObjectHelper() const
 {
     if( !mxImpl->mxOleObjHelper )
-        mxImpl->mxOleObjHelper.reset( new OleObjectHelper( mxImpl->mxModelFactory ) );
+        mxImpl->mxOleObjHelper.reset(new OleObjectHelper(mxImpl->mxModelFactory, mxImpl->mxModel));
     return *mxImpl->mxOleObjHelper;
 }
 
diff --git a/oox/source/export/shapes.cxx b/oox/source/export/shapes.cxx
index 0c087e8..db6ec66 100644
--- a/oox/source/export/shapes.cxx
+++ b/oox/source/export/shapes.cxx
@@ -316,7 +316,7 @@ uno::Reference<io::XInputStream> GetOLEObjectStream(
         {
             lcl_ConvertProgID(i_rProgID, o_rMediaType, o_rRelationType, o_rSuffix);
             xInStream = xParentStorage->cloneStreamElement(entryName)->getInputStream();
-            // TODO: is it possible to take the sMediaType from the stream?
+            // TODO: make it possible to take the sMediaType from the stream
         }
         else // the object is ODF - either the whole document is
         {    // ODF, or the OLE was edited so it was converted to ODF
@@ -1609,6 +1609,44 @@ ShapeExport& ShapeExport::WriteOLE2Shape( Reference< XShape > xShape )
                 uno::Reference<embed::XEmbeddedObject> const xObj(
                     xPropSet->getPropertyValue("EmbeddedObject"), uno::UNO_QUERY);
 
+                uno::Reference<beans::XPropertySet> const xParent(
+                    uno::Reference<container::XChild>(xObj, uno::UNO_QUERY)->getParent(),
+                    uno::UNO_QUERY);
+
+                uno::Sequence<beans::PropertyValue> grabBag;
+                xParent->getPropertyValue("InteropGrabBag") >>= grabBag;
+
+                OUString const entryName(
+                    uno::Reference<embed::XEmbedPersist>(xObj, uno::UNO_QUERY)->getEntryName());
+                OUString progID;
+
+                for (auto const& it : grabBag)
+                {
+                    if (it.Name == "EmbeddedObjects")
+                    {
+                        uno::Sequence<beans::PropertyValue> objects;
+                        it.Value >>= objects;
+                        for (auto const& object : objects)
+                        {
+                            if (object.Name == entryName)
+                            {
+                                uno::Sequence<beans::PropertyValue> props;
+                                object.Value >>= props;
+                                for (auto const& prop : props)
+                                {
+                                    if (prop.Name == "ProgID")
+                                    {
+                                        prop.Value >>= progID;
+                                        break;
+                                    }
+                                }
+                                break;
+                            }
+                        }
+                        break;
+                    }
+                }
+
                 OUString sMediaType;
                 OUString sRelationType;
                 OUString sSuffix;
@@ -1616,7 +1654,7 @@ ShapeExport& ShapeExport::WriteOLE2Shape( Reference< XShape > xShape )
 
                 uno::Reference<io::XInputStream> const xInStream =
                     oox::GetOLEObjectStream(
-                        mpFB->getComponentContext(), xObj, OUString(),
+                        mpFB->getComponentContext(), xObj, progID,
                         sMediaType, sRelationType, sSuffix, pProgID);
 
                 if (!xInStream.is())
@@ -1624,6 +1662,13 @@ ShapeExport& ShapeExport::WriteOLE2Shape( Reference< XShape > xShape )
                     return *this;
                 }
 
+                OString anotherProgID;
+                if (!pProgID && !progID.isEmpty())
+                {
+                    anotherProgID = OUStringToOString(progID, RTL_TEXTENCODING_UTF8);
+                    pProgID = anotherProgID.getStr();
+                }
+
                 assert(!sMediaType.isEmpty());
                 assert(!sRelationType.isEmpty());
                 assert(!sSuffix.isEmpty());
diff --git a/oox/source/ole/oleobjecthelper.cxx b/oox/source/ole/oleobjecthelper.cxx
index 5e6c057..12356c3 100644
--- a/oox/source/ole/oleobjecthelper.cxx
+++ b/oox/source/ole/oleobjecthelper.cxx
@@ -49,10 +49,14 @@ OleObjectInfo::OleObjectInfo() :
 {
 }
 
-OleObjectHelper::OleObjectHelper( const Reference< XMultiServiceFactory >& rxModelFactory ) :
-    maEmbeddedObjScheme( "vnd.sun.star.EmbeddedObject:" ),
-    mnObjectId( 100 )
+OleObjectHelper::OleObjectHelper(
+        const Reference< XMultiServiceFactory >& rxModelFactory,
+        uno::Reference<frame::XModel> const& xModel)
+    : m_xModel(xModel)
+    , maEmbeddedObjScheme("vnd.sun.star.EmbeddedObject:")
+    , mnObjectId( 100 )
 {
+    assert(m_xModel.is());
     if( rxModelFactory.is() ) try
     {
         mxResolver.set( rxModelFactory->createInstance( "com.sun.star.document.ImportEmbeddedObjectResolver" ), UNO_QUERY );
@@ -74,6 +78,10 @@ OleObjectHelper::~OleObjectHelper()
     }
 }
 
+// TODO: this is probably a sub-optimal approach: ideally the media type
+// of the stream from [Content_Types].xml should be stored somewhere for this
+// purpose, but currently the media type of all OLE streams in the storage is
+// just "application/vnd.sun.star.oleobject"
 void SaveInteropProperties(uno::Reference<frame::XModel> const& xModel,
        OUString const& rObjectName, OUString const*const pOldObjectName,
        OUString const& rProgId, OUString const& rDrawAspect)
@@ -137,6 +145,10 @@ bool OleObjectHelper::importOleObject( PropertyMap& rPropMap, const OleObjectInf
             xOutStrm->writeBytes( rOleObject.maEmbeddedData );
             xOutStrm->closeOutput();
 
+            SaveInteropProperties(m_xModel, aObjectId, nullptr,
+                rOleObject.maProgId,
+                rOleObject.mbShowAsIcon ? OUString("Icon") : OUString("Content"));
+
             OUString aUrl = mxResolver->resolveEmbeddedObjectURL( aObjectId );
             OSL_ENSURE( aUrl.match( maEmbeddedObjScheme ), "OleObjectHelper::importOleObject - unexpected URL scheme" );
             OUString aPersistName = aUrl.copy( maEmbeddedObjScheme.getLength() );
commit 9d0d41f0f3c5215770bc7246a089d54a7244df55
Author: Michael Stahl <mstahl at redhat.com>
Date:   Sat Dec 19 23:29:17 2015 +0100

    move saveInteropProperties from writerfilter to oox
    
    Change-Id: I4f9769ad496198d2d002775dee4ee0a2f08d6f3b

diff --git a/include/oox/ole/oleobjecthelper.hxx b/include/oox/ole/oleobjecthelper.hxx
index 868cd0c..febd097 100644
--- a/include/oox/ole/oleobjecthelper.hxx
+++ b/include/oox/ole/oleobjecthelper.hxx
@@ -26,6 +26,7 @@
 namespace com { namespace sun { namespace star {
     namespace awt { struct Size; }
     namespace document { class XEmbeddedObjectResolver; }
+    namespace frame { class XModel; }
     namespace lang { class XMultiServiceFactory; }
 } } }
 
@@ -71,6 +72,11 @@ private:
 };
 
 
+OOX_DLLPUBLIC void SaveInteropProperties(
+       css::uno::Reference<css::frame::XModel> const& xModel,
+       OUString const& rObjectName, OUString const* pOldObjectName,
+       OUString const& rProgId, OUString const& rDrawAspect);
+
 
 } // namespace ole
 } // namespace oox
diff --git a/oox/source/ole/oleobjecthelper.cxx b/oox/source/ole/oleobjecthelper.cxx
index f5d4df4..5e6c057 100644
--- a/oox/source/ole/oleobjecthelper.cxx
+++ b/oox/source/ole/oleobjecthelper.cxx
@@ -21,6 +21,7 @@
 
 #include <com/sun/star/awt/Rectangle.hpp>
 #include <com/sun/star/awt/Size.hpp>
+#include <com/sun/star/beans/XPropertySet.hpp>
 #include <com/sun/star/container/XNameAccess.hpp>
 #include <com/sun/star/document/XEmbeddedObjectResolver.hpp>
 #include <com/sun/star/embed/Aspects.hpp>
@@ -28,6 +29,7 @@
 #include <com/sun/star/lang/XComponent.hpp>
 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
 #include <osl/diagnose.h>
+#include <comphelper/sequenceashashmap.hxx>
 #include "oox/helper/propertymap.hxx"
 
 namespace oox {
@@ -72,6 +74,44 @@ OleObjectHelper::~OleObjectHelper()
     }
 }
 
+void SaveInteropProperties(uno::Reference<frame::XModel> const& xModel,
+       OUString const& rObjectName, OUString const*const pOldObjectName,
+       OUString const& rProgId, OUString const& rDrawAspect)
+{
+    static const char sEmbeddingsPropName[] = "EmbeddedObjects";
+
+    // get interop grab bag from document
+    uno::Reference<beans::XPropertySet> const xDocProps(xModel, uno::UNO_QUERY);
+    comphelper::SequenceAsHashMap aGrabBag(xDocProps->getPropertyValue("InteropGrabBag"));
+
+    // get EmbeddedObjects property inside grab bag
+    comphelper::SequenceAsHashMap objectsList;
+    if (aGrabBag.find(sEmbeddingsPropName) != aGrabBag.end())
+        objectsList << aGrabBag[sEmbeddingsPropName];
+
+    uno::Sequence< beans::PropertyValue > aGrabBagAttribute(2);
+    aGrabBagAttribute[0].Name = "ProgID";
+    aGrabBagAttribute[0].Value <<= rProgId;
+    aGrabBagAttribute[1].Name = "DrawAspect";
+    aGrabBagAttribute[1].Value <<= rDrawAspect;
+
+    // If we got an "old name", erase that first.
+    if (pOldObjectName)
+    {
+        comphelper::SequenceAsHashMap::iterator it = objectsList.find(*pOldObjectName);
+        if (it != objectsList.end())
+            objectsList.erase(it);
+    }
+
+    objectsList[rObjectName] = uno::Any( aGrabBagAttribute );
+
+    // put objects list back into the grab bag
+    aGrabBag[sEmbeddingsPropName] = uno::Any(objectsList.getAsConstPropertyValueList());
+
+    // put grab bag back into the document
+    xDocProps->setPropertyValue("InteropGrabBag", uno::Any(aGrabBag.getAsConstPropertyValueList()));
+}
+
 bool OleObjectHelper::importOleObject( PropertyMap& rPropMap, const OleObjectInfo& rOleObject, const awt::Size& rObjSize )
 {
     bool bRet = false;
diff --git a/writerfilter/source/dmapper/OLEHandler.cxx b/writerfilter/source/dmapper/OLEHandler.cxx
index d282c7b..0fe0955 100644
--- a/writerfilter/source/dmapper/OLEHandler.cxx
+++ b/writerfilter/source/dmapper/OLEHandler.cxx
@@ -22,6 +22,7 @@
 #include "GraphicHelpers.hxx"
 
 #include <editeng/unoprnms.hxx>
+#include <oox/ole/oleobjecthelper.hxx>
 #include <ooxml/resourceids.hxx>
 #include <rtl/ustring.hxx>
 #include <osl/diagnose.h>
@@ -179,43 +180,6 @@ void OLEHandler::lcl_sprm(Sprm & rSprm)
     }
 }
 
-
-void OLEHandler::saveInteropProperties(uno::Reference<text::XTextDocument> const& xTextDocument, const OUString& sObjectName, const OUString& sOldObjectName)
-{
-    static const char sEmbeddingsPropName[] = "EmbeddedObjects";
-
-    // get interop grab bag from document
-    uno::Reference< beans::XPropertySet > xDocProps( xTextDocument, uno::UNO_QUERY );
-    comphelper::SequenceAsHashMap aGrabBag(xDocProps->getPropertyValue(UNO_NAME_MISC_OBJ_INTEROPGRABBAG));
-
-    // get EmbeddedObjects property inside grab bag
-    comphelper::SequenceAsHashMap objectsList;
-    if (aGrabBag.find(sEmbeddingsPropName) != aGrabBag.end())
-        objectsList << aGrabBag[sEmbeddingsPropName];
-
-    uno::Sequence< beans::PropertyValue > aGrabBagAttribute(2);
-    aGrabBagAttribute[0].Name = "ProgID";
-    aGrabBagAttribute[0].Value = uno::Any( m_sProgId );
-    aGrabBagAttribute[1].Name = "DrawAspect";
-    aGrabBagAttribute[1].Value = uno::Any( m_sDrawAspect );
-
-    // If we got an "old name", erase that first.
-    if (!sOldObjectName.isEmpty())
-    {
-        comphelper::SequenceAsHashMap::iterator it = objectsList.find(sOldObjectName);
-        if (it != objectsList.end())
-            objectsList.erase(it);
-    }
-
-    objectsList[sObjectName] = uno::Any( aGrabBagAttribute );
-
-    // put objects list back into the grab bag
-    aGrabBag[sEmbeddingsPropName] = uno::Any(objectsList.getAsConstPropertyValueList());
-
-    // put grab bag back into the document
-    xDocProps->setPropertyValue(UNO_NAME_MISC_OBJ_INTEROPGRABBAG, uno::Any(aGrabBag.getAsConstPropertyValueList()));
-}
-
 void OLEHandler::importStream(uno::Reference<uno::XComponentContext> xComponentContext, uno::Reference<text::XTextDocument> xTextDocument, uno::Reference<text::XTextContent> xOLE)
 {
     OUString aFilterService;
@@ -248,7 +212,9 @@ void OLEHandler::importStream(uno::Reference<uno::XComponentContext> xComponentC
 
     // Now that the data is imported, update the (typically) changed stream name.
     uno::Reference<beans::XPropertySet> xPropertySet(xOLE, uno::UNO_QUERY);
-    saveInteropProperties(xTextDocument, xPropertySet->getPropertyValue("StreamName").get<OUString>(), m_aURL);
+    ::oox::ole::SaveInteropProperties(xTextDocument,
+        xPropertySet->getPropertyValue("StreamName").get<OUString>(), &m_aURL,
+        m_sProgId, m_sDrawAspect);
 }
 
 OUString OLEHandler::getCLSID(uno::Reference<uno::XComponentContext> xComponentContext) const
@@ -305,7 +271,7 @@ OUString OLEHandler::copyOLEOStream(
                 }
             }
 
-            saveInteropProperties( xTextDocument, aURL );
+            ::oox::ole::SaveInteropProperties(xTextDocument, aURL, nullptr, m_sProgId, m_sDrawAspect);
 
             static const char sProtocol[] = "vnd.sun.star.EmbeddedObject:";
             OUString aPersistName( xEmbeddedResolver->resolveEmbeddedObjectURL( aURL ) );
diff --git a/writerfilter/source/dmapper/OLEHandler.hxx b/writerfilter/source/dmapper/OLEHandler.hxx
index 8e2cb13..8d6fbd6 100644
--- a/writerfilter/source/dmapper/OLEHandler.hxx
+++ b/writerfilter/source/dmapper/OLEHandler.hxx
@@ -76,11 +76,6 @@ class OLEHandler : public LoggedProperties
     virtual void lcl_attribute(Id Name, Value & val) override;
     virtual void lcl_sprm(Sprm & sprm) override;
 
-    // Interoperability
-    void saveInteropProperties(css::uno::Reference<css::text::XTextDocument> const& xTextDocument,
-                                        const OUString& sObjectName,
-                                        const OUString& sOldObjectName = OUString());
-
 public:
     OLEHandler(DomainMapper& rDomainMapper);
     virtual ~OLEHandler();
commit 17662cd7d4e5a201ba85f8236d2f71f544b7931e
Author: Michael Stahl <mstahl at redhat.com>
Date:   Sat Dec 19 16:54:20 2015 +0100

    embeddedobj: do not automatically convert alien objects to own
    
    OleEmbeddedObject::changeState() calls TryToConvertToOOo() on non-WNT
    platforms, which appears highly questionable to me, added in commit
    0c3d5fb0ad35ff7fc18917fc86fa58d9312fe3ae.
    
    What this does effectively is load the embedded object, store it as ODF,
    and then load it again as ODF.
    
    For one, it doesn't work in all cases currently.  If changeState() is
    not called from the UI but from some filter code, then no m_xClient may
    be set on the OleEmbeddedObject, hence no m_xClient will be set on the
    new m_xWrappedObject.  Then loading the embedded object will raise
    errors due to missing BaseURL, and storing it will fail in
    SfxObjectShell::SaveTo_Impl().  (It would be possible to solve that by
    copying the "DefaultParentBaseURL" handling code from
    OCommonEmbeddedObject.)
    
    The only reason why the previous code in ShapeExport::WriteOLE2Shape()
    was able to export the object despite the error is that it does not call
    SfxBaseModel functions but directly invokes the export filter, so the
    sfx2 code does not get an opportunity to check its error status.
    
    For another, doing this only on non-WNT platforms is also hazardous.
    
    It's probably better to leave conversion to own formats to an explicit
    UI action, as the OleEmbeddedObject::doVerb(-9) magic currently does,
    where it can hopefully be assumed that the caller at least established
    the client connection first.
    
    Change-Id: Ice3d8f8ceabe81b6e9025957c3eb87de9dbfe61a

diff --git a/embeddedobj/source/msole/oleembed.cxx b/embeddedobj/source/msole/oleembed.cxx
index 6768940..bf5d08c 100644
--- a/embeddedobj/source/msole/oleembed.cxx
+++ b/embeddedobj/source/msole/oleembed.cxx
@@ -587,17 +587,6 @@ void SAL_CALL OleEmbeddedObject::changeState( sal_Int32 nNewState )
         }
     }
     else
-#else
-    // if it is possible, the object will be converted to OOo format
-    if ( !m_bTriedConversion )
-    {
-        m_bTriedConversion = true;
-        if ( TryToConvertToOOo() )
-        {
-            changeState( nNewState );
-            return;
-        }
-    }
 #endif
     {
         throw embed::UnreachableStateException();
commit d54624ff7e7f97d8d7e8fd70572348f63b8a3da5
Author: Michael Stahl <mstahl at redhat.com>
Date:   Sat Dec 19 00:18:29 2015 +0100

    oox: stop pointlessly loading embedded objects to check if it's a chart
    
    This fixes SdExportTest::testBnc822341 again, because the conversion
    TryToConvertToOOo() in OleEmbeddedObject no longer breaks it.
    
    Change-Id: Ib968722af426123afa08865290e5a4e762f19070

diff --git a/oox/source/export/shapes.cxx b/oox/source/export/shapes.cxx
index e03a8f6..0c087e8 100644
--- a/oox/source/export/shapes.cxx
+++ b/oox/source/export/shapes.cxx
@@ -78,6 +78,7 @@
 #include <tools/globname.hxx>
 #include <comphelper/classids.hxx>
 #include <comphelper/storagehelper.hxx>
+#include <sot/exchange.hxx>
 #include <vcl/cvtgrf.hxx>
 #include <unotools/fontcvt.hxx>
 #include <vcl/graph.hxx>
@@ -1584,12 +1585,19 @@ ShapeExport& ShapeExport::WriteOLE2Shape( Reference< XShape > xShape )
 {
     Reference< XPropertySet > xPropSet( xShape, UNO_QUERY );
     if( xPropSet.is() ) {
-        if( GetProperty( xPropSet, "Model" ) )
+        OUString clsid;
+        xPropSet->getPropertyValue("CLSID") >>= clsid;
+        assert(!clsid.isEmpty());
+        SvGlobalName aClassID;
+        bool const isValid(aClassID.MakeId(clsid));
+        assert(isValid); (void)isValid;
+
         {
-            Reference< XChartDocument > xChartDoc;
-            mAny >>= xChartDoc;
-            if( xChartDoc.is() )
+            if (SotExchange::IsChart(aClassID))
             {
+                Reference< XChartDocument > xChartDoc;
+                xPropSet->getPropertyValue("Model") >>= xChartDoc;
+                assert(xChartDoc.is());
                 //export the chart
                 Reference< XModel > xModel( xChartDoc, UNO_QUERY );
                 ChartExport aChartExport( mnXmlNamespace, GetFS(), xModel, GetFB(), GetDocumentType() );
commit ca29357f7310f057f79357e80a9129b670914404
Author: Michael Stahl <mstahl at redhat.com>
Date:   Fri Dec 18 22:12:12 2015 +0100

    oox: replace incomplete implementation of ShapeExport::WriteOLE2Shape()
    
    ... with oox::GetOLEObjectStream(), and add the "progId" attribute while
    at it.  Not sure what the "name" attribute is good for, it appears more
    like a unique name than some kind of type classification?
    
    This makes SdExportTest::testBnc822341 fail temporarily, and also breaks
    roundtripping of OOXML OLEs in PPTX files.
    
    Change-Id: I20043b2a414cf5a28eaa24adaf2ddeb737986250

diff --git a/oox/source/export/shapes.cxx b/oox/source/export/shapes.cxx
index 00f4a94..e03a8f6 100644
--- a/oox/source/export/shapes.cxx
+++ b/oox/source/export/shapes.cxx
@@ -77,6 +77,7 @@
 #include <tools/stream.hxx>
 #include <tools/globname.hxx>
 #include <comphelper/classids.hxx>
+#include <comphelper/storagehelper.hxx>
 #include <vcl/cvtgrf.hxx>
 #include <unotools/fontcvt.hxx>
 #include <vcl/graph.hxx>
@@ -1597,90 +1598,44 @@ ShapeExport& ShapeExport::WriteOLE2Shape( Reference< XShape > xShape )
             }
             else
             {
-                const bool bSpreadSheet = Reference< XSpreadsheetDocument >( mAny, UNO_QUERY ).is();
-                const bool bTextDocument = Reference< css::text::XTextDocument >( mAny, UNO_QUERY ).is();
-                if( ( bSpreadSheet || bTextDocument ) && mpFB)
-                {
-                    Reference< XComponent > xDocument( mAny, UNO_QUERY );
-                    if( xDocument.is() )
-                    {
-                        Reference< XOutputStream > xOutStream;
-                        if( bSpreadSheet )
-                        {
-                            xOutStream = mpFB->openFragmentStream( OUStringBuffer()
-                                                                   .appendAscii( GetComponentDir() )
-                                                                   .append( "/embeddings/spreadsheet" )
-                                                                   .append( static_cast<sal_Int32>(mnEmbeddeDocumentCounter) )
-                                                                   .append( ".xlsx" )
-                                                                   .makeStringAndClear(),
-                                                                   "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" );
-                        }
-                        else
-                        {
-                            xOutStream = mpFB->openFragmentStream( OUStringBuffer()
-                                                                   .appendAscii( GetComponentDir() )
-                                                                   .append( "/embeddings/textdocument" )
-                                                                   .append( static_cast<sal_Int32>(mnEmbeddeDocumentCounter) )
-                                                                   .append( ".docx" )
-                                                                   .makeStringAndClear(),
-                                                                   "application/vnd.openxmlformats-officedocument.wordprocessingml.document" );
-                        }
-
-                        // export the embedded document
-                        Sequence< PropertyValue > rMedia(1);
+                uno::Reference<embed::XEmbeddedObject> const xObj(
+                    xPropSet->getPropertyValue("EmbeddedObject"), uno::UNO_QUERY);
 
-                        rMedia[0].Name = utl::MediaDescriptor::PROP_STREAMFOROUTPUT();
-                        rMedia[0].Value <<= xOutStream;
+                OUString sMediaType;
+                OUString sRelationType;
+                OUString sSuffix;
+                const char * pProgID(nullptr);
 
-                        Reference< XExporter > xExporter;
-                        if( bSpreadSheet )
-                        {
-                            xExporter.set(
-                                mpFB->getComponentContext()->getServiceManager()->
-                                    createInstanceWithContext(
-                                        "com.sun.star.comp.oox.xls.ExcelFilter",
-                                        mpFB->getComponentContext() ),
-                                UNO_QUERY_THROW );
-                        }
-                        else
-                        {
-                            xExporter.set(
-                                mpFB->getComponentContext()->getServiceManager()->
-                                    createInstanceWithContext(
-                                        "com.sun.star.comp.Writer.WriterFilter",
-                                        mpFB->getComponentContext() ),
-                                UNO_QUERY_THROW );
+                uno::Reference<io::XInputStream> const xInStream =
+                    oox::GetOLEObjectStream(
+                        mpFB->getComponentContext(), xObj, OUString(),
+                        sMediaType, sRelationType, sSuffix, pProgID);
 
-                        }
-                        xExporter->setSourceDocument( xDocument );
-                        Reference< XFilter >( xExporter, UNO_QUERY_THROW )->
-                            filter( rMedia );
+                if (!xInStream.is())
+                {
+                    return *this;
+                }
 
-                        xOutStream->closeOutput();
+                assert(!sMediaType.isEmpty());
+                assert(!sRelationType.isEmpty());
+                assert(!sSuffix.isEmpty());
+
+                OUString sFileName = "embeddings/oleObject" + OUString::number(mnEmbeddeDocumentCounter++) + "." + sSuffix;
+                uno::Reference<io::XOutputStream> const xOutStream(
+                    mpFB->openFragmentStream(
+                        OUString::createFromAscii(GetComponentDir()) + "/" + sFileName,
+                        sMediaType));
+                assert(xOutStream.is()); // no reason why that could fail
+
+                try {
+                    ::comphelper::OStorageHelper::CopyInputToOutput(xInStream, xOutStream);
+                } catch (uno::Exception const& e) {
+                    SAL_WARN("oox", "ShapeExport::WriteOLEObject: exception: " << e.Message);
+                }
 
-                        OUString sRelId;
-                        if( bSpreadSheet )
-                        {
-                            sRelId = mpFB->addRelation( mpFS->getOutputStream(),
-                                                        "http://schemas.openxmlformats.org/officeDocument/2006/relationships/package",
-                                                        OUStringBuffer()
-                                                        .appendAscii( GetRelationCompPrefix() )
-                                                        .append( "embeddings/spreadsheet" )
-                                                        .append( static_cast<sal_Int32>(mnEmbeddeDocumentCounter++) )
-                                                        .append( ".xlsx" )
-                                                        .makeStringAndClear() );
-                        }
-                        else
-                        {
-                            sRelId = mpFB->addRelation( mpFS->getOutputStream(),
-                                                        "http://schemas.openxmlformats.org/officeDocument/2006/relationships/package",
-                                                        OUStringBuffer()
-                                                        .appendAscii( GetRelationCompPrefix() )
-                                                        .append( "embeddings/textdocument" )
-                                                        .append( static_cast<sal_Int32>(mnEmbeddeDocumentCounter++) )
-                                                        .append( ".docx" )
-                                                        .makeStringAndClear() );
-                        }
+                OUString const sRelId = mpFB->addRelation(
+                    mpFS->getOutputStream(), sRelationType,
+                    OUString::createFromAscii(GetRelationCompPrefix()) + sFileName);
 
                         mpFS->startElementNS( mnXmlNamespace, XML_graphicFrame, FSEND );
 
@@ -1705,17 +1660,18 @@ ShapeExport& ShapeExport::WriteOLE2Shape( Reference< XShape > xShape )
                         mpFS->startElementNS( XML_a, XML_graphicData,
                                               XML_uri, "http://schemas.openxmlformats.org/presentationml/2006/ole",
                                               FSEND );
-                        if( bSpreadSheet )
+                        if (pProgID)
                         {
                             mpFS->startElementNS( mnXmlNamespace, XML_oleObj,
-                                              XML_name, "Spreadsheet",
+                                              XML_progId, pProgID,
                                               FSNS(XML_r, XML_id), USS( sRelId ),
+                                              XML_spid, "",
                                               FSEND );
                         }
                         else
                         {
                             mpFS->startElementNS( mnXmlNamespace, XML_oleObj,
-                                              XML_name, "Document",
+//?                                              XML_name, "Document",
                                               FSNS(XML_r, XML_id), USS( sRelId ),
                                               // The spec says that this is a required attribute, but PowerPoint can only handle an empty value.
                                               XML_spid, "",
@@ -1741,8 +1697,6 @@ ShapeExport& ShapeExport::WriteOLE2Shape( Reference< XShape > xShape )
                         mpFS->endElementNS( XML_a, XML_graphic );
 
                         mpFS->endElementNS( mnXmlNamespace, XML_graphicFrame );
-                    }
-                }
             }
         }
     }
commit 55bf7e4210e159bbeeaebeb0e092b3700a19d666
Author: Michael Stahl <mstahl at redhat.com>
Date:   Fri Dec 18 21:25:46 2015 +0100

    factor out oox::GetOLEObjectStream() without sw dependencies
    
    Change-Id: I32fa4b6b6d755b613b46b32d3b5961976335c76e

diff --git a/include/oox/export/shapes.hxx b/include/oox/export/shapes.hxx
index 67e52cb..3269df1 100644
--- a/include/oox/export/shapes.hxx
+++ b/include/oox/export/shapes.hxx
@@ -36,8 +36,24 @@ namespace drawing {
     class XShape;
     class XShapes;
 }
+namespace embed {
+    class XEmbeddedObject;
+}
 }}}
 
+namespace oox {
+
+OOX_DLLPUBLIC css::uno::Reference<css::io::XInputStream> GetOLEObjectStream(
+    css::uno::Reference<css::uno::XComponentContext> const& xContext,
+    css::uno::Reference<css::embed::XEmbeddedObject> const& xObj,
+    OUString const& i_rProgID,
+    OUString & o_rMediaType,
+    OUString & o_rRelationType,
+    OUString & o_rSuffix,
+    const char *& o_rpProgID);
+
+}
+
 namespace oox { namespace drawingml {
 
 class OOX_DLLPUBLIC URLTransformer
diff --git a/oox/source/export/shapes.cxx b/oox/source/export/shapes.cxx
index 0958986..00f4a94 100644
--- a/oox/source/export/shapes.cxx
+++ b/oox/source/export/shapes.cxx
@@ -40,8 +40,10 @@
 #include <com/sun/star/beans/XPropertySet.hpp>
 #include <com/sun/star/beans/XPropertySetInfo.hpp>
 #include <com/sun/star/beans/XPropertyState.hpp>
+#include <com/sun/star/container/XChild.hpp>
 #include <com/sun/star/container/XEnumerationAccess.hpp>
 #include <com/sun/star/document/XExporter.hpp>
+#include <com/sun/star/document/XStorageBasedDocument.hpp>
 #include <com/sun/star/drawing/FillStyle.hpp>
 #include <com/sun/star/drawing/BitmapMode.hpp>
 #include <com/sun/star/drawing/ConnectorType.hpp>
@@ -50,6 +52,10 @@
 #include <com/sun/star/drawing/LineStyle.hpp>
 #include <com/sun/star/drawing/TextHorizontalAdjust.hpp>
 #include <com/sun/star/drawing/TextVerticalAdjust.hpp>
+#include <com/sun/star/embed/EmbedStates.hpp>
+#include <com/sun/star/embed/XEmbeddedObject.hpp>
+#include <com/sun/star/embed/XEmbedPersist.hpp>
+#include <com/sun/star/frame/XStorable.hpp>
 #include <com/sun/star/graphic/XGraphic.hpp>
 #include <com/sun/star/i18n/ScriptType.hpp>
 #include <com/sun/star/io/XOutputStream.hpp>
@@ -69,6 +75,8 @@
 #include <com/sun/star/frame/XModel.hpp>
 #include <com/sun/star/table/BorderLine2.hpp>
 #include <tools/stream.hxx>
+#include <tools/globname.hxx>
+#include <comphelper/classids.hxx>
 #include <vcl/cvtgrf.hxx>
 #include <unotools/fontcvt.hxx>
 #include <vcl/graph.hxx>
@@ -106,6 +114,223 @@ using ::sax_fastparser::FSHelperPtr;
 
 #define IDS(x) OString(OStringLiteral(#x " ") + OString::number( mnShapeIdMax++ )).getStr()
 
+namespace oox {
+
+static void lcl_ConvertProgID(OUString const& rProgID,
+    OUString & o_rMediaType, OUString & o_rRelationType, OUString & o_rFileExtension)
+{
+    if (rProgID == "Excel.Sheet.12")
+    {
+        o_rMediaType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
+        o_rRelationType = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/package";
+        o_rFileExtension = "xlsx";
+    }
+    else if (rProgID.startsWith("Excel.SheetBinaryMacroEnabled.12") )
+    {
+        o_rMediaType = "application/vnd.ms-excel.sheet.binary.macroEnabled.12";
+        o_rRelationType = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/package";
+        o_rFileExtension = "xlsb";
+    }
+    else if (rProgID.startsWith("Excel.SheetMacroEnabled.12"))
+    {
+        o_rMediaType = "application/vnd.ms-excel.sheet.macroEnabled.12";
+        o_rRelationType = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/package";
+        o_rFileExtension = "xlsm";
+    }
+    else if (rProgID.startsWith("Excel.Sheet"))
+    {
+        o_rMediaType = "application/vnd.ms-excel";
+        o_rRelationType = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/oleObject";
+        o_rFileExtension = "xls";
+    }
+    else if (rProgID == "PowerPoint.Show.12")
+    {
+        o_rMediaType = "application/vnd.openxmlformats-officedocument.presentationml.presentation";
+        o_rRelationType = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/package";
+        o_rFileExtension = "pptx";
+    }
+    else if (rProgID == "PowerPoint.ShowMacroEnabled.12")
+    {
+        o_rMediaType = "application/vnd.ms-powerpoint.presentation.macroEnabled.12";
+        o_rRelationType = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/package";
+        o_rFileExtension = "pptm";
+    }
+    else if (rProgID.startsWith("PowerPoint.Show"))
+    {
+        o_rMediaType = "application/vnd.ms-powerpoint";
+        o_rRelationType = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/oleObject";
+        o_rFileExtension = "ppt";
+    }
+    else if (rProgID.startsWith("PowerPoint.Slide.12"))
+    {
+        o_rMediaType = "application/vnd.openxmlformats-officedocument.presentationml.slide";
+       o_rRelationType = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/package";
+       o_rFileExtension = "sldx";
+    }
+    else if (rProgID == "PowerPoint.SlideMacroEnabled.12")
+    {
+       o_rMediaType = "application/vnd.ms-powerpoint.slide.macroEnabled.12";
+       o_rRelationType = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/package";
+       o_rFileExtension = "sldm";
+    }
+    else if (rProgID == "Word.DocumentMacroEnabled.12")
+    {
+        o_rMediaType = "application/vnd.ms-word.document.macroEnabled.12";
+        o_rRelationType = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/package";
+        o_rFileExtension = "docm";
+    }
+    else if (rProgID == "Word.Document.12")
+    {
+        o_rMediaType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
+        o_rRelationType = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/package";
+        o_rFileExtension = "docx";
+    }
+    else if (rProgID == "Word.Document.8")
+    {
+        o_rMediaType = "application/msword";
+        o_rRelationType = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/oleObject";
+        o_rFileExtension = "doc";
+    }
+    else if (rProgID == "Excel.Chart.8")
+    {
+        o_rMediaType = "application/vnd.ms-excel";
+        o_rRelationType = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/oleObject";
+        o_rFileExtension = "xls";
+    }
+    else if (rProgID == "AcroExch.Document.11")
+    {
+        o_rMediaType = "application/pdf";
+        o_rRelationType = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/oleObject";
+        o_rFileExtension = "pdf";
+    }
+    else
+    {
+        o_rMediaType = "application/vnd.openxmlformats-officedocument.oleObject";
+        o_rRelationType = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/oleObject";
+        o_rFileExtension = "bin";
+    }
+}
+
+static uno::Reference<io::XInputStream> lcl_StoreOwnAsOOXML(
+    uno::Reference<uno::XComponentContext> const& xContext,
+    uno::Reference<embed::XEmbeddedObject> const& xObj,
+    char const*& o_rpProgID,
+    OUString & o_rMediaType, OUString & o_rRelationType, OUString & o_rSuffix)
+{
+    static struct {
+        struct {
+            sal_uInt32 n1;
+            sal_uInt16 n2, n3;
+            sal_uInt8 b8, b9, b10, b11, b12, b13, b14, b15;
+        } ClassId;
+        char const* pFilterName;
+        char const* pMediaType;
+        char const* pProgID;
+        char const* pSuffix;
+    } s_Mapping[] = {
+        { {SO3_SW_CLASSID_60}, "MS Word 2007 XML", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "Word.Document.12", "docx" },
+        { {SO3_SC_CLASSID_60}, "Calc MS Excel 2007 XML", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "Excel.Sheet.12", "xlsx" },
+        { {SO3_SIMPRESS_CLASSID_60}, "Impress MS PowerPoint 2007 XML", "application/vnd.openxmlformats-officedocument.presentationml.presentation", "PowerPoint.Show.12", "pptx" },
+        // FIXME: Draw does not appear to have a MSO format export filter?
+//            { {SO3_SDRAW_CLASSID}, "", "", "", "" },
+        { {SO3_SCH_CLASSID_60}, "unused", "", "", "" },
+        { {SO3_SM_CLASSID_60}, "unused", "", "", "" },
+    };
+
+    const char * pFilterName(nullptr);
+    SvGlobalName const classId(xObj->getClassID());
+    for (size_t i = 0; i < SAL_N_ELEMENTS(s_Mapping); ++i)
+    {
+        auto const& rId(s_Mapping[i].ClassId);
+        SvGlobalName const temp(rId.n1, rId.n2, rId.n3, rId.b8, rId.b9, rId.b10, rId.b11, rId.b12, rId.b13, rId.b14, rId.b15);
+        if (temp == classId)
+        {
+            assert(SvGlobalName(SO3_SCH_CLASSID_60) != classId); // chart should be written elsewhere!
+            assert(SvGlobalName(SO3_SM_CLASSID_60) != classId); // formula should be written elsewhere!
+            pFilterName = s_Mapping[i].pFilterName;
+            o_rMediaType = OUString::createFromAscii(s_Mapping[i].pMediaType);
+            o_rpProgID = s_Mapping[i].pProgID;
+            o_rSuffix = OUString::createFromAscii(s_Mapping[i].pSuffix);
+            o_rRelationType = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/package";
+            break;
+        }
+    }
+
+    if (!pFilterName)
+    {
+        SAL_WARN("oox", "oox::GetOLEObjectStream: unknown ClassId " << classId.GetHexName());
+        return nullptr;
+    }
+
+    if (embed::EmbedStates::LOADED == xObj->getCurrentState())
+    {
+        xObj->changeState(embed::EmbedStates::RUNNING);
+    }
+    // use a temp stream - while it would work to store directly to a
+    // fragment stream, an error during export means we'd have to delete it
+    uno::Reference<io::XStream> const xTempStream(
+        xContext->getServiceManager()->createInstanceWithContext(
+            "com.sun.star.comp.MemoryStream", xContext),
+        uno::UNO_QUERY_THROW);
+    uno::Sequence<beans::PropertyValue> args(2);
+    args[0].Name = "OutputStream";
+    args[0].Value <<= xTempStream->getOutputStream();
+    args[1].Name = "FilterName";
+    args[1].Value <<= OUString::createFromAscii(pFilterName);
+    uno::Reference<frame::XStorable> xStorable(xObj->getComponent(), uno::UNO_QUERY);
+    try
+    {
+        xStorable->storeToURL("private:stream", args);
+    }
+    catch (uno::Exception const& e)
+    {
+        SAL_WARN("oox", "oox::GetOLEObjectStream: exception: \"" << e.Message << "\"");
+        return nullptr;
+    }
+    xTempStream->getOutputStream()->closeOutput();
+    return xTempStream->getInputStream();
+}
+
+uno::Reference<io::XInputStream> GetOLEObjectStream(
+        uno::Reference<uno::XComponentContext> const& xContext,
+        uno::Reference<embed::XEmbeddedObject> const& xObj,
+        OUString const& i_rProgID,
+        OUString & o_rMediaType,
+        OUString & o_rRelationType,
+        OUString & o_rSuffix,
+        const char *& o_rpProgID)
+{
+    uno::Reference<io::XInputStream> xInStream;
+    try
+    {
+        uno::Reference<document::XStorageBasedDocument> const xParent(
+            uno::Reference<container::XChild>(xObj, uno::UNO_QUERY)->getParent(),
+            uno::UNO_QUERY);
+        uno::Reference<embed::XStorage> const xParentStorage(xParent->getDocumentStorage());
+        OUString const entryName(
+            uno::Reference<embed::XEmbedPersist>(xObj, uno::UNO_QUERY)->getEntryName());
+
+        if (xParentStorage->isStreamElement(entryName))
+        {
+            lcl_ConvertProgID(i_rProgID, o_rMediaType, o_rRelationType, o_rSuffix);
+            xInStream = xParentStorage->cloneStreamElement(entryName)->getInputStream();
+            // TODO: is it possible to take the sMediaType from the stream?
+        }
+        else // the object is ODF - either the whole document is
+        {    // ODF, or the OLE was edited so it was converted to ODF
+            xInStream = lcl_StoreOwnAsOOXML(xContext, xObj,
+                    o_rpProgID, o_rMediaType, o_rRelationType, o_rSuffix);
+        }
+    }
+    catch (uno::Exception const& e)
+    {
+        SAL_WARN("oox", "oox::GetOLEObjectStream: exception: " << e.Message);
+    }
+    return xInStream;
+}
+
+} // namespace oox
+
 namespace oox { namespace drawingml {
 
 URLTransformer::~URLTransformer()
diff --git a/sw/source/filter/ww8/docxexport.cxx b/sw/source/filter/ww8/docxexport.cxx
index cd01cd4..f0a931c 100644
--- a/sw/source/filter/ww8/docxexport.cxx
+++ b/sw/source/filter/ww8/docxexport.cxx
@@ -24,13 +24,9 @@
 
 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
 #include <com/sun/star/document/XDocumentProperties.hpp>
-#include <com/sun/star/document/XStorageBasedDocument.hpp>
 #include <com/sun/star/drawing/XShape.hpp>
-#include <com/sun/star/embed/EmbedStates.hpp>
-#include <com/sun/star/embed/XEmbedPersist.hpp>
 #include <com/sun/star/i18n/ScriptType.hpp>
 #include <com/sun/star/frame/XModel.hpp>
-#include <com/sun/star/frame/XStorable.hpp>
 #include <com/sun/star/xml/dom/XDocument.hpp>
 #include <com/sun/star/xml/sax/XSAXSerializable.hpp>
 #include <com/sun/star/xml/sax/Writer.hpp>
@@ -74,8 +70,6 @@
 #include "ww8par.hxx"
 #include "ww8scan.hxx"
 #include <oox/token/properties.hxx>
-#include <comphelper/classids.hxx>
-#include <comphelper/embeddedobjectcontainer.hxx>
 #include <comphelper/string.hxx>
 #include <rtl/ustrbuf.hxx>
 #include <vcl/font.hxx>
@@ -371,220 +365,20 @@ OString DocxExport::OutputChart( uno::Reference< frame::XModel >& xModel, sal_In
     return OUStringToOString( sId, RTL_TEXTENCODING_UTF8 );
 }
 
-
-static void lcl_ConvertProgID(OUString const& rProgID,
-    OUString & o_rMediaType, OUString & o_rRelationType, OUString & o_rFileExtension)
-{
-    if (rProgID == "Excel.Sheet.12")
-    {
-        o_rMediaType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
-        o_rRelationType = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/package";
-        o_rFileExtension = "xlsx";
-    }
-    else if (rProgID.startsWith("Excel.SheetBinaryMacroEnabled.12") )
-    {
-        o_rMediaType = "application/vnd.ms-excel.sheet.binary.macroEnabled.12";
-        o_rRelationType = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/package";
-        o_rFileExtension = "xlsb";
-    }
-    else if (rProgID.startsWith("Excel.SheetMacroEnabled.12"))
-    {
-        o_rMediaType = "application/vnd.ms-excel.sheet.macroEnabled.12";
-        o_rRelationType = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/package";
-        o_rFileExtension = "xlsm";
-    }
-    else if (rProgID.startsWith("Excel.Sheet"))
-    {
-        o_rMediaType = "application/vnd.ms-excel";
-        o_rRelationType = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/oleObject";
-        o_rFileExtension = "xls";
-    }
-    else if (rProgID == "PowerPoint.Show.12")
-    {
-        o_rMediaType = "application/vnd.openxmlformats-officedocument.presentationml.presentation";
-        o_rRelationType = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/package";
-        o_rFileExtension = "pptx";
-    }
-    else if (rProgID == "PowerPoint.ShowMacroEnabled.12")
-    {
-        o_rMediaType = "application/vnd.ms-powerpoint.presentation.macroEnabled.12";
-        o_rRelationType = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/package";
-        o_rFileExtension = "pptm";
-    }
-    else if (rProgID.startsWith("PowerPoint.Show"))
-    {
-        o_rMediaType = "application/vnd.ms-powerpoint";
-        o_rRelationType = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/oleObject";
-        o_rFileExtension = "ppt";
-    }
-    else if (rProgID.startsWith("PowerPoint.Slide.12"))
-    {
-        o_rMediaType = "application/vnd.openxmlformats-officedocument.presentationml.slide";
-       o_rRelationType = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/package";
-       o_rFileExtension = "sldx";
-    }
-    else if (rProgID == "PowerPoint.SlideMacroEnabled.12")
-    {
-       o_rMediaType = "application/vnd.ms-powerpoint.slide.macroEnabled.12";
-       o_rRelationType = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/package";
-       o_rFileExtension = "sldm";
-    }
-    else if (rProgID == "Word.DocumentMacroEnabled.12")
-    {
-        o_rMediaType = "application/vnd.ms-word.document.macroEnabled.12";
-        o_rRelationType = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/package";
-        o_rFileExtension = "docm";
-    }
-    else if (rProgID == "Word.Document.12")
-    {
-        o_rMediaType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
-        o_rRelationType = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/package";
-        o_rFileExtension = "docx";
-    }
-    else if (rProgID == "Word.Document.8")
-    {
-        o_rMediaType = "application/msword";
-        o_rRelationType = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/oleObject";
-        o_rFileExtension = "doc";
-    }
-    else if (rProgID == "Excel.Chart.8")
-    {
-        o_rMediaType = "application/vnd.ms-excel";
-        o_rRelationType = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/oleObject";
-        o_rFileExtension = "xls";
-    }
-    else if (rProgID == "AcroExch.Document.11")
-    {
-        o_rMediaType = "application/pdf";
-        o_rRelationType = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/oleObject";
-        o_rFileExtension = "pdf";
-    }
-    else
-    {
-        o_rMediaType = "application/vnd.openxmlformats-officedocument.oleObject";
-        o_rRelationType = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/oleObject";
-        o_rFileExtension = "bin";
-    }
-}
-
-static uno::Reference<io::XInputStream> lcl_StoreOwnAsOOXML(
-    uno::Reference<uno::XComponentContext> const& xContext,
-    uno::Reference<embed::XEmbeddedObject> const& xObj,
-    char const*& o_rpProgID,
-    OUString & o_rMediaType, OUString & o_rRelationType, OUString & o_rSuffix)
-{
-    static struct {
-        struct {
-            sal_uInt32 n1;
-            sal_uInt16 n2, n3;
-            sal_uInt8 b8, b9, b10, b11, b12, b13, b14, b15;
-        } ClassId;
-        char const* pFilterName;
-        char const* pMediaType;
-        char const* pProgID;
-        char const* pSuffix;
-    } s_Mapping[] = {
-        { {SO3_SW_CLASSID_60}, "MS Word 2007 XML", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "Word.Document.12", "docx" },
-        { {SO3_SC_CLASSID_60}, "Calc MS Excel 2007 XML", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "Excel.Sheet.12", "xlsx" },
-        { {SO3_SIMPRESS_CLASSID_60}, "Impress MS PowerPoint 2007 XML", "application/vnd.openxmlformats-officedocument.presentationml.presentation", "PowerPoint.Show.12", "pptx" },
-        // FIXME: Draw does not appear to have a MSO format export filter?
-//            { {SO3_SDRAW_CLASSID}, "", "", "", "" },
-        { {SO3_SCH_CLASSID_60}, "unused", "", "", "" },
-        { {SO3_SM_CLASSID_60}, "unused", "", "", "" },
-    };
-
-    const char * pFilterName(nullptr);
-    SvGlobalName const classId(xObj->getClassID());
-    for (size_t i = 0; i < SAL_N_ELEMENTS(s_Mapping); ++i)
-    {
-        auto const& rId(s_Mapping[i].ClassId);
-        SvGlobalName const temp(rId.n1, rId.n2, rId.n3, rId.b8, rId.b9, rId.b10, rId.b11, rId.b12, rId.b13, rId.b14, rId.b15);
-        if (temp == classId)
-        {
-            assert(SvGlobalName(SO3_SCH_CLASSID_60) != classId); // chart should be written elsewhere!
-            assert(SvGlobalName(SO3_SM_CLASSID_60) != classId); // formula should be written elsewhere!
-            pFilterName = s_Mapping[i].pFilterName;
-            o_rMediaType = OUString::createFromAscii(s_Mapping[i].pMediaType);
-            o_rpProgID = s_Mapping[i].pProgID;
-            o_rSuffix = OUString::createFromAscii(s_Mapping[i].pSuffix);
-            o_rRelationType = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/package";
-            break;
-        }
-    }
-
-    if (!pFilterName)
-    {
-        SAL_WARN("sw.ww8", "DocxExport::WriteOLEObject: unknown ClassId " << classId.GetHexName());
-        return nullptr;
-    }
-
-    if (embed::EmbedStates::LOADED == xObj->getCurrentState())
-    {
-        xObj->changeState(embed::EmbedStates::RUNNING);
-    }
-    // use a temp stream - while it would work to store directly to a
-    // fragment stream, an error during export means we'd have to delete it
-    uno::Reference<io::XStream> const xTempStream(
-        xContext->getServiceManager()->createInstanceWithContext(
-            "com.sun.star.comp.MemoryStream", xContext),
-        uno::UNO_QUERY_THROW);
-    uno::Sequence<beans::PropertyValue> args(2);
-    args[0].Name = "OutputStream";
-    args[0].Value <<= xTempStream->getOutputStream();
-    args[1].Name = "FilterName";
-    args[1].Value <<= OUString::createFromAscii(pFilterName);
-    uno::Reference<frame::XStorable> xStorable(xObj->getComponent(), uno::UNO_QUERY);
-    try
-    {
-        xStorable->storeToURL("private:stream", args);
-    }
-    catch (uno::Exception const& e)
-    {
-        SAL_WARN("sw.ww8", "DocxExport::WriteOLEObject: exception: \"" << e.Message << "\"");
-        return nullptr;
-    }
-    xTempStream->getOutputStream()->closeOutput();
-    return xTempStream->getInputStream();
-}
-
 OString DocxExport::WriteOLEObject(SwOLEObj& rObject, OUString & io_rProgID)
 {
     uno::Reference <embed::XEmbeddedObject> xObj( rObject.GetOleRef() );
+    uno::Reference<uno::XComponentContext> const xContext(
+        GetFilter().getComponentContext());
 
-    uno::Reference<io::XInputStream> xInStream;
     OUString sMediaType;
     OUString sRelationType;
     OUString sSuffix;
     const char * pProgID(nullptr);
 
-    try
-    {
-        uno::Reference<document::XStorageBasedDocument> const xParent(
-            uno::Reference<container::XChild>(xObj, uno::UNO_QUERY)->getParent(),
-            uno::UNO_QUERY);
-        uno::Reference<embed::XStorage> const xParentStorage(xParent->getDocumentStorage());
-        OUString const entryName(
-            uno::Reference<embed::XEmbedPersist>(xObj, uno::UNO_QUERY)->getEntryName());
-
-        if (xParentStorage->isStreamElement(entryName))
-        {
-            lcl_ConvertProgID(io_rProgID, sMediaType, sRelationType, sSuffix);
-
-            xInStream = xParentStorage->cloneStreamElement(entryName)->getInputStream();
-            // TODO: is it possible to take the sMediaType from the stream?
-        }
-        else // the object is ODF - either the whole document is
-        {    // ODF, or the OLE was edited so it was converted to ODF
-            uno::Reference<uno::XComponentContext> const xContext(
-                GetFilter().getComponentContext());
-            xInStream = lcl_StoreOwnAsOOXML(xContext, xObj,
-                    pProgID, sMediaType, sRelationType, sSuffix);
-        }
-    }
-    catch (uno::Exception const& e)
-    {
-        SAL_WARN("sw.ww8", "DocxExport::WriteOLEObject: exception: " << e.Message);
-    }
+    uno::Reference<io::XInputStream> const xInStream =
+        oox::GetOLEObjectStream(xContext, xObj, io_rProgID,
+            sMediaType, sRelationType, sSuffix, pProgID);
 
     if (!xInStream.is())
     {
commit 1a5104a6cd7c69b960d84ecb4f375b15d4bc042c
Author: Michael Stahl <mstahl at redhat.com>
Date:   Fri Dec 18 20:48:52 2015 +0100

    sw: stop using SfxObjectShell in DocxExport::WriteOLEObject
    
    Change-Id: I3ffa29c57bcb6d12208ef24cb6972364c2f50315

diff --git a/sw/source/filter/ww8/docxexport.cxx b/sw/source/filter/ww8/docxexport.cxx
index d2c05c4..cd01cd4 100644
--- a/sw/source/filter/ww8/docxexport.cxx
+++ b/sw/source/filter/ww8/docxexport.cxx
@@ -24,8 +24,10 @@
 
 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
 #include <com/sun/star/document/XDocumentProperties.hpp>
+#include <com/sun/star/document/XStorageBasedDocument.hpp>
 #include <com/sun/star/drawing/XShape.hpp>
 #include <com/sun/star/embed/EmbedStates.hpp>
+#include <com/sun/star/embed/XEmbedPersist.hpp>
 #include <com/sun/star/i18n/ScriptType.hpp>
 #include <com/sun/star/frame/XModel.hpp>
 #include <com/sun/star/frame/XStorable.hpp>
@@ -548,24 +550,40 @@ static uno::Reference<io::XInputStream> lcl_StoreOwnAsOOXML(
 OString DocxExport::WriteOLEObject(SwOLEObj& rObject, OUString & io_rProgID)
 {
     uno::Reference <embed::XEmbeddedObject> xObj( rObject.GetOleRef() );
-    comphelper::EmbeddedObjectContainer* aContainer = rObject.GetObject().GetContainer();
-    uno::Reference< io::XInputStream > xInStream = aContainer->GetObjectStream( xObj );
 
+    uno::Reference<io::XInputStream> xInStream;
     OUString sMediaType;
     OUString sRelationType;
     OUString sSuffix;
     const char * pProgID(nullptr);
 
-    if (xInStream.is())
+    try
     {
-        lcl_ConvertProgID(io_rProgID, sMediaType, sRelationType, sSuffix);
+        uno::Reference<document::XStorageBasedDocument> const xParent(
+            uno::Reference<container::XChild>(xObj, uno::UNO_QUERY)->getParent(),
+            uno::UNO_QUERY);
+        uno::Reference<embed::XStorage> const xParentStorage(xParent->getDocumentStorage());
+        OUString const entryName(
+            uno::Reference<embed::XEmbedPersist>(xObj, uno::UNO_QUERY)->getEntryName());
+
+        if (xParentStorage->isStreamElement(entryName))
+        {
+            lcl_ConvertProgID(io_rProgID, sMediaType, sRelationType, sSuffix);
+
+            xInStream = xParentStorage->cloneStreamElement(entryName)->getInputStream();
+            // TODO: is it possible to take the sMediaType from the stream?
+        }
+        else // the object is ODF - either the whole document is
+        {    // ODF, or the OLE was edited so it was converted to ODF
+            uno::Reference<uno::XComponentContext> const xContext(
+                GetFilter().getComponentContext());
+            xInStream = lcl_StoreOwnAsOOXML(xContext, xObj,
+                    pProgID, sMediaType, sRelationType, sSuffix);
+        }
     }
-    else // the object is ODF - either the whole document is
-    {    // ODF, or the OLE was edited so it was converted to ODF
-        uno::Reference<uno::XComponentContext> const xContext(
-            GetFilter().getComponentContext());
-        xInStream = lcl_StoreOwnAsOOXML(xContext, xObj,
-                pProgID, sMediaType, sRelationType, sSuffix);
+    catch (uno::Exception const& e)
+    {
+        SAL_WARN("sw.ww8", "DocxExport::WriteOLEObject: exception: " << e.Message);
     }
 
     if (!xInStream.is())
commit bbbce5e04643a625e8b348f5064b062c013d4953
Author: Michael Stahl <mstahl at redhat.com>
Date:   Sat Dec 19 00:37:11 2015 +0100

    oox: disable obnoxious debugging spew
    
    Clearly the amount of noise here is at the SAL_INFO level, don't enable
    this by default on --enable-debug.
    
    Change-Id: Ifb8944132716c71cd3132892c1920a31286154cc

diff --git a/include/oox/export/utils.hxx b/include/oox/export/utils.hxx
index 66854f6..95d154d 100644
--- a/include/oox/export/utils.hxx
+++ b/include/oox/export/utils.hxx
@@ -28,8 +28,9 @@
 #define BS(x) (x ? "1":"0")
 #define USS(x) OUStringToOString( x, RTL_TEXTENCODING_UTF8 ).getStr()
 
+// FIXME: this should be removed and replaced by SAL_INFO
 #ifndef DBG
-#  if OSL_DEBUG_LEVEL > 0
+#  if OSL_DEBUG_LEVEL > 1
 #    define DBG(x) x
 #  else
 #    define DBG(x)
commit 3cd1826368c9a6573b4e1c6ce867809c502bd25d
Author: Michael Stahl <mstahl at redhat.com>
Date:   Sat Dec 19 00:12:25 2015 +0100

    sfx2: SAL_WARN on the early error return
    
    Change-Id: I77269323a54309658d959adc3076f0d7af0353ce

diff --git a/sfx2/source/doc/objstor.cxx b/sfx2/source/doc/objstor.cxx
index 722630f..68dff6c 100644
--- a/sfx2/source/doc/objstor.cxx
+++ b/sfx2/source/doc/objstor.cxx
@@ -1325,7 +1325,10 @@ bool SfxObjectShell::SaveTo_Impl
 
     // TODO/LATER: error handling
     if( rMedium.GetErrorCode() || pMedium->GetErrorCode() || GetErrorCode() )
+    {
+        SAL_WARN("sfx.doc", "SfxObjectShell::SaveTo_Impl: very early error return");
         return false;
+    }
 
     AddLog( OSL_LOG_PREFIX "Locking" );
 


More information about the Libreoffice-commits mailing list