LibreOffice Module writerperfect (master) 1
EBookImportFilter.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/* EBookImportFilter: Sets up the filter, and calls DocumentCollector
3 * to do the actual filtering
4 *
5 * This file is part of the LibreOffice project.
6 *
7 * This Source Code Form is subject to the terms of the Mozilla Public
8 * License, v. 2.0. If a copy of the MPL was not distributed with this
9 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 */
11
13#include <sal/log.hxx>
14
15#include <libe-book/libe-book.h>
16
17#include "EBookImportFilter.hxx"
18
19using libebook::EBOOKDocument;
20
21bool EBookImportFilter::doImportDocument(weld::Window*, librevenge::RVNGInputStream& rInput,
22 OdtGenerator& rGenerator,
23 utl::MediaDescriptor& rDescriptor)
24{
25 OUString aFilterName;
26
27 rDescriptor[utl::MediaDescriptor::PROP_FILTERNAME] >>= aFilterName;
28 assert(!aFilterName.isEmpty());
29
30 if (aFilterName == "Palm_Text_Document")
31 {
32 return EBOOKDocument::RESULT_OK == EBOOKDocument::parse(&rInput, &rGenerator);
33 }
34 else
35 {
36 EBOOKDocument::Type type = EBOOKDocument::TYPE_UNKNOWN;
37
38 if (aFilterName == "BroadBand eBook")
39 type = EBOOKDocument::TYPE_BBEB;
40 else if (aFilterName == "FictionBook 2")
41 type = EBOOKDocument::TYPE_FICTIONBOOK2;
42 else if (aFilterName == "PalmDoc")
43 type = EBOOKDocument::TYPE_PALMDOC;
44 else if (aFilterName == "Plucker eBook")
45 type = EBOOKDocument::TYPE_PLUCKER;
46
47 if (EBOOKDocument::TYPE_UNKNOWN != type)
48 return EBOOKDocument::RESULT_OK == EBOOKDocument::parse(&rInput, &rGenerator, type);
49 }
50
51 return false;
52}
53
54bool EBookImportFilter::doDetectFormat(librevenge::RVNGInputStream& rInput, OUString& rTypeName)
55{
56 rTypeName.clear();
57
58 EBOOKDocument::Type type = EBOOKDocument::TYPE_UNKNOWN;
59
60 if (EBOOKDocument::CONFIDENCE_EXCELLENT == EBOOKDocument::isSupported(&rInput, &type))
61 {
62 switch (type)
63 {
64 case EBOOKDocument::TYPE_BBEB:
65 rTypeName = "writer_BroadBand_eBook";
66 break;
67 case EBOOKDocument::TYPE_FICTIONBOOK2:
68 rTypeName = "writer_FictionBook_2";
69 break;
70 case EBOOKDocument::TYPE_PALMDOC:
71 rTypeName = "writer_PalmDoc";
72 break;
73 case EBOOKDocument::TYPE_PLUCKER:
74 rTypeName = "writer_Plucker_eBook";
75 break;
76 case EBOOKDocument::TYPE_PEANUTPRESS:
77 case EBOOKDocument::TYPE_TEALDOC:
78 case EBOOKDocument::TYPE_ZTXT:
79 rTypeName = "Palm_Text_Document";
80 break;
81 default:
82 SAL_WARN_IF(type != EBOOKDocument::TYPE_UNKNOWN, "writerperfect",
83 "EBookImportFilter::doDetectFormat: document type "
84 << type << " detected, but ignored");
85 }
86 }
87
88 return !rTypeName.isEmpty();
89}
90
91// XServiceInfo
93{
94 return "org.libreoffice.comp.Writer.EBookImportFilter";
95}
96
97sal_Bool SAL_CALL EBookImportFilter::supportsService(const OUString& rServiceName)
98{
99 return cppu::supportsService(this, rServiceName);
100}
101
102css::uno::Sequence<OUString> SAL_CALL EBookImportFilter::getSupportedServiceNames()
103{
104 return { "com.sun.star.document.ImportFilter", "com.sun.star.document.ExtendedTypeDetection" };
105}
106
107extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
109 css::uno::XComponentContext* const context, const css::uno::Sequence<css::uno::Any>&)
110{
111 return cppu::acquire(new EBookImportFilter(context));
112}
113
114/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * org_libreoffice_comp_Writer_EBookImportFilter_get_implementation(css::uno::XComponentContext *const context, const css::uno::Sequence< css::uno::Any > &)
virtual bool doDetectFormat(librevenge::RVNGInputStream &rInput, OUString &rTypeName) override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual bool doImportDocument(weld::Window *pParent, librevenge::RVNGInputStream &rInput, OdtGenerator &rGenerator, utl::MediaDescriptor &rDescriptor) override
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual OUString SAL_CALL getImplementationName() override
static constexpr OUStringLiteral PROP_FILTERNAME
#define SAL_WARN_IF(condition, area, stream)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
unsigned char sal_Bool
ResultType type