summaryrefslogtreecommitdiff
path: root/writerperfect
diff options
context:
space:
mode:
authorDavid Tardon <dtardon@redhat.com>2013-11-09 15:52:36 +0100
committerDavid Tardon <dtardon@redhat.com>2013-11-11 06:52:50 +0000
commit316be1b6f18963b39aab7729bf93fc9c86519e33 (patch)
tree6aad7dc186011cae21da1441e48c45a4270fbf53 /writerperfect
parentc4a593b6b1732def0a21f455c0ca50f82a9bc40d (diff)
bundle libebook
Change-Id: I05d96875b9d1deb87dadd63f446080a6fe3494a9 Reviewed-on: https://gerrit.libreoffice.org/6630 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_wpftwriter.mk6
-rw-r--r--writerperfect/source/writer/EBookImportFilter.cxx253
-rw-r--r--writerperfect/source/writer/EBookImportFilter.hxx88
-rw-r--r--writerperfect/source/writer/wpftwriter_genericfilter.cxx4
-rw-r--r--writerperfect/util/wpftwriter.component4
5 files changed, 355 insertions, 0 deletions
diff --git a/writerperfect/Library_wpftwriter.mk b/writerperfect/Library_wpftwriter.mk
index 6f5dafae4572..cc69e9d95ec7 100644
--- a/writerperfect/Library_wpftwriter.mk
+++ b/writerperfect/Library_wpftwriter.mk
@@ -49,7 +49,12 @@ $(eval $(call gb_Library_use_static_libraries,wpftwriter,\
$(eval $(call gb_Library_use_externals,wpftwriter,\
boost_headers \
+ ebook \
etonyek \
+ icui18n \
+ icudata \
+ icuuc \
+ libxml2 \
mwaw \
odfgen \
wps \
@@ -59,6 +64,7 @@ $(eval $(call gb_Library_use_externals,wpftwriter,\
))
$(eval $(call gb_Library_add_exception_objects,wpftwriter,\
+ writerperfect/source/writer/EBookImportFilter \
writerperfect/source/writer/MSWorksImportFilter \
writerperfect/source/writer/MWAWImportFilter \
writerperfect/source/writer/WordPerfectImportFilter \
diff --git a/writerperfect/source/writer/EBookImportFilter.cxx b/writerperfect/source/writer/EBookImportFilter.cxx
new file mode 100644
index 000000000000..aa0232947b57
--- /dev/null
+++ b/writerperfect/source/writer/EBookImportFilter.cxx
@@ -0,0 +1,253 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* EBookImportFilter: Sets up the filter, and calls DocumentCollector
+ * to do the actual filtering
+ *
+ * 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/.
+ */
+
+#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 <cppuhelper/supportsservice.hxx>
+
+#include <xmloff/attrlist.hxx>
+#include <ucbhelper/content.hxx>
+
+#include <libe-book/libe-book.h>
+
+#include <libodfgen/libodfgen.hxx>
+
+#include "common/DocumentHandler.hxx"
+#include "common/WPXSvStream.hxx"
+#include "EBookImportFilter.hxx"
+
+#include <iostream>
+
+using namespace ::com::sun::star::uno;
+using com::sun::star::uno::Sequence;
+using com::sun::star::uno::Reference;
+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::ucb::XCommandEnvironment;
+
+using com::sun::star::io::XInputStream;
+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 EBookImportFilter::importImpl( const Sequence< ::com::sun::star::beans::PropertyValue >& aDescriptor )
+throw (RuntimeException)
+{
+ SAL_INFO("writerperfect", "EBookImportFilter::importImpl");
+
+ sal_Int32 nLength = aDescriptor.getLength();
+ const PropertyValue *pValue = aDescriptor.getConstArray();
+ Reference < XInputStream > xInputStream;
+ rtl::OUString sFilterName;
+ for ( sal_Int32 i = 0 ; i < nLength; i++)
+ {
+ if ( pValue[i].Name == "FilterName" )
+ pValue[i].Value >>= sFilterName;
+ else if ( pValue[i].Name == "InputStream" )
+ pValue[i].Value >>= xInputStream;
+ }
+ if ( sFilterName.isEmpty() )
+ {
+ OSL_ASSERT( 0 );
+ return sal_False;
+ }
+ 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.Writer.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 Document Handler: abstract class to handle document SAX messages, concrete implementation here
+ // writes to in-memory target doc
+ DocumentHandler xHandler(xInternalHandler);
+
+ WPXSvInputStream input( xInputStream );
+
+ OdtGenerator collector(&xHandler, ODF_FLAT_XML);
+
+ if (sFilterName == "FictionBook 2")
+ return libebook::FB2Document::parse(&input, &collector);
+ else if (sFilterName == "PalmDoc")
+ return libebook::PDBDocument::parse(&input, &collector);
+ else if (sFilterName == "Plucker eBook")
+ return libebook::PLKRDocument::parse(&input, &collector);
+ else if (sFilterName == "eReader eBook")
+ return libebook::PMLDocument::parse(&input, &collector);
+ else if (sFilterName == "TealDoc")
+ return libebook::TDDocument::parse(&input, &collector);
+ else if (sFilterName == "zTXT")
+ return libebook::ZTXTDocument::parse(&input, &collector);
+
+ return sal_False;
+}
+
+sal_Bool SAL_CALL EBookImportFilter::filter( const Sequence< ::com::sun::star::beans::PropertyValue >& aDescriptor )
+throw (RuntimeException)
+{
+ SAL_INFO("writerperfect", "EBookImportFilter::filter");
+ return importImpl ( aDescriptor );
+}
+void SAL_CALL EBookImportFilter::cancel( )
+throw (RuntimeException)
+{
+ SAL_INFO("writerperfect", "EBookImportFilter::cancel");
+}
+
+// XImporter
+void SAL_CALL EBookImportFilter::setTargetDocument( const Reference< ::com::sun::star::lang::XComponent >& xDoc )
+throw (::com::sun::star::lang::IllegalArgumentException, RuntimeException)
+{
+ SAL_INFO("writerperfect", "EBookImportFilter::getTargetDocument");
+ mxDoc = xDoc;
+}
+
+// XExtendedFilterDetection
+OUString SAL_CALL EBookImportFilter::detect( com::sun::star::uno::Sequence< PropertyValue >& Descriptor )
+throw( com::sun::star::uno::RuntimeException )
+{
+ SAL_INFO("writerperfect", "EBookImportFilter::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 (libebook::FB2Document::isSupported(&input))
+ sTypeName = "writer_FictionBook_2";
+ else if (libebook::PDBDocument::isSupported(&input))
+ sTypeName = "writer_PalmDoc";
+ else if (libebook::PLKRDocument::isSupported(&input))
+ sTypeName = "writer_Plucker_eBook";
+ else if (libebook::PMLDocument::isSupported(&input))
+ sTypeName = "writer_eReader_eBook";
+ else if (libebook::TDDocument::isSupported(&input))
+ sTypeName = "writer_TealDoc";
+ else if (libebook::ZTXTDocument::isSupported(&input))
+ sTypeName = "writer_zTXT";
+
+ if (!sTypeName.isEmpty())
+ {
+ if ( location == nLength )
+ {
+ Descriptor.realloc(nLength+1);
+ Descriptor[location].Name = "TypeName";
+ }
+
+ Descriptor[location].Value <<=sTypeName;
+ }
+
+ return sTypeName;
+}
+
+
+// XInitialization
+void SAL_CALL EBookImportFilter::initialize( const Sequence< Any >& aArguments )
+throw (Exception, RuntimeException)
+{
+ SAL_INFO("writerperfect", "EBookImportFilter::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 EBookImportFilter_getImplementationName ()
+throw (RuntimeException)
+{
+ return OUString ( "org.libreoffice.comp.Writer.EBookImportFilter" );
+}
+
+Sequence< OUString > SAL_CALL EBookImportFilter_getSupportedServiceNames( )
+throw (RuntimeException)
+{
+ Sequence < OUString > aRet(2);
+ OUString *pArray = aRet.getArray();
+ pArray[0] = OUString ( "com.sun.star.document.ImportFilter" );
+ pArray[1] = OUString ( "com.sun.star.document.ExtendedTypeDetection" );
+ return aRet;
+}
+#undef SERVICE_NAME2
+#undef SERVICE_NAME1
+
+Reference< XInterface > SAL_CALL EBookImportFilter_createInstance( const Reference< XComponentContext > & rContext)
+throw( Exception )
+{
+ return (cppu::OWeakObject *) new EBookImportFilter( rContext );
+}
+
+// XServiceInfo
+OUString SAL_CALL EBookImportFilter::getImplementationName( )
+throw (RuntimeException)
+{
+ return EBookImportFilter_getImplementationName();
+}
+sal_Bool SAL_CALL EBookImportFilter::supportsService( const OUString &rServiceName )
+throw (RuntimeException)
+{
+ return cppu::supportsService( this, rServiceName );
+}
+Sequence< OUString > SAL_CALL EBookImportFilter::getSupportedServiceNames( )
+throw (RuntimeException)
+{
+ return EBookImportFilter_getSupportedServiceNames();
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerperfect/source/writer/EBookImportFilter.hxx b/writerperfect/source/writer/EBookImportFilter.hxx
new file mode 100644
index 000000000000..3e844d78b49f
--- /dev/null
+++ b/writerperfect/source/writer/EBookImportFilter.hxx
@@ -0,0 +1,88 @@
+/* -*- 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/.
+ */
+
+#ifndef EBOOKIMPORTFILTER_HXX
+#define EBOOKIMPORTFILTER_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>
+
+/* 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 EBookImportFilter : 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:
+ ::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;
+
+ sal_Bool SAL_CALL importImpl( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aDescriptor )
+ throw (::com::sun::star::uno::RuntimeException);
+
+public:
+ EBookImportFilter( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > &rxContext )
+ : mxContext( rxContext ) {}
+ virtual ~EBookImportFilter() {}
+
+ // 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 EBookImportFilter_getImplementationName()
+throw ( ::com::sun::star::uno::RuntimeException );
+
+::com::sun::star::uno::Sequence< OUString > SAL_CALL EBookImportFilter_getSupportedServiceNames( )
+throw ( ::com::sun::star::uno::RuntimeException );
+
+::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
+SAL_CALL EBookImportFilter_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/writer/wpftwriter_genericfilter.cxx b/writerperfect/source/writer/wpftwriter_genericfilter.cxx
index 0361dd203774..e163f5d0c13b 100644
--- a/writerperfect/source/writer/wpftwriter_genericfilter.cxx
+++ b/writerperfect/source/writer/wpftwriter_genericfilter.cxx
@@ -31,6 +31,7 @@
#include "cppuhelper/implementationentry.hxx"
#include "sal/types.h"
+#include "EBookImportFilter.hxx"
#include "WordPerfectImportFilter.hxx"
#include "MSWorksImportFilter.hxx"
#include "MWAWImportFilter.hxx"
@@ -47,6 +48,9 @@ static cppu::ImplementationEntry const services[] = {
{ &MWAWImportFilter_createInstance, &MWAWImportFilter_getImplementationName,
&MWAWImportFilter_getSupportedServiceNames,
&cppu::createSingleComponentFactory, 0, 0 },
+ { &EBookImportFilter_createInstance, &EBookImportFilter_getImplementationName,
+ &EBookImportFilter_getSupportedServiceNames,
+ &cppu::createSingleComponentFactory, 0, 0 },
{ 0, 0, 0, 0, 0, 0 } };
}
diff --git a/writerperfect/util/wpftwriter.component b/writerperfect/util/wpftwriter.component
index f243d5c96257..e36d8675801e 100644
--- a/writerperfect/util/wpftwriter.component
+++ b/writerperfect/util/wpftwriter.component
@@ -30,4 +30,8 @@
<service name="com.sun.star.document.ExtendedTypeDetection"/>
<service name="com.sun.star.document.ImportFilter"/>
</implementation>
+ <implementation name="org.libreoffice.comp.Writer.EBookImportFilter">
+ <service name="com.sun.star.document.ExtendedTypeDetection"/>
+ <service name="com.sun.star.document.ImportFilter"/>
+ </implementation>
</component>