From c6726bdbd2143ae2875f3373b07b23611eb263d7 Mon Sep 17 00:00:00 2001 From: Markus Mohrhard Date: Sun, 27 Sep 2015 07:14:52 +0200 Subject: make gnumeric xml a real LibreOffice filter format Change-Id: I502f4610718b5c1914a54346c46d4f998c4d370f --- filter/Configuration_filter.mk | 2 + .../config/fragments/filters/calc_Gnumeric.xcu | 29 ++++++ .../config/fragments/types/calc_Gnumeric.xcu | 17 ++++ framework/source/loadenv/loadenv.cxx | 7 -- sc/Library_scfilt.mk | 1 + sc/source/filter/orcus/filterdetect.cxx | 111 +++++++++++++++++++++ sc/util/scfilt.component | 4 + 7 files changed, 164 insertions(+), 7 deletions(-) create mode 100644 filter/source/config/fragments/filters/calc_Gnumeric.xcu create mode 100644 filter/source/config/fragments/types/calc_Gnumeric.xcu create mode 100644 sc/source/filter/orcus/filterdetect.cxx diff --git a/filter/Configuration_filter.mk b/filter/Configuration_filter.mk index 4ff9855000eb..1f7280789091 100644 --- a/filter/Configuration_filter.mk +++ b/filter/Configuration_filter.mk @@ -486,6 +486,7 @@ $(eval $(call filter_Configuration_add_types,fcfg_langpack,fcfg_calc_types.xcu,f calc_HTML \ generic_HTML \ generic_Text \ + calc_Gnumeric \ calc_Lotus \ calc_QPro \ calc_MS_Excel_40 \ @@ -545,6 +546,7 @@ $(eval $(call filter_Configuration_add_filters,fcfg_langpack,fcfg_calc_filters.x dBase \ calc8 \ calc8_template \ + calc_Gnumeric \ calc_MS_Excel_2007_XML \ calc_MS_Excel_2007_VBA_XML \ calc_MS_Excel_2007_XML_Template \ diff --git a/filter/source/config/fragments/filters/calc_Gnumeric.xcu b/filter/source/config/fragments/filters/calc_Gnumeric.xcu new file mode 100644 index 000000000000..421061516c80 --- /dev/null +++ b/filter/source/config/fragments/filters/calc_Gnumeric.xcu @@ -0,0 +1,29 @@ + + + IMPORT ALIEN 3RDPARTYFILTER PREFERRED + + + + Gnumeric XML + + com.sun.star.sheet.SpreadsheetDocument + + Gnumeric Spreadsheet + + diff --git a/filter/source/config/fragments/types/calc_Gnumeric.xcu b/filter/source/config/fragments/types/calc_Gnumeric.xcu new file mode 100644 index 000000000000..4c158cc34cb0 --- /dev/null +++ b/filter/source/config/fragments/types/calc_Gnumeric.xcu @@ -0,0 +1,17 @@ + + + com.sun.star.comp.sc.OrcusFilterDetect + + gnumeric gnm + application/x-gnumeric + false + Gnumeric Spreadsheet + Gnumeric Spreadsheet + + diff --git a/framework/source/loadenv/loadenv.cxx b/framework/source/loadenv/loadenv.cxx index aca4c09eea95..2a7e6e8973ae 100644 --- a/framework/source/loadenv/loadenv.cxx +++ b/framework/source/loadenv/loadenv.cxx @@ -685,13 +685,6 @@ bool queryOrcusTypeAndFilter(const uno::Sequence& rDescrip // exists) in order to find a usable loader. Exploit it as a temporary // hack. - if (aURL.endsWith(".gnumeric")) - { - rType = "generic_Text"; - rFilter = "gnumeric"; - return true; - } - // depending on the experimental mode uno::Reference< uno::XComponentContext > xContext = comphelper::getProcessComponentContext(); if (!xContext.is() || !officecfg::Office::Common::Misc::ExperimentalMode::get(xContext)) diff --git a/sc/Library_scfilt.mk b/sc/Library_scfilt.mk index ed9f4357a7e3..74f2ce5321d8 100644 --- a/sc/Library_scfilt.mk +++ b/sc/Library_scfilt.mk @@ -236,6 +236,7 @@ $(eval $(call gb_Library_add_exception_objects,scfilt,\ sc/source/filter/orcus/interface \ sc/source/filter/orcus/orcusfiltersimpl \ sc/source/filter/orcus/xmlcontext \ + sc/source/filter/orcus/filterdetect \ )) endif diff --git a/sc/source/filter/orcus/filterdetect.cxx b/sc/source/filter/orcus/filterdetect.cxx new file mode 100644 index 000000000000..8c84a5d99cd4 --- /dev/null +++ b/sc/source/filter/orcus/filterdetect.cxx @@ -0,0 +1,111 @@ +/* -*- 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 +#include +#include +#include +#include + +#include + +#include + +#include + +namespace { + +class OrcusFormatDetect : public ::cppu::WeakImplHelper< + ::com::sun::star::document::XExtendedFilterDetection, + ::com::sun::star::lang::XServiceInfo > +{ +public: + explicit OrcusFormatDetect(); + virtual ~OrcusFormatDetect(); + + virtual OUString SAL_CALL getImplementationName() + throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE; + + virtual sal_Bool SAL_CALL supportsService(const OUString& rServiceName) + throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE; + + virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() + throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE; + + virtual OUString SAL_CALL + detect( ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& rMediaDescSeq ) + throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE; + +private: +}; + +OrcusFormatDetect::OrcusFormatDetect() +{ +} + +OrcusFormatDetect::~OrcusFormatDetect() +{ +} + +OUString OrcusFormatDetect::getImplementationName() + throw( ::com::sun::star::uno::RuntimeException, std::exception ) +{ + return OUString(""); +} + +sal_Bool OrcusFormatDetect::supportsService(const OUString& /*rServiceName*/) + throw( ::com::sun::star::uno::RuntimeException, std::exception ) +{ + return false; +} + +css::uno::Sequence OrcusFormatDetect::getSupportedServiceNames() + throw( ::com::sun::star::uno::RuntimeException, std::exception ) +{ + return css::uno::Sequence(); +} + +OUString OrcusFormatDetect::detect(css::uno::Sequence& rMediaDescSeq) + throw( ::com::sun::star::uno::RuntimeException, std::exception ) +{ + utl::MediaDescriptor aMediaDescriptor( rMediaDescSeq ); + bool bAborted = aMediaDescriptor.getUnpackedValueOrDefault(utl::MediaDescriptor::PROP_ABORTED(), false); + if (bAborted) + return OUString(); + + css::uno::Reference xInputStream(aMediaDescriptor[utl::MediaDescriptor::PROP_INPUTSTREAM()], css::uno::UNO_QUERY ); + + static const sal_Int32 nBytes = 4096; + css::uno::Sequence aSeq(nBytes); + bool bEnd = false; + OStringBuffer aContent; + while(!bEnd) + { + sal_Int32 nReadBytes = xInputStream->readBytes(aSeq, nBytes); + bEnd = !(nReadBytes == nBytes); + aContent.append(reinterpret_cast(aSeq.getConstArray()), nReadBytes); + } + + orcus::format_t eFormat = orcus::detect(reinterpret_cast(aContent.getStr()), aContent.getLength()); + if (eFormat == orcus::format_gnumeric) + return OUString("Gnumeric XML"); + + return OUString(); +} + +} + +extern "C" SAL_DLLPUBLIC_EXPORT ::com::sun::star::uno::XInterface* SAL_CALL +com_sun_star_comp_oox_sc_OrcusFormatDetect_get_implementation(::com::sun::star::uno::XComponentContext* , + ::com::sun::star::uno::Sequence const &) +{ + return cppu::acquire(new OrcusFormatDetect()); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/util/scfilt.component b/sc/util/scfilt.component index 42227f49d293..0df939fcfd23 100644 --- a/sc/util/scfilt.component +++ b/sc/util/scfilt.component @@ -28,4 +28,8 @@ constructor="com_sun_star_comp_oox_xls_FormulaParser_get_implementation"> + + + -- cgit