summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorManfred Blume <manfred.blume@cib.de>2017-08-23 18:45:00 +0200
committerThorsten Behrens <Thorsten.Behrens@CIB.de>2017-08-28 00:48:59 +0200
commit9600f5179795380749aa5a7c9fa0bf5387d2b95f (patch)
tree8efc938fdb885691c9c4b21e00aa83dd0da6be5a /sw
parente002de40ca970933d44eec9601e11ea2b8080293 (diff)
fix tdf#112025 insert docx into existing document
Change-Id: I41f694bf3c2aa4edcad19a05d5dda6e87456d08f Reviewed-on: https://gerrit.libreoffice.org/41469 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
Diffstat (limited to 'sw')
-rw-r--r--sw/source/filter/docx/swdocxreader.cxx43
1 files changed, 40 insertions, 3 deletions
diff --git a/sw/source/filter/docx/swdocxreader.cxx b/sw/source/filter/docx/swdocxreader.cxx
index 25ee0567a95e..5dcbb557c63d 100644
--- a/sw/source/filter/docx/swdocxreader.cxx
+++ b/sw/source/filter/docx/swdocxreader.cxx
@@ -38,7 +38,7 @@
#include <tools/ref.hxx>
#include <unotxdoc.hxx>
#include <unotools/streamwrap.hxx>
-
+#include <unotextrange.hxx>
#define AUTOTEXT_GALLERY "autoTxt"
using namespace css;
@@ -48,9 +48,46 @@ extern "C" SAL_DLLPUBLIC_EXPORT Reader* SAL_CALL ImportDOCX()
return new SwDOCXReader;
}
-ErrCode SwDOCXReader::Read( SwDoc& /* rDoc */, const OUString& /* rBaseURL */, SwPaM& /* rPaM */, const OUString& /* FileName */ )
+ErrCode SwDOCXReader::Read(SwDoc& rDoc, const OUString& /* rBaseURL */, SwPaM& rPam, const OUString& /* FileName */ )
{
- return ERR_SWG_READ_ERROR;
+ if (!pMedium->GetInStream())
+ return ERR_SWG_READ_ERROR;
+
+ // We want to work in an empty paragraph.
+ std::shared_ptr<SwNodeIndex> pSttNdIdx(new SwNodeIndex(rDoc.GetNodes()));
+ const SwPosition* pPos = rPam.GetPoint();
+ rDoc.getIDocumentContentOperations().SplitNode(*pPos, false);
+ rDoc.SetTextFormatColl(rPam, rDoc.getIDocumentStylePoolAccess().GetTextCollFromPool(RES_POOLCOLL_STANDARD, false));
+
+ uno::Reference<lang::XMultiServiceFactory> xMultiServiceFactory(comphelper::getProcessServiceFactory());
+ uno::Reference<uno::XInterface> xInterface(xMultiServiceFactory->createInstance("com.sun.star.comp.Writer.WriterFilter"), uno::UNO_QUERY_THROW);
+
+ SwDocShell* pDocShell(rDoc.GetDocShell());
+ uno::Reference<lang::XComponent> xDstDoc(pDocShell->GetModel(), uno::UNO_QUERY_THROW);
+ uno::Reference<document::XImporter> xImporter(xInterface, uno::UNO_QUERY_THROW);
+ xImporter->setTargetDocument(xDstDoc);
+
+ const uno::Reference<text::XTextRange> xInsertTextRange = SwXTextRange::CreateXTextRange(rDoc, *rPam.GetPoint(), nullptr);
+ uno::Reference<io::XStream> xStream(new utl::OStreamWrapper(*pMedium->GetInStream()));
+ uno::Sequence<beans::PropertyValue> aDescriptor(comphelper::InitPropertySequence(
+ {
+ { "InputStream", uno::Any(xStream) },
+ { "InsertMode", uno::Any(true) },
+ { "TextInsertModeRange", uno::Any(xInsertTextRange) }
+ }));
+
+ ErrCode ret = ERRCODE_NONE;
+ uno::Reference<document::XFilter> xFilter(xInterface, uno::UNO_QUERY_THROW);
+ try
+ {
+ xFilter->filter(aDescriptor);
+ }
+ catch (uno::Exception const& e)
+ {
+ SAL_WARN("sw.docx", "SwDOCXReader::Read(): exception: " << e.Message);
+ ret = ERR_SWG_READ_ERROR;
+ }
+ return ret;
}
int SwDOCXReader::GetReaderType()