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 <sfx2/passwd.hxx>
16 #include "StarOfficeWriterImportFilter.hxx"
18 using com::sun::star::uno::Sequence
;
19 using com::sun::star::uno::XComponentContext
;
20 using com::sun::star::uno::XInterface
;
22 static bool handleEmbeddedSTOFFWriterGraphicObject(const librevenge::RVNGBinaryData
& data
,
23 OdfDocumentHandler
* pHandler
,
24 const OdfStreamType streamType
)
26 OdgGenerator exporter
;
27 exporter
.addDocumentHandler(pHandler
, streamType
);
28 return STOFFDocument::decodeGraphic(data
, &exporter
);
31 static bool handleEmbeddedSTOFFWriterSpreadsheetObject(const librevenge::RVNGBinaryData
& data
,
32 OdfDocumentHandler
* pHandler
,
33 const OdfStreamType streamType
)
35 OdsGenerator exporter
;
36 exporter
.registerEmbeddedObjectHandler("image/stoff-odg",
37 &handleEmbeddedSTOFFWriterGraphicObject
);
38 exporter
.addDocumentHandler(pHandler
, streamType
);
39 return STOFFDocument::decodeSpreadsheet(data
, &exporter
);
42 bool StarOfficeWriterImportFilter::doImportDocument(weld::Window
* pParent
,
43 librevenge::RVNGInputStream
& rInput
,
44 OdtGenerator
& rGenerator
, utl::MediaDescriptor
&)
46 STOFFDocument::Kind docKind
= STOFFDocument::STOFF_K_UNKNOWN
;
47 const STOFFDocument::Confidence confidence
48 = STOFFDocument::isFileFormatSupported(&rInput
, docKind
);
50 if (confidence
== STOFFDocument::STOFF_C_SUPPORTED_ENCRYPTION
)
52 // try to ask for a password
55 SfxPasswordDialog
aPasswdDlg(pParent
);
56 aPasswdDlg
.SetMinLen(0);
57 if (!aPasswdDlg
.run())
59 OUString aPasswd
= aPasswdDlg
.GetPassword();
60 aUtf8Passwd
= OUStringToOString(aPasswd
, RTL_TEXTENCODING_UTF8
);
64 // ok, we will probably guess it
67 return STOFFDocument::STOFF_R_OK
68 == STOFFDocument::parse(&rInput
, &rGenerator
,
69 !aUtf8Passwd
.isEmpty() ? aUtf8Passwd
.getStr() : nullptr);
72 bool StarOfficeWriterImportFilter::doDetectFormat(librevenge::RVNGInputStream
& rInput
,
77 STOFFDocument::Kind docKind
= STOFFDocument::STOFF_K_UNKNOWN
;
78 const STOFFDocument::Confidence confidence
79 = STOFFDocument::isFileFormatSupported(&rInput
, docKind
);
81 if (confidence
== STOFFDocument::STOFF_C_EXCELLENT
82 || confidence
== STOFFDocument::STOFF_C_SUPPORTED_ENCRYPTION
)
86 case STOFFDocument::STOFF_K_TEXT
:
87 rTypeName
= "StarOffice_Writer";
94 return !rTypeName
.isEmpty();
97 void StarOfficeWriterImportFilter::doRegisterHandlers(OdtGenerator
& rGenerator
)
99 rGenerator
.registerEmbeddedObjectHandler("image/stoff-odg",
100 &handleEmbeddedSTOFFWriterGraphicObject
);
101 rGenerator
.registerEmbeddedObjectHandler("image/stoff-ods",
102 &handleEmbeddedSTOFFWriterSpreadsheetObject
);
106 OUString SAL_CALL
StarOfficeWriterImportFilter::getImplementationName()
108 return "org.libreoffice.comp.Writer.StarOfficeWriterImportFilter";
111 sal_Bool SAL_CALL
StarOfficeWriterImportFilter::supportsService(const OUString
& rServiceName
)
113 return cppu::supportsService(this, rServiceName
);
116 Sequence
<OUString
> SAL_CALL
StarOfficeWriterImportFilter::getSupportedServiceNames()
118 return { "com.sun.star.document.ImportFilter", "com.sun.star.document.ExtendedTypeDetection" };
121 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
122 org_libreoffice_comp_Writer_StarOfficeWriterImportFilter_get_implementation(
123 css::uno::XComponentContext
* const context
, const css::uno::Sequence
<css::uno::Any
>&)
125 return cppu::acquire(new StarOfficeWriterImportFilter(context
));
128 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */