diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2021-06-30 16:33:48 +0900 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2021-06-30 14:58:20 +0200 |
commit | 95b06d3aa514ce83f82fd538d1731fc6363e4b8a (patch) | |
tree | 6a62ef4d5e7c7d9b55aa037416ef98adf66490ea | |
parent | a876055b6f56e838114cce041d4c49aed43693f9 (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>
-rw-r--r-- | filter/Configuration_filter.mk | 2 | ||||
-rw-r--r-- | filter/source/config/cache/typedetection.cxx | 1 | ||||
-rw-r--r-- | filter/source/config/fragments/filters/writer_indexing_export.xcu | 22 | ||||
-rw-r--r-- | filter/source/config/fragments/types/writer_indexing_export_xml.xcu | 21 | ||||
-rw-r--r-- | sw/Library_sw.mk | 1 | ||||
-rw-r--r-- | sw/source/filter/inc/IndexingExportFilter.hxx | 68 | ||||
-rw-r--r-- | sw/source/filter/indexing/IndexingExportFilter.cxx | 63 | ||||
-rw-r--r-- | sw/util/sw.component | 4 |
8 files changed, 182 insertions, 0 deletions
diff --git a/filter/Configuration_filter.mk b/filter/Configuration_filter.mk index d53afa704fc9..dfeacc6a542c 100644 --- a/filter/Configuration_filter.mk +++ b/filter/Configuration_filter.mk @@ -358,6 +358,7 @@ $(eval $(call filter_Configuration_add_types,fcfg_langpack,fcfg_writer_types.xcu writer_OOXML \ writer_OOXML_Template \ writer_layout_dump_xml \ + writer_indexing_export_xml \ writer_BroadBand_eBook \ writer_FictionBook_2 \ writer_PalmDoc \ @@ -407,6 +408,7 @@ $(eval $(call filter_Configuration_add_filters,fcfg_langpack,fcfg_writer_filters OOXML_Text \ OOXML_Text_Template \ writer_layout_dump \ + writer_indexing_export \ BroadBand_eBook \ FictionBook_2 \ PalmDoc \ diff --git a/filter/source/config/cache/typedetection.cxx b/filter/source/config/cache/typedetection.cxx index 6679a5c8973d..34d0d49d5af9 100644 --- a/filter/source/config/cache/typedetection.cxx +++ b/filter/source/config/cache/typedetection.cxx @@ -273,6 +273,7 @@ int getFlatTypeRank(const OUString& rType) // Export only "writer_layout_dump_xml", + "writer_indexing_export", "graphic_HTML", // Internal use only diff --git a/filter/source/config/fragments/filters/writer_indexing_export.xcu b/filter/source/config/fragments/filters/writer_indexing_export.xcu new file mode 100644 index 000000000000..28cbe5b5b055 --- /dev/null +++ b/filter/source/config/fragments/filters/writer_indexing_export.xcu @@ -0,0 +1,22 @@ +<!-- + * 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/. + * +--> + +<node oor:name="writer_indexing_export" oor:op="replace"> + <prop oor:name="Flags"><value>EXPORT ALIEN 3RDPARTYFILTER</value></prop> + <prop oor:name="UIComponent"/> + <prop oor:name="FilterService"><value>com.sun.star.comp.Writer.IndexingExportFilter</value></prop> + <prop oor:name="UserData"><value></value></prop> + <prop oor:name="UIName"> + <value xml:lang="en-US">Writer Indexing Export XML</value> + </prop> + <prop oor:name="FileFormatVersion"><value>0</value></prop> + <prop oor:name="Type"><value>writer_indexing_export_xml</value></prop> + <prop oor:name="TemplateName"/> + <prop oor:name="DocumentService"><value>com.sun.star.text.TextDocument</value></prop> +</node> diff --git a/filter/source/config/fragments/types/writer_indexing_export_xml.xcu b/filter/source/config/fragments/types/writer_indexing_export_xml.xcu new file mode 100644 index 000000000000..4cda6e597461 --- /dev/null +++ b/filter/source/config/fragments/types/writer_indexing_export_xml.xcu @@ -0,0 +1,21 @@ +<!-- + * 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/. + * +--> + +<node oor:name="writer_indexing_export_xml" oor:op="replace" > + <prop oor:name="DetectService"/> + <prop oor:name="URLPattern"/> + <prop oor:name="Extensions"><value>xml</value></prop> + <prop oor:name="MediaType"/> + <prop oor:name="Preferred"><value>false</value></prop> + <prop oor:name="PreferredFilter"/> + <prop oor:name="UIName"> + <value>Writer Indexing Export XML</value> + </prop> + <prop oor:name="ClipboardFormat"/> +</node> diff --git a/sw/Library_sw.mk b/sw/Library_sw.mk index d85a2f563ba7..02d12d171295 100644 --- a/sw/Library_sw.mk +++ b/sw/Library_sw.mk @@ -571,6 +571,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"/> |