diff options
author | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2015-09-27 07:14:52 +0200 |
---|---|---|
committer | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2015-09-27 07:38:47 +0200 |
commit | c6726bdbd2143ae2875f3373b07b23611eb263d7 (patch) | |
tree | 25bc7d912d662a13c83c970c1eca657a5b90ace0 | |
parent | 3bcc1762216c2b9dff8bf5414b4930b271f038ae (diff) |
make gnumeric xml a real LibreOffice filter format
Change-Id: I502f4610718b5c1914a54346c46d4f998c4d370f
-rw-r--r-- | filter/Configuration_filter.mk | 2 | ||||
-rw-r--r-- | filter/source/config/fragments/filters/calc_Gnumeric.xcu | 29 | ||||
-rw-r--r-- | filter/source/config/fragments/types/calc_Gnumeric.xcu | 17 | ||||
-rw-r--r-- | framework/source/loadenv/loadenv.cxx | 7 | ||||
-rw-r--r-- | sc/Library_scfilt.mk | 1 | ||||
-rw-r--r-- | sc/source/filter/orcus/filterdetect.cxx | 111 | ||||
-rw-r--r-- | sc/util/scfilt.component | 4 |
7 files changed, 164 insertions, 7 deletions
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 @@ +<!-- + * 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . +--> +<node oor:name="Gnumeric Spreadsheet" oor:op="replace"> + <prop oor:name="Flags"><value>IMPORT ALIEN 3RDPARTYFILTER PREFERRED</value></prop> + <prop oor:name="UIComponent"/> + <prop oor:name="FilterService"/> + <prop oor:name="UserData"/> + <prop oor:name="Type"><value>Gnumeric XML</value></prop> + <prop oor:name="TemplateName"/> + <prop oor:name="DocumentService"><value>com.sun.star.sheet.SpreadsheetDocument</value></prop> + <prop oor:name="UIName"> + <value xml:lang="en-US">Gnumeric Spreadsheet</value> + </prop> +</node> 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 @@ +<!-- + * 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="Gnumeric XML" oor:op="replace" > + <prop oor:name="DetectService"><value>com.sun.star.comp.sc.OrcusFilterDetect</value></prop> + <prop oor:name="URLPattern"/> + <prop oor:name="Extensions"><value>gnumeric gnm</value></prop> + <prop oor:name="MediaType"><value>application/x-gnumeric</value></prop> + <prop oor:name="Preferred"><value>false</value></prop> + <prop oor:name="PreferredFilter"><value>Gnumeric Spreadsheet</value></prop> + <prop oor:name="UIName"><value xml:lang="en-US">Gnumeric Spreadsheet</value></prop> + <prop oor:name="ClipboardFormat"/> +</node> 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<beans::PropertyValue>& 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 <com/sun/star/document/XExtendedFilterDetection.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/io/XInputStream.hpp> +#include <cppuhelper/implbase.hxx> + +#include <unotools/mediadescriptor.hxx> + +#include <rtl/strbuf.hxx> + +#include <orcus/format_detection.hpp> + +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<OUString> OrcusFormatDetect::getSupportedServiceNames() + throw( ::com::sun::star::uno::RuntimeException, std::exception ) +{ + return css::uno::Sequence<OUString>(); +} + +OUString OrcusFormatDetect::detect(css::uno::Sequence<css::beans::PropertyValue>& 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<css::io::XInputStream> xInputStream(aMediaDescriptor[utl::MediaDescriptor::PROP_INPUTSTREAM()], css::uno::UNO_QUERY ); + + static const sal_Int32 nBytes = 4096; + css::uno::Sequence<sal_Int8> aSeq(nBytes); + bool bEnd = false; + OStringBuffer aContent; + while(!bEnd) + { + sal_Int32 nReadBytes = xInputStream->readBytes(aSeq, nBytes); + bEnd = !(nReadBytes == nBytes); + aContent.append(reinterpret_cast<const char*>(aSeq.getConstArray()), nReadBytes); + } + + orcus::format_t eFormat = orcus::detect(reinterpret_cast<const unsigned char*>(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<css::uno::Any> 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"> <service name="com.sun.star.sheet.FilterFormulaParser"/> </implementation> + <implementation name="com.sun.star.comp.sc.OrcusFormatDetect" + constructor="com_sun_star_comp_sc_OrcusFormatDetect_get_implementation"> + <service name="com.sun.star.frame.ExtendedTypeDetection"/> + </implementation> </component> |