summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2021-06-30 16:33:48 +0900
committerTomaž Vajngerl <quikee@gmail.com>2021-09-01 05:10:03 +0200
commit551a36a058faea1b66c411bf346772af8be36afd (patch)
treedb204212963990a12a65b2e2f693a5772ad3f568 /sw
parente9e83f118413041d73066b45795ab73ae3c5d25c (diff)
indexing: add indexing export as an export filter for Writer
Change-Id: I26157a8ffeee80b03866569d3d3cec2a34fe377d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118144 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com> (cherry picked from commit 95b06d3aa514ce83f82fd538d1731fc6363e4b8a) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121107 Tested-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'sw')
-rw-r--r--sw/Library_sw.mk1
-rw-r--r--sw/source/filter/inc/IndexingExportFilter.hxx68
-rw-r--r--sw/source/filter/indexing/IndexingExportFilter.cxx63
-rw-r--r--sw/util/sw.component4
4 files changed, 136 insertions, 0 deletions
diff --git a/sw/Library_sw.mk b/sw/Library_sw.mk
index 616b34f44b41..1c5884008c23 100644
--- a/sw/Library_sw.mk
+++ b/sw/Library_sw.mk
@@ -570,6 +570,7 @@ $(eval $(call gb_Library_add_exception_objects,sw,\
sw/source/filter/xml/xmltexte \
sw/source/filter/xml/xmltexti \
sw/source/filter/indexing/IndexingExport \
+ sw/source/filter/indexing/IndexingExportFilter \
sw/source/uibase/app/appenv \
sw/source/uibase/app/apphdl \
sw/source/uibase/app/applab \
diff --git a/sw/source/filter/inc/IndexingExportFilter.hxx b/sw/source/filter/inc/IndexingExportFilter.hxx
new file mode 100644
index 000000000000..82c56dfa9a61
--- /dev/null
+++ b/sw/source/filter/inc/IndexingExportFilter.hxx
@@ -0,0 +1,68 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#pragma once
+
+#include <com/sun/star/document/XFilter.hpp>
+#include <com/sun/star/document/XExporter.hpp>
+#include <com/sun/star/lang/XInitialization.hpp>
+#include <com/sun/star/lang/XServiceInfo.hpp>
+#include <cppuhelper/implbase.hxx>
+#include <cppuhelper/supportsservice.hxx>
+
+namespace sw
+{
+class IndexingExportFilter final
+ : public cppu::WeakImplHelper<css::document::XFilter, css::document::XExporter,
+ css::lang::XInitialization, css::lang::XServiceInfo>
+{
+private:
+ css::uno::Reference<css::lang::XComponent> m_xSourceDocument;
+
+public:
+ IndexingExportFilter() {}
+
+ // XFilter
+ virtual sal_Bool SAL_CALL
+ filter(const css::uno::Sequence<css::beans::PropertyValue>& aDescriptor) override;
+
+ virtual void SAL_CALL cancel() override {}
+
+ // XExporter
+ virtual void SAL_CALL
+ setSourceDocument(const css::uno::Reference<css::lang::XComponent>& xDocument) override
+ {
+ m_xSourceDocument = xDocument;
+ }
+
+ // XInitialization
+ virtual void SAL_CALL
+ initialize(const css::uno::Sequence<css::uno::Any>& /*aArguments*/) override
+ {
+ }
+
+ // XServiceInfo
+ virtual OUString SAL_CALL getImplementationName() override
+ {
+ return "com.sun.star.comp.Writer.IndexingExportFilter";
+ }
+
+ virtual sal_Bool SAL_CALL supportsService(OUString const& rServiceName) override
+ {
+ return cppu::supportsService(this, rServiceName);
+ }
+
+ virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override
+ {
+ return { "com.sun.star.document.ExportFilter" };
+ }
+};
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/indexing/IndexingExportFilter.cxx b/sw/source/filter/indexing/IndexingExportFilter.cxx
new file mode 100644
index 000000000000..52488782aaf9
--- /dev/null
+++ b/sw/source/filter/indexing/IndexingExportFilter.cxx
@@ -0,0 +1,63 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <IndexingExportFilter.hxx>
+#include <IndexingExport.hxx>
+
+#include <unotxdoc.hxx>
+#include <docsh.hxx>
+
+#include <unotools/mediadescriptor.hxx>
+#include <unotools/ucbstreamhelper.hxx>
+#include <comphelper/servicehelper.hxx>
+
+#include <com/sun/star/io/XOutputStream.hpp>
+#include <svl/outstrm.hxx>
+
+using namespace css;
+
+namespace sw
+{
+sal_Bool IndexingExportFilter::filter(const uno::Sequence<beans::PropertyValue>& aDescriptor)
+{
+ bool bReturn = false;
+
+ utl::MediaDescriptor aMediaDesc = aDescriptor;
+
+ // Actually get the SwRootFrame to call dumpAsXml
+ auto pXTextDocument
+ = comphelper::getUnoTunnelImplementation<SwXTextDocument>(m_xSourceDocument);
+ if (pXTextDocument)
+ {
+ uno::Reference<io::XOutputStream> xOutputStream = aMediaDesc.getUnpackedValueOrDefault(
+ utl::MediaDescriptor::PROP_OUTPUTSTREAM(), uno::Reference<io::XOutputStream>());
+
+ std::unique_ptr<SvStream> pStream(new SvOutputStream(xOutputStream));
+ SwDocShell* pShell = pXTextDocument->GetDocShell();
+ SwDoc* pDoc = pShell->GetDoc();
+ if (pDoc)
+ {
+ IndexingExport aIndexingExport(*pStream, pDoc);
+ bReturn = aIndexingExport.runExport();
+ }
+ }
+
+ return bReturn;
+}
+
+} // end namespace sw
+
+extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
+com_sun_star_comp_Writer_IndexingExportFilter_get_implementation(
+ css::uno::XComponentContext*, css::uno::Sequence<css::uno::Any> const&)
+{
+ return cppu::acquire(new sw::IndexingExportFilter());
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/util/sw.component b/sw/util/sw.component
index f4ad4f7e3339..e05a865a6471 100644
--- a/sw/util/sw.component
+++ b/sw/util/sw.component
@@ -151,6 +151,10 @@
constructor="com_sun_star_util_comp_FinalThreadManager_get_implementation">
<service name="com.sun.star.util.JobManager"/>
</implementation>
+ <implementation name="com.sun.star.comp.Writer.IndexingExportFilter"
+ constructor="com_sun_star_comp_Writer_IndexingExportFilter_get_implementation">
+ <service name="com.sun.star.comp.Writer.IndexingExportFilter"/>
+ </implementation>
<implementation name="com.sun.star.comp.Writer.LayoutDump"
constructor="com_sun_star_comp_Writer_LayoutDump_get_implementation">
<service name="com.sun.star.comp.Writer.LayoutDump"/>