summaryrefslogtreecommitdiff
path: root/writerperfect
diff options
context:
space:
mode:
authorDavid Tardon <dtardon@redhat.com>2013-10-30 08:56:06 +0100
committerDavid Tardon <dtardon@redhat.com>2013-10-30 19:49:34 +0000
commit412975713b4838582f635ac9e61a8a8e720ff09c (patch)
tree906f5a53c4d9ef88ca1a53a4640231d89c11c6b4 /writerperfect
parent2c3d648117835df405ff8414c51821d2a0ed1519 (diff)
integrate Apple Keynote import filter
Change-Id: Icc36b761da9262a99af730cfe71f576bcaab3ee1 Reviewed-on: https://gerrit.libreoffice.org/6488 Tested-by: LibreOffice gerrit bot <gerrit@libreoffice.org> Reviewed-by: David Tardon <dtardon@redhat.com> Tested-by: David Tardon <dtardon@redhat.com>
Diffstat (limited to 'writerperfect')
-rw-r--r--writerperfect/Library_wpftimpress.mk61
-rw-r--r--writerperfect/Module_writerperfect.mk4
-rw-r--r--writerperfect/source/impress/KeynoteImportFilter.cxx221
-rw-r--r--writerperfect/source/impress/KeynoteImportFilter.hxx89
-rw-r--r--writerperfect/source/impress/wpftimpress.component16
-rw-r--r--writerperfect/source/impress/wpftimpress_genericfilter.cxx47
6 files changed, 438 insertions, 0 deletions
diff --git a/writerperfect/Library_wpftimpress.mk b/writerperfect/Library_wpftimpress.mk
new file mode 100644
index 000000000000..cb69f98ca7a7
--- /dev/null
+++ b/writerperfect/Library_wpftimpress.mk
@@ -0,0 +1,61 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+# This file incorporates work covered by the following license notice:
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed
+# with this work for additional information regarding copyright
+# ownership. The ASF licenses this file to you under the Apache
+# License, Version 2.0 (the "License"); you may not use this file
+# except in compliance with the License. You may obtain a copy of
+# the License at http://www.apache.org/licenses/LICENSE-2.0 .
+#
+
+$(eval $(call gb_Library_Library,wpftimpress))
+
+$(eval $(call gb_Library_set_componentfile,wpftimpress,writerperfect/source/impress/wpftimpress))
+
+$(eval $(call gb_Library_set_include,wpftimpress,\
+ $$(INCLUDE) \
+ -I$(SRCDIR)/writerperfect/source \
+))
+
+$(eval $(call gb_Library_use_sdk_api,wpftimpress))
+
+$(eval $(call gb_Library_use_libraries,wpftimpress,\
+ comphelper \
+ cppu \
+ cppuhelper \
+ sal \
+ sot \
+ tl \
+ utl \
+ xo \
+ $(gb_UWINAPI) \
+))
+
+$(eval $(call gb_Library_use_static_libraries,wpftimpress,\
+ writerperfect \
+))
+
+$(eval $(call gb_Library_use_externals,wpftimpress,\
+ etonyek \
+ odfgen \
+ wpd \
+ wpg \
+ zlib \
+ libxml2 \
+))
+
+$(eval $(call gb_Library_add_exception_objects,wpftimpress,\
+ writerperfect/source/impress/KeynoteImportFilter \
+ writerperfect/source/impress/wpftimpress_genericfilter \
+))
+
+# vim: set noet sw=4 ts=4:
diff --git a/writerperfect/Module_writerperfect.mk b/writerperfect/Module_writerperfect.mk
index fee590dc5344..8f02300ce3ff 100644
--- a/writerperfect/Module_writerperfect.mk
+++ b/writerperfect/Module_writerperfect.mk
@@ -45,6 +45,10 @@ endif
endif
endif
+$(eval $(call gb_Module_add_targets,writerperfect,\
+ Library_wpftimpress \
+))
+
ifneq (,$(SYSTEM_WPD))
ifneq (,$(SYSTEM_WPG))
ifneq (,$(SYSTEM_ODFGEN))
diff --git a/writerperfect/source/impress/KeynoteImportFilter.cxx b/writerperfect/source/impress/KeynoteImportFilter.cxx
new file mode 100644
index 000000000000..0035d5df7a29
--- /dev/null
+++ b/writerperfect/source/impress/KeynoteImportFilter.cxx
@@ -0,0 +1,221 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* KeynoteImportFilter: Sets up the filter, and calls OdpExporter
+ * to do the actual filtering
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <osl/diagnose.h>
+#include <rtl/tencinfo.h>
+
+#include <com/sun/star/io/XInputStream.hpp>
+#include <com/sun/star/xml/sax/XAttributeList.hpp>
+#include <com/sun/star/xml/sax/XDocumentHandler.hpp>
+#include <com/sun/star/xml/sax/InputSource.hpp>
+#include <com/sun/star/xml/sax/XParser.hpp>
+#include <com/sun/star/io/XSeekable.hpp>
+#include <com/sun/star/uno/Reference.h>
+
+#include <xmloff/attrlist.hxx>
+
+#include <libetonyek/libetonyek.h>
+#include <libodfgen/libodfgen.hxx>
+
+#include "common/DocumentHandler.hxx"
+#include "common/WPXSvStream.hxx"
+#include "KeynoteImportFilter.hxx"
+
+#include <iostream>
+
+using namespace ::com::sun::star::uno;
+using com::sun::star::uno::Reference;
+using com::sun::star::io::XInputStream;
+using com::sun::star::io::XSeekable;
+using com::sun::star::uno::Sequence;
+using com::sun::star::uno::Any;
+using com::sun::star::uno::UNO_QUERY;
+using com::sun::star::uno::XInterface;
+using com::sun::star::uno::Exception;
+using com::sun::star::uno::RuntimeException;
+using com::sun::star::beans::PropertyValue;
+using com::sun::star::document::XFilter;
+using com::sun::star::document::XExtendedFilterDetection;
+using com::sun::star::document::XImporter;
+using com::sun::star::xml::sax::InputSource;
+using com::sun::star::xml::sax::XAttributeList;
+using com::sun::star::xml::sax::XDocumentHandler;
+using com::sun::star::xml::sax::XParser;
+
+
+sal_Bool SAL_CALL KeynoteImportFilter::filter( const Sequence< ::com::sun::star::beans::PropertyValue >& aDescriptor )
+throw (RuntimeException)
+{
+ SAL_INFO("writerperfect", "KeynoteImportFilter::filter");
+ sal_Int32 nLength = aDescriptor.getLength();
+ const PropertyValue *pValue = aDescriptor.getConstArray();
+ Reference < XInputStream > xInputStream;
+ for ( sal_Int32 i = 0 ; i < nLength; i++)
+ {
+ if ( pValue[i].Name == "InputStream" )
+ pValue[i].Value >>= xInputStream;
+ }
+ if ( !xInputStream.is() )
+ {
+ OSL_ASSERT( 0 );
+ return sal_False;
+ }
+
+ // An XML import service: what we push sax messages to..
+ Reference < XDocumentHandler > xInternalHandler(
+ mxContext->getServiceManager()->createInstanceWithContext(
+ "com.sun.star.comp.Draw.XMLOasisImporter", mxContext),
+ css::uno::UNO_QUERY_THROW);
+
+ // The XImporter sets up an empty target document for XDocumentHandler to write to..
+ Reference < XImporter > xImporter(xInternalHandler, UNO_QUERY);
+ xImporter->setTargetDocument( mxDoc );
+
+ // OO Graphics Handler: abstract class to handle document SAX messages, concrete implementation here
+ // writes to in-memory target doc
+ DocumentHandler xHandler(xInternalHandler);
+
+ WPXSvInputStream input( xInputStream );
+
+ OdpGenerator exporter(&xHandler, ODF_FLAT_XML);
+ bool tmpParseResult = libetonyek::KEYDocument::parse(&input, &exporter);
+ return tmpParseResult;
+}
+
+void SAL_CALL KeynoteImportFilter::cancel( )
+throw (RuntimeException)
+{
+ SAL_INFO("writerperfect", "KeynoteImportFilter::cancel");
+}
+
+// XImporter
+void SAL_CALL KeynoteImportFilter::setTargetDocument( const Reference< ::com::sun::star::lang::XComponent >& xDoc )
+throw (::com::sun::star::lang::IllegalArgumentException, RuntimeException)
+{
+ SAL_INFO("writerperfect", "KeynoteImportFilter::setTargetDocument");
+ mxDoc = xDoc;
+}
+
+// XExtendedFilterDetection
+OUString SAL_CALL KeynoteImportFilter::detect( com::sun::star::uno::Sequence< PropertyValue >& Descriptor )
+throw( com::sun::star::uno::RuntimeException )
+{
+ SAL_INFO("writerperfect", "KeynoteImportFilter::detect");
+ OUString sTypeName;
+ sal_Int32 nLength = Descriptor.getLength();
+ sal_Int32 location = nLength;
+ const PropertyValue *pValue = Descriptor.getConstArray();
+ Reference < XInputStream > xInputStream;
+ for ( sal_Int32 i = 0 ; i < nLength; i++)
+ {
+ if ( pValue[i].Name == "TypeName" )
+ location=i;
+ else if ( pValue[i].Name == "InputStream" )
+ pValue[i].Value >>= xInputStream;
+ }
+
+ if (!xInputStream.is())
+ return OUString();
+
+ WPXSvInputStream input( xInputStream );
+
+ if (libetonyek::KEYDocument::isSupported(&input))
+ sTypeName = "impress_AppleKeynote";
+
+ if (!sTypeName.isEmpty())
+ {
+ if ( location == nLength )
+ {
+ Descriptor.realloc(nLength+1);
+ Descriptor[location].Name = "TypeName";
+ }
+
+ Descriptor[location].Value <<=sTypeName;
+ }
+ return sTypeName;
+}
+
+
+// XInitialization
+void SAL_CALL KeynoteImportFilter::initialize( const Sequence< Any >& aArguments )
+throw (Exception, RuntimeException)
+{
+ SAL_INFO("writerperfect", "KeynoteImportFilter::initialize");
+ Sequence < PropertyValue > aAnySeq;
+ sal_Int32 nLength = aArguments.getLength();
+ if ( nLength && ( aArguments[0] >>= aAnySeq ) )
+ {
+ const PropertyValue *pValue = aAnySeq.getConstArray();
+ nLength = aAnySeq.getLength();
+ for ( sal_Int32 i = 0 ; i < nLength; i++)
+ {
+ if ( pValue[i].Name == "Type" )
+ {
+ pValue[i].Value >>= msFilterName;
+ break;
+ }
+ }
+ }
+}
+OUString KeynoteImportFilter_getImplementationName ()
+throw (RuntimeException)
+{
+ SAL_INFO("writerperfect", "KeynoteImportFilter_getImplementationName");
+ return OUString ( "org.libreoffice.comp.Impress.KeynoteImportFilter" );
+}
+
+#define SERVICE_NAME1 "com.sun.star.document.ImportFilter"
+#define SERVICE_NAME2 "com.sun.star.document.ExtendedTypeDetection"
+sal_Bool SAL_CALL KeynoteImportFilter_supportsService( const OUString &ServiceName )
+throw (RuntimeException)
+{
+ SAL_INFO("writerperfect", "KeynoteImportFilter_supportsService");
+ return ( ServiceName == SERVICE_NAME1 || ServiceName == SERVICE_NAME2 );
+}
+Sequence< OUString > SAL_CALL KeynoteImportFilter_getSupportedServiceNames( )
+throw (RuntimeException)
+{
+ SAL_INFO("writerperfect", "KeynoteImportFilter_getSupportedServiceNames");
+ Sequence < OUString > aRet(2);
+ OUString *pArray = aRet.getArray();
+ pArray[0] = OUString ( SERVICE_NAME1 );
+ pArray[1] = OUString ( SERVICE_NAME2 );
+ return aRet;
+}
+#undef SERVICE_NAME2
+#undef SERVICE_NAME1
+
+Reference< XInterface > SAL_CALL KeynoteImportFilter_createInstance( const Reference< XComponentContext > & rContext)
+throw( Exception )
+{
+ SAL_INFO("writerperfect", "KeynoteImportFilter_createInstance");
+ return (cppu::OWeakObject *) new KeynoteImportFilter( rContext );
+}
+
+// XServiceInfo
+OUString SAL_CALL KeynoteImportFilter::getImplementationName( )
+throw (RuntimeException)
+{
+ SAL_INFO("writerperfect", "KeynoteImportFilter::getImplementationName");
+ return KeynoteImportFilter_getImplementationName();
+}
+sal_Bool SAL_CALL KeynoteImportFilter::supportsService( const OUString &rServiceName )
+throw (RuntimeException)
+{
+ SAL_INFO("writerperfect", "KeynoteImportFilter::supportsService");
+ return KeynoteImportFilter_supportsService( rServiceName );
+}
+Sequence< OUString > SAL_CALL KeynoteImportFilter::getSupportedServiceNames( )
+throw (RuntimeException)
+{
+ SAL_INFO("writerperfect", "KeynoteImportFilter::getSupportedServiceNames");
+ return KeynoteImportFilter_getSupportedServiceNames();
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerperfect/source/impress/KeynoteImportFilter.hxx b/writerperfect/source/impress/KeynoteImportFilter.hxx
new file mode 100644
index 000000000000..05d235b71af9
--- /dev/null
+++ b/writerperfect/source/impress/KeynoteImportFilter.hxx
@@ -0,0 +1,89 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef INCLUDED_WRITERPERFECT_SOURCE_IMPRESS_KEYNOTEIMPORTFILTER_HXX
+#define INCLUDED_WRITERPERFECT_SOURCE_IMPRESS_KEYNOTEIMPORTFILTER_HXX
+
+#include <com/sun/star/document/XFilter.hpp>
+#include <com/sun/star/document/XImporter.hpp>
+#include <com/sun/star/document/XExtendedFilterDetection.hpp>
+#include <com/sun/star/lang/XInitialization.hpp>
+#include <com/sun/star/lang/XServiceInfo.hpp>
+#include <com/sun/star/uno/XComponentContext.hpp>
+#include <com/sun/star/xml/sax/XDocumentHandler.hpp>
+#include <cppuhelper/implbase5.hxx>
+
+#include <stdio.h>
+
+/* This component will be instantiated for both import or export. Whether it calls
+ * setSourceDocument or setTargetDocument determines which Impl function the filter
+ * member calls */
+class KeynoteImportFilter : public cppu::WeakImplHelper5
+ <
+ com::sun::star::document::XFilter,
+ com::sun::star::document::XImporter,
+ com::sun::star::document::XExtendedFilterDetection,
+ com::sun::star::lang::XInitialization,
+ com::sun::star::lang::XServiceInfo
+ >
+{
+protected:
+ // oo.org declares
+ ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > mxContext;
+ ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > mxDoc;
+ OUString msFilterName;
+ ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler > mxHandler;
+
+public:
+ KeynoteImportFilter( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > &rxContext)
+ : mxContext( rxContext ) {}
+ virtual ~KeynoteImportFilter() {}
+
+ // XFilter
+ virtual sal_Bool SAL_CALL filter( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aDescriptor )
+ throw (::com::sun::star::uno::RuntimeException);
+ virtual void SAL_CALL cancel( )
+ throw (::com::sun::star::uno::RuntimeException);
+
+ // XImporter
+ virtual void SAL_CALL setTargetDocument( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& xDoc )
+ throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
+
+ //XExtendedFilterDetection
+ virtual OUString SAL_CALL detect( com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >& Descriptor )
+ throw( com::sun::star::uno::RuntimeException );
+
+ // XInitialization
+ virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments )
+ throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
+
+ // XServiceInfo
+ virtual OUString SAL_CALL getImplementationName( )
+ throw (::com::sun::star::uno::RuntimeException);
+ virtual sal_Bool SAL_CALL supportsService( const OUString &ServiceName )
+ throw (::com::sun::star::uno::RuntimeException);
+ virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( )
+ throw (::com::sun::star::uno::RuntimeException);
+
+};
+
+OUString KeynoteImportFilter_getImplementationName()
+throw ( ::com::sun::star::uno::RuntimeException );
+
+sal_Bool SAL_CALL KeynoteImportFilter_supportsService( const OUString &ServiceName )
+throw ( ::com::sun::star::uno::RuntimeException );
+
+::com::sun::star::uno::Sequence< OUString > SAL_CALL KeynoteImportFilter_getSupportedServiceNames( )
+throw ( ::com::sun::star::uno::RuntimeException );
+
+::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
+SAL_CALL KeynoteImportFilter_createInstance( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > & rContext)
+throw ( ::com::sun::star::uno::Exception );
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerperfect/source/impress/wpftimpress.component b/writerperfect/source/impress/wpftimpress.component
new file mode 100644
index 000000000000..b7b87c56a264
--- /dev/null
+++ b/writerperfect/source/impress/wpftimpress.component
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+-->
+<component loader="com.sun.star.loader.SharedLibrary" prefix="wpftimpress"
+ xmlns="http://openoffice.org/2010/uno-components">
+ <implementation name="org.libreoffice.comp.Impress.KeynoteImportFilter">
+ <service name="com.sun.star.document.ImportFilter"/>
+ <service name="com.sun.star.document.ExtendedTypeDetection"/>
+ </implementation>
+</component>
diff --git a/writerperfect/source/impress/wpftimpress_genericfilter.cxx b/writerperfect/source/impress/wpftimpress_genericfilter.cxx
new file mode 100644
index 000000000000..4081137cdf03
--- /dev/null
+++ b/writerperfect/source/impress/wpftimpress_genericfilter.cxx
@@ -0,0 +1,47 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+/* genericfilter: mostly generic code for registering the filter */
+
+#include "sal/config.h"
+
+#include "cppuhelper/factory.hxx"
+#include "cppuhelper/implementationentry.hxx"
+#include "sal/types.h"
+
+#include "KeynoteImportFilter.hxx"
+
+namespace {
+
+static cppu::ImplementationEntry const services[] = {
+ { &KeynoteImportFilter_createInstance, &KeynoteImportFilter_getImplementationName,
+ &KeynoteImportFilter_getSupportedServiceNames,
+ &cppu::createSingleComponentFactory, 0, 0 },
+ { 0, 0, 0, 0, 0, 0 } };
+
+}
+
+extern "C" SAL_DLLPUBLIC_EXPORT void * SAL_CALL wpftimpress_component_getFactory(
+ char const * pImplName, void * pServiceManager, void * pRegistryKey)
+{
+ return cppu::component_getFactoryHelper(
+ pImplName, pServiceManager, pRegistryKey, services);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */