Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /* MWAWDrawImportFilter: 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 : #include <libodfgen/libodfgen.hxx>
17 :
18 : #include "MWAWDrawImportFilter.hxx"
19 :
20 : using com::sun::star::uno::Sequence;
21 : using com::sun::star::uno::Reference;
22 : using com::sun::star::uno::Any;
23 : using com::sun::star::uno::XInterface;
24 : using com::sun::star::uno::Exception;
25 : using com::sun::star::uno::RuntimeException;
26 : using com::sun::star::uno::XComponentContext;
27 :
28 0 : static bool handleEmbeddedMWAWGraphicObject(const librevenge::RVNGBinaryData &data, OdfDocumentHandler *pHandler, const OdfStreamType streamType)
29 : {
30 0 : OdgGenerator exporter;
31 0 : exporter.addDocumentHandler(pHandler, streamType);
32 0 : return MWAWDocument::decodeGraphic(data, &exporter);
33 : }
34 :
35 0 : static bool handleEmbeddedMWAWSpreadsheetObject(const librevenge::RVNGBinaryData &data, OdfDocumentHandler *pHandler, const OdfStreamType streamType)
36 : {
37 0 : OdsGenerator exporter;
38 0 : exporter.addDocumentHandler(pHandler, streamType);
39 0 : return MWAWDocument::decodeSpreadsheet(data, &exporter);
40 : }
41 :
42 40 : bool MWAWDrawImportFilter::doImportDocument(librevenge::RVNGInputStream &rInput, OdgGenerator &rGenerator, utl::MediaDescriptor &)
43 : {
44 40 : return MWAWDocument::MWAW_R_OK == MWAWDocument::parse(&rInput, &rGenerator);
45 : }
46 :
47 40 : bool MWAWDrawImportFilter::doDetectFormat(librevenge::RVNGInputStream &rInput, OUString &rTypeName)
48 : {
49 40 : rTypeName = "";
50 :
51 40 : MWAWDocument::Type docType = MWAWDocument::MWAW_T_UNKNOWN;
52 40 : MWAWDocument::Kind docKind = MWAWDocument::MWAW_K_UNKNOWN;
53 40 : const MWAWDocument::Confidence confidence = MWAWDocument::isFileFormatSupported(&rInput, docType, docKind);
54 :
55 40 : if (confidence == MWAWDocument::MWAW_C_EXCELLENT)
56 : {
57 40 : if (docKind == MWAWDocument::MWAW_K_DRAW || docKind == MWAWDocument::MWAW_K_PAINT)
58 : {
59 40 : switch (docType)
60 : {
61 : case MWAWDocument::MWAW_T_BEAGLEWORKS:
62 8 : rTypeName = "draw_Beagle_Works";
63 8 : break;
64 : case MWAWDocument::MWAW_T_CLARISWORKS:
65 8 : rTypeName = "draw_ClarisWorks";
66 8 : break;
67 : case MWAWDocument::MWAW_T_GREATWORKS:
68 4 : rTypeName = "draw_Great_Works";
69 4 : break;
70 : case MWAWDocument::MWAW_T_MACDRAW:
71 4 : rTypeName = "draw_MacDraw";
72 4 : break;
73 : case MWAWDocument::MWAW_T_MACDRAWPRO:
74 2 : rTypeName = "draw_MacDrawPro";
75 2 : break;
76 : case MWAWDocument::MWAW_T_MACPAINT:
77 6 : rTypeName = "draw_MacPaint";
78 6 : break;
79 : case MWAWDocument::MWAW_T_MICROSOFTWORKS:
80 4 : rTypeName = "draw_Mac_Works";
81 4 : break;
82 : case MWAWDocument::MWAW_T_SUPERPAINT:
83 4 : rTypeName = "draw_SuperPaint";
84 4 : break;
85 :
86 : case MWAWDocument::MWAW_T_ACTA:
87 : case MWAWDocument::MWAW_T_ADOBEILLUSTRATOR:
88 : case MWAWDocument::MWAW_T_CLARISRESOLVE:
89 : case MWAWDocument::MWAW_T_DBASE:
90 : case MWAWDocument::MWAW_T_DOCMAKER:
91 : case MWAWDocument::MWAW_T_EDOC:
92 : case MWAWDocument::MWAW_T_FAMILYTREEMAKER:
93 : case MWAWDocument::MWAW_T_FILEMAKER:
94 : case MWAWDocument::MWAW_T_FOXBASE:
95 : case MWAWDocument::MWAW_T_FRAMEMAKER:
96 : case MWAWDocument::MWAW_T_FULLIMPACT:
97 : case MWAWDocument::MWAW_T_FULLPAINT:
98 : case MWAWDocument::MWAW_T_FULLWRITE:
99 : case MWAWDocument::MWAW_T_INFOGENIE:
100 : case MWAWDocument::MWAW_T_KALEIDAGRAPH:
101 : case MWAWDocument::MWAW_T_HANMACWORDJ:
102 : case MWAWDocument::MWAW_T_HANMACWORDK:
103 : case MWAWDocument::MWAW_T_LIGHTWAYTEXT:
104 : case MWAWDocument::MWAW_T_MACDOC:
105 : case MWAWDocument::MWAW_T_MACDRAFT:
106 : case MWAWDocument::MWAW_T_MACWRITE:
107 : case MWAWDocument::MWAW_T_MACWRITEPRO:
108 : case MWAWDocument::MWAW_T_MARINERWRITE:
109 : case MWAWDocument::MWAW_T_MINDWRITE:
110 : case MWAWDocument::MWAW_T_MICROSOFTFILE:
111 : case MWAWDocument::MWAW_T_MICROSOFTMULTIPLAN:
112 : case MWAWDocument::MWAW_T_MICROSOFTWORD:
113 : case MWAWDocument::MWAW_T_MORE:
114 : case MWAWDocument::MWAW_T_NISUSWRITER:
115 : case MWAWDocument::MWAW_T_OVERVUE:
116 : case MWAWDocument::MWAW_T_PAGEMAKER:
117 : case MWAWDocument::MWAW_T_PIXELPAINT:
118 : case MWAWDocument::MWAW_T_RAGTIME:
119 : case MWAWDocument::MWAW_T_READYSETGO:
120 : case MWAWDocument::MWAW_T_SYMPOSIUM:
121 : case MWAWDocument::MWAW_T_TEACHTEXT:
122 : case MWAWDocument::MWAW_T_TEXEDIT:
123 : case MWAWDocument::MWAW_T_TRAPEZE:
124 : case MWAWDocument::MWAW_T_WINGZ:
125 : case MWAWDocument::MWAW_T_WRITENOW:
126 : case MWAWDocument::MWAW_T_WRITERPLUS:
127 : case MWAWDocument::MWAW_T_XPRESS:
128 : case MWAWDocument::MWAW_T_ZWRITE:
129 : case MWAWDocument::MWAW_T_4DIMENSION:
130 :
131 : case MWAWDocument::MWAW_T_RESERVED1:
132 : case MWAWDocument::MWAW_T_RESERVED2:
133 : case MWAWDocument::MWAW_T_RESERVED3:
134 : case MWAWDocument::MWAW_T_RESERVED4:
135 : case MWAWDocument::MWAW_T_RESERVED5:
136 : case MWAWDocument::MWAW_T_RESERVED6:
137 : case MWAWDocument::MWAW_T_RESERVED7:
138 : case MWAWDocument::MWAW_T_RESERVED8:
139 : case MWAWDocument::MWAW_T_RESERVED9:
140 : case MWAWDocument::MWAW_T_UNKNOWN:
141 : default:
142 0 : break;
143 : }
144 : }
145 : }
146 :
147 40 : return !rTypeName.isEmpty();
148 : }
149 :
150 40 : void MWAWDrawImportFilter::doRegisterHandlers(OdgGenerator &rGenerator)
151 : {
152 40 : rGenerator.registerEmbeddedObjectHandler("image/mwaw-odg", &handleEmbeddedMWAWGraphicObject);
153 40 : rGenerator.registerEmbeddedObjectHandler("image/mwaw-ods", &handleEmbeddedMWAWSpreadsheetObject);
154 40 : }
155 :
156 14 : OUString MWAWDrawImportFilter_getImplementationName()
157 : throw (RuntimeException)
158 : {
159 14 : return OUString("com.sun.star.comp.Draw.MWAWDrawImportFilter");
160 : }
161 :
162 2 : Sequence< OUString > SAL_CALL MWAWDrawImportFilter_getSupportedServiceNames()
163 : throw (RuntimeException)
164 : {
165 2 : Sequence < OUString > aRet(2);
166 2 : OUString *pArray = aRet.getArray();
167 2 : pArray[0] = "com.sun.star.document.ImportFilter";
168 2 : pArray[1] = "com.sun.star.document.ExtendedTypeDetection";
169 2 : return aRet;
170 : }
171 :
172 2 : Reference< XInterface > SAL_CALL MWAWDrawImportFilter_createInstance(const Reference< XComponentContext > &rContext)
173 : throw(Exception)
174 : {
175 2 : return (cppu::OWeakObject *) new MWAWDrawImportFilter(rContext);
176 : }
177 :
178 : // XServiceInfo
179 0 : OUString SAL_CALL MWAWDrawImportFilter::getImplementationName()
180 : throw (RuntimeException, std::exception)
181 : {
182 0 : return MWAWDrawImportFilter_getImplementationName();
183 : }
184 0 : sal_Bool SAL_CALL MWAWDrawImportFilter::supportsService(const OUString &rServiceName)
185 : throw (RuntimeException, std::exception)
186 : {
187 0 : return cppu::supportsService(this, rServiceName);
188 : }
189 0 : Sequence< OUString > SAL_CALL MWAWDrawImportFilter::getSupportedServiceNames()
190 : throw (RuntimeException, std::exception)
191 : {
192 0 : return MWAWDrawImportFilter_getSupportedServiceNames();
193 : }
194 :
195 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|