Kaydet (Commit) 9129b5ac authored tarafından Kishor Bhat's avatar Kishor Bhat Kaydeden (comit) David Tardon

tdf#84168 convert wpftimpress to use ImportFilter base class

Change-Id: Ie41613e66a2fad1b6d4dd22b59d864e8684aad7b
Reviewed-on: https://gerrit.libreoffice.org/14359Reviewed-by: 's avatarDavid Tardon <dtardon@redhat.com>
Tested-by: 's avatarDavid Tardon <dtardon@redhat.com>
üst b97341c8
......@@ -19,6 +19,11 @@
$(eval $(call gb_Library_Library,wpftimpress))
$(eval $(call gb_Library_set_include,wpftimpress,\
-I$(SRCDIR)/writerperfect/inc \
$$(INCLUDE) \
))
$(eval $(call gb_Library_set_componentfile,wpftimpress,writerperfect/source/impress/wpftimpress))
$(eval $(call gb_Library_use_sdk_api,wpftimpress))
......@@ -48,7 +53,6 @@ $(eval $(call gb_Library_use_externals,wpftimpress,\
))
$(eval $(call gb_Library_add_exception_objects,wpftimpress,\
writerperfect/source/impress/ImportFilterBase \
writerperfect/source/impress/KeynoteImportFilter \
writerperfect/source/impress/MWAWPresentationImportFilter \
writerperfect/source/impress/wpftimpress_genericfilter \
......
/* -*- 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_DOCUMENTHANDLERFORODP_HXX
#define INCLUDED_WRITERPERFECT_SOURCE_IMPRESS_DOCUMENTHANDLERFORODP_HXX
#include <libodfgen/libodfgen.hxx>
#include "writerperfect/DocumentHandlerFor.hxx"
namespace writerperfect
{
template<>
struct DocumentHandlerFor<OdpGenerator>
{
static const rtl::OUString name()
{
return rtl::OUString("com.sun.star.comp.Impress.XMLOasisImporter");
}
};
}
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
\ No newline at end of file
/* -*- 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/.
*/
#include <boost/shared_ptr.hpp>
#include <com/sun/star/beans/NamedValue.hpp>
#include <com/sun/star/beans/PropertyValue.hpp>
#include <com/sun/star/io/XInputStream.hpp>
#include <com/sun/star/io/XSeekable.hpp>
#include <com/sun/star/ucb/XCommandEnvironment.hpp>
#include <com/sun/star/ucb/XContent.hpp>
#include <com/sun/star/uno/Reference.h>
#include <com/sun/star/uno/XComponentContext.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 <osl/diagnose.h>
#include <writerperfect/DirectoryStream.hxx>
#include <writerperfect/DocumentHandler.hxx>
#include <writerperfect/WPXSvInputStream.hxx>
#include <xmloff/attrlist.hxx>
#include <libodfgen/libodfgen.hxx>
#include "ImportFilterBase.hxx"
using boost::shared_ptr;
namespace writerperfect
{
namespace presentation
{
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;
using writerperfect::DocumentHandler;
using writerperfect::WPXSvInputStream;
namespace
{
template<class T>
bool lcl_queryIsPackage(const Sequence<T> &lComponentData)
{
bool bIsPackage = false;
const sal_Int32 nLength = lComponentData.getLength();
const T *pValue = lComponentData.getConstArray();
for (sal_Int32 i = 0; i < nLength; ++i)
{
if (pValue[i].Name == "IsPackage")
{
pValue[i].Value >>= bIsPackage;
break;
}
}
return bIsPackage;
}
bool lcl_isPackage(const Any &rComponentData)
{
Sequence < ::com::sun::star::beans::NamedValue > lComponentDataNV;
Sequence < ::com::sun::star::beans::PropertyValue > lComponentDataPV;
if (rComponentData >>= lComponentDataNV)
return lcl_queryIsPackage(lComponentDataNV);
else if (rComponentData >>= lComponentDataPV)
return lcl_queryIsPackage(lComponentDataPV);
return false;
}
}
ImportFilterImpl::ImportFilterImpl(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > &rxContext)
: mxContext(rxContext)
{
}
ImportFilterImpl::~ImportFilterImpl()
{
}
sal_Bool SAL_CALL ImportFilterImpl::filter(const Sequence< ::com::sun::star::beans::PropertyValue > &aDescriptor)
throw (RuntimeException, std::exception)
{
sal_Int32 nLength = aDescriptor.getLength();
const PropertyValue *pValue = aDescriptor.getConstArray();
Reference < XInputStream > xInputStream;
Reference < ::com::sun::star::ucb::XContent > xContent;
bool bIsPackage = false;
for (sal_Int32 i = 0 ; i < nLength; i++)
{
if (pValue[i].Name == "ComponentData")
bIsPackage = lcl_isPackage(pValue[i].Value);
else if (pValue[i].Name == "InputStream")
pValue[i].Value >>= xInputStream;
else if (pValue[i].Name == "UCBContent")
pValue[i].Value >>= xContent;
}
if (!xInputStream.is())
{
OSL_ASSERT(false);
return sal_False;
}
if (bIsPackage && !xContent.is())
{
SAL_WARN("writerperfect", "presentation::ImportFilterImpl::filter: the input claims to be a package, but does not have UCBContent");
bIsPackage = false;
}
// An XML import service: what we push sax messages to..
Reference < XDocumentHandler > xInternalHandler(
mxContext->getServiceManager()->createInstanceWithContext(
"com.sun.star.comp.Impress.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);
shared_ptr< librevenge::RVNGInputStream > input;
if (bIsPackage)
input.reset(new writerperfect::DirectoryStream(xContent));
else
input.reset(new WPXSvInputStream(xInputStream));
OdpGenerator exporter;
exporter.addDocumentHandler(&xHandler, ODF_FLAT_XML);
doRegisterHandlers(exporter);
bool result=doImportDocument(*input, exporter);
return result;
}
void SAL_CALL ImportFilterImpl::cancel()
throw (RuntimeException, std::exception)
{
}
// XImporter
void SAL_CALL ImportFilterImpl::setTargetDocument(const Reference< ::com::sun::star::lang::XComponent > &xDoc)
throw (::com::sun::star::lang::IllegalArgumentException, RuntimeException, std::exception)
{
mxDoc = xDoc;
}
// XExtendedFilterDetection
OUString SAL_CALL ImportFilterImpl::detect(com::sun::star::uno::Sequence< PropertyValue > &Descriptor)
throw(com::sun::star::uno::RuntimeException, std::exception)
{
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 (doDetectFormat(input, sTypeName))
{
assert(!sTypeName.isEmpty());
if (location == nLength)
{
Descriptor.realloc(nLength+1);
Descriptor[location].Name = "TypeName";
}
Descriptor[location].Value <<=sTypeName;
}
return sTypeName;
}
// XInitialization
void SAL_CALL ImportFilterImpl::initialize(const Sequence< Any > &aArguments)
throw (Exception, RuntimeException, std::exception)
{
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;
}
}
}
}
bool ImportFilterImpl::doDetectFormat(librevenge::RVNGInputStream &, OUString &)
{
SAL_WARN("writerperfect", "presentation::ImportFilterImpl::doDetectFormat must not be called");
return false;
}
void ImportFilterImpl::doRegisterHandlers(OdpGenerator &)
{
}
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- 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_IMPORTFILTERBASE_HXX
#define INCLUDED_WRITERPERFECT_SOURCE_IMPRESS_IMPORTFILTERBASE_HXX
#include <librevenge/librevenge.h>
#include <librevenge-stream/librevenge-stream.h>
#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 <cppuhelper/implbase1.hxx>
#include <cppuhelper/implbase4.hxx>
namespace com
{
namespace sun
{
namespace star
{
namespace beans
{
struct PropertyValue;
}
namespace lang
{
class XComponent;
}
namespace uno
{
class XComponentContext;
}
namespace xml
{
namespace sax
{
class XDocumentHandler;
}
}
}
}
}
class OdpGenerator;
namespace writerperfect
{
namespace presentation
{
/* 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 ImportFilterImpl : public cppu::WeakImplHelper4
<
com::sun::star::document::XFilter,
com::sun::star::document::XImporter,
com::sun::star::document::XExtendedFilterDetection,
com::sun::star::lang::XInitialization
>
{
public:
ImportFilterImpl(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > &rxContext);
virtual ~ImportFilterImpl();
// 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, std::exception) SAL_OVERRIDE;
virtual void SAL_CALL cancel()
throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
// 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, std::exception) SAL_OVERRIDE;
//XExtendedFilterDetection
virtual OUString SAL_CALL detect(com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue > &Descriptor)
throw(com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
// 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, std::exception) SAL_OVERRIDE;
private:
virtual bool doDetectFormat(librevenge::RVNGInputStream &rInput, OUString &rTypeName);
virtual bool doImportDocument(librevenge::RVNGInputStream &rInput, librevenge::RVNGPresentationInterface &rGenerator) = 0;
virtual void doRegisterHandlers(OdpGenerator &rGenerator);
private:
::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;
};
/** A base class for import filters.
*/
typedef cppu::ImplInheritanceHelper1<ImportFilterImpl, com::sun::star::lang::XServiceInfo> ImportFilterBase;
}
}
#endif // INCLUDED_WRITERPERFECT_SOURCE_DRAW_IMPORTFILTERBASE_HXX
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -52,11 +52,22 @@ namespace beans = com::sun::star::beans;
namespace container = com::sun::star::container;
namespace ucb = com::sun::star::ucb;
bool KeynoteImportFilter::doImportDocument(librevenge::RVNGInputStream &rInput, librevenge::RVNGPresentationInterface &rGenerator)
bool KeynoteImportFilter::doImportDocument(librevenge::RVNGInputStream &rInput, OdpGenerator &rGenerator, utl::MediaDescriptor &)
{
return libetonyek::EtonyekDocument::parse(&rInput, &rGenerator);
}
bool KeynoteImportFilter::doDetectFormat(librevenge::RVNGInputStream &rInput, OUString &rTypeName)
{
if (libetonyek::EtonyekDocument::isSupported(&rInput))
{
rTypeName = "impress_Keynote_Document";
return true;
}
return false;
}
// XExtendedFilterDetection
OUString SAL_CALL KeynoteImportFilter::detect(com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue > &Descriptor)
throw(com::sun::star::uno::RuntimeException, std::exception)
......
......@@ -11,17 +11,19 @@
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/uno/XComponentContext.hpp>
#include "ImportFilterBase.hxx"
#include "writerperfect/ImportFilter.hxx"
#include "DocumentHandlerForOdp.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 writerperfect::presentation::ImportFilterBase
class KeynoteImportFilter : public writerperfect::ImportFilter<OdpGenerator>
{
public:
KeynoteImportFilter(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > &rxContext)
: writerperfect::presentation::ImportFilterBase(rxContext) {}
: writerperfect::ImportFilter<OdpGenerator>(rxContext) {}
virtual ~KeynoteImportFilter() {}
//XExtendedFilterDetection
......@@ -37,7 +39,8 @@ public:
throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
private:
virtual bool doImportDocument(librevenge::RVNGInputStream &rInput, librevenge::RVNGPresentationInterface &rGenerator) SAL_OVERRIDE;
virtual bool doDetectFormat(librevenge::RVNGInputStream &rInput, OUString &rTypeName) SAL_OVERRIDE;
virtual bool doImportDocument(librevenge::RVNGInputStream &rInput, OdpGenerator &rGenerator, utl::MediaDescriptor &) SAL_OVERRIDE;
};
OUString KeynoteImportFilter_getImplementationName()
......
......@@ -39,7 +39,7 @@ static bool handleEmbeddedMWAWSpreadsheetObject(const librevenge::RVNGBinaryData
return MWAWDocument::decodeSpreadsheet(data, &exporter);
}
bool MWAWPresentationImportFilter::doImportDocument(librevenge::RVNGInputStream &rInput, librevenge::RVNGPresentationInterface &rGenerator)
bool MWAWPresentationImportFilter::doImportDocument(librevenge::RVNGInputStream &rInput, OdpGenerator &rGenerator, utl::MediaDescriptor &)
{
return MWAWDocument::MWAW_R_OK == MWAWDocument::parse(&rInput, &rGenerator);
}
......
......@@ -13,16 +13,18 @@
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/uno/XComponentContext.hpp>
#include "ImportFilterBase.hxx"
#include "writerperfect/ImportFilter.hxx"
#include "DocumentHandlerForOdp.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 MWAWPresentationImportFilter : public writerperfect::presentation::ImportFilterBase
class MWAWPresentationImportFilter : public writerperfect::ImportFilter<OdpGenerator>
{
public:
MWAWPresentationImportFilter(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > &rxContext)
: writerperfect::presentation::ImportFilterBase(rxContext) {}
: writerperfect::ImportFilter<OdpGenerator>(rxContext) {}
// XServiceInfo
virtual OUString SAL_CALL getImplementationName()
......@@ -34,7 +36,7 @@ public:
private:
virtual bool doDetectFormat(librevenge::RVNGInputStream &rInput, OUString &rTypeName) SAL_OVERRIDE;
virtual bool doImportDocument(librevenge::RVNGInputStream &rInput, librevenge::RVNGPresentationInterface &rGenerator) SAL_OVERRIDE;
virtual bool doImportDocument(librevenge::RVNGInputStream &rInput, OdpGenerator &rGenerator, utl::MediaDescriptor &) SAL_OVERRIDE;
virtual void doRegisterHandlers(OdpGenerator &rGenerator) SAL_OVERRIDE;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment