LCOV - code coverage report
Current view: top level - writerperfect/source/draw - CDRImportFilter.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 25 79 31.6 %
Date: 2012-08-25 Functions: 6 14 42.9 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 15 94 16.0 %

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

Generated by: LCOV version 1.10