1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #include <cppuhelper/supportsservice.hxx>
12 #include <libstaroffice/libstaroffice.hxx>
14 #include "StarOfficeCalcImportFilter.hxx"
16 using com::sun::star::uno::Sequence
;
17 using com::sun::star::uno::XComponentContext
;
18 using com::sun::star::uno::XInterface
;
20 static bool handleEmbeddedSTOFFGraphicObject(const librevenge::RVNGBinaryData
& data
,
21 OdfDocumentHandler
* pHandler
,
22 const OdfStreamType streamType
)
24 OdgGenerator exporter
;
25 exporter
.addDocumentHandler(pHandler
, streamType
);
26 return STOFFDocument::decodeGraphic(data
, &exporter
);
29 static bool handleEmbeddedSTOFFSpreadsheetObject(const librevenge::RVNGBinaryData
& data
,
30 OdfDocumentHandler
* pHandler
,
31 const OdfStreamType streamType
)
33 OdsGenerator exporter
;
34 exporter
.addDocumentHandler(pHandler
, streamType
);
35 return STOFFDocument::decodeSpreadsheet(data
, &exporter
);
38 bool StarOfficeCalcImportFilter::doImportDocument(weld::Window
*,
39 librevenge::RVNGInputStream
& rInput
,
40 OdsGenerator
& rGenerator
, utl::MediaDescriptor
&)
42 return STOFFDocument::STOFF_R_OK
== STOFFDocument::parse(&rInput
, &rGenerator
);
45 bool StarOfficeCalcImportFilter::doDetectFormat(librevenge::RVNGInputStream
& rInput
,
49 STOFFDocument::Kind docKind
= STOFFDocument::STOFF_K_UNKNOWN
;
50 const STOFFDocument::Confidence confidence
51 = STOFFDocument::isFileFormatSupported(&rInput
, docKind
);
52 if (confidence
== STOFFDocument::STOFF_C_EXCELLENT
53 || confidence
== STOFFDocument::STOFF_C_SUPPORTED_ENCRYPTION
)
57 case STOFFDocument::STOFF_K_DATABASE
:
58 case STOFFDocument::STOFF_K_SPREADSHEET
:
59 rTypeName
= "StarOffice_Spreadsheet";
66 return !rTypeName
.isEmpty();
69 void StarOfficeCalcImportFilter::doRegisterHandlers(OdsGenerator
& rGenerator
)
71 rGenerator
.registerEmbeddedObjectHandler("image/stoff-odg", &handleEmbeddedSTOFFGraphicObject
);
72 rGenerator
.registerEmbeddedObjectHandler("image/stoff-ods",
73 &handleEmbeddedSTOFFSpreadsheetObject
);
77 OUString SAL_CALL
StarOfficeCalcImportFilter::getImplementationName()
79 return u
"org.libreoffice.comp.Calc.StarOfficeCalcImportFilter"_ustr
;
82 sal_Bool SAL_CALL
StarOfficeCalcImportFilter::supportsService(const OUString
& rServiceName
)
84 return cppu::supportsService(this, rServiceName
);
87 Sequence
<OUString
> SAL_CALL
StarOfficeCalcImportFilter::getSupportedServiceNames()
89 return { u
"com.sun.star.document.ImportFilter"_ustr
,
90 u
"com.sun.star.document.ExtendedTypeDetection"_ustr
};
93 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
94 org_libreoffice_comp_Calc_StarOfficeCalcImportFilter_get_implementation(
95 css::uno::XComponentContext
* const context
, const css::uno::Sequence
<css::uno::Any
>&)
97 return cppu::acquire(new StarOfficeCalcImportFilter(context
));
100 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */