Kaydet (Commit) ae510e67 authored tarafından Miklos Vajna's avatar Miklos Vajna

sw XHTML export: handle native data of OLE objects

Write the native data and refer it from the XHTML stream.

Change-Id: I8952ed07108ddc92b1d136bd9af6f21d3ed604f0
Reviewed-on: https://gerrit.libreoffice.org/50941Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
Tested-by: 's avatarJenkins <ci@libreoffice.org>
üst a8959a26
......@@ -346,6 +346,17 @@ DECLARE_HTMLEXPORT_TEST(testReqIfParagraph, "reqif-p.xhtml")
CPPUNIT_ASSERT_EQUAL(aExpected, aActual);
}
DECLARE_HTMLEXPORT_ROUNDTRIP_TEST(testReqIfOleData, "reqif-ole-data.xhtml")
{
uno::Reference<text::XTextEmbeddedObjectsSupplier> xSupplier(mxComponent, uno::UNO_QUERY);
uno::Reference<container::XIndexAccess> xObjects(xSupplier->getEmbeddedObjects(),
uno::UNO_QUERY);
// This was 0, <object> without URL was ignored.
// Then this was 0 on export, as data of OLE nodes was ignored.
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), xObjects->getCount());
}
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -295,15 +295,6 @@ DECLARE_HTMLIMPORT_TEST(testReqIfBr, "reqif-br.xhtml")
CPPUNIT_ASSERT(getParagraph(1)->getString().startsWith("aaa\nbbb"));
}
DECLARE_HTMLIMPORT_TEST(testReqIfOleData, "reqif-ole-data.xhtml")
{
uno::Reference<text::XTextEmbeddedObjectsSupplier> xSupplier(mxComponent, uno::UNO_QUERY);
uno::Reference<container::XIndexAccess> xObjects(xSupplier->getEmbeddedObjects(),
uno::UNO_QUERY);
// This was 0, <object> without URL was ignored.
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), xObjects->getCount());
}
DECLARE_HTMLIMPORT_TEST(testReqIfOleImg, "reqif-ole-img.xhtml")
{
uno::Reference<text::XTextEmbeddedObjectsSupplier> xSupplier(mxComponent, uno::UNO_QUERY);
......
......@@ -739,6 +739,23 @@ protected:
{
setTestInteractionHandler(pPassword, aFilterOptions);
}
if (!maImportFilterOptions.isEmpty())
{
beans::PropertyValue aValue;
aValue.Name = "FilterOptions";
aValue.Value <<= maImportFilterOptions;
aFilterOptions.push_back(aValue);
}
if (!maImportFilterName.isEmpty())
{
beans::PropertyValue aValue;
aValue.Name = "FilterName";
aValue.Value <<= maImportFilterName;
aFilterOptions.push_back(aValue);
}
mxComponent = loadFromDesktop(maTempFile.GetURL(), "com.sun.star.text.TextDocument", comphelper::containerToSequence(aFilterOptions));
if (pPassword)
{
......
......@@ -1392,6 +1392,48 @@ Writer& OutHTML_FrameFormatOLENodeGrf( Writer& rWrt, const SwFrameFormat& rFrame
}
Graphic aGraphic( *pOLENd->GetGraphic() );
SwDocShell* pDocSh = rHTMLWrt.pDoc->GetDocShell();
bool bObjectOpened = false;
if (rHTMLWrt.mbXHTML && pDocSh)
{
// Map native data to an outer <object> element.
// Calculate the file name, which is meant to be the same as the
// replacement image, just with a .ole extension.
OUString aFileName;
if (rHTMLWrt.GetOrigFileName())
aFileName = *rHTMLWrt.GetOrigFileName();
INetURLObject aURL(aFileName);
OUString aName(aURL.getBase());
aName += "_";
aName += aURL.getExtension();
aName += "_";
aName += OUString::number(aGraphic.GetChecksum(), 16);
aURL.setBase(aName);
aURL.setExtension("ole");
aFileName = aURL.GetMainURL(INetURLObject::DecodeMechanism::NONE);
// Write the data.
OUString aStreamName = pOLENd->GetOLEObj().GetCurrentPersistName();
uno::Reference<embed::XStorage> xStorage = pDocSh->GetStorage();
uno::Reference<io::XStream> xInStream
= xStorage->openStreamElement(aStreamName, embed::ElementModes::READ);
SvFileStream aOutStream(aFileName, StreamMode::WRITE);
uno::Reference<io::XStream> xOutStream(new utl::OStreamWrapper(aOutStream));
comphelper::OStorageHelper::CopyInputToOutput(xInStream->getInputStream(),
xOutStream->getOutputStream());
aFileName = URIHelper::simpleNormalizedMakeRelative(rWrt.GetBaseURL(), aFileName);
// Refer to this data.
if (rHTMLWrt.m_bLFPossible)
rHTMLWrt.OutNewLine();
rWrt.Strm().WriteOString("<" + rHTMLWrt.GetNamespace() + OOO_STRING_SVTOOLS_HTML_object);
rWrt.Strm().WriteOString(" data=\"" + aFileName.toUtf8() + "\">");
bObjectOpened = true;
rHTMLWrt.m_bLFPossible = true;
}
OUString aGraphicURL;
if(!rHTMLWrt.mbEmbedImages)
{
......@@ -1419,6 +1461,11 @@ Writer& OutHTML_FrameFormatOLENodeGrf( Writer& rWrt, const SwFrameFormat& rFrame
pOLENd->GetTitle(), pOLENd->GetTwipSize(),
nFlags, "ole" );
if (bObjectOpened)
// Close native data.
rWrt.Strm().WriteOString("</" + rHTMLWrt.GetNamespace() + OOO_STRING_SVTOOLS_HTML_object
">");
return rWrt;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment