Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /* MWAWImportFilter: 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 <libmwaw/libmwaw.hxx>
16 :
17 : #include "MWAWImportFilter.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 10 : static bool handleEmbeddedMWAWGraphicObject(const librevenge::RVNGBinaryData &data, OdfDocumentHandler *pHandler, const OdfStreamType streamType)
28 : {
29 10 : OdgGenerator exporter;
30 10 : exporter.addDocumentHandler(pHandler, streamType);
31 10 : return MWAWDocument::decodeGraphic(data, &exporter);
32 : }
33 :
34 0 : static bool handleEmbeddedMWAWSpreadsheetObject(const librevenge::RVNGBinaryData &data, OdfDocumentHandler *pHandler, const OdfStreamType streamType)
35 : {
36 0 : OdsGenerator exporter;
37 0 : exporter.addDocumentHandler(pHandler, streamType);
38 0 : return MWAWDocument::decodeSpreadsheet(data, &exporter);
39 : }
40 :
41 66 : bool MWAWImportFilter::doImportDocument(librevenge::RVNGInputStream &rInput, OdtGenerator &rGenerator, utl::MediaDescriptor &)
42 : {
43 66 : return MWAWDocument::MWAW_R_OK == MWAWDocument::parse(&rInput, &rGenerator);
44 : }
45 :
46 66 : bool MWAWImportFilter::doDetectFormat(librevenge::RVNGInputStream &rInput, OUString &rTypeName)
47 : {
48 66 : rTypeName = "";
49 :
50 66 : MWAWDocument::Type docType = MWAWDocument::MWAW_T_UNKNOWN;
51 66 : MWAWDocument::Kind docKind = MWAWDocument::MWAW_K_UNKNOWN;
52 66 : const MWAWDocument::Confidence confidence = MWAWDocument::isFileFormatSupported(&rInput, docType, docKind);
53 :
54 66 : if (confidence == MWAWDocument::MWAW_C_EXCELLENT)
55 : {
56 66 : if (docKind == MWAWDocument::MWAW_K_TEXT)
57 : {
58 66 : switch (docType)
59 : {
60 : case MWAWDocument::MWAW_T_ACTA:
61 2 : rTypeName = "writer_Mac_Acta";
62 2 : break;
63 : case MWAWDocument::MWAW_T_BEAGLEWORKS:
64 2 : rTypeName = "writer_Beagle_Works";
65 2 : break;
66 : case MWAWDocument::MWAW_T_CLARISWORKS:
67 6 : rTypeName = "writer_ClarisWorks";
68 6 : break;
69 : case MWAWDocument::MWAW_T_DOCMAKER:
70 2 : rTypeName = "writer_DocMaker";
71 2 : break;
72 : case MWAWDocument::MWAW_T_EDOC:
73 2 : rTypeName = "writer_eDoc_Document";
74 2 : break;
75 : case MWAWDocument::MWAW_T_FULLWRITE:
76 4 : rTypeName = "writer_FullWrite_Professional";
77 4 : break;
78 : case MWAWDocument::MWAW_T_GREATWORKS:
79 2 : rTypeName = "writer_Great_Works";
80 2 : break;
81 : case MWAWDocument::MWAW_T_HANMACWORDJ:
82 2 : rTypeName = "writer_HanMac_Word_J";
83 2 : break;
84 : case MWAWDocument::MWAW_T_HANMACWORDK:
85 2 : rTypeName = "writer_HanMac_Word_K";
86 2 : break;
87 : case MWAWDocument::MWAW_T_LIGHTWAYTEXT:
88 2 : rTypeName = "writer_LightWayText";
89 2 : break;
90 : case MWAWDocument::MWAW_T_MACDOC:
91 2 : rTypeName = "writer_MacDoc";
92 2 : break;
93 : case MWAWDocument::MWAW_T_MACWRITE:
94 2 : rTypeName = "writer_MacWrite";
95 2 : break;
96 : case MWAWDocument::MWAW_T_MACWRITEPRO:
97 2 : rTypeName = "writer_MacWritePro";
98 2 : break;
99 : case MWAWDocument::MWAW_T_MARINERWRITE:
100 4 : rTypeName = "writer_Mariner_Write";
101 4 : break;
102 : case MWAWDocument::MWAW_T_MICROSOFTWORD:
103 6 : rTypeName = "writer_Mac_Word";
104 6 : break;
105 : case MWAWDocument::MWAW_T_MICROSOFTWORKS:
106 4 : rTypeName = "writer_Mac_Works";
107 4 : break;
108 : case MWAWDocument::MWAW_T_MINDWRITE:
109 2 : rTypeName = "writer_MindWrite";
110 2 : break;
111 : case MWAWDocument::MWAW_T_MORE:
112 2 : rTypeName = "writer_Mac_More";
113 2 : break;
114 : case MWAWDocument::MWAW_T_NISUSWRITER:
115 2 : rTypeName = "writer_Nisus_Writer";
116 2 : break;
117 : case MWAWDocument::MWAW_T_RAGTIME:
118 4 : rTypeName = "writer_Mac_RagTime";
119 4 : break;
120 : case MWAWDocument::MWAW_T_TEACHTEXT:
121 2 : rTypeName = "writer_TeachText";
122 2 : break;
123 : case MWAWDocument::MWAW_T_TEXEDIT:
124 2 : rTypeName = "writer_TexEdit";
125 2 : break;
126 : case MWAWDocument::MWAW_T_WRITENOW:
127 4 : rTypeName = "writer_WriteNow";
128 4 : break;
129 : case MWAWDocument::MWAW_T_WRITERPLUS:
130 2 : rTypeName = "writer_WriterPlus";
131 2 : break;
132 : case MWAWDocument::MWAW_T_ZWRITE:
133 0 : rTypeName = "writer_ZWrite";
134 0 : break;
135 :
136 : case MWAWDocument::MWAW_T_ADOBEILLUSTRATOR:
137 : case MWAWDocument::MWAW_T_CLARISRESOLVE:
138 : case MWAWDocument::MWAW_T_DBASE:
139 : case MWAWDocument::MWAW_T_FAMILYTREEMAKER:
140 : case MWAWDocument::MWAW_T_FILEMAKER:
141 : case MWAWDocument::MWAW_T_FOXBASE:
142 : case MWAWDocument::MWAW_T_FULLIMPACT:
143 : case MWAWDocument::MWAW_T_FULLPAINT:
144 : case MWAWDocument::MWAW_T_FRAMEMAKER:
145 : case MWAWDocument::MWAW_T_INFOGENIE:
146 : case MWAWDocument::MWAW_T_KALEIDAGRAPH:
147 : case MWAWDocument::MWAW_T_MACDRAFT:
148 : case MWAWDocument::MWAW_T_MACDRAW:
149 : case MWAWDocument::MWAW_T_MACDRAWPRO:
150 : case MWAWDocument::MWAW_T_MACPAINT:
151 : case MWAWDocument::MWAW_T_MICROSOFTFILE:
152 : case MWAWDocument::MWAW_T_MICROSOFTMULTIPLAN:
153 : case MWAWDocument::MWAW_T_OVERVUE:
154 : case MWAWDocument::MWAW_T_PAGEMAKER:
155 : case MWAWDocument::MWAW_T_PIXELPAINT:
156 : case MWAWDocument::MWAW_T_READYSETGO:
157 : case MWAWDocument::MWAW_T_SUPERPAINT:
158 : case MWAWDocument::MWAW_T_SYMPOSIUM:
159 : case MWAWDocument::MWAW_T_TRAPEZE:
160 : case MWAWDocument::MWAW_T_WINGZ:
161 : case MWAWDocument::MWAW_T_XPRESS:
162 : case MWAWDocument::MWAW_T_4DIMENSION:
163 :
164 : case MWAWDocument::MWAW_T_RESERVED1:
165 : case MWAWDocument::MWAW_T_RESERVED2:
166 : case MWAWDocument::MWAW_T_RESERVED3:
167 : case MWAWDocument::MWAW_T_RESERVED4:
168 : case MWAWDocument::MWAW_T_RESERVED5:
169 : case MWAWDocument::MWAW_T_RESERVED6:
170 : case MWAWDocument::MWAW_T_RESERVED7:
171 : case MWAWDocument::MWAW_T_RESERVED8:
172 : case MWAWDocument::MWAW_T_RESERVED9:
173 : case MWAWDocument::MWAW_T_UNKNOWN:
174 : default:
175 0 : break;
176 : }
177 : }
178 : }
179 :
180 66 : return !rTypeName.isEmpty();
181 : }
182 :
183 66 : void MWAWImportFilter::doRegisterHandlers(OdtGenerator &rGenerator)
184 : {
185 66 : rGenerator.registerEmbeddedObjectHandler("image/mwaw-odg", &handleEmbeddedMWAWGraphicObject);
186 66 : rGenerator.registerEmbeddedObjectHandler("image/mwaw-ods", &handleEmbeddedMWAWSpreadsheetObject);
187 66 : }
188 :
189 10 : OUString MWAWImportFilter_getImplementationName()
190 : throw (RuntimeException)
191 : {
192 10 : return OUString("com.sun.star.comp.Writer.MWAWImportFilter");
193 : }
194 :
195 2 : Sequence< OUString > SAL_CALL MWAWImportFilter_getSupportedServiceNames()
196 : throw (RuntimeException)
197 : {
198 2 : Sequence < OUString > aRet(2);
199 2 : OUString *pArray = aRet.getArray();
200 2 : pArray[0] = "com.sun.star.document.ImportFilter";
201 2 : pArray[1] = "com.sun.star.document.ExtendedTypeDetection";
202 2 : return aRet;
203 : }
204 :
205 2 : Reference< XInterface > SAL_CALL MWAWImportFilter_createInstance(const Reference< XComponentContext > &rContext)
206 : throw(Exception)
207 : {
208 2 : return (cppu::OWeakObject *) new MWAWImportFilter(rContext);
209 : }
210 :
211 : // XServiceInfo
212 0 : OUString SAL_CALL MWAWImportFilter::getImplementationName()
213 : throw (RuntimeException, std::exception)
214 : {
215 0 : return MWAWImportFilter_getImplementationName();
216 : }
217 0 : sal_Bool SAL_CALL MWAWImportFilter::supportsService(const OUString &rServiceName)
218 : throw (RuntimeException, std::exception)
219 : {
220 0 : return cppu::supportsService(this, rServiceName);
221 : }
222 0 : Sequence< OUString > SAL_CALL MWAWImportFilter::getSupportedServiceNames()
223 : throw (RuntimeException, std::exception)
224 : {
225 0 : return MWAWImportFilter_getSupportedServiceNames();
226 : }
227 :
228 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|