cid#1640468 Dereference after null check
[LibreOffice.git] / writerperfect / source / draw / MWAWDrawImportFilter.cxx
blob5292d2362c1e0b511d9a77eb892d5481bb963acb
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
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 "MWAWDrawImportFilter.hxx"
18 static bool handleEmbeddedMWAWGraphicObject(const librevenge::RVNGBinaryData& data,
19 OdfDocumentHandler* pHandler,
20 const OdfStreamType streamType)
22 OdgGenerator exporter;
23 exporter.addDocumentHandler(pHandler, streamType);
24 return MWAWDocument::decodeGraphic(data, &exporter);
27 static bool handleEmbeddedMWAWSpreadsheetObject(const librevenge::RVNGBinaryData& data,
28 OdfDocumentHandler* pHandler,
29 const OdfStreamType streamType)
31 OdsGenerator exporter;
32 exporter.registerEmbeddedObjectHandler("image/mwaw-odg", &handleEmbeddedMWAWGraphicObject);
33 exporter.addDocumentHandler(pHandler, streamType);
34 return MWAWDocument::decodeSpreadsheet(data, &exporter);
37 bool MWAWDrawImportFilter::doImportDocument(weld::Window*, librevenge::RVNGInputStream& rInput,
38 OdgGenerator& rGenerator, utl::MediaDescriptor&)
40 return MWAWDocument::MWAW_R_OK == MWAWDocument::parse(&rInput, &rGenerator);
43 bool MWAWDrawImportFilter::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
50 = MWAWDocument::isFileFormatSupported(&rInput, docType, docKind);
52 if (confidence == MWAWDocument::MWAW_C_EXCELLENT)
54 switch (docKind)
56 case MWAWDocument::MWAW_K_DRAW:
57 switch (docType)
59 case MWAWDocument::MWAW_T_CLARISWORKS:
60 rTypeName = "draw_ClarisWorks";
61 break;
62 default:
63 rTypeName = "MWAW_Drawing";
64 break;
66 break;
67 case MWAWDocument::MWAW_K_PAINT:
68 switch (docType)
70 case MWAWDocument::MWAW_T_CLARISWORKS:
71 rTypeName = "draw_ClarisWorks";
72 break;
73 default:
74 rTypeName = "MWAW_Bitmap";
75 break;
77 break;
78 default:
79 break;
83 return !rTypeName.isEmpty();
86 void MWAWDrawImportFilter::doRegisterHandlers(OdgGenerator& rGenerator)
88 rGenerator.registerEmbeddedObjectHandler("image/mwaw-odg", &handleEmbeddedMWAWGraphicObject);
89 rGenerator.registerEmbeddedObjectHandler("image/mwaw-ods",
90 &handleEmbeddedMWAWSpreadsheetObject);
93 // XServiceInfo
94 OUString SAL_CALL MWAWDrawImportFilter::getImplementationName()
96 return u"com.sun.star.comp.Draw.MWAWDrawImportFilter"_ustr;
99 sal_Bool SAL_CALL MWAWDrawImportFilter::supportsService(const OUString& rServiceName)
101 return cppu::supportsService(this, rServiceName);
104 css::uno::Sequence<OUString> SAL_CALL MWAWDrawImportFilter::getSupportedServiceNames()
106 return { u"com.sun.star.document.ImportFilter"_ustr,
107 u"com.sun.star.document.ExtendedTypeDetection"_ustr };
110 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
111 com_sun_star_comp_Draw_MWAWDrawImportFilter_get_implementation(
112 css::uno::XComponentContext* const context, const css::uno::Sequence<css::uno::Any>&)
114 return cppu::acquire(new MWAWDrawImportFilter(context));
117 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */