diff options
Diffstat (limited to 'writerperfect/source/writer/AbiWordImportFilter.cxx')
-rw-r--r-- | writerperfect/source/writer/AbiWordImportFilter.cxx | 160 |
1 files changed, 9 insertions, 151 deletions
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) { |