Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /* MSWorksImportFilter: 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 <libwps/libwps.h>
16 :
17 : #include "MSWorksImportFilter.hxx"
18 :
19 : using com::sun::star::uno::Sequence;
20 : using com::sun::star::uno::Reference;
21 : using com::sun::star::uno::Any;
22 : using com::sun::star::uno::XInterface;
23 : using com::sun::star::uno::Exception;
24 : using com::sun::star::uno::RuntimeException;
25 : using com::sun::star::uno::XComponentContext;
26 :
27 0 : static bool handleEmbeddedWKSObject(const librevenge::RVNGBinaryData &data, OdfDocumentHandler *pHandler, const OdfStreamType streamType)
28 : {
29 0 : OdsGenerator exporter;
30 0 : exporter.addDocumentHandler(pHandler, streamType);
31 0 : return libwps::WPSDocument::parse(data.getDataStream(), &exporter)==libwps::WPS_OK;
32 : }
33 :
34 10 : bool MSWorksImportFilter::doImportDocument(librevenge::RVNGInputStream &rInput, OdtGenerator &rGenerator, utl::MediaDescriptor &)
35 : {
36 10 : return libwps::WPS_OK == libwps::WPSDocument::parse(&rInput, &rGenerator);
37 : }
38 :
39 10 : bool MSWorksImportFilter::doDetectFormat(librevenge::RVNGInputStream &rInput, OUString &rTypeName)
40 : {
41 10 : libwps::WPSKind kind = libwps::WPS_TEXT;
42 10 : const libwps::WPSConfidence confidence = libwps::WPSDocument::isFileFormatSupported(&rInput, kind);
43 :
44 10 : if ((kind == libwps::WPS_TEXT) && (confidence == libwps::WPS_CONFIDENCE_EXCELLENT))
45 : {
46 10 : rTypeName = "writer_MS_Works_Document";
47 10 : return true;
48 : }
49 :
50 0 : return false;
51 : }
52 :
53 10 : void MSWorksImportFilter::doRegisterHandlers(OdtGenerator &rGenerator)
54 : {
55 10 : rGenerator.registerEmbeddedObjectHandler("image/wks-ods", &handleEmbeddedWKSObject);
56 10 : }
57 :
58 10 : OUString MSWorksImportFilter_getImplementationName()
59 : throw (RuntimeException)
60 : {
61 10 : return OUString("com.sun.star.comp.Writer.MSWorksImportFilter");
62 : }
63 :
64 2 : Sequence< OUString > SAL_CALL MSWorksImportFilter_getSupportedServiceNames()
65 : throw (RuntimeException)
66 : {
67 2 : Sequence < OUString > aRet(2);
68 2 : OUString *pArray = aRet.getArray();
69 2 : pArray[0] = "com.sun.star.document.ImportFilter";
70 2 : pArray[1] = "com.sun.star.document.ExtendedTypeDetection";
71 2 : return aRet;
72 : }
73 : #undef SERVICE_NAME2
74 : #undef SERVICE_NAME1
75 :
76 2 : Reference< XInterface > SAL_CALL MSWorksImportFilter_createInstance(const Reference< XComponentContext > &rContext)
77 : throw(Exception)
78 : {
79 2 : return (cppu::OWeakObject *) new MSWorksImportFilter(rContext);
80 : }
81 :
82 : // XServiceInfo
83 0 : OUString SAL_CALL MSWorksImportFilter::getImplementationName()
84 : throw (RuntimeException, std::exception)
85 : {
86 0 : return MSWorksImportFilter_getImplementationName();
87 : }
88 0 : sal_Bool SAL_CALL MSWorksImportFilter::supportsService(const OUString &rServiceName)
89 : throw (RuntimeException, std::exception)
90 : {
91 0 : return cppu::supportsService(this, rServiceName);
92 : }
93 0 : Sequence< OUString > SAL_CALL MSWorksImportFilter::getSupportedServiceNames()
94 : throw (RuntimeException, std::exception)
95 : {
96 0 : return MSWorksImportFilter_getSupportedServiceNames();
97 : }
98 :
99 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|