LCOV - code coverage report
Current view: top level - sd/source/ui/unoidl - sddetect.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 30 67 44.8 %
Date: 2014-11-03 Functions: 9 12 75.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             : /*
       3             :  * This file is part of the LibreOffice project.
       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             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "sddetect.hxx"
      21             : 
      22             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      23             : #include <com/sun/star/beans/PropertyValue.hpp>
      24             : #include <cppuhelper/supportsservice.hxx>
      25             : #include <com/sun/star/container/XNameAccess.hpp>
      26             : #include <com/sun/star/io/XInputStream.hpp>
      27             : #include <vcl/graphicfilter.hxx>
      28             : #include <rtl/ustring.h>
      29             : #include <sfx2/docfile.hxx>
      30             : #include <sfx2/docfilt.hxx>
      31             : #include <sfx2/fcontnr.hxx>
      32             : #include <vcl/FilterConfigItem.hxx>
      33             : #include <sot/storage.hxx>
      34             : #include <unotools/mediadescriptor.hxx>
      35             : 
      36             : using namespace ::com::sun::star;
      37             : using namespace ::com::sun::star::uno;
      38             : using namespace ::com::sun::star::io;
      39             : using namespace ::com::sun::star::task;
      40             : using namespace ::com::sun::star::beans;
      41             : using namespace ::com::sun::star::lang;
      42             : using utl::MediaDescriptor;
      43             : 
      44           2 : SdFilterDetect::SdFilterDetect( const Reference < XMultiServiceFactory >&  )
      45             : {
      46           2 : }
      47             : 
      48           4 : SdFilterDetect::~SdFilterDetect()
      49             : {
      50           4 : }
      51             : 
      52           2 : OUString SAL_CALL SdFilterDetect::detect( Sequence< beans::PropertyValue >& lDescriptor ) throw( RuntimeException, std::exception )
      53             : {
      54           2 :     MediaDescriptor aMediaDesc( lDescriptor );
      55           4 :     OUString aTypeName = aMediaDesc.getUnpackedValueOrDefault( MediaDescriptor::PROP_TYPENAME(), OUString() );
      56           4 :     uno::Reference< io::XInputStream > xInStream ( aMediaDesc[MediaDescriptor::PROP_INPUTSTREAM()], uno::UNO_QUERY );
      57           2 :     if ( !xInStream.is() )
      58           0 :         return OUString();
      59             : 
      60           4 :     SfxMedium aMedium;
      61           2 :     aMedium.UseInteractionHandler( false );
      62           2 :     aMedium.setStreamToLoadFrom( xInStream, true );
      63             : 
      64           2 :     SvStream *pInStrm = aMedium.GetInStream();
      65           2 :     if ( !pInStrm || pInStrm->GetError() )
      66           0 :         return OUString();
      67             : 
      68           2 :     if ( aTypeName.startsWith( "impress_MS_PowerPoint_97" ) )
      69             :     {
      70             :         // Do not attempt to create an SotStorage on a
      71             :         // 0-length stream as that would create the compound
      72             :         // document header on the stream and effectively write to
      73             :         // disk!
      74           2 :         pInStrm->Seek( STREAM_SEEK_TO_BEGIN );
      75           2 :         if ( pInStrm->remainingSize() == 0 )
      76           0 :             return OUString();
      77             : 
      78             :         try
      79             :         {
      80           2 :             SotStorageRef aStorage = new SotStorage( pInStrm, false );
      81           2 :             if ( !aStorage->GetError() && aStorage->IsStream( "PowerPoint Document" ) )
      82           2 :                 return aTypeName;
      83             :         }
      84           0 :         catch (const css::ucb::ContentCreationException&)
      85             :         {
      86             :         }
      87             :     }
      88             :     else
      89             :     {
      90           0 :         pInStrm->Seek( STREAM_SEEK_TO_BEGIN );
      91             : 
      92           0 :         const OUString aFileName( aMediaDesc.getUnpackedValueOrDefault( MediaDescriptor::PROP_URL(), OUString() ) );
      93           0 :         GraphicDescriptor aDesc( *pInStrm, &aFileName );
      94           0 :         if( !aDesc.Detect( false ) )
      95             :         {
      96           0 :             INetURLObject aCheckURL( aFileName );
      97           0 :             if( aCheckURL.getExtension().equalsIgnoreAsciiCase("cgm") )
      98             :             {
      99             :                 sal_uInt8 n8;
     100           0 :                 pInStrm->Seek( STREAM_SEEK_TO_BEGIN );
     101           0 :                 pInStrm->ReadUChar( n8 );
     102           0 :                 if ( ( n8 & 0xf0 ) == 0 )
     103             :                     // we are supporting binary cgm format only, so
     104             :                     // this is a small test to exclude cgm text
     105           0 :                     return OUString("impress_CGM_Computer_Graphics_Metafile");
     106           0 :             }
     107             :         }
     108             :         else
     109             :         {
     110           0 :             OUString aShortName( GraphicDescriptor::GetImportFormatShortName( aDesc.GetFileFormat() ) );
     111           0 :             GraphicFilter &rGrfFilter = GraphicFilter::GetGraphicFilter();
     112           0 :             const OUString aName( rGrfFilter.GetImportFormatTypeName( rGrfFilter.GetImportFormatNumberForShortName( aShortName ) ) );
     113             : 
     114           0 :             if ( aShortName.equalsIgnoreAsciiCase( "PCD" ) )    // there is a multiple pcd selection possible
     115             :             {
     116           0 :                 sal_Int32 nBase = 2;    // default Base0
     117           0 :                 if ( aTypeName == "pcd_Photo_CD_Base4" )
     118           0 :                     nBase = 1;
     119           0 :                 else if ( aTypeName == "pcd_Photo_CD_Base16" )
     120           0 :                     nBase = 0;
     121           0 :                 FilterConfigItem aFilterConfigItem( "Office.Common/Filter/Graphic/Import/PCD" );
     122           0 :                 aFilterConfigItem.WriteInt32( "Resolution" , nBase );
     123             :             }
     124             : 
     125           0 :             SfxFilterMatcher aMatch("sdraw");
     126           0 :             const SfxFilter* pFilter = aMatch.GetFilter4FilterName( aName );
     127           0 :             if ( pFilter )
     128           0 :                 return pFilter->GetRealTypeName();
     129           0 :         }
     130             :     }
     131             : 
     132           2 :     return OUString();
     133             : }
     134             : 
     135             : // XServiceInfo
     136           0 : OUString SAL_CALL SdFilterDetect::getImplementationName() throw( RuntimeException, std::exception )
     137             : {
     138           0 :     return impl_getStaticImplementationName();
     139             : }
     140             : 
     141             : // XServiceInfo
     142           0 : sal_Bool SAL_CALL SdFilterDetect::supportsService( const OUString& sServiceName ) throw( RuntimeException, std::exception )
     143             : {
     144           0 :     return cppu::supportsService(this, sServiceName);
     145             : }
     146             : 
     147             : // XServiceInfo
     148           0 : Sequence< OUString > SAL_CALL SdFilterDetect::getSupportedServiceNames() throw( RuntimeException, std::exception )
     149             : {
     150           0 :     return impl_getStaticSupportedServiceNames();
     151             : }
     152             : 
     153             : // Helper for XServiceInfo
     154           2 : Sequence< OUString > SdFilterDetect::impl_getStaticSupportedServiceNames()
     155             : {
     156           2 :     Sequence< OUString > seqServiceNames( 1 );
     157           2 :     seqServiceNames.getArray() [0] = "com.sun.star.frame.ExtendedTypeDetection"  ;
     158           2 :     return seqServiceNames ;
     159             : }
     160             : 
     161             : // Helper for XServiceInfo
     162           4 : OUString SdFilterDetect::impl_getStaticImplementationName()
     163             : {
     164           4 :     return OUString( "com.sun.star.comp.draw.FormatDetector" );
     165             : }
     166             : 
     167             : // Helper for registry
     168           2 : Reference< XInterface > SAL_CALL SdFilterDetect::impl_createInstance( const Reference< XMultiServiceFactory >& xServiceManager ) throw( Exception )
     169             : {
     170             :     return static_cast< cppu::OWeakObject * >(
     171           2 :         new SdFilterDetect( xServiceManager ) );
     172           6 : }
     173             : 
     174             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10