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

Generated by: LCOV version 1.11