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

Generated by: LCOV version 1.10