diff options
Diffstat (limited to 'writerperfect')
-rw-r--r-- | writerperfect/Library_wpftwriter.mk | 1 | ||||
-rw-r--r-- | writerperfect/source/writer/AbiWordImportFilter.cxx | 160 | ||||
-rw-r--r-- | writerperfect/source/writer/AbiWordImportFilter.hxx | 50 | ||||
-rw-r--r-- | writerperfect/source/writer/EBookImportFilter.cxx | 216 | ||||
-rw-r--r-- | writerperfect/source/writer/EBookImportFilter.hxx | 50 | ||||
-rw-r--r-- | writerperfect/source/writer/ImportFilterBase.cxx | 186 | ||||
-rw-r--r-- | writerperfect/source/writer/ImportFilterBase.hxx | 102 | ||||
-rw-r--r-- | writerperfect/source/writer/MSWorksImportFilter.cxx | 159 | ||||
-rw-r--r-- | writerperfect/source/writer/MSWorksImportFilter.hxx | 50 | ||||
-rw-r--r-- | writerperfect/source/writer/MWAWImportFilter.cxx | 202 | ||||
-rw-r--r-- | writerperfect/source/writer/MWAWImportFilter.hxx | 51 |
11 files changed, 402 insertions, 825 deletions
diff --git a/writerperfect/Library_wpftwriter.mk b/writerperfect/Library_wpftwriter.mk index f6f8d3fe2209..c8a16313b0e9 100644 --- a/writerperfect/Library_wpftwriter.mk +++ b/writerperfect/Library_wpftwriter.mk @@ -58,6 +58,7 @@ $(eval $(call gb_Library_use_externals,wpftwriter,\ $(eval $(call gb_Library_add_exception_objects,wpftwriter,\ writerperfect/source/writer/AbiWordImportFilter \ writerperfect/source/writer/EBookImportFilter \ + writerperfect/source/writer/ImportFilterBase \ writerperfect/source/writer/MSWorksImportFilter \ writerperfect/source/writer/MWAWImportFilter \ writerperfect/source/writer/WordPerfectImportFilter \ diff --git a/writerperfect/source/writer/AbiWordImportFilter.cxx b/writerperfect/source/writer/AbiWordImportFilter.cxx index 04048e2bb321..034f2480ffc8 100644 --- a/writerperfect/source/writer/AbiWordImportFilter.cxx +++ b/writerperfect/source/writer/AbiWordImportFilter.cxx @@ -9,179 +9,37 @@ * 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 <writerperfect/DocumentHandler.hxx> -#include <writerperfect/WPXSvInputStream.hxx> - -#include <xmloff/attrlist.hxx> -#include <ucbhelper/content.hxx> - #include <libabw/libabw.h> -#include <libodfgen/libodfgen.hxx> - #include "AbiWordImportFilter.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; - -using writerperfect::DocumentHandler; -using writerperfect::WPXSvInputStream; - -sal_Bool SAL_CALL AbiWordImportFilter::importImpl( const Sequence< ::com::sun::star::beans::PropertyValue >& aDescriptor ) -throw (RuntimeException) -{ - SAL_INFO("writerperfect", "AbiWordImportFilter::importImpl"); - - 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( false ); - 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 (libabw::AbiDocument::parse(&input, &collector)) - return sal_True; - return sal_False; -} - -sal_Bool SAL_CALL AbiWordImportFilter::filter( const Sequence< ::com::sun::star::beans::PropertyValue >& aDescriptor ) -throw (RuntimeException, std::exception) -{ - SAL_INFO("writerperfect", "AbiWordImportFilter::filter"); - return importImpl ( aDescriptor ); -} -void SAL_CALL AbiWordImportFilter::cancel( ) -throw (RuntimeException, std::exception) -{ - SAL_INFO("writerperfect", "AbiWordImportFilter::cancel"); -} +using com::sun::star::uno::XComponentContext; +using com::sun::star::uno::XInterface; -// XImporter -void SAL_CALL AbiWordImportFilter::setTargetDocument( const Reference< ::com::sun::star::lang::XComponent >& xDoc ) -throw (::com::sun::star::lang::IllegalArgumentException, RuntimeException, std::exception) +bool AbiWordImportFilter::doImportDocument( WPXInputStream &rInput, const rtl::OUString &, WPXDocumentInterface &rGenerator ) { - SAL_INFO("writerperfect", "AbiWordImportFilter::getTargetDocument"); - mxDoc = xDoc; + return libabw::AbiDocument::parse(&rInput, &rGenerator); } -// XExtendedFilterDetection -OUString SAL_CALL AbiWordImportFilter::detect( com::sun::star::uno::Sequence< PropertyValue >& Descriptor ) -throw( com::sun::star::uno::RuntimeException, std::exception ) +bool AbiWordImportFilter::doDetectFormat( WPXInputStream &rInput, OUString &rTypeName ) { - SAL_INFO("writerperfect", "AbiWordImportFilter::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 (libabw::AbiDocument::isFileFormatSupported(&rInput)) { - if ( pValue[i].Name == "TypeName" ) - location=i; - else if ( pValue[i].Name == "InputStream" ) - pValue[i].Value >>= xInputStream; + rTypeName = "writer_AbiWord_Document"; + return true; } - if (!xInputStream.is()) - return OUString(); - - WPXSvInputStream input( xInputStream ); - - if (libabw::AbiDocument::isFileFormatSupported(&input)) - sTypeName = "writer_AbiWord_Document"; - - if (!sTypeName.isEmpty()) - { - if ( location == nLength ) - { - Descriptor.realloc(nLength+1); - Descriptor[location].Name = "TypeName"; - } - - Descriptor[location].Value <<=sTypeName; - } - - return sTypeName; + return false; } - -// XInitialization -void SAL_CALL AbiWordImportFilter::initialize( const Sequence< Any >& aArguments ) -throw (Exception, RuntimeException, std::exception) -{ - SAL_INFO("writerperfect", "AbiWordImportFilter::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 AbiWordImportFilter_getImplementationName () throw (RuntimeException) { diff --git a/writerperfect/source/writer/AbiWordImportFilter.hxx b/writerperfect/source/writer/AbiWordImportFilter.hxx index fa6085487016..c1a75d503046 100644 --- a/writerperfect/source/writer/AbiWordImportFilter.hxx +++ b/writerperfect/source/writer/AbiWordImportFilter.hxx @@ -10,58 +10,19 @@ #ifndef _ABIWORDIMPORTFILTER_HXX #define _ABIWORDIMPORTFILTER_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 "ImportFilterBase.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 AbiWordImportFilter : 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 - > +class AbiWordImportFilter : public writerperfect::writer::ImportFilterBase { -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: AbiWordImportFilter( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > &rxContext ) - : mxContext( rxContext ) {} - virtual ~AbiWordImportFilter() {} - - // 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; + : writerperfect::writer::ImportFilterBase( rxContext ) {} // XServiceInfo virtual OUString SAL_CALL getImplementationName( ) @@ -71,6 +32,9 @@ public: virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; +private: + virtual bool doDetectFormat( WPXInputStream &rInput, OUString &rTypeName ) SAL_OVERRIDE; + virtual bool doImportDocument( WPXInputStream &rInput, const rtl::OUString &rFilterName, WPXDocumentInterface &rGenerator ) SAL_OVERRIDE; }; OUString AbiWordImportFilter_getImplementationName() diff --git a/writerperfect/source/writer/EBookImportFilter.cxx b/writerperfect/source/writer/EBookImportFilter.cxx index f566be5a10d1..6c1434761ef1 100644 --- a/writerperfect/source/writer/EBookImportFilter.cxx +++ b/writerperfect/source/writer/EBookImportFilter.cxx @@ -9,209 +9,59 @@ * 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 <writerperfect/DocumentHandler.hxx> -#include <writerperfect/WPXSvInputStream.hxx> - -#include <xmloff/attrlist.hxx> -#include <ucbhelper/content.hxx> - #include <libe-book/libe-book.h> -#include <libodfgen/libodfgen.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; - -using writerperfect::DocumentHandler; -using writerperfect::WPXSvInputStream; - -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( false ); - return sal_False; - } - if ( !xInputStream.is() ) - { - OSL_ASSERT( false ); - 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; -} +using com::sun::star::uno::XComponentContext; -sal_Bool SAL_CALL EBookImportFilter::filter( const Sequence< ::com::sun::star::beans::PropertyValue >& aDescriptor ) -throw (RuntimeException, std::exception) -{ - SAL_INFO("writerperfect", "EBookImportFilter::filter"); - return importImpl ( aDescriptor ); -} -void SAL_CALL EBookImportFilter::cancel( ) -throw (RuntimeException, std::exception) +bool EBookImportFilter::doImportDocument( WPXInputStream &rInput, const rtl::OUString &rFilterName, WPXDocumentInterface &rGenerator ) { - SAL_INFO("writerperfect", "EBookImportFilter::cancel"); + if (rFilterName == "FictionBook 2") + return libebook::FB2Document::parse(&rInput, &rGenerator); + else if (rFilterName == "PalmDoc") + return libebook::PDBDocument::parse(&rInput, &rGenerator); + else if (rFilterName == "Plucker eBook") + return libebook::PLKRDocument::parse(&rInput, &rGenerator); + else if (rFilterName == "eReader eBook") + return libebook::PMLDocument::parse(&rInput, &rGenerator); + else if (rFilterName == "TealDoc") + return libebook::TDDocument::parse(&rInput, &rGenerator); + else if (rFilterName == "zTXT") + return libebook::ZTXTDocument::parse(&rInput, &rGenerator); + + return false; } -// XImporter -void SAL_CALL EBookImportFilter::setTargetDocument( const Reference< ::com::sun::star::lang::XComponent >& xDoc ) -throw (::com::sun::star::lang::IllegalArgumentException, RuntimeException, std::exception) +bool EBookImportFilter::doDetectFormat( WPXInputStream &rInput, OUString &rTypeName ) { - 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, std::exception ) -{ - 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; + rTypeName = ""; + + if (libebook::FB2Document::isSupported(&rInput)) + rTypeName = "writer_FictionBook_2"; + else if (libebook::PDBDocument::isSupported(&rInput)) + rTypeName = "writer_PalmDoc"; + else if (libebook::PLKRDocument::isSupported(&rInput)) + rTypeName = "writer_Plucker_eBook"; + else if (libebook::PMLDocument::isSupported(&rInput)) + rTypeName = "writer_eReader_eBook"; + else if (libebook::TDDocument::isSupported(&rInput)) + rTypeName = "writer_TealDoc"; + else if (libebook::ZTXTDocument::isSupported(&rInput)) + rTypeName = "writer_zTXT"; + + return !rTypeName.isEmpty(); } - -// XInitialization -void SAL_CALL EBookImportFilter::initialize( const Sequence< Any >& aArguments ) -throw (Exception, RuntimeException, std::exception) -{ - 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) { diff --git a/writerperfect/source/writer/EBookImportFilter.hxx b/writerperfect/source/writer/EBookImportFilter.hxx index 3240bc8f64ac..693ce31280af 100644 --- a/writerperfect/source/writer/EBookImportFilter.hxx +++ b/writerperfect/source/writer/EBookImportFilter.hxx @@ -10,58 +10,19 @@ #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> + +#include "ImportFilterBase.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 - > +class EBookImportFilter : public writerperfect::writer::ImportFilterBase { -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, 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; + : writerperfect::writer::ImportFilterBase( rxContext ) {} // XServiceInfo virtual OUString SAL_CALL getImplementationName( ) @@ -71,6 +32,9 @@ public: virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; +private: + virtual bool doDetectFormat( WPXInputStream &rInput, OUString &rTypeName ) SAL_OVERRIDE; + virtual bool doImportDocument( WPXInputStream &rInput, const rtl::OUString &rFilterName, WPXDocumentInterface &rGenerator ) SAL_OVERRIDE; }; OUString EBookImportFilter_getImplementationName() diff --git a/writerperfect/source/writer/ImportFilterBase.cxx b/writerperfect/source/writer/ImportFilterBase.cxx new file mode 100644 index 000000000000..f5bc6b9ff736 --- /dev/null +++ b/writerperfect/source/writer/ImportFilterBase.cxx @@ -0,0 +1,186 @@ +/* -*- 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 <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/io/XInputStream.hpp> +#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 <com/sun/star/io/XSeekable.hpp> +#include <com/sun/star/uno/Reference.h> + +#include <writerperfect/DocumentHandler.hxx> +#include <writerperfect/WPXSvInputStream.hxx> + +#include <xmloff/attrlist.hxx> + +#include "ImportFilterBase.hxx" + +namespace writerperfect +{ +namespace writer +{ + +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; + +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_INFO("writerperfect", "ImportFilterImpl::filter"); + 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 ( !xInputStream.is() ) + { + OSL_ASSERT( false ); + 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 Graphics Handler: abstract class to handle document SAX messages, concrete implementation here + // writes to in-memory target doc + DocumentHandler xHandler(xInternalHandler); + + WPXSvInputStream input( xInputStream ); + + OdtGenerator exporter(&xHandler, ODF_FLAT_XML); + + doRegisterHandlers(exporter); + + return doImportDocument(input, sFilterName, exporter); +} + +void SAL_CALL ImportFilterImpl::cancel( ) +throw (RuntimeException, std::exception) +{ + SAL_INFO("writerperfect", "ImportFilterImpl::cancel"); +} + +// XImporter +void SAL_CALL ImportFilterImpl::setTargetDocument( const Reference< ::com::sun::star::lang::XComponent >& xDoc ) +throw (::com::sun::star::lang::IllegalArgumentException, RuntimeException, std::exception) +{ + SAL_INFO("writerperfect", "ImportFilterImpl::setTargetDocument"); + mxDoc = xDoc; +} + +// XExtendedFilterDetection +OUString SAL_CALL ImportFilterImpl::detect( com::sun::star::uno::Sequence< PropertyValue >& Descriptor ) +throw( com::sun::star::uno::RuntimeException, std::exception ) +{ + SAL_INFO("writerperfect", "ImportFilterImpl::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 ( 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) +{ + SAL_INFO("writerperfect", "ImportFilterImpl::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; + } + } + } +} + +void ImportFilterImpl::doRegisterHandlers( OdtGenerator & ) +{ +} + +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/writer/ImportFilterBase.hxx b/writerperfect/source/writer/ImportFilterBase.hxx new file mode 100644 index 000000000000..90dc4e2dd9f1 --- /dev/null +++ b/writerperfect/source/writer/ImportFilterBase.hxx @@ -0,0 +1,102 @@ +/* -*- 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_WRITER_IMPORTFILTERBASE_HXX +#define INCLUDED_WRITERPERFECT_SOURCE_WRITER_IMPORTFILTERBASE_HXX + +#include <libodfgen/libodfgen.hxx> + +#include <libwpd/libwpd.h> +#include <libwpd-stream/libwpd-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; +} +} +} } } + +namespace writerperfect +{ +namespace writer +{ + +/* 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( WPXInputStream &rInput, OUString &rTypeName ) = 0; + virtual bool doImportDocument( WPXInputStream &rInput, const rtl::OUString &rFilterName, WPXDocumentInterface &rGenerator ) = 0; + virtual void doRegisterHandlers( OdtGenerator &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_WRITER_IMPORTFILTERBASE_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/writer/MSWorksImportFilter.cxx b/writerperfect/source/writer/MSWorksImportFilter.cxx index 0a43e64926a1..7aef8e983ecd 100644 --- a/writerperfect/source/writer/MSWorksImportFilter.cxx +++ b/writerperfect/source/writer/MSWorksImportFilter.cxx @@ -9,182 +9,39 @@ * 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 <writerperfect/DocumentHandler.hxx> -#include <writerperfect/WPXSvInputStream.hxx> - -#include <xmloff/attrlist.hxx> -#include <ucbhelper/content.hxx> - #include <libwps/libwps.h> -#include <libodfgen/libodfgen.hxx> - #include "MSWorksImportFilter.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; +using com::sun::star::uno::XComponentContext; -using writerperfect::DocumentHandler; -using writerperfect::WPXSvInputStream; - -sal_Bool SAL_CALL MSWorksImportFilter::importImpl( const Sequence< ::com::sun::star::beans::PropertyValue >& aDescriptor ) -throw (RuntimeException) +bool MSWorksImportFilter::doImportDocument( WPXInputStream &rInput, const rtl::OUString &, WPXDocumentInterface &rGenerator ) { - SAL_INFO("writerperfect", "MSWorksImportFilter::importImpl"); - - 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( false ); - 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 (WPS_OK == WPSDocument::parse(&input, &collector)) - return sal_True; - return sal_False; + return WPS_OK == WPSDocument::parse(&rInput, &rGenerator); } -sal_Bool SAL_CALL MSWorksImportFilter::filter( const Sequence< ::com::sun::star::beans::PropertyValue >& aDescriptor ) -throw (RuntimeException, std::exception) +bool MSWorksImportFilter::doDetectFormat( WPXInputStream &rInput, OUString &rTypeName ) { - SAL_INFO("writerperfect", "MSWorksImportFilter::filter"); - return importImpl ( aDescriptor ); -} -void SAL_CALL MSWorksImportFilter::cancel( ) -throw (RuntimeException, std::exception) -{ - SAL_INFO("writerperfect", "MSWorksImportFilter::cancel"); -} - -// XImporter -void SAL_CALL MSWorksImportFilter::setTargetDocument( const Reference< ::com::sun::star::lang::XComponent >& xDoc ) -throw (::com::sun::star::lang::IllegalArgumentException, RuntimeException, std::exception) -{ - SAL_INFO("writerperfect", "MSWorksImportFilter::getTargetDocument"); - mxDoc = xDoc; -} - -// XExtendedFilterDetection -OUString SAL_CALL MSWorksImportFilter::detect( com::sun::star::uno::Sequence< PropertyValue >& Descriptor ) -throw( com::sun::star::uno::RuntimeException, std::exception ) -{ - SAL_INFO("writerperfect", "MSWorksImportFilter::detect"); - - WPSConfidence confidence = WPS_CONFIDENCE_NONE; - 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 ); - - confidence = WPSDocument::isFileFormatSupported(&input); + const WPSConfidence confidence = WPSDocument::isFileFormatSupported(&rInput); if ((confidence == WPS_CONFIDENCE_EXCELLENT) || (confidence == WPS_CONFIDENCE_GOOD)) - sTypeName = "writer_MS_Works_Document"; - - if (!sTypeName.isEmpty()) { - if ( location == nLength ) - { - Descriptor.realloc(nLength+1); - Descriptor[location].Name = "TypeName"; - } - - Descriptor[location].Value <<=sTypeName; + rTypeName = "writer_MS_Works_Document"; + return true; } - return sTypeName; + return false; } - -// XInitialization -void SAL_CALL MSWorksImportFilter::initialize( const Sequence< Any >& aArguments ) -throw (Exception, RuntimeException, std::exception) -{ - SAL_INFO("writerperfect", "MSWorksImportFilter::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 MSWorksImportFilter_getImplementationName () throw (RuntimeException) { diff --git a/writerperfect/source/writer/MSWorksImportFilter.hxx b/writerperfect/source/writer/MSWorksImportFilter.hxx index 839b695711a1..924e2c207255 100644 --- a/writerperfect/source/writer/MSWorksImportFilter.hxx +++ b/writerperfect/source/writer/MSWorksImportFilter.hxx @@ -10,58 +10,19 @@ #ifndef _MSWORKSIMPORTFILTER_HXX #define _MSWORKSIMPORTFILTER_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 "ImportFilterBase.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 MSWorksImportFilter : 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 - > +class MSWorksImportFilter : public writerperfect::writer::ImportFilterBase { -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: MSWorksImportFilter( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > &rxContext ) - : mxContext( rxContext ) {} - virtual ~MSWorksImportFilter() {} - - // 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; + : writerperfect::writer::ImportFilterBase( rxContext ) {} // XServiceInfo virtual OUString SAL_CALL getImplementationName( ) @@ -71,6 +32,9 @@ public: virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; +private: + virtual bool doDetectFormat( WPXInputStream &rInput, OUString &rTypeName ) SAL_OVERRIDE; + virtual bool doImportDocument( WPXInputStream &rInput, const rtl::OUString &rFilterName, WPXDocumentInterface &rGenerator ) SAL_OVERRIDE; }; OUString MSWorksImportFilter_getImplementationName() diff --git a/writerperfect/source/writer/MWAWImportFilter.cxx b/writerperfect/source/writer/MWAWImportFilter.cxx index b5a4a7168a6e..97f414ac0812 100644 --- a/writerperfect/source/writer/MWAWImportFilter.cxx +++ b/writerperfect/source/writer/MWAWImportFilter.cxx @@ -9,48 +9,20 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#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 <writerperfect/DocumentHandler.hxx> -#include <writerperfect/WPXSvInputStream.hxx> - -#include <xmloff/attrlist.hxx> -#include <ucbhelper/content.hxx> - #include <libmwaw/libmwaw.hxx> -#include <libodfgen/libodfgen.hxx> #include "MWAWImportFilter.hxx" -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; - -using writerperfect::DocumentHandler; -using writerperfect::WPXSvInputStream; +using com::sun::star::uno::XComponentContext; static bool handleEmbeddedMWAWObject(const WPXBinaryData &data, OdfDocumentHandler *pHandler, const OdfStreamType streamType) { @@ -58,96 +30,18 @@ static bool handleEmbeddedMWAWObject(const WPXBinaryData &data, OdfDocumentHandl return MWAWDocument::decodeGraphic(data, &exporter); } -sal_Bool SAL_CALL MWAWImportFilter::importImpl( const Sequence< ::com::sun::star::beans::PropertyValue > &aDescriptor ) -throw (RuntimeException) +bool MWAWImportFilter::doImportDocument( WPXInputStream &rInput, const rtl::OUString &, WPXDocumentInterface &rGenerator ) { - SAL_INFO("writerperfect", "MWAWImportFilter::importImpl"); - - 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( false ); - 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); - collector.registerEmbeddedObjectHandler("image/mwaw-odg", &handleEmbeddedMWAWObject); - if (MWAWDocument::MWAW_R_OK == MWAWDocument::parse(&input, &collector)) - return sal_True; - return sal_False; + return MWAWDocument::MWAW_R_OK == MWAWDocument::parse(&rInput, &rGenerator); } -sal_Bool SAL_CALL MWAWImportFilter::filter( const Sequence< ::com::sun::star::beans::PropertyValue > &aDescriptor ) -throw (RuntimeException, std::exception) +bool MWAWImportFilter::doDetectFormat( WPXInputStream &rInput, OUString &rTypeName ) { - SAL_INFO("writerperfect", "MWAWImportFilter::filter"); - return importImpl ( aDescriptor ); -} -void SAL_CALL MWAWImportFilter::cancel( ) -throw (RuntimeException, std::exception) -{ - SAL_INFO("writerperfect", "MWAWImportFilter::cancel"); -} - -// XImporter -void SAL_CALL MWAWImportFilter::setTargetDocument( const Reference< ::com::sun::star::lang::XComponent > &xDoc ) -throw (::com::sun::star::lang::IllegalArgumentException, RuntimeException, std::exception) -{ - SAL_INFO("writerperfect", "MWAWImportFilter::getTargetDocument"); - mxDoc = xDoc; -} + rTypeName = ""; -// XExtendedFilterDetection -OUString SAL_CALL MWAWImportFilter::detect( com::sun::star::uno::Sequence< PropertyValue > &Descriptor ) -throw( com::sun::star::uno::RuntimeException, std::exception ) -{ - SAL_INFO("writerperfect", "MWAWImportFilter::detect"); - - MWAWDocument::Confidence confidence = MWAWDocument::MWAW_C_NONE; MWAWDocument::Type docType = MWAWDocument::MWAW_T_UNKNOWN; MWAWDocument::Kind docKind = MWAWDocument::MWAW_K_UNKNOWN; - 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 ); - - confidence = MWAWDocument::isFileFormatSupported(&input, docType, docKind); + const MWAWDocument::Confidence confidence = MWAWDocument::isFileFormatSupported(&rInput, docType, docKind); if (confidence == MWAWDocument::MWAW_C_EXCELLENT) { @@ -156,76 +50,76 @@ throw( com::sun::star::uno::RuntimeException, std::exception ) switch (docType) { case MWAWDocument::MWAW_T_ACTA: - sTypeName = "writer_Mac_Acta"; + rTypeName = "writer_Mac_Acta"; break; case MWAWDocument::MWAW_T_BEAGLEWORKS: - sTypeName = "writer_Beagle_Works"; + rTypeName = "writer_Beagle_Works"; break; case MWAWDocument::MWAW_T_CLARISWORKS: - sTypeName = "writer_ClarisWorks"; + rTypeName = "writer_ClarisWorks"; break; case MWAWDocument::MWAW_T_DOCMAKER: - sTypeName = "writer_DocMaker"; + rTypeName = "writer_DocMaker"; break; case MWAWDocument::MWAW_T_EDOC: - sTypeName = "writer_eDoc_Document"; + rTypeName = "writer_eDoc_Document"; break; case MWAWDocument::MWAW_T_GREATWORKS: - sTypeName = "writer_Great_Works"; + rTypeName = "writer_Great_Works"; break; case MWAWDocument::MWAW_T_FULLWRITE: - sTypeName = "writer_FullWrite_Professional"; + rTypeName = "writer_FullWrite_Professional"; break; case MWAWDocument::MWAW_T_HANMACWORDJ: - sTypeName = "writer_HanMac_Word_J"; + rTypeName = "writer_HanMac_Word_J"; break; case MWAWDocument::MWAW_T_HANMACWORDK: - sTypeName = "writer_HanMac_Word_K"; + rTypeName = "writer_HanMac_Word_K"; break; case MWAWDocument::MWAW_T_LIGHTWAYTEXT: - sTypeName = "writer_LightWayText"; + rTypeName = "writer_LightWayText"; break; case MWAWDocument::MWAW_T_MACDOC: - sTypeName = "writer_MacDoc"; + rTypeName = "writer_MacDoc"; break; case MWAWDocument::MWAW_T_MARINERWRITE: - sTypeName = "writer_Mariner_Write"; + rTypeName = "writer_Mariner_Write"; break; case MWAWDocument::MWAW_T_MINDWRITE: - sTypeName = "writer_MindWrite"; + rTypeName = "writer_MindWrite"; break; case MWAWDocument::MWAW_T_MACWRITE: - sTypeName = "writer_MacWrite"; + rTypeName = "writer_MacWrite"; break; case MWAWDocument::MWAW_T_MACWRITEPRO: - sTypeName = "writer_MacWritePro"; + rTypeName = "writer_MacWritePro"; break; case MWAWDocument::MWAW_T_MICROSOFTWORD: - sTypeName = "writer_Mac_Word"; + rTypeName = "writer_Mac_Word"; break; case MWAWDocument::MWAW_T_MICROSOFTWORKS: - sTypeName = "writer_Mac_Works"; + rTypeName = "writer_Mac_Works"; break; case MWAWDocument::MWAW_T_MORE: - sTypeName = "writer_Mac_More"; + rTypeName = "writer_Mac_More"; break; case MWAWDocument::MWAW_T_NISUSWRITER: - sTypeName = "writer_Nisus_Writer"; + rTypeName = "writer_Nisus_Writer"; break; case MWAWDocument::MWAW_T_TEACHTEXT: - sTypeName = "writer_TeachText"; + rTypeName = "writer_TeachText"; break; case MWAWDocument::MWAW_T_TEXEDIT: - sTypeName = "writer_TexEdit"; + rTypeName = "writer_TexEdit"; break; case MWAWDocument::MWAW_T_WRITENOW: - sTypeName = "writer_WriteNow"; + rTypeName = "writer_WriteNow"; break; case MWAWDocument::MWAW_T_WRITERPLUS: - sTypeName = "writer_WriterPlus"; + rTypeName = "writer_WriterPlus"; break; case MWAWDocument::MWAW_T_ZWRITE: - sTypeName = "writer_ZWrite"; + rTypeName = "writer_ZWrite"; break; case MWAWDocument::MWAW_T_FRAMEMAKER: @@ -251,42 +145,14 @@ throw( com::sun::star::uno::RuntimeException, std::exception ) } } - if (!sTypeName.isEmpty()) - { - if ( location == nLength ) - { - Descriptor.realloc(nLength+1); - Descriptor[location].Name = "TypeName"; - } - - Descriptor[location].Value <<=sTypeName; - } - - return sTypeName; + return !rTypeName.isEmpty(); } - -// XInitialization -void SAL_CALL MWAWImportFilter::initialize( const Sequence< Any > &aArguments ) -throw (Exception, RuntimeException, std::exception) +void MWAWImportFilter::doRegisterHandlers( OdtGenerator &rGenerator ) { - SAL_INFO("writerperfect", "MWAWImportFilter::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; - } - } - } + rGenerator.registerEmbeddedObjectHandler("image/mwaw-odg", &handleEmbeddedMWAWObject); } + OUString MWAWImportFilter_getImplementationName () throw (RuntimeException) { diff --git a/writerperfect/source/writer/MWAWImportFilter.hxx b/writerperfect/source/writer/MWAWImportFilter.hxx index 48064e2294dc..4efe185cab48 100644 --- a/writerperfect/source/writer/MWAWImportFilter.hxx +++ b/writerperfect/source/writer/MWAWImportFilter.hxx @@ -10,58 +10,19 @@ #ifndef _MWAWIMPORTFILTER_HXX #define _MWAWIMPORTFILTER_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 "ImportFilterBase.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 MWAWImportFilter : 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 - > +class MWAWImportFilter : public writerperfect::writer::ImportFilterBase { -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: MWAWImportFilter( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > &rxContext ) - : mxContext( rxContext ) {} - virtual ~MWAWImportFilter() {} - - // 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; + : writerperfect::writer::ImportFilterBase( rxContext ) {} // XServiceInfo virtual OUString SAL_CALL getImplementationName( ) @@ -71,6 +32,10 @@ public: virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; +private: + virtual bool doDetectFormat( WPXInputStream &rInput, OUString &rTypeName ) SAL_OVERRIDE; + virtual bool doImportDocument( WPXInputStream &rInput, const rtl::OUString &rFilterName, WPXDocumentInterface &rGenerator ) SAL_OVERRIDE; + virtual void doRegisterHandlers( OdtGenerator &rGenerator ) SAL_OVERRIDE; }; OUString MWAWImportFilter_getImplementationName() |