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

Generated by: LCOV version 1.10