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 | |
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
-rw-r--r-- | include/sfx2/docfile.hxx | 1 | ||||
-rw-r--r-- | include/sfx2/objsh.hxx | 6 | ||||
-rw-r--r-- | sfx2/source/doc/docfile.cxx | 5 | ||||
-rw-r--r-- | sfx2/source/doc/objserv.cxx | 5 | ||||
-rw-r--r-- | sfx2/source/doc/objstor.cxx | 10 | ||||
-rw-r--r-- | sfx2/source/doc/sfxbasemodel.cxx | 2 | ||||
-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 |
10 files changed, 79 insertions, 11 deletions
diff --git a/include/sfx2/docfile.hxx b/include/sfx2/docfile.hxx index f51066a26ddc..58c17c23d57b 100644 --- a/include/sfx2/docfile.hxx +++ b/include/sfx2/docfile.hxx @@ -123,6 +123,7 @@ public: const OUString& GetOrigURL() const; SfxItemSet * GetItemSet() const; + void SetArgs(const css::uno::Sequence<css::beans::PropertyValue>& rArgs); css::uno::Sequence<css::beans::PropertyValue> GetArgs() const; void Close(); void CloseAndRelease(); diff --git a/include/sfx2/objsh.hxx b/include/sfx2/objsh.hxx index 4a1d5565d392..1f41cb430d64 100644 --- a/include/sfx2/objsh.hxx +++ b/include/sfx2/objsh.hxx @@ -722,9 +722,9 @@ public: SAL_DLLPRIVATE void SetNamedVisibility_Impl(); SAL_DLLPRIVATE bool DoSave_Impl( const SfxItemSet* pSet ); SAL_DLLPRIVATE bool Save_Impl( const SfxItemSet* pSet ); - SAL_DLLPRIVATE bool PreDoSaveAs_Impl(const OUString& rFileName, const OUString& rFiltName, SfxItemSet& rItemSet); - SAL_DLLPRIVATE bool APISaveAs_Impl(const OUString& aFileName, SfxItemSet& rItemSet); - SAL_DLLPRIVATE bool CommonSaveAs_Impl(const INetURLObject& aURL, const OUString& aFilterName, SfxItemSet& rItemSet); + SAL_DLLPRIVATE bool PreDoSaveAs_Impl(const OUString& rFileName, const OUString& rFiltName, SfxItemSet& rItemSet, const css::uno::Sequence<css::beans::PropertyValue>& rArgs); + SAL_DLLPRIVATE bool APISaveAs_Impl(const OUString& aFileName, SfxItemSet& rItemSet, const css::uno::Sequence<css::beans::PropertyValue>& rArgs); + SAL_DLLPRIVATE bool CommonSaveAs_Impl(const INetURLObject& aURL, const OUString& aFilterName, SfxItemSet& rItemSet, const css::uno::Sequence<css::beans::PropertyValue>& rArgs); SAL_DLLPRIVATE bool GeneralInit_Impl( const css::uno::Reference< css::embed::XStorage >& xStorage, bool bTypeMustBeSetAlready ); diff --git a/sfx2/source/doc/docfile.cxx b/sfx2/source/doc/docfile.cxx index 8b217620c1ad..7c20ba58d3c9 100644 --- a/sfx2/source/doc/docfile.cxx +++ b/sfx2/source/doc/docfile.cxx @@ -3057,6 +3057,11 @@ SfxMedium::SfxMedium( const uno::Sequence<beans::PropertyValue>& aArgs ) : Init_Impl(); } +void SfxMedium::SetArgs(const uno::Sequence<beans::PropertyValue>& rArgs) +{ + pImpl->m_aArgs = rArgs; +} + uno::Sequence<beans::PropertyValue> SfxMedium::GetArgs() const { return pImpl->m_aArgs; } SfxMedium::SfxMedium( const uno::Reference < embed::XStorage >& rStor, const OUString& rBaseURL, const SfxItemSet* p ) : diff --git a/sfx2/source/doc/objserv.cxx b/sfx2/source/doc/objserv.cxx index 16265c2510d5..78f2c1ba0f38 100644 --- a/sfx2/source/doc/objserv.cxx +++ b/sfx2/source/doc/objserv.cxx @@ -259,7 +259,8 @@ void SfxObjectShell::PrintState_Impl(SfxItemSet &rSet) rSet.Put( SfxBoolItem( SID_PRINTOUT, bPrinting ) ); } -bool SfxObjectShell::APISaveAs_Impl(const OUString& aFileName, SfxItemSet& rItemSet) +bool SfxObjectShell::APISaveAs_Impl(const OUString& aFileName, SfxItemSet& rItemSet, + const css::uno::Sequence<css::beans::PropertyValue>& rArgs) { bool bOk = false; @@ -304,7 +305,7 @@ bool SfxObjectShell::APISaveAs_Impl(const OUString& aFileName, SfxItemSet& rItem if ( pDocTitleItem ) getDocProperties()->setTitle( pDocTitleItem->GetValue() ); - bOk = CommonSaveAs_Impl(INetURLObject(aFileName), aFilterName, rItemSet); + bOk = CommonSaveAs_Impl(INetURLObject(aFileName), aFilterName, rItemSet, rArgs); } } diff --git a/sfx2/source/doc/objstor.cxx b/sfx2/source/doc/objstor.cxx index 0397b0614054..4a05347d3d0c 100644 --- a/sfx2/source/doc/objstor.cxx +++ b/sfx2/source/doc/objstor.cxx @@ -2577,7 +2577,9 @@ bool SfxObjectShell::Save_Impl( const SfxItemSet* pSet ) return bSaved; } -bool SfxObjectShell::CommonSaveAs_Impl(const INetURLObject& aURL, const OUString& aFilterName, SfxItemSet& rItemSet) +bool SfxObjectShell::CommonSaveAs_Impl(const INetURLObject& aURL, const OUString& aFilterName, + SfxItemSet& rItemSet, + const uno::Sequence<beans::PropertyValue>& rArgs) { if( aURL.HasError() ) { @@ -2652,7 +2654,8 @@ bool SfxObjectShell::CommonSaveAs_Impl(const INetURLObject& aURL, const OUString if ( IsDocShared() ) aTempFileURL = pMedium->GetURLObject().GetMainURL( INetURLObject::DecodeMechanism::NONE ); - if (PreDoSaveAs_Impl(aURL.GetMainURL(INetURLObject::DecodeMechanism::NONE), aFilterName, rItemSet)) + if (PreDoSaveAs_Impl(aURL.GetMainURL(INetURLObject::DecodeMechanism::NONE), aFilterName, + rItemSet, rArgs)) { // Update Data on media SfxItemSet *pSet = GetMedium()->GetItemSet(); @@ -2716,7 +2719,7 @@ bool SfxObjectShell::CommonSaveAs_Impl(const INetURLObject& aURL, const OUString return false; } -bool SfxObjectShell::PreDoSaveAs_Impl(const OUString& rFileName, const OUString& aFilterName, SfxItemSet& rItemSet) +bool SfxObjectShell::PreDoSaveAs_Impl(const OUString& rFileName, const OUString& aFilterName, SfxItemSet& rItemSet, const uno::Sequence<beans::PropertyValue>& rArgs) { // copy all items stored in the itemset of the current medium SfxAllItemSet* pMergedParams = new SfxAllItemSet( *pMedium->GetItemSet() ); @@ -2752,6 +2755,7 @@ bool SfxObjectShell::PreDoSaveAs_Impl(const OUString& rFileName, const OUString& // create a medium for the target URL SfxMedium *pNewFile = new SfxMedium( rFileName, StreamMode::READWRITE | StreamMode::SHARE_DENYWRITE | StreamMode::TRUNC, nullptr, pMergedParams ); + pNewFile->SetArgs(rArgs); const SfxBoolItem* pNoFileSync = pMergedParams->GetItem<SfxBoolItem>(SID_NO_FILE_SYNC, false); if (pNoFileSync && pNoFileSync->GetValue()) diff --git a/sfx2/source/doc/sfxbasemodel.cxx b/sfx2/source/doc/sfxbasemodel.cxx index b4b9b52593c5..601ca323262e 100644 --- a/sfx2/source/doc/sfxbasemodel.cxx +++ b/sfx2/source/doc/sfxbasemodel.cxx @@ -3008,7 +3008,7 @@ void SfxBaseModel::impl_store( const OUString& sURL m_pData->m_xDocumentProperties = xNewDocProps; } - bool bRet = m_pData->m_pObjectShell->APISaveAs_Impl(sURL, *pItemSet); + bool bRet = m_pData->m_pObjectShell->APISaveAs_Impl(sURL, *pItemSet, seqArguments); if ( bCopyTo ) { 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; |