LCOV - code coverage report
Current view: top level - writerperfect/source/draw - WPGImportFilter.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 75 0.0 %
Date: 2014-04-14 Functions: 0 13 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             : #include <cppuhelper/supportsservice.hxx>
      27             : 
      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, std::exception)
      61             : {
      62             :     SAL_INFO("writerperfect", "WPGImportFilter::filter");
      63           0 :     sal_Int32 nLength = aDescriptor.getLength();
      64           0 :     const PropertyValue *pValue = aDescriptor.getConstArray();
      65           0 :     Reference < XInputStream > xInputStream;
      66           0 :     for ( sal_Int32 i = 0 ; i < nLength; i++)
      67             :     {
      68           0 :         if ( pValue[i].Name == "InputStream" )
      69           0 :             pValue[i].Value >>= xInputStream;
      70             :     }
      71           0 :     if ( !xInputStream.is() )
      72             :     {
      73             :         OSL_ASSERT( false );
      74           0 :         return sal_False;
      75             :     }
      76             : 
      77             :     // An XML import service: what we push sax messages to..
      78             :     Reference < XDocumentHandler > xInternalHandler(
      79           0 :         mxContext->getServiceManager()->createInstanceWithContext(
      80           0 :             "com.sun.star.comp.Draw.XMLOasisImporter", mxContext),
      81           0 :         css::uno::UNO_QUERY_THROW);
      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, std::exception)
     100             : {
     101             :     SAL_INFO("writerperfect", "WPGImportFilter::cancel");
     102           0 : }
     103             : 
     104             : // XImporter
     105           0 : void SAL_CALL WPGImportFilter::setTargetDocument( const Reference< ::com::sun::star::lang::XComponent >& xDoc )
     106             : throw (::com::sun::star::lang::IllegalArgumentException, RuntimeException, std::exception)
     107             : {
     108             :     SAL_INFO("writerperfect", "WPGImportFilter::setTargetDocument");
     109           0 :     mxDoc = xDoc;
     110           0 : }
     111             : 
     112             : // XExtendedFilterDetection
     113           0 : OUString SAL_CALL WPGImportFilter::detect( com::sun::star::uno::Sequence< PropertyValue >& Descriptor )
     114             : throw( com::sun::star::uno::RuntimeException, std::exception )
     115             : {
     116             :     SAL_INFO("writerperfect", "WPGImportFilter::detect");
     117           0 :     OUString sTypeName;
     118           0 :     sal_Int32 nLength = Descriptor.getLength();
     119           0 :     sal_Int32 location = nLength;
     120           0 :     const PropertyValue *pValue = Descriptor.getConstArray();
     121           0 :     Reference < XInputStream > xInputStream;
     122           0 :     for ( sal_Int32 i = 0 ; i < nLength; i++)
     123             :     {
     124           0 :         if ( pValue[i].Name == "TypeName" )
     125           0 :             location=i;
     126           0 :         else if ( pValue[i].Name == "InputStream" )
     127           0 :             pValue[i].Value >>= xInputStream;
     128             :     }
     129             : 
     130           0 :     if (!xInputStream.is())
     131           0 :         return OUString();
     132             : 
     133           0 :     WPXSvInputStream input( xInputStream );
     134             : 
     135           0 :     if (libwpg::WPGraphics::isSupported(&input))
     136           0 :         sTypeName = "draw_WordPerfect_Graphics";
     137             : 
     138           0 :     if (!sTypeName.isEmpty())
     139             :     {
     140           0 :         if ( location == nLength )
     141             :         {
     142           0 :             Descriptor.realloc(nLength+1);
     143           0 :             Descriptor[location].Name = "TypeName";
     144             :         }
     145             : 
     146           0 :         Descriptor[location].Value <<=sTypeName;
     147             :     }
     148           0 :     return sTypeName;
     149             : }
     150             : 
     151             : 
     152             : // XInitialization
     153           0 : void SAL_CALL WPGImportFilter::initialize( const Sequence< Any >& aArguments )
     154             : throw (Exception, RuntimeException, std::exception)
     155             : {
     156             :     SAL_INFO("writerperfect", "WPGImportFilter::initialize");
     157           0 :     Sequence < PropertyValue > aAnySeq;
     158           0 :     sal_Int32 nLength = aArguments.getLength();
     159           0 :     if ( nLength && ( aArguments[0] >>= aAnySeq ) )
     160             :     {
     161           0 :         const PropertyValue *pValue = aAnySeq.getConstArray();
     162           0 :         nLength = aAnySeq.getLength();
     163           0 :         for ( sal_Int32 i = 0 ; i < nLength; i++)
     164             :         {
     165           0 :             if ( pValue[i].Name == "Type" )
     166             :             {
     167           0 :                 pValue[i].Value >>= msFilterName;
     168           0 :                 break;
     169             :             }
     170             :         }
     171           0 :     }
     172           0 : }
     173           0 : OUString WPGImportFilter_getImplementationName ()
     174             : throw (RuntimeException)
     175             : {
     176             :     SAL_INFO("writerperfect", "WPGImportFilter_getImplementationName");
     177           0 :     return OUString (  "com.sun.star.comp.Draw.WPGImportFilter"  );
     178             : }
     179             : 
     180           0 : Sequence< OUString > SAL_CALL WPGImportFilter_getSupportedServiceNames(  )
     181             : throw (RuntimeException)
     182             : {
     183             :     SAL_INFO("writerperfect", "WPGImportFilter_getSupportedServiceNames");
     184           0 :     Sequence < OUString > aRet(2);
     185           0 :     OUString *pArray = aRet.getArray();
     186           0 :     pArray[0] =  "com.sun.star.document.ImportFilter";
     187           0 :     pArray[1] =  "com.sun.star.document.ExtendedTypeDetection";
     188           0 :     return aRet;
     189             : }
     190             : 
     191           0 : Reference< XInterface > SAL_CALL WPGImportFilter_createInstance( const Reference< XComponentContext > & rContext)
     192             : throw( Exception )
     193             : {
     194             :     SAL_INFO("writerperfect", "WPGImportFilter_createInstance");
     195           0 :     return (cppu::OWeakObject *) new WPGImportFilter( rContext );
     196             : }
     197             : 
     198             : // XServiceInfo
     199           0 : OUString SAL_CALL WPGImportFilter::getImplementationName(  )
     200             : throw (RuntimeException, std::exception)
     201             : {
     202             :     SAL_INFO("writerperfect", "WPGImportFilter::getImplementationName");
     203           0 :     return WPGImportFilter_getImplementationName();
     204             : }
     205           0 : sal_Bool SAL_CALL WPGImportFilter::supportsService( const OUString &rServiceName )
     206             : throw (RuntimeException, std::exception)
     207             : {
     208             :     SAL_INFO("writerperfect", "WPGImportFilter::supportsService");
     209           0 :     return cppu::supportsService( this, rServiceName );
     210             : }
     211           0 : Sequence< OUString > SAL_CALL WPGImportFilter::getSupportedServiceNames(  )
     212             : throw (RuntimeException, std::exception)
     213             : {
     214             :     SAL_INFO("writerperfect", "WPGImportFilter::getSupportedServiceNames");
     215           0 :     return WPGImportFilter_getSupportedServiceNames();
     216           0 : }
     217             : 
     218             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10