diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2019-12-17 17:54:21 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2019-12-18 10:31:10 +0100 |
commit | 4b113550df32f1aca3f3dd07dc23e338b8bbefec (patch) | |
tree | 1eb0b8c34cc2ebb563f8f5183d0a6989422dbfe3 /sw | |
parent | 2b225483903fa495cee1a22ede4b20eb0b6da44e (diff) |
sw reqif-xhtml export: add a new RTFOLEMimeType parameter
This is similar to commit e0f20211a8048a87b078aa4cf0f28c0c847487ad (sw
reqif-xhtml import: add a new AllowedRTFOLEMimeTypes parameter,
2019-12-16), except that was for the import and this is for the import.
The situation was similar, SfxBaseModel::impl_store() still had the
custom store parameters, but later functions lost it, so at the end
OutHTML_FrameFormatOLENodeGrf() in the sw HTML export could not respect
it.
Fix the problem in a similar way, so the SfxMedium instance created for
the duration of the export provides the custom options via
SfxMedium::GetArgs().
(cherry picked from commit 037cd13af81f8a1169d01e95036ed942f261f9a6)
Conflicts:
include/sfx2/objsh.hxx
sfx2/source/doc/objstor.cxx
sfx2/source/doc/sfxbasemodel.cxx
sw/source/filter/html/wrthtml.cxx
sw/source/filter/html/wrthtml.hxx
Change-Id: I71d2c7920f42d98133f345703cfdfd50f0e8550c
Diffstat (limited to 'sw')
-rw-r--r-- | sw/qa/extras/htmlexport/htmlexport.cxx | 35 | ||||
-rw-r--r-- | sw/source/filter/html/htmlplug.cxx | 14 | ||||
-rw-r--r-- | sw/source/filter/html/wrthtml.cxx | 10 | ||||
-rw-r--r-- | sw/source/filter/html/wrthtml.hxx | 2 |
4 files changed, 59 insertions, 2 deletions
diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx index 9b5c22c2f3c7..91a20f9c0ab1 100644 --- a/sw/qa/extras/htmlexport/htmlexport.cxx +++ b/sw/qa/extras/htmlexport/htmlexport.cxx @@ -25,6 +25,7 @@ #include <test/htmltesttools.hxx> #include <tools/urlobj.hxx> #include <svtools/rtfkeywd.hxx> +#include <comphelper/propertyvalue.hxx> class HtmlExportTest : public SwModelTestBase, public HtmlTestTools { @@ -110,6 +111,8 @@ class SwHtmlDomExportTest : public SwModelTestBase, public HtmlTestTools { }; +char const DATA_DIRECTORY[] = "/sw/qa/extras/htmlexport/data/"; + DECLARE_HTMLEXPORT_ROUNDTRIP_TEST(testFdo81276, "fdo81276.html") { uno::Reference<container::XNameAccess> xPageStyles(getStyles("PageStyles")); @@ -746,6 +749,38 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testBlockQuoteReqIf) assertXPath(pDoc, "/reqif-xhtml:html/reqif-xhtml:div/reqif-xhtml:blockquote/reqif-xhtml:p", 1); } +CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testRTFOLEMimeType) +{ + // Import a document with an embedded object. + OUString aType("test/rtf"); + uno::Sequence<beans::PropertyValue> aLoadProperties = { + comphelper::makePropertyValue("FilterName", OUString("HTML (StarWriter)")), + comphelper::makePropertyValue("FilterOptions", OUString("xhtmlns=reqif-xhtml")), + }; + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "reqif-ole-data.xhtml"; + mxComponent = loadFromDesktop(aURL, "com.sun.star.text.TextDocument", aLoadProperties); + + // Export it. + uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY); + uno::Sequence<beans::PropertyValue> aStoreProperties = { + comphelper::makePropertyValue("FilterName", OUString("HTML (StarWriter)")), + comphelper::makePropertyValue("FilterOptions", OUString("xhtmlns=reqif-xhtml")), + comphelper::makePropertyValue("RTFOLEMimeType", aType), + }; + xStorable->storeToURL(maTempFile.GetURL(), aStoreProperties); + SvMemoryStream aStream; + HtmlExportTest::wrapFragment(maTempFile, aStream); + xmlDocPtr pDoc = parseXmlStream(&aStream); + CPPUNIT_ASSERT(pDoc); + + // Without the accompanying fix in place, this test would have failed with: + // - Expected: test/rtf + // - Actual : text/rtf + // i.e. the MIME type was always text/rtf, not taking the store parameter into account. + assertXPath(pDoc, "/reqif-xhtml:html/reqif-xhtml:div/reqif-xhtml:p/reqif-xhtml:object", "type", + aType); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/filter/html/htmlplug.cxx b/sw/source/filter/html/htmlplug.cxx index 5e35c8ebb6a5..36115cf4322f 100644 --- a/sw/source/filter/html/htmlplug.cxx +++ b/sw/source/filter/html/htmlplug.cxx @@ -1527,6 +1527,12 @@ Writer& OutHTML_FrameFormatOLENodeGrf( Writer& rWrt, const SwFrameFormat& rFrame SwDocShell* pDocSh = rHTMLWrt.pDoc->GetDocShell(); bool bObjectOpened = false; + OUString aRTFType = "text/rtf"; + if (!rHTMLWrt.m_aRTFOLEMimeType.isEmpty()) + { + aRTFType = rHTMLWrt.m_aRTFOLEMimeType; + } + if (rHTMLWrt.mbXHTML && pDocSh) { // Map native data to an outer <object> element. @@ -1557,7 +1563,7 @@ Writer& OutHTML_FrameFormatOLENodeGrf( Writer& rWrt, const SwFrameFormat& rFrame if (SwReqIfReader::WrapOleInRtf(*pStream, aOutStream, *pOLENd)) { // Data always wrapped in RTF. - aFileType = "text/rtf"; + aFileType = aRTFType; } } } @@ -1576,7 +1582,7 @@ Writer& OutHTML_FrameFormatOLENodeGrf( Writer& rWrt, const SwFrameFormat& rFrame if (SwReqIfReader::WrapOleInRtf(aMemory, aOutStream, *pOLENd)) { // Data always wrapped in RTF. - aFileType = "text/rtf"; + aFileType = aRTFType; } } else @@ -1603,6 +1609,10 @@ Writer& OutHTML_FrameFormatOLENodeGrf( Writer& rWrt, const SwFrameFormat& rFrame uno::Reference<beans::XPropertySet> xOutStreamProps(xInStream, uno::UNO_QUERY); if (xOutStreamProps.is()) xOutStreamProps->getPropertyValue("MediaType") >>= aFileType; + if (!aRTFType.isEmpty()) + { + aFileType = aRTFType; + } } aFileName = URIHelper::simpleNormalizedMakeRelative(rWrt.GetBaseURL(), aFileName); diff --git a/sw/source/filter/html/wrthtml.cxx b/sw/source/filter/html/wrthtml.cxx index 730b7a1ebd58..79f7e0822c14 100644 --- a/sw/source/filter/html/wrthtml.cxx +++ b/sw/source/filter/html/wrthtml.cxx @@ -79,6 +79,7 @@ #include <osl/file.hxx> #include <comphelper/scopeguard.hxx> #include <unotools/tempfile.hxx> +#include <comphelper/sequenceashashmap.hxx> #define MAX_INDENT_LEVEL 20 @@ -214,6 +215,15 @@ void SwHTMLWriter::SetupFilterOptions(SfxMedium& rMedium) mbXHTML = true; } } + + comphelper::SequenceAsHashMap aStoreMap(rMedium.GetArgs()); + auto it = aStoreMap.find("RTFOLEMimeType"); + if (it == aStoreMap.end()) + { + return; + } + + it->second >>= m_aRTFOLEMimeType; } sal_uLong SwHTMLWriter::WriteStream() diff --git a/sw/source/filter/html/wrthtml.hxx b/sw/source/filter/html/wrthtml.hxx index e1097cb23b25..ed81edd7be62 100644 --- a/sw/source/filter/html/wrthtml.hxx +++ b/sw/source/filter/html/wrthtml.hxx @@ -409,6 +409,8 @@ public: /// Tracks which text portion attributes are currently open: a which id -> open count map. std::map<sal_uInt16, int> maStartedAttributes; + OUString m_aRTFOLEMimeType; + explicit SwHTMLWriter( const OUString& rBaseURL ); virtual ~SwHTMLWriter() override; |