Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /* MWAWPresentationImportFilter: 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 "MWAWPresentationImportFilter.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 1 : bool MWAWPresentationImportFilter::doImportDocument(librevenge::RVNGInputStream &rInput, OdpGenerator &rGenerator, utl::MediaDescriptor &)
43 : {
44 1 : return MWAWDocument::MWAW_R_OK == MWAWDocument::parse(&rInput, &rGenerator);
45 : }
46 :
47 88 : bool MWAWPresentationImportFilter::doDetectFormat(librevenge::RVNGInputStream &rInput, OUString &rTypeName)
48 : {
49 88 : rTypeName.clear();
50 :
51 88 : MWAWDocument::Type docType = MWAWDocument::MWAW_T_UNKNOWN;
52 88 : MWAWDocument::Kind docKind = MWAWDocument::MWAW_K_UNKNOWN;
53 88 : const MWAWDocument::Confidence confidence = MWAWDocument::isFileFormatSupported(&rInput, docType, docKind);
54 :
55 88 : if (confidence == MWAWDocument::MWAW_C_EXCELLENT)
56 : {
57 1 : if (docKind == MWAWDocument::MWAW_K_PRESENTATION)
58 : {
59 1 : switch (docType)
60 : {
61 : case MWAWDocument::MWAW_T_CLARISWORKS:
62 1 : rTypeName = "impress_ClarisWorks";
63 1 : break;
64 :
65 : case MWAWDocument::MWAW_T_ACTA:
66 : case MWAWDocument::MWAW_T_BEAGLEWORKS:
67 : case MWAWDocument::MWAW_T_ADOBEILLUSTRATOR:
68 : case MWAWDocument::MWAW_T_CLARISRESOLVE:
69 : case MWAWDocument::MWAW_T_DBASE:
70 : case MWAWDocument::MWAW_T_DOCMAKER:
71 : case MWAWDocument::MWAW_T_EDOC:
72 : case MWAWDocument::MWAW_T_FAMILYTREEMAKER:
73 : case MWAWDocument::MWAW_T_FILEMAKER:
74 : case MWAWDocument::MWAW_T_FOXBASE:
75 : case MWAWDocument::MWAW_T_FRAMEMAKER:
76 : case MWAWDocument::MWAW_T_FULLIMPACT:
77 : case MWAWDocument::MWAW_T_FULLPAINT:
78 : case MWAWDocument::MWAW_T_FULLWRITE:
79 : case MWAWDocument::MWAW_T_GREATWORKS:
80 : case MWAWDocument::MWAW_T_INFOGENIE:
81 : case MWAWDocument::MWAW_T_KALEIDAGRAPH:
82 : case MWAWDocument::MWAW_T_HANMACWORDJ:
83 : case MWAWDocument::MWAW_T_HANMACWORDK:
84 : case MWAWDocument::MWAW_T_LIGHTWAYTEXT:
85 : case MWAWDocument::MWAW_T_MACDOC:
86 : case MWAWDocument::MWAW_T_MACDRAFT:
87 : case MWAWDocument::MWAW_T_MACDRAW:
88 : case MWAWDocument::MWAW_T_MACDRAWPRO:
89 : case MWAWDocument::MWAW_T_MACPAINT:
90 : case MWAWDocument::MWAW_T_MACWRITE:
91 : case MWAWDocument::MWAW_T_MACWRITEPRO:
92 : case MWAWDocument::MWAW_T_MARINERWRITE:
93 : case MWAWDocument::MWAW_T_MINDWRITE:
94 : case MWAWDocument::MWAW_T_MICROSOFTFILE:
95 : case MWAWDocument::MWAW_T_MICROSOFTMULTIPLAN:
96 : case MWAWDocument::MWAW_T_MICROSOFTWORD:
97 : case MWAWDocument::MWAW_T_MICROSOFTWORKS:
98 : case MWAWDocument::MWAW_T_MORE:
99 : case MWAWDocument::MWAW_T_NISUSWRITER:
100 : case MWAWDocument::MWAW_T_OVERVUE:
101 : case MWAWDocument::MWAW_T_PAGEMAKER:
102 : case MWAWDocument::MWAW_T_PIXELPAINT:
103 : case MWAWDocument::MWAW_T_RAGTIME:
104 : case MWAWDocument::MWAW_T_READYSETGO:
105 : case MWAWDocument::MWAW_T_SUPERPAINT:
106 : case MWAWDocument::MWAW_T_SYMPOSIUM:
107 : case MWAWDocument::MWAW_T_TEACHTEXT:
108 : case MWAWDocument::MWAW_T_TEXEDIT:
109 : case MWAWDocument::MWAW_T_TRAPEZE:
110 : case MWAWDocument::MWAW_T_WINGZ:
111 : case MWAWDocument::MWAW_T_WRITENOW:
112 : case MWAWDocument::MWAW_T_WRITERPLUS:
113 : case MWAWDocument::MWAW_T_XPRESS:
114 : case MWAWDocument::MWAW_T_ZWRITE:
115 : case MWAWDocument::MWAW_T_4DIMENSION:
116 :
117 : case MWAWDocument::MWAW_T_RESERVED1:
118 : case MWAWDocument::MWAW_T_RESERVED2:
119 : case MWAWDocument::MWAW_T_RESERVED3:
120 : case MWAWDocument::MWAW_T_RESERVED4:
121 : case MWAWDocument::MWAW_T_RESERVED5:
122 : case MWAWDocument::MWAW_T_RESERVED6:
123 : case MWAWDocument::MWAW_T_RESERVED7:
124 : case MWAWDocument::MWAW_T_RESERVED8:
125 : case MWAWDocument::MWAW_T_RESERVED9:
126 : case MWAWDocument::MWAW_T_UNKNOWN:
127 : default:
128 0 : break;
129 : }
130 : }
131 : }
132 :
133 88 : return !rTypeName.isEmpty();
134 : }
135 :
136 1 : void MWAWPresentationImportFilter::doRegisterHandlers(OdpGenerator &rGenerator)
137 : {
138 1 : rGenerator.registerEmbeddedObjectHandler("image/mwaw-odg", &handleEmbeddedMWAWGraphicObject);
139 1 : rGenerator.registerEmbeddedObjectHandler("image/mwaw-ods", &handleEmbeddedMWAWSpreadsheetObject);
140 1 : }
141 :
142 13 : OUString MWAWPresentationImportFilter_getImplementationName()
143 : throw (RuntimeException)
144 : {
145 13 : return OUString("com.sun.star.comp.Impress.MWAWPresentationImportFilter");
146 : }
147 :
148 7 : Sequence< OUString > SAL_CALL MWAWPresentationImportFilter_getSupportedServiceNames()
149 : throw (RuntimeException)
150 : {
151 7 : Sequence < OUString > aRet(2);
152 7 : OUString *pArray = aRet.getArray();
153 7 : pArray[0] = "com.sun.star.document.ImportFilter";
154 7 : pArray[1] = "com.sun.star.document.ExtendedTypeDetection";
155 7 : return aRet;
156 : }
157 :
158 89 : Reference< XInterface > SAL_CALL MWAWPresentationImportFilter_createInstance(const Reference< XComponentContext > &rContext)
159 : throw(Exception)
160 : {
161 89 : return static_cast<cppu::OWeakObject *>(new MWAWPresentationImportFilter(rContext));
162 : }
163 :
164 : // XServiceInfo
165 1 : OUString SAL_CALL MWAWPresentationImportFilter::getImplementationName()
166 : throw (RuntimeException, std::exception)
167 : {
168 1 : return MWAWPresentationImportFilter_getImplementationName();
169 : }
170 0 : sal_Bool SAL_CALL MWAWPresentationImportFilter::supportsService(const OUString &rServiceName)
171 : throw (RuntimeException, std::exception)
172 : {
173 0 : return cppu::supportsService(this, rServiceName);
174 : }
175 1 : Sequence< OUString > SAL_CALL MWAWPresentationImportFilter::getSupportedServiceNames()
176 : throw (RuntimeException, std::exception)
177 : {
178 1 : return MWAWPresentationImportFilter_getSupportedServiceNames();
179 : }
180 :
181 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|