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
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 <com/sun/star/uno/Reference.h>
13 #include <cppuhelper/supportsservice.hxx>
15 #include <libmwaw/libmwaw.hxx>
17 #include "MWAWImportFilter.hxx"
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
;
27 static bool handleEmbeddedMWAWGraphicObject(const librevenge::RVNGBinaryData
&data
, OdfDocumentHandler
*pHandler
, const OdfStreamType streamType
)
29 OdgGenerator exporter
;
30 exporter
.addDocumentHandler(pHandler
, streamType
);
31 return MWAWDocument::decodeGraphic(data
, &exporter
);
34 static bool handleEmbeddedMWAWSpreadsheetObject(const librevenge::RVNGBinaryData
&data
, OdfDocumentHandler
*pHandler
, const OdfStreamType streamType
)
36 OdsGenerator exporter
;
37 exporter
.addDocumentHandler(pHandler
, streamType
);
38 return MWAWDocument::decodeSpreadsheet(data
, &exporter
);
41 bool MWAWImportFilter::doImportDocument(librevenge::RVNGInputStream
&rInput
, OdtGenerator
&rGenerator
, utl::MediaDescriptor
&)
43 return MWAWDocument::MWAW_R_OK
== MWAWDocument::parse(&rInput
, &rGenerator
);
46 bool MWAWImportFilter::doDetectFormat(librevenge::RVNGInputStream
&rInput
, OUString
&rTypeName
)
50 MWAWDocument::Type docType
= MWAWDocument::MWAW_T_UNKNOWN
;
51 MWAWDocument::Kind docKind
= MWAWDocument::MWAW_K_UNKNOWN
;
52 const MWAWDocument::Confidence confidence
= MWAWDocument::isFileFormatSupported(&rInput
, docType
, docKind
);
54 if (confidence
== MWAWDocument::MWAW_C_EXCELLENT
)
56 if (docKind
== MWAWDocument::MWAW_K_TEXT
)
60 case MWAWDocument::MWAW_T_ACTA
:
61 rTypeName
= "writer_Mac_Acta";
63 case MWAWDocument::MWAW_T_BEAGLEWORKS
:
64 rTypeName
= "writer_Beagle_Works";
66 case MWAWDocument::MWAW_T_CLARISWORKS
:
67 rTypeName
= "writer_ClarisWorks";
69 case MWAWDocument::MWAW_T_DOCMAKER
:
70 rTypeName
= "writer_DocMaker";
72 case MWAWDocument::MWAW_T_EDOC
:
73 rTypeName
= "writer_eDoc_Document";
75 case MWAWDocument::MWAW_T_FULLWRITE
:
76 rTypeName
= "writer_FullWrite_Professional";
78 case MWAWDocument::MWAW_T_GREATWORKS
:
79 rTypeName
= "writer_Great_Works";
81 case MWAWDocument::MWAW_T_HANMACWORDJ
:
82 rTypeName
= "writer_HanMac_Word_J";
84 case MWAWDocument::MWAW_T_HANMACWORDK
:
85 rTypeName
= "writer_HanMac_Word_K";
87 case MWAWDocument::MWAW_T_LIGHTWAYTEXT
:
88 rTypeName
= "writer_LightWayText";
90 case MWAWDocument::MWAW_T_MACDOC
:
91 rTypeName
= "writer_MacDoc";
93 case MWAWDocument::MWAW_T_MACWRITE
:
94 rTypeName
= "writer_MacWrite";
96 case MWAWDocument::MWAW_T_MACWRITEPRO
:
97 rTypeName
= "writer_MacWritePro";
99 case MWAWDocument::MWAW_T_MARINERWRITE
:
100 rTypeName
= "writer_Mariner_Write";
102 case MWAWDocument::MWAW_T_MICROSOFTWORD
:
103 rTypeName
= "writer_Mac_Word";
105 case MWAWDocument::MWAW_T_MICROSOFTWORKS
:
106 rTypeName
= "writer_Mac_Works";
108 case MWAWDocument::MWAW_T_MINDWRITE
:
109 rTypeName
= "writer_MindWrite";
111 case MWAWDocument::MWAW_T_MORE
:
112 rTypeName
= "writer_Mac_More";
114 case MWAWDocument::MWAW_T_NISUSWRITER
:
115 rTypeName
= "writer_Nisus_Writer";
117 case MWAWDocument::MWAW_T_RAGTIME
:
118 rTypeName
= "writer_Mac_RagTime";
120 case MWAWDocument::MWAW_T_TEACHTEXT
:
121 rTypeName
= "writer_TeachText";
123 case MWAWDocument::MWAW_T_TEXEDIT
:
124 rTypeName
= "writer_TexEdit";
126 case MWAWDocument::MWAW_T_WRITENOW
:
127 rTypeName
= "writer_WriteNow";
129 case MWAWDocument::MWAW_T_WRITERPLUS
:
130 rTypeName
= "writer_WriterPlus";
132 case MWAWDocument::MWAW_T_ZWRITE
:
133 rTypeName
= "writer_ZWrite";
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
:
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
:
180 return !rTypeName
.isEmpty();
183 void MWAWImportFilter::doRegisterHandlers(OdtGenerator
&rGenerator
)
185 rGenerator
.registerEmbeddedObjectHandler("image/mwaw-odg", &handleEmbeddedMWAWGraphicObject
);
186 rGenerator
.registerEmbeddedObjectHandler("image/mwaw-ods", &handleEmbeddedMWAWSpreadsheetObject
);
189 OUString
MWAWImportFilter_getImplementationName()
190 throw (RuntimeException
)
192 return OUString("com.sun.star.comp.Writer.MWAWImportFilter");
195 Sequence
< OUString
> SAL_CALL
MWAWImportFilter_getSupportedServiceNames()
196 throw (RuntimeException
)
198 Sequence
< OUString
> aRet(2);
199 OUString
*pArray
= aRet
.getArray();
200 pArray
[0] = "com.sun.star.document.ImportFilter";
201 pArray
[1] = "com.sun.star.document.ExtendedTypeDetection";
205 Reference
< XInterface
> SAL_CALL
MWAWImportFilter_createInstance(const Reference
< XComponentContext
> &rContext
)
208 return (cppu::OWeakObject
*) new MWAWImportFilter(rContext
);
212 OUString SAL_CALL
MWAWImportFilter::getImplementationName()
213 throw (RuntimeException
, std::exception
)
215 return MWAWImportFilter_getImplementationName();
217 sal_Bool SAL_CALL
MWAWImportFilter::supportsService(const OUString
&rServiceName
)
218 throw (RuntimeException
, std::exception
)
220 return cppu::supportsService(this, rServiceName
);
222 Sequence
< OUString
> SAL_CALL
MWAWImportFilter::getSupportedServiceNames()
223 throw (RuntimeException
, std::exception
)
225 return MWAWImportFilter_getSupportedServiceNames();
228 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */