Avoid potential negative array index access to cached text.
[LibreOffice.git] / writerperfect / source / writer / MWAWImportFilter.cxx
blob33fe2d95f222389d72e659e82d78d37ff21d0c7d
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 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 MWAWImportFilter::doImportDocument(weld::Window*, librevenge::RVNGInputStream& rInput,
38 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
50 = MWAWDocument::isFileFormatSupported(&rInput, docType, docKind);
52 if (confidence == MWAWDocument::MWAW_C_EXCELLENT)
54 if (docKind == MWAWDocument::MWAW_K_TEXT)
56 switch (docType)
58 case MWAWDocument::MWAW_T_CLARISWORKS:
59 rTypeName = "writer_ClarisWorks";
60 break;
61 case MWAWDocument::MWAW_T_MACWRITE:
62 case MWAWDocument::MWAW_T_MACWRITEPRO:
63 rTypeName = "writer_MacWrite";
64 break;
65 case MWAWDocument::MWAW_T_MARINERWRITE:
66 rTypeName = "writer_Mariner_Write";
67 break;
68 case MWAWDocument::MWAW_T_MICROSOFTWORD:
69 rTypeName = "writer_Mac_Word";
70 break;
71 case MWAWDocument::MWAW_T_MICROSOFTWORKS:
72 rTypeName = "writer_Mac_Works";
73 break;
74 case MWAWDocument::MWAW_T_WRITENOW:
75 rTypeName = "writer_WriteNow";
76 break;
77 default:
78 rTypeName = "MWAW_Text_Document";
79 break;
84 return !rTypeName.isEmpty();
87 void MWAWImportFilter::doRegisterHandlers(OdtGenerator& rGenerator)
89 rGenerator.registerEmbeddedObjectHandler("image/mwaw-odg", &handleEmbeddedMWAWGraphicObject);
90 rGenerator.registerEmbeddedObjectHandler("image/mwaw-ods",
91 &handleEmbeddedMWAWSpreadsheetObject);
94 // XServiceInfo
95 OUString SAL_CALL MWAWImportFilter::getImplementationName()
97 return "com.sun.star.comp.Writer.MWAWImportFilter";
100 sal_Bool SAL_CALL MWAWImportFilter::supportsService(const OUString& rServiceName)
102 return cppu::supportsService(this, rServiceName);
105 css::uno::Sequence<OUString> SAL_CALL MWAWImportFilter::getSupportedServiceNames()
107 return { "com.sun.star.document.ImportFilter", "com.sun.star.document.ExtendedTypeDetection" };
110 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
111 com_sun_star_comp_Writer_MWAWImportFilter_get_implementation(
112 css::uno::XComponentContext* const context, const css::uno::Sequence<css::uno::Any>&)
114 return cppu::acquire(new MWAWImportFilter(context));
117 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */