diff options
author | David Tardon <dtardon@redhat.com> | 2014-04-24 16:25:59 +0200 |
---|---|---|
committer | David Tardon <dtardon@redhat.com> | 2014-04-24 16:27:43 +0200 |
commit | ec544e5329b413fa6add9eef07ae598b15837eb1 (patch) | |
tree | 7f6e1d4c86a8dbd3526a0f1ff63371d73bdb533a /writerperfect | |
parent | b7fa9950a9ef68bf2652b8c93887b6d531866471 (diff) |
refactor to decrease the amount of copypasta
Change-Id: Iedfa2a358bf098f6a5e28b994c4c340654a7c295
Diffstat (limited to 'writerperfect')
-rw-r--r-- | writerperfect/Library_wpftdraw.mk | 1 | ||||
-rw-r--r-- | writerperfect/source/draw/CDRImportFilter.cxx | 150 | ||||
-rw-r--r-- | writerperfect/source/draw/CDRImportFilter.hxx | 55 | ||||
-rw-r--r-- | writerperfect/source/draw/CMXImportFilter.cxx | 150 | ||||
-rw-r--r-- | writerperfect/source/draw/CMXImportFilter.hxx | 55 | ||||
-rw-r--r-- | writerperfect/source/draw/FreehandImportFilter.cxx | 150 | ||||
-rw-r--r-- | writerperfect/source/draw/FreehandImportFilter.hxx | 55 | ||||
-rw-r--r-- | writerperfect/source/draw/ImportFilterBase.cxx | 180 | ||||
-rw-r--r-- | writerperfect/source/draw/ImportFilterBase.hxx | 100 | ||||
-rw-r--r-- | writerperfect/source/draw/MSPUBImportFilter.cxx | 148 | ||||
-rw-r--r-- | writerperfect/source/draw/MSPUBImportFilter.hxx | 55 | ||||
-rw-r--r-- | writerperfect/source/draw/VisioImportFilter.cxx | 150 | ||||
-rw-r--r-- | writerperfect/source/draw/VisioImportFilter.hxx | 55 | ||||
-rw-r--r-- | writerperfect/source/draw/WPGImportFilter.cxx | 151 | ||||
-rw-r--r-- | writerperfect/source/draw/WPGImportFilter.hxx | 55 |
15 files changed, 413 insertions, 1097 deletions
diff --git a/writerperfect/Library_wpftdraw.mk b/writerperfect/Library_wpftdraw.mk index faf805deb1e3..2f730eafddde 100644 --- a/writerperfect/Library_wpftdraw.mk +++ b/writerperfect/Library_wpftdraw.mk @@ -56,6 +56,7 @@ $(eval $(call gb_Library_add_exception_objects,wpftdraw,\ writerperfect/source/draw/CDRImportFilter \ writerperfect/source/draw/CMXImportFilter \ writerperfect/source/draw/FreehandImportFilter \ + writerperfect/source/draw/ImportFilterBase \ writerperfect/source/draw/MSPUBImportFilter \ writerperfect/source/draw/VisioImportFilter \ writerperfect/source/draw/WPGImportFilter \ diff --git a/writerperfect/source/draw/CDRImportFilter.cxx b/writerperfect/source/draw/CDRImportFilter.cxx index 246486006405..396ab45720d5 100644 --- a/writerperfect/source/draw/CDRImportFilter.cxx +++ b/writerperfect/source/draw/CDRImportFilter.cxx @@ -11,166 +11,42 @@ * Corel Corporation or Corel Corporation Limited." */ -#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 <com/sun/star/uno/XComponentContext.hpp> #include <cppuhelper/supportsservice.hxx> -#include <writerperfect/DocumentHandler.hxx> -#include <writerperfect/WPXSvInputStream.hxx> - -#include <xmloff/attrlist.hxx> - #include <libcdr/libcdr.h> #include <libodfgen/libodfgen.hxx> #include "CDRImportFilter.hxx" -#include <iostream> - -using namespace ::com::sun::star::uno; 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; +using com::sun::star::uno::Sequence; +using com::sun::star::uno::XComponentContext; +using com::sun::star::uno::XInterface; -sal_Bool SAL_CALL CDRImportFilter::filter( const Sequence< ::com::sun::star::beans::PropertyValue >& aDescriptor ) -throw (RuntimeException, std::exception) +bool CDRImportFilter::doImportDocument( WPXInputStream &rInput, libwpg::WPGPaintInterface &rGenerator ) { - SAL_INFO("writerperfect", "CDRImportFilter::filter"); - 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.Draw.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 ); + SAL_INFO("writerperfect", "CDRImportFilter::doImportDocument"); - OdgGenerator exporter(&xHandler, ODF_FLAT_XML); - bool tmpParseResult = libcdr::CDRDocument::parse(&input, &exporter); - return tmpParseResult; + return libcdr::CDRDocument::parse(&rInput, &rGenerator); } -void SAL_CALL CDRImportFilter::cancel( ) -throw (RuntimeException, std::exception) +bool CDRImportFilter::doDetectFormat( WPXInputStream &rInput, OUString &rTypeName ) { - SAL_INFO("writerperfect", "CDRImportFilter::cancel"); -} - -// XImporter -void SAL_CALL CDRImportFilter::setTargetDocument( const Reference< ::com::sun::star::lang::XComponent >& xDoc ) -throw (::com::sun::star::lang::IllegalArgumentException, RuntimeException, std::exception) -{ - SAL_INFO("writerperfect", "CDRImportFilter::setTargetDocument"); - mxDoc = xDoc; -} + SAL_INFO("writerperfect", "CDRImportFilter::doDetectFormat"); -// XExtendedFilterDetection -OUString SAL_CALL CDRImportFilter::detect( com::sun::star::uno::Sequence< PropertyValue >& Descriptor ) -throw( com::sun::star::uno::RuntimeException, std::exception ) -{ - SAL_INFO("writerperfect", "CDRImportFilter::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 (libcdr::CDRDocument::isSupported(&rInput)) { - if ( pValue[i].Name == "TypeName" ) - location=i; - else if ( pValue[i].Name == "InputStream" ) - pValue[i].Value >>= xInputStream; + rTypeName = "draw_CorelDraw_Document"; + return true; } - if (!xInputStream.is()) - return OUString(); - - WPXSvInputStream input( xInputStream ); - - if (libcdr::CDRDocument::isSupported(&input)) - sTypeName = "draw_CorelDraw_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 CDRImportFilter::initialize( const Sequence< Any >& aArguments ) -throw (Exception, RuntimeException, std::exception) -{ - SAL_INFO("writerperfect", "CDRImportFilter::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 CDRImportFilter_getImplementationName () throw (RuntimeException) { diff --git a/writerperfect/source/draw/CDRImportFilter.hxx b/writerperfect/source/draw/CDRImportFilter.hxx index 351a3e8fa2c6..cf8a254ba4e7 100644 --- a/writerperfect/source/draw/CDRImportFilter.hxx +++ b/writerperfect/source/draw/CDRImportFilter.hxx @@ -11,58 +11,18 @@ #ifndef _CDRIMPORTFILTER_HXX #define _CDRIMPORTFILTER_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 <stdio.h> +#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 CDRImportFilter : 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 CDRImportFilter : public writerperfect::draw::ImportFilterBase { -protected: - // oo.org declares - ::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; - public: - CDRImportFilter( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > &rxContext) - : mxContext( rxContext ) {} - virtual ~CDRImportFilter() {} - - // 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; + CDRImportFilter( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > &rxContext ) + : writerperfect::draw::ImportFilterBase( rxContext ) + { + } // XServiceInfo virtual OUString SAL_CALL getImplementationName( ) @@ -72,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, libwpg::WPGPaintInterface &rGenerator ) SAL_OVERRIDE; }; OUString CDRImportFilter_getImplementationName() diff --git a/writerperfect/source/draw/CMXImportFilter.cxx b/writerperfect/source/draw/CMXImportFilter.cxx index fe944322e30a..cc8f1e803f20 100644 --- a/writerperfect/source/draw/CMXImportFilter.cxx +++ b/writerperfect/source/draw/CMXImportFilter.cxx @@ -11,166 +11,42 @@ * Corel Corporation or Corel Corporation Limited." */ -#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 <com/sun/star/uno/XComponentContext.hpp> #include <cppuhelper/supportsservice.hxx> -#include <writerperfect/DocumentHandler.hxx> -#include <writerperfect/WPXSvInputStream.hxx> - -#include <xmloff/attrlist.hxx> - #include <libcdr/libcdr.h> #include <libodfgen/libodfgen.hxx> #include "CMXImportFilter.hxx" -#include <iostream> - -using namespace ::com::sun::star::uno; 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; +using com::sun::star::uno::Sequence; +using com::sun::star::uno::XComponentContext; +using com::sun::star::uno::XInterface; -sal_Bool SAL_CALL CMXImportFilter::filter( const Sequence< ::com::sun::star::beans::PropertyValue >& aDescriptor ) -throw (RuntimeException, std::exception) +bool CMXImportFilter::doImportDocument( WPXInputStream &rInput, libwpg::WPGPaintInterface &rGenerator ) { - SAL_INFO("writerperfect", "CMXImportFilter::filter"); - 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.Draw.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 ); + SAL_INFO("writerperfect", "CMXImportFilter::doImportDocument"); - OdgGenerator exporter(&xHandler, ODF_FLAT_XML); - bool tmpParseResult = libcdr::CMXDocument::parse(&input, &exporter); - return tmpParseResult; + return libcdr::CMXDocument::parse(&rInput, &rGenerator); } -void SAL_CALL CMXImportFilter::cancel( ) -throw (RuntimeException, std::exception) +bool CMXImportFilter::doDetectFormat( WPXInputStream &rInput, OUString &rTypeName ) { - SAL_INFO("writerperfect", "CMXImportFilter::cancel"); -} - -// XImporter -void SAL_CALL CMXImportFilter::setTargetDocument( const Reference< ::com::sun::star::lang::XComponent >& xDoc ) -throw (::com::sun::star::lang::IllegalArgumentException, RuntimeException, std::exception) -{ - SAL_INFO("writerperfect", "CMXImportFilter::setTargetDocument"); - mxDoc = xDoc; -} + SAL_INFO("writerperfect", "CMXImportFilter::doDetectFormat"); -// XExtendedFilterDetection -OUString SAL_CALL CMXImportFilter::detect( com::sun::star::uno::Sequence< PropertyValue >& Descriptor ) -throw( com::sun::star::uno::RuntimeException, std::exception ) -{ - SAL_INFO("writerperfect", "CMXImportFilter::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 (libcdr::CMXDocument::isSupported(&rInput)) { - if ( pValue[i].Name == "TypeName" ) - location=i; - else if ( pValue[i].Name == "InputStream" ) - pValue[i].Value >>= xInputStream; + rTypeName = "draw_Corel_Presentation_Exchange"; + return true; } - if (!xInputStream.is()) - return OUString(); - - WPXSvInputStream input( xInputStream ); - - if (libcdr::CMXDocument::isSupported(&input)) - sTypeName = "draw_Corel_Presentation_Exchange"; - - 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 CMXImportFilter::initialize( const Sequence< Any >& aArguments ) -throw (Exception, RuntimeException, std::exception) -{ - SAL_INFO("writerperfect", "CMXImportFilter::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 CMXImportFilter_getImplementationName () throw (RuntimeException) { diff --git a/writerperfect/source/draw/CMXImportFilter.hxx b/writerperfect/source/draw/CMXImportFilter.hxx index 0c0e49f1dc14..4bc37ebead3e 100644 --- a/writerperfect/source/draw/CMXImportFilter.hxx +++ b/writerperfect/source/draw/CMXImportFilter.hxx @@ -11,58 +11,18 @@ #ifndef _CMXIMPORTFILTER_HXX #define _CMXIMPORTFILTER_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 <stdio.h> +#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 CMXImportFilter : 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 CMXImportFilter : public writerperfect::draw::ImportFilterBase { -protected: - // oo.org declares - ::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; - public: - CMXImportFilter( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > &rxContext) - : mxContext( rxContext ) {} - virtual ~CMXImportFilter() {} - - // 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; + CMXImportFilter( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > &rxContext ) + : writerperfect::draw::ImportFilterBase( rxContext ) + { + } // XServiceInfo virtual OUString SAL_CALL getImplementationName( ) @@ -72,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, libwpg::WPGPaintInterface &rGenerator ) SAL_OVERRIDE; }; OUString CMXImportFilter_getImplementationName() diff --git a/writerperfect/source/draw/FreehandImportFilter.cxx b/writerperfect/source/draw/FreehandImportFilter.cxx index b73aa4a7d870..cfc0a491ae55 100644 --- a/writerperfect/source/draw/FreehandImportFilter.cxx +++ b/writerperfect/source/draw/FreehandImportFilter.cxx @@ -7,166 +7,42 @@ * 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 <com/sun/star/uno/XComponentContext.hpp> #include <cppuhelper/supportsservice.hxx> -#include <writerperfect/DocumentHandler.hxx> -#include <writerperfect/WPXSvInputStream.hxx> - -#include <xmloff/attrlist.hxx> - #include <libfreehand/libfreehand.h> #include <libodfgen/libodfgen.hxx> #include "FreehandImportFilter.hxx" -#include <iostream> - -using namespace ::com::sun::star::uno; 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; +using com::sun::star::uno::Sequence; +using com::sun::star::uno::XComponentContext; +using com::sun::star::uno::XInterface; -sal_Bool SAL_CALL FreehandImportFilter::filter( const Sequence< ::com::sun::star::beans::PropertyValue >& aDescriptor ) -throw (RuntimeException, std::exception) +bool FreehandImportFilter::doImportDocument( WPXInputStream &rInput, libwpg::WPGPaintInterface &rGenerator ) { - SAL_INFO("writerperfect", "FreehandImportFilter::filter"); - 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.Draw.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 ); + SAL_INFO("writerperfect", "FreehandImportFilter::doImportDocument"); - OdgGenerator exporter(&xHandler, ODF_FLAT_XML); - bool tmpParseResult = libfreehand::FreeHandDocument::parse(&input, &exporter); - return tmpParseResult; + return libfreehand::FreeHandDocument::parse(&rInput, &rGenerator); } -void SAL_CALL FreehandImportFilter::cancel( ) -throw (RuntimeException, std::exception) +bool FreehandImportFilter::doDetectFormat( WPXInputStream &rInput, OUString &rTypeName ) { - SAL_INFO("writerperfect", "FreehandImportFilter::cancel"); -} - -// XImporter -void SAL_CALL FreehandImportFilter::setTargetDocument( const Reference< ::com::sun::star::lang::XComponent >& xDoc ) -throw (::com::sun::star::lang::IllegalArgumentException, RuntimeException, std::exception) -{ - SAL_INFO("writerperfect", "FreehandImportFilter::setTargetDocument"); - mxDoc = xDoc; -} + SAL_INFO("writerperfect", "FreehandImportFilter::doDetectFormat"); -// XExtendedFilterDetection -OUString SAL_CALL FreehandImportFilter::detect( com::sun::star::uno::Sequence< PropertyValue >& Descriptor ) -throw( com::sun::star::uno::RuntimeException, std::exception ) -{ - SAL_INFO("writerperfect", "FreehandImportFilter::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 (libfreehand::FreeHandDocument::isSupported(&rInput)) { - if ( pValue[i].Name == "TypeName" ) - location=i; - else if ( pValue[i].Name == "InputStream" ) - pValue[i].Value >>= xInputStream; + rTypeName = "draw_Freehand_Document"; + return true; } - if (!xInputStream.is()) - return OUString(); - - WPXSvInputStream input( xInputStream ); - - if (libfreehand::FreeHandDocument::isSupported(&input)) - sTypeName = "draw_Freehand_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 FreehandImportFilter::initialize( const Sequence< Any >& aArguments ) -throw (Exception, RuntimeException, std::exception) -{ - SAL_INFO("writerperfect", "FreehandImportFilter::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 FreehandImportFilter_getImplementationName () throw (RuntimeException) { diff --git a/writerperfect/source/draw/FreehandImportFilter.hxx b/writerperfect/source/draw/FreehandImportFilter.hxx index 455e23f0d968..adb683329310 100644 --- a/writerperfect/source/draw/FreehandImportFilter.hxx +++ b/writerperfect/source/draw/FreehandImportFilter.hxx @@ -8,58 +8,18 @@ #ifndef _FREEHANDIMPORTFILTER_HXX #define _FREEHANDIMPORTFILTER_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 <stdio.h> +#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 FreehandImportFilter : 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 FreehandImportFilter : public writerperfect::draw::ImportFilterBase { -protected: - // oo.org declares - ::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; - public: - FreehandImportFilter( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > &rxContext) - : mxContext( rxContext ) {} - virtual ~FreehandImportFilter() {} - - // 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; + FreehandImportFilter( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > &rxContext ) + : writerperfect::draw::ImportFilterBase( rxContext ) + { + } // XServiceInfo virtual OUString SAL_CALL getImplementationName( ) @@ -69,6 +29,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 ); + virtual bool doImportDocument( WPXInputStream &rInput, libwpg::WPGPaintInterface &rGenerator ); }; OUString FreehandImportFilter_getImplementationName() diff --git a/writerperfect/source/draw/ImportFilterBase.cxx b/writerperfect/source/draw/ImportFilterBase.cxx new file mode 100644 index 000000000000..4488c6a8baa0 --- /dev/null +++ b/writerperfect/source/draw/ImportFilterBase.cxx @@ -0,0 +1,180 @@ +/* -*- 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 <libodfgen/libodfgen.hxx> + +#include "ImportFilterBase.hxx" + +namespace writerperfect +{ +namespace draw +{ + +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; + 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.Draw.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 ); + + OdgGenerator exporter(&xHandler, ODF_FLAT_XML); + + return doImportDocument(input, 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; + } + } + } +} + +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/draw/ImportFilterBase.hxx b/writerperfect/source/draw/ImportFilterBase.hxx new file mode 100644 index 000000000000..7287a5a13095 --- /dev/null +++ b/writerperfect/source/draw/ImportFilterBase.hxx @@ -0,0 +1,100 @@ +/* -*- 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_DRAW_IMPORTFILTERBASE_HXX +#define INCLUDED_WRITERPERFECT_SOURCE_DRAW_IMPORTFILTERBASE_HXX + +#include <libwpd-stream/libwpd-stream.h> + +#include <libwpg/libwpg.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 +{ + class PropertyValue; +} +namespace lang +{ + class XComponent; +} +namespace uno +{ + class XComponentContext; +} +namespace xml { namespace sax { + class XDocumentHandler; +} +} +} } } + +namespace writerperfect +{ +namespace draw +{ + +/* 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, libwpg::WPGPaintInterface &rGenerator ) = 0; + +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: */ diff --git a/writerperfect/source/draw/MSPUBImportFilter.cxx b/writerperfect/source/draw/MSPUBImportFilter.cxx index b7537b03da78..ca6c8a2ba930 100644 --- a/writerperfect/source/draw/MSPUBImportFilter.cxx +++ b/writerperfect/source/draw/MSPUBImportFilter.cxx @@ -7,23 +7,10 @@ * 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 <com/sun/star/uno/XComponentContext.hpp> #include <cppuhelper/supportsservice.hxx> -#include <writerperfect/DocumentHandler.hxx> -#include <writerperfect/WPXSvInputStream.hxx> - -#include <xmloff/attrlist.hxx> - #include <libmspub/libmspub.h> #include <libodfgen/libodfgen.hxx> @@ -31,142 +18,33 @@ #include <iostream> -using namespace ::com::sun::star::uno; 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; +using com::sun::star::uno::Sequence; +using com::sun::star::uno::XComponentContext; +using com::sun::star::uno::XInterface; -sal_Bool SAL_CALL MSPUBImportFilter::filter( const Sequence< ::com::sun::star::beans::PropertyValue >& aDescriptor ) -throw (RuntimeException, std::exception) +bool MSPUBImportFilter::doImportDocument( WPXInputStream &rInput, libwpg::WPGPaintInterface &rGenerator ) { - SAL_INFO("writerperfect", "MSPUBImportFilter::filter"); - 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.Draw.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 ); + SAL_INFO("writerperfect", "MSPUBImportFilter::doImportDocument"); - OdgGenerator exporter(&xHandler, ODF_FLAT_XML); - bool tmpParseResult = libmspub::MSPUBDocument::parse(&input, &exporter); - return tmpParseResult; + return libmspub::MSPUBDocument::parse(&rInput, &rGenerator); } -void SAL_CALL MSPUBImportFilter::cancel( ) -throw (RuntimeException, std::exception) +bool MSPUBImportFilter::doDetectFormat( WPXInputStream &rInput, OUString &rTypeName ) { - SAL_INFO("writerperfect", "MSPUBImportFilter::cancel"); -} - -// XImporter -void SAL_CALL MSPUBImportFilter::setTargetDocument( const Reference< ::com::sun::star::lang::XComponent >& xDoc ) -throw (::com::sun::star::lang::IllegalArgumentException, RuntimeException, std::exception) -{ - SAL_INFO("writerperfect", "MSPUBImportFilter::setTargetDocument"); - mxDoc = xDoc; -} + SAL_INFO("writerperfect", "MSPUBImportFilter::doDetectFormat"); -// XExtendedFilterDetection -OUString SAL_CALL MSPUBImportFilter::detect( com::sun::star::uno::Sequence< PropertyValue >& Descriptor ) -throw( com::sun::star::uno::RuntimeException, std::exception ) -{ - SAL_INFO("writerperfect", "MSPUBImportFilter::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 (libmspub::MSPUBDocument::isSupported(&rInput)) { - if ( pValue[i].Name == "TypeName" ) - location=i; - else if ( pValue[i].Name == "InputStream" ) - pValue[i].Value >>= xInputStream; + rTypeName = "draw_Publisher_Document"; + return true; } - if (!xInputStream.is()) - return OUString(); - - WPXSvInputStream input( xInputStream ); - - if (libmspub::MSPUBDocument::isSupported(&input)) - sTypeName = "draw_Publisher_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 MSPUBImportFilter::initialize( const Sequence< Any >& aArguments ) -throw (Exception, RuntimeException, std::exception) -{ - SAL_INFO("writerperfect", "MSPUBImportFilter::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 MSPUBImportFilter_getImplementationName () throw (RuntimeException) { diff --git a/writerperfect/source/draw/MSPUBImportFilter.hxx b/writerperfect/source/draw/MSPUBImportFilter.hxx index 3ef251056428..c92fb19c788f 100644 --- a/writerperfect/source/draw/MSPUBImportFilter.hxx +++ b/writerperfect/source/draw/MSPUBImportFilter.hxx @@ -8,58 +8,18 @@ #ifndef _MSPUBIMPORTFILTER_HXX #define _MSPUBIMPORTFILTER_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 <stdio.h> +#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 MSPUBImportFilter : 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 MSPUBImportFilter : public writerperfect::draw::ImportFilterBase { -protected: - // oo.org declares - ::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; - public: - MSPUBImportFilter( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > &rxContext) - : mxContext( rxContext ) {} - virtual ~MSPUBImportFilter() {} - - // 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; + MSPUBImportFilter( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > &rxContext ) + : writerperfect::draw::ImportFilterBase( rxContext ) + { + } // XServiceInfo virtual OUString SAL_CALL getImplementationName( ) @@ -69,6 +29,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 ); + virtual bool doImportDocument( WPXInputStream &rInput, libwpg::WPGPaintInterface &rGenerator ); }; OUString MSPUBImportFilter_getImplementationName() diff --git a/writerperfect/source/draw/VisioImportFilter.cxx b/writerperfect/source/draw/VisioImportFilter.cxx index 7d388211e762..0c5d32fcf007 100644 --- a/writerperfect/source/draw/VisioImportFilter.cxx +++ b/writerperfect/source/draw/VisioImportFilter.cxx @@ -7,166 +7,42 @@ * 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 <com/sun/star/uno/XComponentContext.hpp> #include <cppuhelper/supportsservice.hxx> -#include <writerperfect/DocumentHandler.hxx> -#include <writerperfect/WPXSvInputStream.hxx> - -#include <xmloff/attrlist.hxx> - #include <libvisio/libvisio.h> #include <libodfgen/libodfgen.hxx> #include "VisioImportFilter.hxx" -#include <iostream> - -using namespace ::com::sun::star::uno; 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; +using com::sun::star::uno::Sequence; +using com::sun::star::uno::XComponentContext; +using com::sun::star::uno::XInterface; -sal_Bool SAL_CALL VisioImportFilter::filter( const Sequence< ::com::sun::star::beans::PropertyValue >& aDescriptor ) -throw (RuntimeException, std::exception) +bool VisioImportFilter::doImportDocument( WPXInputStream &rInput, libwpg::WPGPaintInterface &rGenerator ) { - SAL_INFO("writerperfect", "VisioImportFilter::filter"); - 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.Draw.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 ); + SAL_INFO("writerperfect", "VisioImportFilter::doImportDocument"); - OdgGenerator exporter(&xHandler, ODF_FLAT_XML); - bool tmpParseResult = libvisio::VisioDocument::parse(&input, &exporter); - return tmpParseResult; + return libvisio::VisioDocument::parse(&rInput, &rGenerator); } -void SAL_CALL VisioImportFilter::cancel( ) -throw (RuntimeException, std::exception) +bool VisioImportFilter::doDetectFormat( WPXInputStream &rInput, OUString &rTypeName ) { - SAL_INFO("writerperfect", "VisioImportFilter::cancel"); -} - -// XImporter -void SAL_CALL VisioImportFilter::setTargetDocument( const Reference< ::com::sun::star::lang::XComponent >& xDoc ) -throw (::com::sun::star::lang::IllegalArgumentException, RuntimeException, std::exception) -{ - SAL_INFO("writerperfect", "VisioImportFilter::setTargetDocument"); - mxDoc = xDoc; -} + SAL_INFO("writerperfect", "VisioImportFilter::doDetectFormat"); -// XExtendedFilterDetection -OUString SAL_CALL VisioImportFilter::detect( com::sun::star::uno::Sequence< PropertyValue >& Descriptor ) -throw( com::sun::star::uno::RuntimeException, std::exception ) -{ - SAL_INFO("writerperfect", "VisioImportFilter::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 (libvisio::VisioDocument::isSupported(&rInput)) { - if ( pValue[i].Name == "TypeName" ) - location=i; - else if ( pValue[i].Name == "InputStream" ) - pValue[i].Value >>= xInputStream; + rTypeName = "draw_Visio_Document"; + return true; } - if (!xInputStream.is()) - return OUString(); - - WPXSvInputStream input( xInputStream ); - - if (libvisio::VisioDocument::isSupported(&input)) - sTypeName = "draw_Visio_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 VisioImportFilter::initialize( const Sequence< Any >& aArguments ) -throw (Exception, RuntimeException, std::exception) -{ - SAL_INFO("writerperfect", "VisioImportFilter::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 VisioImportFilter_getImplementationName () throw (RuntimeException) { diff --git a/writerperfect/source/draw/VisioImportFilter.hxx b/writerperfect/source/draw/VisioImportFilter.hxx index 56f03951921b..b35c44b2b965 100644 --- a/writerperfect/source/draw/VisioImportFilter.hxx +++ b/writerperfect/source/draw/VisioImportFilter.hxx @@ -8,58 +8,18 @@ #ifndef _VISIOIMPORTFILTER_HXX #define _VISIOIMPORTFILTER_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 <stdio.h> +#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 VisioImportFilter : 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 VisioImportFilter : public writerperfect::draw::ImportFilterBase { -protected: - // oo.org declares - ::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; - public: - VisioImportFilter( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > &rxContext) - : mxContext( rxContext ) {} - virtual ~VisioImportFilter() {} - - // 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; + VisioImportFilter( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > &rxContext ) + : writerperfect::draw::ImportFilterBase( rxContext ) + { + } // XServiceInfo virtual OUString SAL_CALL getImplementationName( ) @@ -69,6 +29,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 ); + virtual bool doImportDocument( WPXInputStream &rInput, libwpg::WPGPaintInterface &rGenerator ); }; OUString VisioImportFilter_getImplementationName() diff --git a/writerperfect/source/draw/WPGImportFilter.cxx b/writerperfect/source/draw/WPGImportFilter.cxx index b5b3d7fce612..6e4dd3a00411 100644 --- a/writerperfect/source/draw/WPGImportFilter.cxx +++ b/writerperfect/source/draw/WPGImportFilter.cxx @@ -13,166 +13,41 @@ * Corel Corporation or Corel Corporation Limited." */ -#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 <com/sun/star/uno/XComponentContext.hpp> #include <cppuhelper/supportsservice.hxx> -#include <writerperfect/DocumentHandler.hxx> -#include <writerperfect/WPXSvInputStream.hxx> - -#include <xmloff/attrlist.hxx> - #include <libodfgen/libodfgen.hxx> #include "WPGImportFilter.hxx" -#include <iostream> - -using namespace ::com::sun::star::uno; 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 namespace ::rtl; -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; +using com::sun::star::uno::Sequence; +using com::sun::star::uno::XComponentContext; +using com::sun::star::uno::XInterface; -sal_Bool SAL_CALL WPGImportFilter::filter( const Sequence< ::com::sun::star::beans::PropertyValue >& aDescriptor ) -throw (RuntimeException, std::exception) +bool WPGImportFilter::doImportDocument( WPXInputStream &rInput, libwpg::WPGPaintInterface &rGenerator ) { - SAL_INFO("writerperfect", "WPGImportFilter::filter"); - 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.Draw.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 ); + SAL_INFO("writerperfect", "WPGImportFilter::doImportDocument"); - OdgGenerator exporter(&xHandler, ODF_FLAT_XML); - bool tmpParseResult = libwpg::WPGraphics::parse(&input, &exporter); - return tmpParseResult; + return libwpg::WPGraphics::parse(&rInput, &rGenerator); } -void SAL_CALL WPGImportFilter::cancel( ) -throw (RuntimeException, std::exception) +bool WPGImportFilter::doDetectFormat( WPXInputStream &rInput, OUString &rTypeName ) { - SAL_INFO("writerperfect", "WPGImportFilter::cancel"); -} - -// XImporter -void SAL_CALL WPGImportFilter::setTargetDocument( const Reference< ::com::sun::star::lang::XComponent >& xDoc ) -throw (::com::sun::star::lang::IllegalArgumentException, RuntimeException, std::exception) -{ - SAL_INFO("writerperfect", "WPGImportFilter::setTargetDocument"); - mxDoc = xDoc; -} + SAL_INFO("writerperfect", "WPGImportFilter::doDetectFormat"); -// XExtendedFilterDetection -OUString SAL_CALL WPGImportFilter::detect( com::sun::star::uno::Sequence< PropertyValue >& Descriptor ) -throw( com::sun::star::uno::RuntimeException, std::exception ) -{ - SAL_INFO("writerperfect", "WPGImportFilter::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 (libwpg::WPGraphics::isSupported(&rInput)) { - if ( pValue[i].Name == "TypeName" ) - location=i; - else if ( pValue[i].Name == "InputStream" ) - pValue[i].Value >>= xInputStream; + rTypeName = "draw_WordPerfect_Graphics"; + return true; } - if (!xInputStream.is()) - return OUString(); - - WPXSvInputStream input( xInputStream ); - - if (libwpg::WPGraphics::isSupported(&input)) - sTypeName = "draw_WordPerfect_Graphics"; - - 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 WPGImportFilter::initialize( const Sequence< Any >& aArguments ) -throw (Exception, RuntimeException, std::exception) -{ - SAL_INFO("writerperfect", "WPGImportFilter::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 WPGImportFilter_getImplementationName () throw (RuntimeException) { diff --git a/writerperfect/source/draw/WPGImportFilter.hxx b/writerperfect/source/draw/WPGImportFilter.hxx index 8b3b7677f374..53c487cbf77d 100644 --- a/writerperfect/source/draw/WPGImportFilter.hxx +++ b/writerperfect/source/draw/WPGImportFilter.hxx @@ -13,58 +13,18 @@ #ifndef _WPGIMPORTFILTER_HXX #define _WPGIMPORTFILTER_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 <stdio.h> +#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 WPGImportFilter : 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 WPGImportFilter : public writerperfect::draw::ImportFilterBase { -protected: - // oo.org declares - ::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; - public: - WPGImportFilter( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > &rxContext) - : mxContext( rxContext ) {} - virtual ~WPGImportFilter() {} - - // 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; + WPGImportFilter( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > &rxContext ) + : writerperfect::draw::ImportFilterBase( rxContext ) + { + } // XServiceInfo virtual OUString SAL_CALL getImplementationName( ) @@ -74,6 +34,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 ); + virtual bool doImportDocument( WPXInputStream &rInput, libwpg::WPGPaintInterface &rGenerator ); }; OUString WPGImportFilter_getImplementationName() |