LCOV - code coverage report
Current view: top level - sfx2/source/doc - docfilt.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 62 98 63.3 %
Date: 2012-08-25 Functions: 6 9 66.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 89 290 30.7 %

           Branch data     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                 :       4772 : 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 [ +  - ][ +  - ]:       4772 :     aFilterName( rName )
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
      61                 :            : {
      62 [ +  - ][ +  - ]:       4772 :     String aExts = GetWildcard().getGlob();
      63 [ +  - ][ +  - ]:       4772 :     String aShort, aLong;
      64         [ +  - ]:       4772 :     String aRet;
      65                 :       4772 :     sal_uInt16 nMaxLength = USHRT_MAX;
      66         [ +  - ]:       4772 :     String aTest;
      67                 :       4772 :     sal_uInt16 nPos = 0;
      68 [ +  - ][ +  - ]:      10923 :     while( ( aRet = aExts.GetToken( nPos++, ';' ) ).Len() )
         [ +  - ][ +  + ]
      69                 :            :     {
      70         [ +  - ]:       6151 :         aTest = aRet;
      71 [ +  - ][ +  - ]:       6151 :         aTest.SearchAndReplace( DEFINE_CONST_UNICODE( "*." ), String() );
         [ +  - ][ +  - ]
                 [ +  - ]
      72         [ +  - ]:       6151 :         if( aTest.Len() <= nMaxLength )
      73                 :            :         {
      74 [ +  + ][ +  - ]:       6151 :             if( aShort.Len() ) aShort += ';';
      75         [ +  - ]:       6151 :             aShort += aRet;
      76                 :            :         }
      77                 :            :         else
      78                 :            :         {
      79 [ #  # ][ #  # ]:          0 :             if( aLong.Len() ) aLong += ';';
      80         [ #  # ]:          0 :             aLong += aRet;
      81                 :            :         }
      82                 :            :     }
      83 [ +  + ][ -  + ]:       4772 :     if( aShort.Len() && aLong.Len() )
                 [ -  + ]
      84                 :            :     {
      85         [ #  # ]:          0 :         aShort += ';';
      86         [ #  # ]:          0 :         aShort += aLong;
      87                 :            :     }
      88 [ +  - ][ +  - ]:       4772 :     aWildCard.setGlob(aShort);
      89                 :            : 
      90                 :       4772 :     nVersion = SOFFICE_FILEFORMAT_50;
      91 [ +  - ][ +  - ]:       4772 :     aUIName = aFilterName;
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
      92                 :       4772 : }
      93                 :            : 
      94 [ +  - ][ +  - ]:         18 : SfxFilter::~SfxFilter()
         [ +  - ][ +  - ]
                 [ +  - ]
      95                 :            : {
      96                 :         18 : }
      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                 :         10 : const SfxFilter* SfxFilter::GetDefaultFilter( const String& rName )
     112                 :            : {
     113                 :         10 :     return SfxFilterContainer::GetDefaultFilter_Impl( rName );
     114                 :            : }
     115                 :            : 
     116                 :         10 : const SfxFilter* SfxFilter::GetDefaultFilterFromFactory( const String& rFact )
     117                 :            : {
     118         [ +  - ]:         10 :     return GetDefaultFilter( SfxObjectShell::GetServiceNameFromFactory( rFact ) );
     119                 :            : }
     120                 :            : 
     121                 :       8254 : const SfxFilter* SfxFilter::GetFilterByName( const String& rName )
     122                 :            : {
     123         [ +  - ]:       8254 :     SfxFilterMatcher aMatch;
     124 [ +  - ][ +  - ]:       8254 :     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                 :       1846 : 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         [ +  - ]:       1846 :     SfxFilterMatcher aMatcher;
     174                 :       1846 :     const char* pType=0;
     175         [ +  - ]:       1846 :     String aName;
     176         [ +  + ]:       1846 :     if ( pFilterName )
     177                 :            :     {
     178         [ +  - ]:        142 :         aName = *pFilterName;
     179         [ +  - ]:        142 :         pFilterName->Erase();
     180                 :            :     }
     181                 :            : 
     182         [ +  - ]:       1846 :     com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet > xProps( xStorage, com::sun::star::uno::UNO_QUERY );
     183         [ +  - ]:       1846 :     if ( xProps.is() )
     184                 :            :     {
     185                 :       1846 :         ::rtl::OUString aMediaType;
     186 [ +  - ][ +  - ]:       1846 :         xProps->getPropertyValue( ::rtl::OUString("MediaType") ) >>= aMediaType;
     187         [ +  - ]:       1846 :         if ( !aMediaType.isEmpty() )
     188                 :            :         {
     189                 :       1846 :             ::com::sun::star::datatransfer::DataFlavor aDataFlavor;
     190                 :       1846 :             aDataFlavor.MimeType = aMediaType;
     191         [ +  - ]:       1846 :             sal_uInt32 nClipId = SotExchange::GetFormat( aDataFlavor );
     192         [ +  - ]:       1846 :             if ( nClipId )
     193                 :            :             {
     194                 :       1846 :                 SfxFilterFlags nMust = SFX_FILTER_IMPORT, nDont = SFX_FILTER_NOTINSTALLED;
     195         [ +  + ]:       1846 :                 if ( bTemplate )
     196                 :            :                     // template filter was preselected, try to verify
     197                 :          4 :                     nMust |= SFX_FILTER_TEMPLATEPATH;
     198                 :            :                 else
     199                 :            :                     // template filters shouldn't be detected if not explicitly asked for
     200                 :       1842 :                     nDont |= SFX_FILTER_TEMPLATEPATH;
     201                 :            : 
     202                 :       1846 :                 const SfxFilter* pFilter = 0;
     203         [ +  + ]:       1846 :                 if ( aName.Len() )
     204                 :            :                     // get preselected Filter if it matches the desired filter flags
     205         [ +  - ]:         99 :                     pFilter = aMatcher.GetFilter4FilterName( aName, nMust, nDont );
     206                 :            : 
     207 [ +  + ][ +  + ]:       1846 :                 if ( !pFilter || pFilter->GetFormat() != nClipId )
                 [ +  + ]
     208                 :            :                 {
     209                 :            :                     // get filter from storage MediaType
     210         [ +  - ]:       1752 :                     pFilter = aMatcher.GetFilter4ClipBoardId( nClipId, nMust, nDont );
     211         [ +  + ]:       1752 :                     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         [ +  - ]:          3 :                         pFilter = aMatcher.GetFilter4ClipBoardId( nClipId );
     215                 :            :                 }
     216                 :            : 
     217         [ +  - ]:       1846 :                 if ( pFilter )
     218                 :            :                 {
     219         [ +  + ]:       1846 :                     if ( pFilterName )
     220         [ +  - ]:        142 :                         *pFilterName = pFilter->GetName();
     221         [ +  - ]:       1846 :                     return pFilter->GetTypeName();
     222                 :            :                 }
     223         [ -  + ]:       1846 :             }
     224         [ -  + ]:       1846 :         }
     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 [ #  # ][ #  # ]:       1846 :     return aRet;
         [ +  - ][ +  - ]
     238                 :            : }
     239                 :            : 
     240                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10