diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2018-03-05 17:29:51 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2018-03-05 18:27:11 +0100 |
commit | c40afac8a39403f1c785151c9066becccf79078b (patch) | |
tree | 41c9af4bd074ce0c1ac6ddfc3ca4dd6ebc877e02 /sw | |
parent | 6ca3a21ba96f93b9ed729202ef5d4170daddd6f7 (diff) |
sw XHTML import: map <object> to OLE objects
This handles native data only so far, replacement image still needs
doing.
Change-Id: I5f51bc7d837309fa0b88b277c1b754e435cb4208
Reviewed-on: https://gerrit.libreoffice.org/50778
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Tested-by: Jenkins <ci@libreoffice.org>
Diffstat (limited to 'sw')
-rw-r--r-- | sw/qa/extras/htmlimport/data/reqif-ole-data.ole | 1 | ||||
-rw-r--r-- | sw/qa/extras/htmlimport/data/reqif-ole-data.xhtml | 3 | ||||
-rw-r--r-- | sw/qa/extras/htmlimport/htmlimport.cxx | 9 | ||||
-rw-r--r-- | sw/source/filter/html/htmlplug.cxx | 62 | ||||
-rw-r--r-- | sw/source/filter/html/swhtml.cxx | 8 | ||||
-rw-r--r-- | sw/source/filter/html/swhtml.hxx | 2 |
6 files changed, 73 insertions, 12 deletions
diff --git a/sw/qa/extras/htmlimport/data/reqif-ole-data.ole b/sw/qa/extras/htmlimport/data/reqif-ole-data.ole new file mode 100644 index 000000000000..d3dc23d793e2 --- /dev/null +++ b/sw/qa/extras/htmlimport/data/reqif-ole-data.ole @@ -0,0 +1 @@ +{\pict} diff --git a/sw/qa/extras/htmlimport/data/reqif-ole-data.xhtml b/sw/qa/extras/htmlimport/data/reqif-ole-data.xhtml new file mode 100644 index 000000000000..9e0cfaa378b4 --- /dev/null +++ b/sw/qa/extras/htmlimport/data/reqif-ole-data.xhtml @@ -0,0 +1,3 @@ +<reqif-xhtml:div> + <reqif-xhtml:object data="reqif-ole-data.ole" type="text/rtf"/> +</reqif-xhtml:div> diff --git a/sw/qa/extras/htmlimport/htmlimport.cxx b/sw/qa/extras/htmlimport/htmlimport.cxx index 2e42b9f841e8..03d500850edd 100644 --- a/sw/qa/extras/htmlimport/htmlimport.cxx +++ b/sw/qa/extras/htmlimport/htmlimport.cxx @@ -297,6 +297,15 @@ 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()); +} + 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 54861e8aef25..3ebef3437dde 100644 --- a/sw/source/filter/html/htmlplug.cxx +++ b/sw/source/filter/html/htmlplug.cxx @@ -49,6 +49,7 @@ #include <swerror.h> #include <ndole.hxx> #include <swtable.hxx> +#include <docsh.hxx> #include "swhtml.hxx" #include "wrthtml.hxx" #include "htmlfly.hxx" @@ -58,9 +59,12 @@ #include <com/sun/star/embed/Aspects.hpp> #include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/frame/XStorable.hpp> +#include <com/sun/star/embed/ElementModes.hpp> #include <comphelper/embeddedobjectcontainer.hxx> #include <comphelper/classids.hxx> +#include <rtl/uri.hxx> +#include <comphelper/storagehelper.hxx> using namespace com::sun::star; @@ -291,6 +295,7 @@ void SwHTMLParser::SetSpace( const Size& rPixSpace, void SwHTMLParser::InsertEmbed() { OUString aURL, aType, aName, aAlt, aId, aStyle, aClass; + OUString aData; Size aSize( USHRT_MAX, USHRT_MAX ); Size aSpace( USHRT_MAX, USHRT_MAX ); bool bPrcWidth = false, bPrcHeight = false, bHidden = false; @@ -357,6 +362,10 @@ void SwHTMLParser::InsertEmbed() if( USHRT_MAX==aSpace.Height() ) aSpace.setHeight( static_cast<long>(rOption.GetNumber()) ); break; + case HtmlOptionId::DATA: + if (m_bXHTML && aURL.isEmpty()) + aData = rOption.GetString(); + break; case HtmlOptionId::UNKNOWN: if (rOption.GetTokenString().equalsIgnoreAsciiCase( OOO_STRING_SW_HTML_O_Hidden)) @@ -399,31 +408,60 @@ void SwHTMLParser::InsertEmbed() URIHelper::SmartRel2Abs( INetURLObject(m_sBaseURL), aURL, URIHelper::GetMaybeFileHdl()) ); + bool bHasData = !aData.isEmpty(); + try + { + aURLObj.SetURL(rtl::Uri::convertRelToAbs(m_sBaseURL, aData)); + } + catch (const rtl::MalformedUriException& /*rException*/) + { + bHasData = false; + } // do not insert plugin if it has neither URL nor type bool bHasType = !aType.isEmpty(); - if( !bHasURL && !bHasType ) + if( !bHasURL && !bHasType && !bHasData ) return; // create the plug-in comphelper::EmbeddedObjectContainer aCnt; OUString aObjName; - uno::Reference < embed::XEmbeddedObject > xObj = aCnt.CreateEmbeddedObject( SvGlobalName( SO3_PLUGIN_CLASSID ).GetByteSequence(), aObjName ); - if ( svt::EmbeddedObjectRef::TryRunningState( xObj ) ) + uno::Reference < embed::XEmbeddedObject > xObj; + if (!bHasData) { - uno::Reference < beans::XPropertySet > xSet( xObj->getComponent(), uno::UNO_QUERY ); - if ( xSet.is() ) + xObj = aCnt.CreateEmbeddedObject( SvGlobalName( SO3_PLUGIN_CLASSID ).GetByteSequence(), aObjName ); + if ( svt::EmbeddedObjectRef::TryRunningState( xObj ) ) { - if( bHasURL ) - xSet->setPropertyValue("PluginURL", uno::makeAny( aURL ) ); - if( bHasType ) - xSet->setPropertyValue("PluginMimeType", uno::makeAny( aType ) ); + uno::Reference < beans::XPropertySet > xSet( xObj->getComponent(), uno::UNO_QUERY ); + if ( xSet.is() ) + { + if( bHasURL ) + xSet->setPropertyValue("PluginURL", uno::makeAny( aURL ) ); + if( bHasType ) + xSet->setPropertyValue("PluginMimeType", uno::makeAny( aType ) ); - uno::Sequence < beans::PropertyValue > aProps; - aCmdLst.FillSequence( aProps ); - xSet->setPropertyValue("PluginCommands", uno::makeAny( aProps ) ); + uno::Sequence < beans::PropertyValue > aProps; + aCmdLst.FillSequence( aProps ); + xSet->setPropertyValue("PluginCommands", uno::makeAny( aProps ) ); + } + } + } + else if (SwDocShell* pDocSh = m_xDoc->GetDocShell()) + { + // Has non-empty data attribute in XHTML: map that to an OLE object. + uno::Reference<embed::XStorage> xStorage = pDocSh->GetStorage(); + aCnt.SwitchPersistence(xStorage); + aObjName = aCnt.CreateUniqueObjectName(); + { + SvFileStream aFileStream(aURLObj.GetMainURL(INetURLObject::DecodeMechanism::NONE), + StreamMode::READ); + uno::Reference<io::XInputStream> xInStream(new utl::OStreamWrapper(aFileStream)); + uno::Reference<io::XStream> xOutStream + = xStorage->openStreamElement(aObjName, embed::ElementModes::READWRITE); + comphelper::OStorageHelper::CopyInputToOutput(xInStream, xOutStream->getOutputStream()); } + xObj = aCnt.GetEmbeddedObject(aObjName); } SfxItemSet aFrameSet( m_xDoc->GetAttrPool(), diff --git a/sw/source/filter/html/swhtml.cxx b/sw/source/filter/html/swhtml.cxx index 9e4212dbcd67..d798f0ba0a51 100644 --- a/sw/source/filter/html/swhtml.cxx +++ b/sw/source/filter/html/swhtml.cxx @@ -1413,6 +1413,11 @@ void SwHTMLParser::NextToken( HtmlTokenId nToken ) break; case HtmlTokenId::OBJECT_ON: + if (m_bXHTML) + { + InsertEmbed(); + break; + } #if HAVE_FEATURE_JAVA NewObject(); m_bCallNextToken = m_pAppletImpl!=nullptr && m_xTable; @@ -5559,7 +5564,10 @@ void SwHTMLParser::SetupFilterOptions() OUString aFilterOptions = pItem->GetValue(); const OUString aXhtmlNsKey("xhtmlns="); if (aFilterOptions.startsWith(aXhtmlNsKey)) + { SetNamespace(aFilterOptions.copy(aXhtmlNsKey.getLength())); + m_bXHTML = true; + } } namespace diff --git a/sw/source/filter/html/swhtml.hxx b/sw/source/filter/html/swhtml.hxx index d4b10d48fe8e..ffbb42d334aa 100644 --- a/sw/source/filter/html/swhtml.hxx +++ b/sw/source/filter/html/swhtml.hxx @@ -504,6 +504,8 @@ class SwHTMLParser : public SfxHTMLParser, public SwClient SfxViewFrame* m_pTempViewFrame; + bool m_bXHTML = false; + void DeleteFormImpl(); void DocumentDetected(); |