LCOV - code coverage report
Current view: top level - libreoffice/sfx2/source/doc - docfilt.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 56 98 57.1 %
Date: 2012-12-17 Functions: 4 9 44.4 %
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             : #ifdef SOLARIS
      21             : #include <ctime>
      22             : #endif
      23             : 
      24             : #include <string>
      25             : #include <sot/exchange.hxx>
      26             : #include <comphelper/processfactory.hxx>
      27             : #include <comphelper/string.hxx>
      28             : #include <com/sun/star/beans/XPropertySet.hpp>
      29             : #include <com/sun/star/container/XNameAccess.hpp>
      30             : 
      31             : #include <sfx2/docfac.hxx>
      32             : #include <sfx2/docfilt.hxx>
      33             : #include "fltfnc.hxx"
      34             : #include <sfx2/sfxuno.hxx>
      35             : #include <sfx2/objsh.hxx>
      36             : 
      37             : using namespace ::com::sun::star;
      38             : 
      39             : // STATIC DATA -----------------------------------------------------------
      40             : 
      41             : DBG_NAME(SfxFilter)
      42             : 
      43        2140 : SfxFilter::SfxFilter(  const String &rName,
      44             :                        const String &rWildCard,
      45             :                        SfxFilterFlags nType,
      46             :                        sal_uInt32 lFmt,
      47             :                        const String &rTypNm,
      48             :                        sal_uInt16 nIcon,
      49             :                        const String &rMimeType,
      50             :                        const String &rUsrDat,
      51             :                        const String &rServiceName ):
      52             :     aWildCard(rWildCard, ';'),
      53             :     lFormat(lFmt),
      54             :     aTypeName(rTypNm),
      55             :     aUserData(rUsrDat),
      56             :     nFormatType(nType),
      57             :     nDocIcon(nIcon),
      58             :     aServiceName( rServiceName ),
      59             :     aMimeType( rMimeType ),
      60        2140 :     aFilterName( rName )
      61             : {
      62        2140 :     String aExts = GetWildcard().getGlob();
      63        2140 :     String aShort, aLong;
      64        2140 :     String aRet;
      65        2140 :     sal_uInt16 nMaxLength = USHRT_MAX;
      66        2140 :     String aTest;
      67        2140 :     sal_uInt16 nPos = 0;
      68        6950 :     while( ( aRet = aExts.GetToken( nPos++, ';' ) ).Len() )
      69             :     {
      70        2670 :         aTest = aRet;
      71        2670 :         aTest.SearchAndReplace( DEFINE_CONST_UNICODE( "*." ), String() );
      72        2670 :         if( aTest.Len() <= nMaxLength )
      73             :         {
      74        2670 :             if( aShort.Len() ) aShort += ';';
      75        2670 :             aShort += aRet;
      76             :         }
      77             :         else
      78             :         {
      79           0 :             if( aLong.Len() ) aLong += ';';
      80           0 :             aLong += aRet;
      81             :         }
      82             :     }
      83        2140 :     if( aShort.Len() && aLong.Len() )
      84             :     {
      85           0 :         aShort += ';';
      86           0 :         aShort += aLong;
      87             :     }
      88        2140 :     aWildCard.setGlob(aShort);
      89             : 
      90        2140 :     nVersion = SOFFICE_FILEFORMAT_50;
      91        2140 :     aUIName = aFilterName;
      92        2140 : }
      93             : 
      94          16 : SfxFilter::~SfxFilter()
      95             : {
      96          16 : }
      97             : 
      98           0 : String SfxFilter::GetDefaultExtension() const
      99             : {
     100           0 :     return comphelper::string::getToken(GetWildcard().getGlob(), 0, ';');
     101             : }
     102             : 
     103           0 : String SfxFilter::GetSuffixes() const
     104             : {
     105           0 :     String aRet = GetWildcard().getGlob();
     106           0 :     while( aRet.SearchAndReplaceAscii( "*.", String() ) != STRING_NOTFOUND ) ;
     107           0 :     while( aRet.SearchAndReplace( ';', ',' ) != STRING_NOTFOUND ) ;
     108           0 :     return aRet;
     109             : }
     110             : 
     111           0 : const SfxFilter* SfxFilter::GetDefaultFilter( const String& rName )
     112             : {
     113           0 :     return SfxFilterContainer::GetDefaultFilter_Impl( rName );
     114             : }
     115             : 
     116           0 : const SfxFilter* SfxFilter::GetDefaultFilterFromFactory( const String& rFact )
     117             : {
     118           0 :     return GetDefaultFilter( SfxObjectShell::GetServiceNameFromFactory( rFact ) );
     119             : }
     120             : 
     121        4421 : const SfxFilter* SfxFilter::GetFilterByName( const String& rName )
     122             : {
     123        4421 :     SfxFilterMatcher aMatch;
     124        4421 :     return aMatch.GetFilter4FilterName( rName, 0, 0 );
     125             : }
     126             : 
     127           0 : String SfxFilter::GetTypeFromStorage( const SotStorage& rStg )
     128             : {
     129           0 :     const char* pType=0;
     130           0 :     if ( rStg.IsStream( rtl::OUString("WordDocument") ) )
     131             :     {
     132           0 :         if ( rStg.IsStream( rtl::OUString("0Table") ) || rStg.IsStream( rtl::OUString("1Table") ) )
     133           0 :             pType = "writer_MS_Word_97";
     134             :         else
     135           0 :             pType = "writer_MS_Word_95";
     136             :     }
     137           0 :     else if ( rStg.IsStream( rtl::OUString("Book") ) )
     138             :     {
     139           0 :         pType = "calc_MS_Excel_95";
     140             :     }
     141           0 :     else if ( rStg.IsStream( rtl::OUString("Workbook" ) ) )
     142             :     {
     143           0 :         pType = "calc_MS_Excel_97";
     144             :     }
     145           0 :     else if ( rStg.IsStream( rtl::OUString("PowerPoint Document") ) )
     146             :     {
     147           0 :         pType = "impress_MS_PowerPoint_97";
     148             :     }
     149           0 :     else if ( rStg.IsStream( rtl::OUString("Equation Native") ) )
     150             :     {
     151           0 :         pType = "math_MathType_3x";
     152             :     }
     153             :     else
     154             :     {
     155           0 :         sal_Int32 nClipId = ((SotStorage&)rStg).GetFormat();
     156           0 :         if ( nClipId )
     157             :         {
     158           0 :             const SfxFilter* pFilter = SfxFilterMatcher().GetFilter4ClipBoardId( nClipId );
     159           0 :             if ( pFilter )
     160           0 :                 return pFilter->GetTypeName();
     161             :         }
     162             :     }
     163             : 
     164           0 :     return pType ? rtl::OUString::createFromAscii(pType) : rtl::OUString();
     165             : }
     166             : 
     167        1191 : String SfxFilter::GetTypeFromStorage( const com::sun::star::uno::Reference< com::sun::star::embed::XStorage >& xStorage, sal_Bool bTemplate,
     168             :                                         String* pFilterName )
     169             :         throw ( beans::UnknownPropertyException,
     170             :                 lang::WrappedTargetException,
     171             :                 uno::RuntimeException )
     172             : {
     173        1191 :     SfxFilterMatcher aMatcher;
     174        1191 :     const char* pType=0;
     175        1191 :     String aName;
     176        1191 :     if ( pFilterName )
     177             :     {
     178          55 :         aName = *pFilterName;
     179          55 :         pFilterName->Erase();
     180             :     }
     181             : 
     182        1191 :     com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet > xProps( xStorage, com::sun::star::uno::UNO_QUERY );
     183        1191 :     if ( xProps.is() )
     184             :     {
     185        1191 :         ::rtl::OUString aMediaType;
     186        1191 :         xProps->getPropertyValue( ::rtl::OUString("MediaType") ) >>= aMediaType;
     187        1191 :         if ( !aMediaType.isEmpty() )
     188             :         {
     189        1191 :             ::com::sun::star::datatransfer::DataFlavor aDataFlavor;
     190        1191 :             aDataFlavor.MimeType = aMediaType;
     191        1191 :             sal_uInt32 nClipId = SotExchange::GetFormat( aDataFlavor );
     192        1191 :             if ( nClipId )
     193             :             {
     194        1191 :                 SfxFilterFlags nMust = SFX_FILTER_IMPORT, nDont = SFX_FILTER_NOTINSTALLED;
     195        1191 :                 if ( bTemplate )
     196             :                     // template filter was preselected, try to verify
     197           0 :                     nMust |= SFX_FILTER_TEMPLATEPATH;
     198             :                 else
     199             :                     // template filters shouldn't be detected if not explicitly asked for
     200        1191 :                     nDont |= SFX_FILTER_TEMPLATEPATH;
     201             : 
     202        1191 :                 const SfxFilter* pFilter = 0;
     203        1191 :                 if ( aName.Len() )
     204             :                     // get preselected Filter if it matches the desired filter flags
     205          51 :                     pFilter = aMatcher.GetFilter4FilterName( aName, nMust, nDont );
     206             : 
     207        1191 :                 if ( !pFilter || pFilter->GetFormat() != nClipId )
     208             :                 {
     209             :                     // get filter from storage MediaType
     210        1142 :                     pFilter = aMatcher.GetFilter4ClipBoardId( nClipId, nMust, nDont );
     211        1142 :                     if ( !pFilter )
     212             :                         // template filter is asked for , but there isn't one; so at least the "normal" format should be detected
     213             :                         // or storage *is* a template, but bTemplate is not set
     214           2 :                         pFilter = aMatcher.GetFilter4ClipBoardId( nClipId );
     215             :                 }
     216             : 
     217        1191 :                 if ( pFilter )
     218             :                 {
     219        1191 :                     if ( pFilterName )
     220          55 :                         *pFilterName = pFilter->GetName();
     221        1191 :                     return pFilter->GetTypeName();
     222             :                 }
     223        1191 :             }
     224        1191 :         }
     225             :     }
     226             : 
     227             :     //TODO: do it without SfxFilter
     228             :     //TODO/LATER: don't yield FilterName, should be done in FWK!
     229           0 :     String aRet;
     230           0 :     if ( pType )
     231             :     {
     232           0 :         aRet = rtl::OUString::createFromAscii(pType);
     233           0 :         if ( pFilterName )
     234           0 :             *pFilterName = aMatcher.GetFilter4EA( aRet )->GetName();
     235             :     }
     236             : 
     237           0 :     return aRet;
     238             : }
     239             : 
     240             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10