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

Generated by: LCOV version 1.10