From 867ccbc19b419e688c81485257371e2681a7775a Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Tue, 19 May 2015 10:48:43 +0200 Subject: Remove redundant writerperfect/inc/writerperfect hierarchy segment Change-Id: Ib2c84536d829b3d4cf2f0112a9735cc132ee7d24 --- writerperfect/inc/DocumentHandlerFor.hxx | 28 +++ writerperfect/inc/ImportFilter.hxx | 207 +++++++++++++++++++++ .../inc/writerperfect/DocumentHandlerFor.hxx | 28 --- writerperfect/inc/writerperfect/ImportFilter.hxx | 207 --------------------- 4 files changed, 235 insertions(+), 235 deletions(-) create mode 100644 writerperfect/inc/DocumentHandlerFor.hxx create mode 100644 writerperfect/inc/ImportFilter.hxx delete mode 100644 writerperfect/inc/writerperfect/DocumentHandlerFor.hxx delete mode 100644 writerperfect/inc/writerperfect/ImportFilter.hxx (limited to 'writerperfect/inc') diff --git a/writerperfect/inc/DocumentHandlerFor.hxx b/writerperfect/inc/DocumentHandlerFor.hxx new file mode 100644 index 000000000000..fbe10a795e8d --- /dev/null +++ b/writerperfect/inc/DocumentHandlerFor.hxx @@ -0,0 +1,28 @@ +/* -*- 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_INC_WRITERPERFECT_DOCUMENTHANDLERFOR_HXX +#define INCLUDED_WRITERPERFECT_INC_WRITERPERFECT_DOCUMENTHANDLERFOR_HXX + +namespace writerperfect +{ + +/** Definition of XML import service used with a Generator. + + This template must be specialized for every libodfgen generator. + */ +template +struct DocumentHandlerFor +{ + // static const rtl::OUString name(); +}; + +} + +#endif // INCLUDED_WRITERPERFECT_INC_WRITERPERFECT_DOCUMENTHANDLERFOR_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/inc/ImportFilter.hxx b/writerperfect/inc/ImportFilter.hxx new file mode 100644 index 000000000000..d3d1e04acd7a --- /dev/null +++ b/writerperfect/inc/ImportFilter.hxx @@ -0,0 +1,207 @@ +/* -*- 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_INC_WRITERPERFECT_IMPORTFILTER_HXX +#define INCLUDED_WRITERPERFECT_INC_WRITERPERFECT_IMPORTFILTER_HXX + +#include + +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include + +#include +#include + +#include + +#include "DocumentHandlerFor.hxx" + +namespace writerperfect +{ + +namespace detail +{ + +template +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) + : mxContext(rxContext) + { + } + + virtual ~ImportFilterImpl() + { + } + + // XFilter + virtual sal_Bool SAL_CALL filter(const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > &rDescriptor) + throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE + { + utl::MediaDescriptor aDescriptor(rDescriptor); + css::uno::Reference < css::io::XInputStream > xInputStream; + aDescriptor[utl::MediaDescriptor::PROP_INPUTSTREAM()] >>= xInputStream; + if (!xInputStream.is()) + { + OSL_ASSERT(false); + return sal_False; + } + + // An XML import service: what we push sax messages to.. + css::uno::Reference < css::xml::sax::XDocumentHandler > xInternalHandler( + mxContext->getServiceManager()->createInstanceWithContext( + DocumentHandlerFor::name(), mxContext), + css::uno::UNO_QUERY_THROW); + + // The XImporter sets up an empty target document for XDocumentHandler to write to.. + css::uno::Reference < css::document::XImporter > xImporter(xInternalHandler, css::uno::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); + + Generator exporter; + exporter.addDocumentHandler(&xHandler, ODF_FLAT_XML); + + this->doRegisterHandlers(exporter); + + return this->doImportDocument(input, exporter, aDescriptor); + } + + 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 + { + mxDoc = xDoc; + } + + //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 + { + OUString sTypeName; + sal_Int32 nLength = Descriptor.getLength(); + sal_Int32 location = nLength; + const css::beans::PropertyValue *pValue = Descriptor.getConstArray(); + css::uno::Reference < css::io::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 (this->doDetectFormat(input, sTypeName)) + { + assert(!sTypeName.isEmpty()); + + if (location == nLength) + { + Descriptor.realloc(nLength+1); + Descriptor[location].Name = "TypeName"; + } + + Descriptor[location].Value <<=sTypeName; + } + + return sTypeName; + } + + // 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 + { + css::uno::Sequence < css::beans::PropertyValue > aAnySeq; + sal_Int32 nLength = aArguments.getLength(); + if (nLength && (aArguments[0] >>= aAnySeq)) + { + const css::beans::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; + } + } + } + } + +private: + virtual bool doDetectFormat(librevenge::RVNGInputStream &rInput, OUString &rTypeName) = 0; + virtual bool doImportDocument(librevenge::RVNGInputStream &rInput, Generator &rGenerator, utl::MediaDescriptor &rDescriptor) = 0; + virtual void doRegisterHandlers(Generator &) + { + } + +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. + */ +template +struct ImportFilter : public cppu::ImplInheritanceHelper1, com::sun::star::lang::XServiceInfo> +{ + ImportFilter(const css::uno::Reference &rxContext) + : cppu::ImplInheritanceHelper1, com::sun::star::lang::XServiceInfo>(rxContext) + { + } +}; + +} + +#endif // INCLUDED_WRITERPERFECT_INC_WRITERPERFECT_IMPORTFILTER_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/inc/writerperfect/DocumentHandlerFor.hxx b/writerperfect/inc/writerperfect/DocumentHandlerFor.hxx deleted file mode 100644 index fbe10a795e8d..000000000000 --- a/writerperfect/inc/writerperfect/DocumentHandlerFor.hxx +++ /dev/null @@ -1,28 +0,0 @@ -/* -*- 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_INC_WRITERPERFECT_DOCUMENTHANDLERFOR_HXX -#define INCLUDED_WRITERPERFECT_INC_WRITERPERFECT_DOCUMENTHANDLERFOR_HXX - -namespace writerperfect -{ - -/** Definition of XML import service used with a Generator. - - This template must be specialized for every libodfgen generator. - */ -template -struct DocumentHandlerFor -{ - // static const rtl::OUString name(); -}; - -} - -#endif // INCLUDED_WRITERPERFECT_INC_WRITERPERFECT_DOCUMENTHANDLERFOR_HXX - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/inc/writerperfect/ImportFilter.hxx b/writerperfect/inc/writerperfect/ImportFilter.hxx deleted file mode 100644 index 214f02e675e8..000000000000 --- a/writerperfect/inc/writerperfect/ImportFilter.hxx +++ /dev/null @@ -1,207 +0,0 @@ -/* -*- 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_INC_WRITERPERFECT_IMPORTFILTER_HXX -#define INCLUDED_WRITERPERFECT_INC_WRITERPERFECT_IMPORTFILTER_HXX - -#include - -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include - -#include -#include - -#include - -#include "writerperfect/DocumentHandlerFor.hxx" - -namespace writerperfect -{ - -namespace detail -{ - -template -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) - : mxContext(rxContext) - { - } - - virtual ~ImportFilterImpl() - { - } - - // XFilter - virtual sal_Bool SAL_CALL filter(const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > &rDescriptor) - throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE - { - utl::MediaDescriptor aDescriptor(rDescriptor); - css::uno::Reference < css::io::XInputStream > xInputStream; - aDescriptor[utl::MediaDescriptor::PROP_INPUTSTREAM()] >>= xInputStream; - if (!xInputStream.is()) - { - OSL_ASSERT(false); - return sal_False; - } - - // An XML import service: what we push sax messages to.. - css::uno::Reference < css::xml::sax::XDocumentHandler > xInternalHandler( - mxContext->getServiceManager()->createInstanceWithContext( - DocumentHandlerFor::name(), mxContext), - css::uno::UNO_QUERY_THROW); - - // The XImporter sets up an empty target document for XDocumentHandler to write to.. - css::uno::Reference < css::document::XImporter > xImporter(xInternalHandler, css::uno::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); - - Generator exporter; - exporter.addDocumentHandler(&xHandler, ODF_FLAT_XML); - - this->doRegisterHandlers(exporter); - - return this->doImportDocument(input, exporter, aDescriptor); - } - - 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 - { - mxDoc = xDoc; - } - - //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 - { - OUString sTypeName; - sal_Int32 nLength = Descriptor.getLength(); - sal_Int32 location = nLength; - const css::beans::PropertyValue *pValue = Descriptor.getConstArray(); - css::uno::Reference < css::io::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 (this->doDetectFormat(input, sTypeName)) - { - assert(!sTypeName.isEmpty()); - - if (location == nLength) - { - Descriptor.realloc(nLength+1); - Descriptor[location].Name = "TypeName"; - } - - Descriptor[location].Value <<=sTypeName; - } - - return sTypeName; - } - - // 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 - { - css::uno::Sequence < css::beans::PropertyValue > aAnySeq; - sal_Int32 nLength = aArguments.getLength(); - if (nLength && (aArguments[0] >>= aAnySeq)) - { - const css::beans::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; - } - } - } - } - -private: - virtual bool doDetectFormat(librevenge::RVNGInputStream &rInput, OUString &rTypeName) = 0; - virtual bool doImportDocument(librevenge::RVNGInputStream &rInput, Generator &rGenerator, utl::MediaDescriptor &rDescriptor) = 0; - virtual void doRegisterHandlers(Generator &) - { - } - -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. - */ -template -struct ImportFilter : public cppu::ImplInheritanceHelper1, com::sun::star::lang::XServiceInfo> -{ - ImportFilter(const css::uno::Reference &rxContext) - : cppu::ImplInheritanceHelper1, com::sun::star::lang::XServiceInfo>(rxContext) - { - } -}; - -} - -#endif // INCLUDED_WRITERPERFECT_INC_WRITERPERFECT_IMPORTFILTER_HXX - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit