From 832e2019a9c45b1e605a87dcfec2143f03bde97f Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Mon, 19 Oct 2015 09:21:02 +0200 Subject: tdf#94374 DOCX import: allow insert -> object -> document MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (cherry picked from commit 50d48709af3406eb270e5357f5d2cc6a218337a9) Conflicts: sw/qa/extras/ooxmlimport/ooxmlimport.cxx Change-Id: I977930d59ef1ae9ae8bd2dfa9a7f3816c46d982c Reviewed-on: https://gerrit.libreoffice.org/19758 Tested-by: Jenkins Reviewed-by: Caolán McNamara Tested-by: Caolán McNamara (cherry picked from commit 36fa2b8cf538baee272bf91da3d6cda2da6a392c) --- sw/qa/extras/ooxmlimport/data/hello.docx | Bin 0 -> 12578 bytes sw/qa/extras/ooxmlimport/data/tdf94374.docx | Bin 0 -> 12578 bytes sw/qa/extras/ooxmlimport/ooxmlimport.cxx | 30 ++++++++++++++++++++++++++++ writerfilter/source/filter/WriterFilter.cxx | 3 ++- 4 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 sw/qa/extras/ooxmlimport/data/hello.docx create mode 100644 sw/qa/extras/ooxmlimport/data/tdf94374.docx diff --git a/sw/qa/extras/ooxmlimport/data/hello.docx b/sw/qa/extras/ooxmlimport/data/hello.docx new file mode 100644 index 000000000000..d5d8d43ebdac Binary files /dev/null and b/sw/qa/extras/ooxmlimport/data/hello.docx differ diff --git a/sw/qa/extras/ooxmlimport/data/tdf94374.docx b/sw/qa/extras/ooxmlimport/data/tdf94374.docx new file mode 100644 index 000000000000..d5d8d43ebdac Binary files /dev/null and b/sw/qa/extras/ooxmlimport/data/tdf94374.docx differ diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx index 1668defeff33..8a186ef4e793 100644 --- a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx +++ b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx @@ -66,6 +66,8 @@ #include #include #include +#include +#include #include #include #include @@ -75,6 +77,7 @@ #include #include #include +#include #include @@ -96,6 +99,24 @@ public: if (OString(filename) == "smartart.docx" || OString(filename) == "strict-smartart.docx" || OString(filename) == "fdo87488.docx") SvtFilterOptions::Get().SetSmartArt2Shape(false); } +protected: + /// Copy&paste helper. + bool paste(const OUString& rFilename, const uno::Reference& xTextRange) + { + uno::Reference xFilter(m_xSFactory->createInstance("com.sun.star.comp.Writer.WriterFilter"), uno::UNO_QUERY_THROW); + uno::Reference xImporter(xFilter, uno::UNO_QUERY_THROW); + xImporter->setTargetDocument(mxComponent); + uno::Sequence aDescriptor(3); + aDescriptor[0].Name = "InputStream"; + SvStream* pStream = utl::UcbStreamHelper::CreateStream(getURLFromSrc("/sw/qa/extras/ooxmlimport/data/") + rFilename, StreamMode::READ); + uno::Reference xStream(new utl::OStreamWrapper(*pStream)); + aDescriptor[0].Value <<= xStream; + aDescriptor[1].Name = "InsertMode"; + aDescriptor[1].Value <<= sal_True; + aDescriptor[2].Name = "TextInsertModeRange"; + aDescriptor[2].Value <<= xTextRange; + return xFilter->filter(aDescriptor); + } }; class FailTest : public Test @@ -2806,6 +2827,15 @@ DECLARE_OOXMLIMPORT_TEST(testTdf89165, "tdf89165.docx") // This must not hang in layout } +DECLARE_OOXMLIMPORT_TEST(testTdf94374, "hello.docx") +{ + uno::Reference xTextDocument(mxComponent, uno::UNO_QUERY); + uno::Reference xText(xTextDocument->getText(), uno::UNO_QUERY); + uno::Reference xEnd = xText->getEnd(); + // This failed: it wasn't possible to insert a DOCX document into an existing Writer one. + CPPUNIT_ASSERT(paste("tdf94374.docx", xEnd)); +} + #endif CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/writerfilter/source/filter/WriterFilter.cxx b/writerfilter/source/filter/WriterFilter.cxx index a2f289ad7903..546b852f8060 100644 --- a/writerfilter/source/filter/WriterFilter.cxx +++ b/writerfilter/source/filter/WriterFilter.cxx @@ -171,8 +171,9 @@ sal_Bool WriterFilter::filter(const uno::Sequence< beans::PropertyValue >& aDesc return sal_False; writerfilter::dmapper::SourceDocumentType eType = writerfilter::dmapper::SourceDocumentType::OOXML; + uno::Reference xInsertTextRange = aMediaDesc.getUnpackedValueOrDefault("TextInsertModeRange", uno::Reference()); writerfilter::Stream::Pointer_t pStream( - writerfilter::dmapper::DomainMapperFactory::createMapper(m_xContext, xInputStream, m_xDstDoc, bRepairStorage, eType, uno::Reference(), aMediaDesc)); + writerfilter::dmapper::DomainMapperFactory::createMapper(m_xContext, xInputStream, m_xDstDoc, bRepairStorage, eType, xInsertTextRange, aMediaDesc)); //create the tokenizer and domain mapper writerfilter::ooxml::OOXMLStream::Pointer_t pDocStream = writerfilter::ooxml::OOXMLDocumentFactory::createStream(m_xContext, xInputStream, bRepairStorage); uno::Reference xStatusIndicator = aMediaDesc.getUnpackedValueOrDefault(utl::MediaDescriptor::PROP_STATUSINDICATOR(), uno::Reference()); -- cgit v1.2.3