summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2018-11-14 17:17:46 +0100
committerMiklos Vajna <vmiklos@collabora.com>2018-11-14 19:20:43 +0100
commit72e6269b88a32a672e00d2c25f0d0400038d1360 (patch)
tree13ba7aecd52a64f354f5d2a94a62dba7fc0aa5dc /sw
parent6e566c2b2b23d457a9fd47c16df15ce11e84c8e8 (diff)
sw: fix modification of ole obj native data during HTML import
It is expected that if you load an OLE2 storage (from reqif-xhtml) and you save it as ODT, the OLE2 data is not modified. This was almost the case, but we insisted on removing the OLE2 preview from the storage. Add a new flag to OleEmbeddedObject, so import filters can opt in for not modifying the OLE2 data. [ The nice situation is that we already had a test file which had a preview stream in the OLE2 storage, so we can easily assert there that the size doesn't change. ] Change-Id: I9b8b29f015dd4f2513e51a1066767218580cb5d8 Reviewed-on: https://gerrit.libreoffice.org/63381 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
Diffstat (limited to 'sw')
-rw-r--r--sw/qa/extras/htmlexport/htmlexport.cxx7
-rw-r--r--sw/source/filter/html/htmlplug.cxx19
2 files changed, 25 insertions, 1 deletions
diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx
index d1db894519b0..81d851a7f831 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -555,7 +555,12 @@ DECLARE_HTMLEXPORT_ROUNDTRIP_TEST(testReqIfOle2, "reqif-ole2.xhtml")
uno::Reference<io::XSeekable> xStream(xEmbeddedObject->getStream(), uno::UNO_QUERY);
// This was 80913, the RTF hexdump -> OLE1 binary -> OLE2 conversion was
// missing.
- CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int64>(38912), xStream->getLength());
+ // Also, this was 38912 when we re-generated the OLE2 preview, which is
+ // wrong, the OLE2 data is 38375 bytes in the ole2.ole (referenced by
+ // reqif-ole2.xhtml). To see that this is the correct value, convert the
+ // hexdump in ole2.ole to binary, remove the ole1 header and check the byte
+ // size.
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int64>(38375), xStream->getLength());
// Finally the export also failed as it tried to open the stream from the
// document storage, but the embedded object already opened it, so an
// exception of type com.sun.star.io.IOException was thrown.
diff --git a/sw/source/filter/html/htmlplug.cxx b/sw/source/filter/html/htmlplug.cxx
index a7725b8f5b59..f067d18be3b3 100644
--- a/sw/source/filter/html/htmlplug.cxx
+++ b/sw/source/filter/html/htmlplug.cxx
@@ -65,6 +65,7 @@
#include <com/sun/star/io/XActiveDataStreamer.hpp>
#include <com/sun/star/io/IOException.hpp>
#include <com/sun/star/embed/XEmbedPersist2.hpp>
+#include <com/sun/star/lang/XInitialization.hpp>
#include <comphelper/embeddedobjectcontainer.hxx>
#include <comphelper/classids.hxx>
@@ -76,6 +77,7 @@
#include <filter/msfilter/msoleexp.hxx>
#include <comphelper/fileurl.hxx>
#include <osl/file.hxx>
+#include <comphelper/propertyvalue.hxx>
using namespace com::sun::star;
@@ -632,10 +634,27 @@ bool SwHTMLParser::InsertEmbed()
SetSpace( aSpace, aItemSet, aPropInfo, aFrameSet );
// and insert into the document
+ uno::Reference<lang::XInitialization> xObjInitialization(xObj, uno::UNO_QUERY);
+ if (xObjInitialization.is())
+ {
+ // Request that the native data of the embedded object is not modified
+ // during parsing.
+ uno::Sequence<beans::PropertyValue> aValues{ comphelper::makePropertyValue("StreamReadOnly",
+ true) };
+ uno::Sequence<uno::Any> aArguments{ uno::makeAny(aValues) };
+ xObjInitialization->initialize(aArguments);
+ }
SwFrameFormat* pFlyFormat =
m_xDoc->getIDocumentContentOperations().InsertEmbObject(*m_pPam,
::svt::EmbeddedObjectRef(xObj, embed::Aspects::MSOLE_CONTENT),
&aFrameSet);
+ if (xObjInitialization.is())
+ {
+ uno::Sequence<beans::PropertyValue> aValues{ comphelper::makePropertyValue("StreamReadOnly",
+ false) };
+ uno::Sequence<uno::Any> aArguments{ uno::makeAny(aValues) };
+ xObjInitialization->initialize(aArguments);
+ }
// set name at FrameFormat
if( !aName.isEmpty() )