LCOV - code coverage report
Current view: top level - libreoffice/writerperfect/source/draw - MSPUBImportFilter.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 79 0.0 %
Date: 2012-12-27 Functions: 0 14 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /* MSPUBImportFilter: Sets up the filter, and calls OdgExporter
       3             :  * to do the actual filtering
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  */
       9             : 
      10             : #include <osl/diagnose.h>
      11             : #include <rtl/tencinfo.h>
      12             : 
      13             : #include <com/sun/star/io/XInputStream.hpp>
      14             : #include <com/sun/star/xml/sax/XAttributeList.hpp>
      15             : #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
      16             : #include <com/sun/star/xml/sax/InputSource.hpp>
      17             : #include <com/sun/star/xml/sax/XParser.hpp>
      18             : #include <com/sun/star/io/XSeekable.hpp>
      19             : #include <com/sun/star/uno/Reference.h>
      20             : 
      21             : #include <comphelper/componentcontext.hxx>
      22             : #include <xmloff/attrlist.hxx>
      23             : 
      24             : #include <libmspub/libmspub.h>
      25             : #include "filter/DocumentHandler.hxx"
      26             : #include "filter/OdgGenerator.hxx"
      27             : #include "MSPUBImportFilter.hxx"
      28             : #include "stream/WPXSvStream.h"
      29             : 
      30             : #include <iostream>
      31             : 
      32             : using namespace ::com::sun::star::uno;
      33             : using com::sun::star::uno::Reference;
      34             : using com::sun::star::io::XInputStream;
      35             : using com::sun::star::io::XSeekable;
      36             : using com::sun::star::uno::Sequence;
      37             : using namespace ::rtl;
      38             : using rtl::OString;
      39             : using rtl::OUString;
      40             : using com::sun::star::uno::Sequence;
      41             : using com::sun::star::uno::Reference;
      42             : using com::sun::star::uno::Any;
      43             : using com::sun::star::uno::UNO_QUERY;
      44             : using com::sun::star::uno::XInterface;
      45             : using com::sun::star::uno::Exception;
      46             : using com::sun::star::uno::RuntimeException;
      47             : using com::sun::star::beans::PropertyValue;
      48             : using com::sun::star::document::XFilter;
      49             : using com::sun::star::document::XExtendedFilterDetection;
      50             : 
      51             : using com::sun::star::io::XInputStream;
      52             : using com::sun::star::document::XImporter;
      53             : using com::sun::star::xml::sax::InputSource;
      54             : using com::sun::star::xml::sax::XAttributeList;
      55             : using com::sun::star::xml::sax::XDocumentHandler;
      56             : using com::sun::star::xml::sax::XParser;
      57             : 
      58             : 
      59           0 : sal_Bool SAL_CALL MSPUBImportFilter::filter( const Sequence< ::com::sun::star::beans::PropertyValue >& aDescriptor )
      60             : throw (RuntimeException)
      61             : {
      62             : #ifdef DEBUG
      63             :     std::cerr << "MSPUBImportFilter::filter" << std::endl;
      64             : #endif
      65           0 :     sal_Int32 nLength = aDescriptor.getLength();
      66           0 :     const PropertyValue *pValue = aDescriptor.getConstArray();
      67           0 :     OUString sURL;
      68           0 :     Reference < XInputStream > xInputStream;
      69           0 :     for ( sal_Int32 i = 0 ; i < nLength; i++)
      70             :     {
      71           0 :         if ( pValue[i].Name == "InputStream" )
      72           0 :             pValue[i].Value >>= xInputStream;
      73           0 :         else if ( pValue[i].Name == "URL" )
      74           0 :             pValue[i].Value >>= sURL;
      75             :     }
      76           0 :     if ( !xInputStream.is() )
      77             :     {
      78             :         OSL_ASSERT( 0 );
      79           0 :         return sal_False;
      80             :     }
      81           0 :     OString sFileName;
      82           0 :     sFileName = OUStringToOString(sURL, RTL_TEXTENCODING_INFO_ASCII);
      83             : 
      84             :     // An XML import service: what we push sax messages to..
      85           0 :     OUString sXMLImportService ( "com.sun.star.comp.Draw.XMLOasisImporter" );
      86           0 :     Reference < XDocumentHandler > xInternalHandler( comphelper::ComponentContext( mxContext ).createComponent( sXMLImportService ), UNO_QUERY );
      87             : 
      88             :     // The XImporter sets up an empty target document for XDocumentHandler to write to..
      89           0 :     Reference < XImporter > xImporter(xInternalHandler, UNO_QUERY);
      90           0 :     xImporter->setTargetDocument( mxDoc );
      91             : 
      92             :     // OO Graphics Handler: abstract class to handle document SAX messages, concrete implementation here
      93             :     // writes to in-memory target doc
      94           0 :     DocumentHandler xHandler(xInternalHandler);
      95             : 
      96           0 :     WPXSvInputStream input( xInputStream );
      97             : 
      98           0 :     OdgGenerator exporter(&xHandler, ODF_FLAT_XML);
      99           0 :     bool tmpParseResult = libmspub::MSPUBDocument::parse(&input, &exporter);
     100           0 :     return tmpParseResult;
     101             : }
     102             : 
     103           0 : void SAL_CALL MSPUBImportFilter::cancel(  )
     104             : throw (RuntimeException)
     105             : {
     106             : #ifdef DEBUG
     107             :     std::cerr << "MSPUBImportFilter::cancel" << std::endl;
     108             : #endif
     109           0 : }
     110             : 
     111             : // XImporter
     112           0 : void SAL_CALL MSPUBImportFilter::setTargetDocument( const Reference< ::com::sun::star::lang::XComponent >& xDoc )
     113             : throw (::com::sun::star::lang::IllegalArgumentException, RuntimeException)
     114             : {
     115             : #ifdef DEBUG
     116             :     std::cerr << "MSPUBImportFilter::setTargetDocument" << std::endl;
     117             : #endif
     118           0 :     mxDoc = xDoc;
     119           0 : }
     120             : 
     121             : // XExtendedFilterDetection
     122           0 : OUString SAL_CALL MSPUBImportFilter::detect( com::sun::star::uno::Sequence< PropertyValue >& Descriptor )
     123             : throw( com::sun::star::uno::RuntimeException )
     124             : {
     125             : #ifdef DEBUG
     126             :     std::cerr << "MSPUBImportFilter::detect" << std::endl;
     127             : #endif
     128           0 :     OUString sTypeName;
     129           0 :     sal_Int32 nLength = Descriptor.getLength();
     130           0 :     sal_Int32 location = nLength;
     131           0 :     const PropertyValue *pValue = Descriptor.getConstArray();
     132           0 :     Reference < XInputStream > xInputStream;
     133           0 :     for ( sal_Int32 i = 0 ; i < nLength; i++)
     134             :     {
     135           0 :         if ( pValue[i].Name == "TypeName" )
     136           0 :             location=i;
     137           0 :         else if ( pValue[i].Name == "InputStream" )
     138           0 :             pValue[i].Value >>= xInputStream;
     139             :     }
     140             : 
     141           0 :     WPXSvInputStream input( xInputStream );
     142             : 
     143           0 :     if (libmspub::MSPUBDocument::isSupported(&input))
     144           0 :         sTypeName = "draw_Publisher_Document";
     145             : 
     146           0 :     if (sTypeName.getLength())
     147             :     {
     148           0 :         if ( location == Descriptor.getLength() )
     149             :         {
     150           0 :             Descriptor.realloc(nLength+1);
     151           0 :             Descriptor[location].Name = "TypeName";
     152             :         }
     153             : 
     154           0 :         Descriptor[location].Value <<=sTypeName;
     155             :     }
     156           0 :     return sTypeName;
     157             : }
     158             : 
     159             : 
     160             : // XInitialization
     161           0 : void SAL_CALL MSPUBImportFilter::initialize( const Sequence< Any >& aArguments )
     162             : throw (Exception, RuntimeException)
     163             : {
     164             : #ifdef DEBUG
     165             :     std::cerr << "MSPUBImportFilter::initialize" << std::endl;
     166             : #endif
     167           0 :     Sequence < PropertyValue > aAnySeq;
     168           0 :     sal_Int32 nLength = aArguments.getLength();
     169           0 :     if ( nLength && ( aArguments[0] >>= aAnySeq ) )
     170             :     {
     171           0 :         const PropertyValue *pValue = aAnySeq.getConstArray();
     172           0 :         nLength = aAnySeq.getLength();
     173           0 :         for ( sal_Int32 i = 0 ; i < nLength; i++)
     174             :         {
     175           0 :             if ( pValue[i].Name == "Type" )
     176             :             {
     177           0 :                 pValue[i].Value >>= msFilterName;
     178           0 :                 break;
     179             :             }
     180             :         }
     181           0 :     }
     182           0 : }
     183           0 : OUString MSPUBImportFilter_getImplementationName ()
     184             : throw (RuntimeException)
     185             : {
     186             : #ifdef DEBUG
     187             :     std::cerr << "MSPUBImportFilter_getImplementationName" << std::endl;
     188             : #endif
     189           0 :     return OUString ( "com.sun.star.comp.Draw.MSPUBImportFilter" );
     190             : }
     191             : 
     192             : #define SERVICE_NAME1 "com.sun.star.document.ImportFilter"
     193             : #define SERVICE_NAME2 "com.sun.star.document.ExtendedTypeDetection"
     194           0 : sal_Bool SAL_CALL MSPUBImportFilter_supportsService( const OUString &ServiceName )
     195             : throw (RuntimeException)
     196             : {
     197             : #ifdef DEBUG
     198             :     std::cerr << "MSPUBImportFilter_supportsService" << std::endl;
     199             : #endif
     200           0 :     return ( ServiceName == SERVICE_NAME1 || ServiceName == SERVICE_NAME2 );
     201             : }
     202           0 : Sequence< OUString > SAL_CALL MSPUBImportFilter_getSupportedServiceNames(  )
     203             : throw (RuntimeException)
     204             : {
     205             : #ifdef DEBUG
     206             :     std::cerr << "MSPUBImportFilter_getSupportedServiceNames" << std::endl;
     207             : #endif
     208           0 :     Sequence < OUString > aRet(2);
     209           0 :     OUString *pArray = aRet.getArray();
     210           0 :     pArray[0] =  OUString ( SERVICE_NAME1 );
     211           0 :     pArray[1] =  OUString ( SERVICE_NAME2 );
     212           0 :     return aRet;
     213             : }
     214             : #undef SERVICE_NAME2
     215             : #undef SERVICE_NAME1
     216             : 
     217           0 : Reference< XInterface > SAL_CALL MSPUBImportFilter_createInstance( const Reference< XComponentContext > & rContext)
     218             : throw( Exception )
     219             : {
     220             : #ifdef DEBUG
     221             :     std::cerr << "MSPUBImportFilter_createInstance" << std::endl;
     222             : #endif
     223           0 :     return (cppu::OWeakObject *) new MSPUBImportFilter( rContext );
     224             : }
     225             : 
     226             : // XServiceInfo
     227           0 : OUString SAL_CALL MSPUBImportFilter::getImplementationName(  )
     228             : throw (RuntimeException)
     229             : {
     230             : #ifdef DEBUG
     231             :     std::cerr << "MSPUBImportFilter::getImplementationName" << std::endl;
     232             : #endif
     233           0 :     return MSPUBImportFilter_getImplementationName();
     234             : }
     235           0 : sal_Bool SAL_CALL MSPUBImportFilter::supportsService( const OUString &rServiceName )
     236             : throw (RuntimeException)
     237             : {
     238             : #ifdef DEBUG
     239             :     std::cerr << "MSPUBImportFilter::supportsService" << std::endl;
     240             : #endif
     241           0 :     return MSPUBImportFilter_supportsService( rServiceName );
     242             : }
     243           0 : Sequence< OUString > SAL_CALL MSPUBImportFilter::getSupportedServiceNames(  )
     244             : throw (RuntimeException)
     245             : {
     246             : #ifdef DEBUG
     247             :     std::cerr << "MSPUBImportFilter::getSupportedServiceNames" << std::endl;
     248             : #endif
     249           0 :     return MSPUBImportFilter_getSupportedServiceNames();
     250           0 : }
     251             : 
     252             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10