LibreOffice Module writerperfect (master) 1
StarOfficeWriterImportFilter.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 */
9
11
12#include <libstaroffice/libstaroffice.hxx>
13
14#include <sfx2/passwd.hxx>
15
17
19using com::sun::star::uno::XComponentContext;
20using com::sun::star::uno::XInterface;
21
22static bool handleEmbeddedSTOFFWriterGraphicObject(const librevenge::RVNGBinaryData& data,
23 OdfDocumentHandler* pHandler,
24 const OdfStreamType streamType)
25{
26 OdgGenerator exporter;
27 exporter.addDocumentHandler(pHandler, streamType);
28 return STOFFDocument::decodeGraphic(data, &exporter);
29}
30
31static bool handleEmbeddedSTOFFWriterSpreadsheetObject(const librevenge::RVNGBinaryData& data,
32 OdfDocumentHandler* pHandler,
33 const OdfStreamType streamType)
34{
35 OdsGenerator exporter;
36 exporter.registerEmbeddedObjectHandler("image/stoff-odg",
38 exporter.addDocumentHandler(pHandler, streamType);
39 return STOFFDocument::decodeSpreadsheet(data, &exporter);
40}
41
43 librevenge::RVNGInputStream& rInput,
44 OdtGenerator& rGenerator, utl::MediaDescriptor&)
45{
46 STOFFDocument::Kind docKind = STOFFDocument::STOFF_K_UNKNOWN;
47 const STOFFDocument::Confidence confidence
48 = STOFFDocument::isFileFormatSupported(&rInput, docKind);
49 OString aUtf8Passwd;
50 if (confidence == STOFFDocument::STOFF_C_SUPPORTED_ENCRYPTION)
51 {
52 // try to ask for a password
53 try
54 {
55 SfxPasswordDialog aPasswdDlg(pParent);
56 aPasswdDlg.SetMinLen(0);
57 if (!aPasswdDlg.run())
58 return false;
59 OUString aPasswd = aPasswdDlg.GetPassword();
60 aUtf8Passwd = OUStringToOString(aPasswd, RTL_TEXTENCODING_UTF8);
61 }
62 catch (...)
63 {
64 // ok, we will probably guess it
65 }
66 }
67 return STOFFDocument::STOFF_R_OK
68 == STOFFDocument::parse(&rInput, &rGenerator,
69 !aUtf8Passwd.isEmpty() ? aUtf8Passwd.getStr() : nullptr);
70}
71
72bool StarOfficeWriterImportFilter::doDetectFormat(librevenge::RVNGInputStream& rInput,
73 OUString& rTypeName)
74{
75 rTypeName.clear();
76
77 STOFFDocument::Kind docKind = STOFFDocument::STOFF_K_UNKNOWN;
78 const STOFFDocument::Confidence confidence
79 = STOFFDocument::isFileFormatSupported(&rInput, docKind);
80
81 if (confidence == STOFFDocument::STOFF_C_EXCELLENT
82 || confidence == STOFFDocument::STOFF_C_SUPPORTED_ENCRYPTION)
83 {
84 switch (docKind)
85 {
86 case STOFFDocument::STOFF_K_TEXT:
87 rTypeName = "StarOffice_Writer";
88 break;
89 default:
90 break;
91 }
92 }
93
94 return !rTypeName.isEmpty();
95}
96
98{
99 rGenerator.registerEmbeddedObjectHandler("image/stoff-odg",
101 rGenerator.registerEmbeddedObjectHandler("image/stoff-ods",
103}
104
105// XServiceInfo
107{
108 return "org.libreoffice.comp.Writer.StarOfficeWriterImportFilter";
109}
110
111sal_Bool SAL_CALL StarOfficeWriterImportFilter::supportsService(const OUString& rServiceName)
112{
113 return cppu::supportsService(this, rServiceName);
114}
115
117{
118 return { "com.sun.star.document.ImportFilter", "com.sun.star.document.ExtendedTypeDetection" };
119}
120
121extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
123 css::uno::XComponentContext* const context, const css::uno::Sequence<css::uno::Any>&)
124{
125 return cppu::acquire(new StarOfficeWriterImportFilter(context));
126}
127
128/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static bool handleEmbeddedSTOFFWriterGraphicObject(const librevenge::RVNGBinaryData &data, OdfDocumentHandler *pHandler, const OdfStreamType streamType)
static bool handleEmbeddedSTOFFWriterSpreadsheetObject(const librevenge::RVNGBinaryData &data, OdfDocumentHandler *pHandler, const OdfStreamType streamType)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * org_libreoffice_comp_Writer_StarOfficeWriterImportFilter_get_implementation(css::uno::XComponentContext *const context, const css::uno::Sequence< css::uno::Any > &)
OUString GetPassword() const
virtual short run() override
void SetMinLen(sal_uInt16 Len)
virtual void doRegisterHandlers(OdtGenerator &rGenerator) override
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual bool doImportDocument(weld::Window *pParent, librevenge::RVNGInputStream &rInput, OdtGenerator &rGenerator, utl::MediaDescriptor &) override
virtual bool doDetectFormat(librevenge::RVNGInputStream &rInput, OUString &rTypeName) override
virtual OUString SAL_CALL getImplementationName() override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
unsigned char sal_Bool