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
5 * This file is part of the LibreOffice project.
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/.
12 #include <cppuhelper/supportsservice.hxx>
13 #include <sal/log.hxx>
15 #include <libe-book/libe-book.h>
17 #include "EBookImportFilter.hxx"
19 using libebook::EBOOKDocument
;
21 bool EBookImportFilter::doImportDocument(weld::Window
*, librevenge::RVNGInputStream
& rInput
,
22 OdtGenerator
& rGenerator
,
23 utl::MediaDescriptor
& rDescriptor
)
27 rDescriptor
[utl::MediaDescriptor::PROP_FILTERNAME
] >>= aFilterName
;
28 assert(!aFilterName
.isEmpty());
30 if (aFilterName
== "Palm_Text_Document")
32 return EBOOKDocument::RESULT_OK
== EBOOKDocument::parse(&rInput
, &rGenerator
);
36 EBOOKDocument::Type type
= EBOOKDocument::TYPE_UNKNOWN
;
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
;
47 if (EBOOKDocument::TYPE_UNKNOWN
!= type
)
48 return EBOOKDocument::RESULT_OK
== EBOOKDocument::parse(&rInput
, &rGenerator
, type
);
54 bool EBookImportFilter::doDetectFormat(librevenge::RVNGInputStream
& rInput
, OUString
& rTypeName
)
58 EBOOKDocument::Type type
= EBOOKDocument::TYPE_UNKNOWN
;
60 if (EBOOKDocument::CONFIDENCE_EXCELLENT
== EBOOKDocument::isSupported(&rInput
, &type
))
64 case EBOOKDocument::TYPE_BBEB
:
65 rTypeName
= "writer_BroadBand_eBook";
67 case EBOOKDocument::TYPE_FICTIONBOOK2
:
68 rTypeName
= "writer_FictionBook_2";
70 case EBOOKDocument::TYPE_PALMDOC
:
71 rTypeName
= "writer_PalmDoc";
73 case EBOOKDocument::TYPE_PLUCKER
:
74 rTypeName
= "writer_Plucker_eBook";
76 case EBOOKDocument::TYPE_PEANUTPRESS
:
77 case EBOOKDocument::TYPE_TEALDOC
:
78 case EBOOKDocument::TYPE_ZTXT
:
79 rTypeName
= "Palm_Text_Document";
82 SAL_WARN_IF(type
!= EBOOKDocument::TYPE_UNKNOWN
, "writerperfect",
83 "EBookImportFilter::doDetectFormat: document type "
84 << type
<< " detected, but ignored");
88 return !rTypeName
.isEmpty();
92 OUString SAL_CALL
EBookImportFilter::getImplementationName()
94 return u
"org.libreoffice.comp.Writer.EBookImportFilter"_ustr
;
97 sal_Bool SAL_CALL
EBookImportFilter::supportsService(const OUString
& rServiceName
)
99 return cppu::supportsService(this, rServiceName
);
102 css::uno::Sequence
<OUString
> SAL_CALL
EBookImportFilter::getSupportedServiceNames()
104 return { u
"com.sun.star.document.ImportFilter"_ustr
,
105 u
"com.sun.star.document.ExtendedTypeDetection"_ustr
};
108 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
109 org_libreoffice_comp_Writer_EBookImportFilter_get_implementation(
110 css::uno::XComponentContext
* const context
, const css::uno::Sequence
<css::uno::Any
>&)
112 return cppu::acquire(new EBookImportFilter(context
));
115 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */