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

Generated by: LCOV version 1.10