LCOV - code coverage report
Current view: top level - sd/source/ui/unoidl - sddetect.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 40 63 63.5 %
Date: 2015-06-13 12:38:46 Functions: 7 10 70.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        2609 : SdFilterDetect::SdFilterDetect()
      45             : {
      46        2609 : }
      47             : 
      48        5218 : SdFilterDetect::~SdFilterDetect()
      49             : {
      50        5218 : }
      51             : 
      52        2609 : OUString SAL_CALL SdFilterDetect::detect( Sequence< beans::PropertyValue >& lDescriptor ) throw( RuntimeException, std::exception )
      53             : {
      54        2609 :     MediaDescriptor aMediaDesc( lDescriptor );
      55        5218 :     OUString aTypeName = aMediaDesc.getUnpackedValueOrDefault( MediaDescriptor::PROP_TYPENAME(), OUString() );
      56        5218 :     uno::Reference< io::XInputStream > xInStream ( aMediaDesc[MediaDescriptor::PROP_INPUTSTREAM()], uno::UNO_QUERY );
      57        2609 :     if ( !xInStream.is() )
      58           0 :         return OUString();
      59             : 
      60        5218 :     SfxMedium aMedium;
      61        2609 :     aMedium.UseInteractionHandler( false );
      62        2609 :     aMedium.setStreamToLoadFrom( xInStream, true );
      63             : 
      64        2609 :     SvStream *pInStrm = aMedium.GetInStream();
      65        2609 :     if ( !pInStrm || pInStrm->GetError() )
      66           0 :         return OUString();
      67             : 
      68        2609 :     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         253 :         pInStrm->Seek( STREAM_SEEK_TO_BEGIN );
      75         253 :         if ( pInStrm->remainingSize() == 0 )
      76           0 :             return OUString();
      77             : 
      78             :         try
      79             :         {
      80         253 :             tools::SvRef<SotStorage> aStorage = new SotStorage( pInStrm, false );
      81         253 :             if ( !aStorage->GetError() && aStorage->IsStream( "PowerPoint Document" ) )
      82           1 :                 return aTypeName;
      83             :         }
      84           0 :         catch (const css::ucb::ContentCreationException&)
      85             :         {
      86             :         }
      87             :     }
      88             :     else
      89             :     {
      90        2356 :         pInStrm->Seek( STREAM_SEEK_TO_BEGIN );
      91             : 
      92        2356 :         const OUString aFileName( aMediaDesc.getUnpackedValueOrDefault( MediaDescriptor::PROP_URL(), OUString() ) );
      93        4708 :         GraphicDescriptor aDesc( *pInStrm, &aFileName );
      94        2356 :         if( !aDesc.Detect( false ) )
      95             :         {
      96        2352 :             INetURLObject aCheckURL( aFileName );
      97        2352 :             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        2352 :             }
     107             :         }
     108             :         else
     109             :         {
     110           4 :             OUString aShortName( GraphicDescriptor::GetImportFormatShortName( aDesc.GetFileFormat() ) );
     111           4 :             GraphicFilter &rGrfFilter = GraphicFilter::GetGraphicFilter();
     112           4 :             const OUString aName( rGrfFilter.GetImportFormatTypeName( rGrfFilter.GetImportFormatNumberForShortName( aShortName ) ) );
     113             : 
     114           4 :             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           4 :             SfxFilterMatcher aMatch("sdraw");
     126           4 :             const SfxFilter* pFilter = aMatch.GetFilter4FilterName( aName );
     127           4 :             if ( pFilter )
     128           4 :                 return pFilter->GetRealTypeName();
     129        2352 :         }
     130             :     }
     131             : 
     132        5213 :     return OUString();
     133             : }
     134             : 
     135             : // XServiceInfo
     136           0 : OUString SAL_CALL SdFilterDetect::getImplementationName() throw( RuntimeException, std::exception )
     137             : {
     138           0 :     return OUString( "com.sun.star.comp.draw.FormatDetector" );
     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 :     Sequence< OUString > seqServiceNames( 1 );
     151           0 :     seqServiceNames.getArray() [0] = "com.sun.star.frame.ExtendedTypeDetection"  ;
     152           0 :     return seqServiceNames ;
     153             : }
     154             : 
     155             : 
     156             : extern "C" SAL_DLLPUBLIC_EXPORT ::com::sun::star::uno::XInterface* SAL_CALL
     157        2609 : com_sun_star_comp_draw_FormatDetector_get_implementation(::com::sun::star::uno::XComponentContext*,
     158             :                                                          ::com::sun::star::uno::Sequence<css::uno::Any> const &)
     159             : {
     160        2609 :     return cppu::acquire(new SdFilterDetect());
     161          15 : }
     162             : 
     163             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11