Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / writerperfect / source / writer / MWAWImportFilter.cxx
blob2b06ea163cbd2aba619860e6a0e9bcd419e9c02c
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 <cppuhelper/supportsservice.hxx>
14 #include <libmwaw/libmwaw.hxx>
16 #include "MWAWImportFilter.hxx"
18 using com::sun::star::uno::Sequence;
19 using com::sun::star::uno::XInterface;
20 using com::sun::star::uno::RuntimeException;
21 using com::sun::star::uno::XComponentContext;
23 static bool handleEmbeddedMWAWGraphicObject(const librevenge::RVNGBinaryData &data, OdfDocumentHandler *pHandler, const OdfStreamType streamType)
25 OdgGenerator exporter;
26 exporter.addDocumentHandler(pHandler, streamType);
27 return MWAWDocument::decodeGraphic(data, &exporter);
30 static bool handleEmbeddedMWAWSpreadsheetObject(const librevenge::RVNGBinaryData &data, OdfDocumentHandler *pHandler, const OdfStreamType streamType)
32 OdsGenerator exporter;
33 exporter.registerEmbeddedObjectHandler("image/mwaw-odg", &handleEmbeddedMWAWGraphicObject);
34 exporter.addDocumentHandler(pHandler, streamType);
35 return MWAWDocument::decodeSpreadsheet(data, &exporter);
38 bool MWAWImportFilter::doImportDocument(librevenge::RVNGInputStream &rInput, OdtGenerator &rGenerator, utl::MediaDescriptor &)
40 return MWAWDocument::MWAW_R_OK == MWAWDocument::parse(&rInput, &rGenerator);
43 bool MWAWImportFilter::doDetectFormat(librevenge::RVNGInputStream &rInput, OUString &rTypeName)
45 rTypeName.clear();
47 MWAWDocument::Type docType = MWAWDocument::MWAW_T_UNKNOWN;
48 MWAWDocument::Kind docKind = MWAWDocument::MWAW_K_UNKNOWN;
49 const MWAWDocument::Confidence confidence = MWAWDocument::isFileFormatSupported(&rInput, docType, docKind);
51 if (confidence == MWAWDocument::MWAW_C_EXCELLENT)
53 if (docKind == MWAWDocument::MWAW_K_TEXT)
55 switch (docType)
57 case MWAWDocument::MWAW_T_CLARISWORKS:
58 rTypeName = "writer_ClarisWorks";
59 break;
60 case MWAWDocument::MWAW_T_MACWRITE:
61 case MWAWDocument::MWAW_T_MACWRITEPRO:
62 rTypeName = "writer_MacWrite";
63 break;
64 case MWAWDocument::MWAW_T_MARINERWRITE:
65 rTypeName = "writer_Mariner_Write";
66 break;
67 case MWAWDocument::MWAW_T_MICROSOFTWORD:
68 rTypeName = "writer_Mac_Word";
69 break;
70 case MWAWDocument::MWAW_T_MICROSOFTWORKS:
71 rTypeName = "writer_Mac_Works";
72 break;
73 case MWAWDocument::MWAW_T_WRITENOW:
74 rTypeName = "writer_WriteNow";
75 break;
76 default:
77 rTypeName = "MWAW_Text_Document";
78 break;
83 return !rTypeName.isEmpty();
86 void MWAWImportFilter::doRegisterHandlers(OdtGenerator &rGenerator)
88 rGenerator.registerEmbeddedObjectHandler("image/mwaw-odg", &handleEmbeddedMWAWGraphicObject);
89 rGenerator.registerEmbeddedObjectHandler("image/mwaw-ods", &handleEmbeddedMWAWSpreadsheetObject);
92 // XServiceInfo
93 OUString SAL_CALL MWAWImportFilter::getImplementationName()
94 throw (RuntimeException, std::exception)
96 return OUString("com.sun.star.comp.Writer.MWAWImportFilter");
99 sal_Bool SAL_CALL MWAWImportFilter::supportsService(const OUString &rServiceName)
100 throw (RuntimeException, std::exception)
102 return cppu::supportsService(this, rServiceName);
105 Sequence< OUString > SAL_CALL MWAWImportFilter::getSupportedServiceNames()
106 throw (RuntimeException, std::exception)
108 Sequence < OUString > aRet(2);
109 OUString *pArray = aRet.getArray();
110 pArray[0] = "com.sun.star.document.ImportFilter";
111 pArray[1] = "com.sun.star.document.ExtendedTypeDetection";
112 return aRet;
115 extern "C"
116 SAL_DLLPUBLIC_EXPORT css::uno::XInterface *SAL_CALL
117 com_sun_star_comp_Writer_MWAWImportFilter_get_implementation(
118 css::uno::XComponentContext *const context,
119 const css::uno::Sequence<css::uno::Any> &)
121 return cppu::acquire(new MWAWImportFilter(context));
124 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */