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>
This commit is contained in:
David Tardon 2013-11-09 15:52:36 +01:00
parent c4a593b6b1
commit 316be1b6f1
31 changed files with 906 additions and 0 deletions

View file

@ -76,6 +76,7 @@ $(WORKDIR)/download: $(BUILDDIR)/config_host.mk $(SRCDIR)/download.lst $(SRCDIR)
$(foreach item, \
$(call fetch_Optional,LIBATOMIC_OPS,LIBATOMIC_OPS_TARBALL) \
$(call fetch_Optional,CDR,CDR_TARBALL) \
$(call fetch_Optional,EBOOK,EBOOK_TARBALL) \
$(call fetch_Optional,FREEHAND,FREEHAND_TARBALL) \
$(call fetch_Optional,ETONYEK,ETONYEK_TARBALL) \
$(call fetch_Optional,FIREBIRD,FIREBIRD_TARBALL) \

View file

@ -1402,6 +1402,41 @@ endef
endif # SYSTEM_CDR
ifeq ($(SYSTEM_EBOOK),YES)
define gb_LinkTarget__use_ebook
$(call gb_LinkTarget_set_include,$(1),\
$$(INCLUDE) \
$(EBOOK_CFLAGS) \
)
$(call gb_LinkTarget_add_libs,$(1),$(EBOOK_LIBS))
endef
gb_ExternalProject__use_ebook :=
else # !SYSTEM_EBOOK
define gb_LinkTarget__use_ebook
$(call gb_LinkTarget_set_include,$(1),\
$(EBOOK_CFLAGS) \
$$(INCLUDE) \
)
$(call gb_LinkTarget_add_libs,$(1),\
$(call gb_UnpackedTarball_get_dir,libebook)/src/lib/.libs/libe-book-0.0$(gb_StaticLibrary_PLAINEXT) \
)
$(call gb_LinkTarget_use_external_project,$(1),libebook)
endef
define gb_ExternalProject__use_ebook
$(call gb_ExternalProject_use_external_project,$(1),libebook)
endef
endif # SYSTEM_EBOOK
ifeq ($(SYSTEM_ETONYEK),YES)
define gb_LinkTarget__use_etonyek

View file

@ -102,6 +102,8 @@ export DOCDIR=@DOCDIR@
export DOXYGEN=@DOXYGEN@
export DO_FETCH_TARBALLS=@DO_FETCH_TARBALLS@
export DPKG=@DPKG@
export EBOOK_CFLAGS=$(gb_SPACE)@EBOOK_CFLAGS@
export EBOOK_LIBS=$(gb_SPACE)@EBOOK_LIBS@
export ENABLE_AVAHI=@ENABLE_AVAHI@
export ENABLE_CAIRO_CANVAS=@ENABLE_CAIRO_CANVAS@
export ENABLE_CORETEXT=@ENABLE_CORETEXT@
@ -504,6 +506,7 @@ export SYSTEM_JPEG=@SYSTEM_JPEG@
export SYSTEM_LCMS2=@SYSTEM_LCMS2@
export SYSTEM_CDR=@SYSTEM_CDR@
export SYSTEM_CMIS=@SYSTEM_CMIS@
export SYSTEM_EBOOK=@SYSTEM_EBOOK@
export SYSTEM_ETONYEK=@SYSTEM_ETONYEK@
export SYSTEM_FREEHAND=@SYSTEM_FREEHAND@
export SYSTEM_LIBATOMIC_OPS=@SYSTEM_LIBATOMIC_OPS@

View file

@ -7654,6 +7654,11 @@ else
fi
AC_SUBST(SYSTEM_EXPAT)
dnl ===================================================================
dnl Check for system libebook
dnl ===================================================================
libo_CHECK_SYSTEM_MODULE([libebook],[EBOOK],[libe-book-0.0],["-I${WORKDIR}/UnpackedTarball/libebook/inc"],["-L${WORKDIR}/UnpackedTarball/libebook/src/lib/.libs -le-book-0.0"])
dnl ===================================================================
dnl Check for system libetonyek
dnl ===================================================================

View file

@ -1,5 +1,7 @@
CDR_MD5SUM := d88f9b94df880d2c05be943b000ca112
export CDR_TARBALL := libcdr-0.0.14.tar.bz2
EBOOK_MD5SUM := 74524e1eecc8ab3ac2e8e8a8bb75d6e4
export EBOOK_TARBALL := libe-book-0.0.1.tar.bz2
ETONYEK_MD5SUM := 040e0d7ce0cc0eb3a016964699d54a6c
export ETONYEK_TARBALL := libetonyek-0.0.1.tar.bz2
FREEHAND_MD5SUM := 496dd00028afcc19f896b01394769043

View file

@ -32,6 +32,7 @@ $(eval $(call gb_Module_add_moduledirs,external,\
$(call gb_Helper_optional,CPPUNIT,cppunit) \
$(call gb_Helper_optional,CT2N,ct2n) \
$(call gb_Helper_optional,CURL,curl) \
$(call gb_Helper_optional,EBOOK,libebook) \
$(call gb_Helper_optional,EPM,epm) \
$(call gb_Helper_optional,ETONYEK,libetonyek) \
$(call gb_Helper_optional,EXPAT,expat) \

View file

@ -0,0 +1,45 @@
# -*- 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/.
#
$(eval $(call gb_ExternalProject_ExternalProject,libebook))
$(eval $(call gb_ExternalProject_use_autoconf,libebook,build))
$(eval $(call gb_ExternalProject_register_targets,libebook,\
build \
))
$(eval $(call gb_ExternalProject_use_externals,libebook,\
boost_headers \
icu \
libxml2 \
wpd \
zlib \
))
$(call gb_ExternalProject_get_state_target,libebook,build) :
$(call gb_ExternalProject_run,build,\
export PKG_CONFIG="" \
&& ./configure \
--with-pic \
--enable-static \
--disable-shared \
--without-docs \
--disable-debug \
--disable-werror \
--disable-weffc \
CXXFLAGS="$(if $(filter NO,$(SYSTEM_BOOST)),-I$(call gb_UnpackedTarball_get_dir,boost),$(BOOST_CPPFLAGS))" \
XML_CFLAGS="$(if $(filter NO,$(SYSTEM_LIBXML)),-I$(call gb_UnpackedTarball_get_dir,xml2)/include,$(LIBXML_CFLAGS))" \
XML_LIBS="$(LIBXML_LIBS)" \
$(if $(filter YES,$(CROSS_COMPILING)),--build=$(BUILD_PLATFORM) --host=$(HOST_PLATFORM)) \
&& cd src/lib \
&& $(MAKE) $(if $(VERBOSE)$(verbose),V=1) \
)
# vim: set noet sw=4 ts=4:

7
external/libebook/Makefile vendored Normal file
View file

@ -0,0 +1,7 @@
# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
module_directory:=$(dir $(realpath $(firstword $(MAKEFILE_LIST))))
include $(module_directory)/../../solenv/gbuild/partial_build.mk
# vim: set noet sw=4 ts=4:

17
external/libebook/Module_libebook.mk vendored Normal file
View file

@ -0,0 +1,17 @@
# -*- 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/.
#
$(eval $(call gb_Module_Module,libebook))
$(eval $(call gb_Module_add_targets,libebook,\
ExternalProject_libebook \
UnpackedTarball_libebook \
))
# vim: set noet sw=4 ts=4:

1
external/libebook/README vendored Normal file
View file

@ -0,0 +1 @@
Library for import of various non-HTML reflowable e-book formats.

View file

@ -0,0 +1,14 @@
# -*- 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/.
#
$(eval $(call gb_UnpackedTarball_UnpackedTarball,libebook))
$(eval $(call gb_UnpackedTarball_set_tarball,libebook,$(EBOOK_TARBALL)))
# vim: set noet sw=4 ts=4:

View file

@ -357,6 +357,13 @@ $(call filter_Configuration_add_types,fcfg_langpack,fcfg_writer_types.xcu,filter
writer_OOXML \
writer_OOXML_Template \
writer_layout_dump_xml \
writer_BroadBand_eBook \
writer_eReader_eBook \
writer_FictionBook_2 \
writer_PalmDoc \
writer_Plucker_eBook \
writer_TealDoc \
writer_zTXT \
)
$(call filter_Configuration_add_filters,fcfg_langpack,fcfg_writer_filters.xcu,filter/source/config/fragments/filters,\
@ -407,6 +414,13 @@ $(call filter_Configuration_add_filters,fcfg_langpack,fcfg_writer_filters.xcu,fi
OOXML_Text \
OOXML_Text_Template \
writer_layout_dump \
BroadBand_eBook \
eReader_eBook \
FictionBook_2 \
PalmDoc \
Plucker_eBook \
TealDoc \
zTXT \
)
$(call filter_Configuration_add_ui_filters,fcfg_langpack,filter/source/config/fragments/filters,\

View file

@ -0,0 +1,29 @@
<!--
* 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/.
*
-->
<node oor:name="BroadBand eBook" oor:op="replace">
<prop oor:name="Flags">
<value>IMPORT ALIEN USESOPTIONS 3RDPARTYFILTER PREFERRED</value>
</prop>
<prop oor:name="FilterService">
<value>org.libreoffice.comp.Writer.EBookImportFilter</value>
</prop>
<prop oor:name="UIName">
<value xml:lang="x-default">BroadBand eBook</value>
</prop>
<prop oor:name="FileFormatVersion">
<value>0</value>
</prop>
<prop oor:name="Type">
<value>writer_BroadBand_eBook</value>
</prop>
<prop oor:name="DocumentService">
<value>com.sun.star.text.TextDocument</value>
</prop>
</node>

View file

@ -0,0 +1,29 @@
<!--
* 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/.
*
-->
<node oor:name="FictionBook 2" oor:op="replace">
<prop oor:name="Flags">
<value>IMPORT ALIEN USESOPTIONS 3RDPARTYFILTER PREFERRED</value>
</prop>
<prop oor:name="FilterService">
<value>org.libreoffice.comp.Writer.EBookImportFilter</value>
</prop>
<prop oor:name="UIName">
<value xml:lang="x-default">FictionBook 2.0</value>
</prop>
<prop oor:name="FileFormatVersion">
<value>0</value>
</prop>
<prop oor:name="Type">
<value>writer_FictionBook_2</value>
</prop>
<prop oor:name="DocumentService">
<value>com.sun.star.text.TextDocument</value>
</prop>
</node>

View file

@ -0,0 +1,29 @@
<!--
* 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/.
*
-->
<node oor:name="PalmDoc" oor:op="replace">
<prop oor:name="Flags">
<value>IMPORT ALIEN USESOPTIONS 3RDPARTYFILTER PREFERRED</value>
</prop>
<prop oor:name="FilterService">
<value>org.libreoffice.comp.Writer.EBookImportFilter</value>
</prop>
<prop oor:name="UIName">
<value xml:lang="x-default">PalmDoc eBook</value>
</prop>
<prop oor:name="FileFormatVersion">
<value>0</value>
</prop>
<prop oor:name="Type">
<value>writer_PalmDoc</value>
</prop>
<prop oor:name="DocumentService">
<value>com.sun.star.text.TextDocument</value>
</prop>
</node>

View file

@ -0,0 +1,29 @@
<!--
* 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/.
*
-->
<node oor:name="Plucker eBook" oor:op="replace">
<prop oor:name="Flags">
<value>IMPORT ALIEN USESOPTIONS 3RDPARTYFILTER PREFERRED</value>
</prop>
<prop oor:name="FilterService">
<value>org.libreoffice.comp.Writer.EBookImportFilter</value>
</prop>
<prop oor:name="UIName">
<value xml:lang="x-default">Plucker eBook</value>
</prop>
<prop oor:name="FileFormatVersion">
<value>0</value>
</prop>
<prop oor:name="Type">
<value>writer_Plucker_eBook</value>
</prop>
<prop oor:name="DocumentService">
<value>com.sun.star.text.TextDocument</value>
</prop>
</node>

View file

@ -0,0 +1,29 @@
<!--
* 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/.
*
-->
<node oor:name="TealDoc" oor:op="replace">
<prop oor:name="Flags">
<value>IMPORT ALIEN USESOPTIONS 3RDPARTYFILTER PREFERRED</value>
</prop>
<prop oor:name="FilterService">
<value>org.libreoffice.comp.Writer.EBookImportFilter</value>
</prop>
<prop oor:name="UIName">
<value xml:lang="x-default">TealDoc eBook</value>
</prop>
<prop oor:name="FileFormatVersion">
<value>0</value>
</prop>
<prop oor:name="Type">
<value>writer_TealDoc</value>
</prop>
<prop oor:name="DocumentService">
<value>com.sun.star.text.TextDocument</value>
</prop>
</node>

View file

@ -0,0 +1,29 @@
<!--
* 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/.
*
-->
<node oor:name="eReader eBook" oor:op="replace">
<prop oor:name="Flags">
<value>IMPORT ALIEN USESOPTIONS 3RDPARTYFILTER PREFERRED</value>
</prop>
<prop oor:name="FilterService">
<value>org.libreoffice.comp.Writer.EBookImportFilter</value>
</prop>
<prop oor:name="UIName">
<value xml:lang="x-default">eReader eBook</value>
</prop>
<prop oor:name="FileFormatVersion">
<value>0</value>
</prop>
<prop oor:name="Type">
<value>writer_eReader_eBook</value>
</prop>
<prop oor:name="DocumentService">
<value>com.sun.star.text.TextDocument</value>
</prop>
</node>

View file

@ -0,0 +1,29 @@
<!--
* 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/.
*
-->
<node oor:name="zTXT" oor:op="replace">
<prop oor:name="Flags">
<value>IMPORT ALIEN USESOPTIONS 3RDPARTYFILTER PREFERRED</value>
</prop>
<prop oor:name="FilterService">
<value>org.libreoffice.comp.Writer.EBookImportFilter</value>
</prop>
<prop oor:name="UIName">
<value xml:lang="x-default">zTXT eBook</value>
</prop>
<prop oor:name="FileFormatVersion">
<value>0</value>
</prop>
<prop oor:name="Type">
<value>writer_zTXT</value>
</prop>
<prop oor:name="DocumentService">
<value>com.sun.star.text.TextDocument</value>
</prop>
</node>

View file

@ -0,0 +1,29 @@
<!--
* 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/.
*
-->
<node oor:name="writer_BroadBand_eBook" oor:op="replace">
<prop oor:name="DetectService">
<value>org.libreoffice.comp.Writer.EBookImportFilter</value>
</prop>
<prop oor:name="Extensions">
<value>lrf</value>
</prop>
<prop oor:name="MediaType">
<value>application/x-sony-bbeb</value>
</prop>
<prop oor:name="Preferred">
<value>true</value>
</prop>
<prop oor:name="PreferredFilter">
<value>BroadBand eBook</value>
</prop>
<prop oor:name="UIName">
<value>BroadBand eBook</value>
</prop>
</node>

View file

@ -0,0 +1,29 @@
<!--
* 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/.
*
-->
<node oor:name="writer_FictionBook_2" oor:op="replace">
<prop oor:name="DetectService">
<value>org.libreoffice.comp.Writer.EBookImportFilter</value>
</prop>
<prop oor:name="Extensions">
<value>fb2 zip</value>
</prop>
<prop oor:name="MediaType">
<value>text/xml</value>
</prop>
<prop oor:name="Preferred">
<value>true</value>
</prop>
<prop oor:name="PreferredFilter">
<value>FictionBook 2</value>
</prop>
<prop oor:name="UIName">
<value>FictionBook 2.0</value>
</prop>
</node>

View file

@ -0,0 +1,29 @@
<!--
* 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/.
*
-->
<node oor:name="writer_PalmDoc" oor:op="replace">
<prop oor:name="DetectService">
<value>org.libreoffice.comp.Writer.EBookImportFilter</value>
</prop>
<prop oor:name="Extensions">
<value>pdb</value>
</prop>
<prop oor:name="MediaType">
<value>application/vnd.palm</value>
</prop>
<prop oor:name="Preferred">
<value>true</value>
</prop>
<prop oor:name="PreferredFilter">
<value>PalmDoc</value>
</prop>
<prop oor:name="UIName">
<value>PalmDoc eBook</value>
</prop>
</node>

View file

@ -0,0 +1,29 @@
<!--
* 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/.
*
-->
<node oor:name="writer_Plucker_eBook" oor:op="replace">
<prop oor:name="DetectService">
<value>org.libreoffice.comp.Writer.EBookImportFilter</value>
</prop>
<prop oor:name="Extensions">
<value>pdb</value>
</prop>
<prop oor:name="MediaType">
<value>application/prs.plucker</value>
</prop>
<prop oor:name="Preferred">
<value>true</value>
</prop>
<prop oor:name="PreferredFilter">
<value>Plucker eBook</value>
</prop>
<prop oor:name="UIName">
<value>Plucker eBook</value>
</prop>
</node>

View file

@ -0,0 +1,29 @@
<!--
* 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/.
*
-->
<node oor:name="writer_TealDoc" oor:op="replace">
<prop oor:name="DetectService">
<value>org.libreoffice.comp.Writer.EBookImportFilter</value>
</prop>
<prop oor:name="Extensions">
<value>pdb</value>
</prop>
<prop oor:name="MediaType">
<value>application/vnd.palm</value>
</prop>
<prop oor:name="Preferred">
<value>true</value>
</prop>
<prop oor:name="PreferredFilter">
<value>TealDoc</value>
</prop>
<prop oor:name="UIName">
<value>TealDoc eBook</value>
</prop>
</node>

View file

@ -0,0 +1,29 @@
<!--
* 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/.
*
-->
<node oor:name="writer_eReader_eBook" oor:op="replace">
<prop oor:name="DetectService">
<value>org.libreoffice.comp.Writer.EBookImportFilter</value>
</prop>
<prop oor:name="Extensions">
<value>pdb</value>
</prop>
<prop oor:name="MediaType">
<value>application/vnd.palm</value>
</prop>
<prop oor:name="Preferred">
<value>true</value>
</prop>
<prop oor:name="PreferredFilter">
<value>eReader eBook</value>
</prop>
<prop oor:name="UIName">
<value>eReader eBook</value>
</prop>
</node>

View file

@ -0,0 +1,29 @@
<!--
* 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/.
*
-->
<node oor:name="writer_zTXT" oor:op="replace">
<prop oor:name="DetectService">
<value>org.libreoffice.comp.Writer.EBookImportFilter</value>
</prop>
<prop oor:name="Extensions">
<value>pdb</value>
</prop>
<prop oor:name="MediaType">
<value>application/vnd.palm</value>
</prop>
<prop oor:name="Preferred">
<value>true</value>
</prop>
<prop oor:name="PreferredFilter">
<value>zTXT</value>
</prop>
<prop oor:name="UIName">
<value>zTXT eBook</value>
</prop>
</node>

View file

@ -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 \

View file

@ -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: */

View file

@ -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: */

View file

@ -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 } };
}

View file

@ -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>