Line data Source code
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 :
12 : #include <com/sun/star/uno/Reference.h>
13 : #include <cppuhelper/supportsservice.hxx>
14 :
15 : #include <libe-book/libe-book.h>
16 :
17 : #include "EBookImportFilter.hxx"
18 :
19 : using com::sun::star::uno::Sequence;
20 : using com::sun::star::uno::Reference;
21 : using com::sun::star::uno::Any;
22 : using com::sun::star::uno::XInterface;
23 : using com::sun::star::uno::Exception;
24 : using com::sun::star::uno::RuntimeException;
25 : using com::sun::star::uno::XComponentContext;
26 :
27 : using libebook::EBOOKDocument;
28 :
29 8 : bool EBookImportFilter::doImportDocument(librevenge::RVNGInputStream &rInput, OdtGenerator &rGenerator, utl::MediaDescriptor &rDescriptor)
30 : {
31 8 : EBOOKDocument::Type type = EBOOKDocument::TYPE_UNKNOWN;
32 :
33 8 : rtl::OUString aFilterName;
34 :
35 8 : rDescriptor[utl::MediaDescriptor::PROP_FILTERNAME()] >>= aFilterName;
36 : assert(!aFilterName.isEmpty());
37 :
38 8 : if (aFilterName == "FictionBook 2")
39 4 : type = EBOOKDocument::TYPE_FICTIONBOOK2;
40 4 : else if (aFilterName == "PalmDoc")
41 2 : type = EBOOKDocument::TYPE_PALMDOC;
42 2 : else if (aFilterName == "Plucker eBook")
43 0 : type = EBOOKDocument::TYPE_PLUCKER;
44 2 : else if (aFilterName == "eReader eBook")
45 2 : type = EBOOKDocument::TYPE_PEANUTPRESS;
46 0 : else if (aFilterName == "TealDoc")
47 0 : type = EBOOKDocument::TYPE_TEALDOC;
48 0 : else if (aFilterName == "zTXT")
49 0 : type = EBOOKDocument::TYPE_ZTXT;
50 :
51 8 : if (EBOOKDocument::TYPE_UNKNOWN != type)
52 8 : return EBOOKDocument::RESULT_OK == EBOOKDocument::parse(&rInput, &rGenerator, type);
53 :
54 0 : return false;
55 : }
56 :
57 10 : bool EBookImportFilter::doDetectFormat(librevenge::RVNGInputStream &rInput, OUString &rTypeName)
58 : {
59 10 : rTypeName = "";
60 :
61 10 : EBOOKDocument::Type type = EBOOKDocument::TYPE_UNKNOWN;
62 :
63 10 : if (EBOOKDocument::CONFIDENCE_EXCELLENT == EBOOKDocument::isSupported(&rInput, &type))
64 : {
65 8 : switch (type)
66 : {
67 : case EBOOKDocument::TYPE_FICTIONBOOK2 :
68 4 : rTypeName = "writer_FictionBook_2";
69 4 : break;
70 : case EBOOKDocument::TYPE_PALMDOC :
71 2 : rTypeName = "writer_PalmDoc";
72 2 : break;
73 : case EBOOKDocument::TYPE_PLUCKER :
74 0 : rTypeName = "writer_Plucker_eBook";
75 0 : break;
76 : case EBOOKDocument::TYPE_PEANUTPRESS :
77 2 : rTypeName = "writer_eReader_eBook";
78 2 : break;
79 : case EBOOKDocument::TYPE_TEALDOC :
80 0 : rTypeName = "writer_TealDoc";
81 0 : break;
82 : case EBOOKDocument::TYPE_ZTXT :
83 0 : rTypeName = "writer_zTXT";
84 0 : break;
85 : default :
86 : SAL_WARN_IF(type != EBOOKDocument::TYPE_UNKNOWN, "writerperfect", "EBookImportFilter::doDetectFormat: document type " << type << " detected, but ignored");
87 : }
88 : }
89 :
90 10 : return !rTypeName.isEmpty();
91 : }
92 :
93 10 : OUString EBookImportFilter_getImplementationName()
94 : throw (RuntimeException)
95 : {
96 10 : return OUString("org.libreoffice.comp.Writer.EBookImportFilter");
97 : }
98 :
99 2 : Sequence< OUString > SAL_CALL EBookImportFilter_getSupportedServiceNames()
100 : throw (RuntimeException)
101 : {
102 2 : Sequence < OUString > aRet(2);
103 2 : OUString *pArray = aRet.getArray();
104 2 : pArray[0] = "com.sun.star.document.ImportFilter";
105 2 : pArray[1] = "com.sun.star.document.ExtendedTypeDetection";
106 2 : return aRet;
107 : }
108 : #undef SERVICE_NAME2
109 : #undef SERVICE_NAME1
110 :
111 2 : Reference< XInterface > SAL_CALL EBookImportFilter_createInstance(const Reference< XComponentContext > &rContext)
112 : throw(Exception)
113 : {
114 2 : return (cppu::OWeakObject *) new EBookImportFilter(rContext);
115 : }
116 :
117 : // XServiceInfo
118 0 : OUString SAL_CALL EBookImportFilter::getImplementationName()
119 : throw (RuntimeException, std::exception)
120 : {
121 0 : return EBookImportFilter_getImplementationName();
122 : }
123 0 : sal_Bool SAL_CALL EBookImportFilter::supportsService(const OUString &rServiceName)
124 : throw (RuntimeException, std::exception)
125 : {
126 0 : return cppu::supportsService(this, rServiceName);
127 : }
128 0 : Sequence< OUString > SAL_CALL EBookImportFilter::getSupportedServiceNames()
129 : throw (RuntimeException, std::exception)
130 : {
131 0 : return EBookImportFilter_getSupportedServiceNames();
132 : }
133 :
134 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|