LCOV - code coverage report
Current view: top level - sc/source/ui/vba - vbafilesearch.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 101 0.0 %
Date: 2012-08-25 Functions: 0 20 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 148 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright IBM Corporation 2009, 2010.
       7                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       8                 :            :  *
       9                 :            :  * OpenOffice.org - a multi-platform office productivity suite
      10                 :            :  *
      11                 :            :  * This file is part of OpenOffice.org.
      12                 :            :  *
      13                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      14                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      15                 :            :  * only, as published by the Free Software Foundation.
      16                 :            :  *
      17                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      18                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      19                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      20                 :            :  * GNU Lesser General Public License version 3 for more details
      21                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      22                 :            :  *
      23                 :            :  * You should have received a copy of the GNU Lesser General Public License
      24                 :            :  * version 3 along with OpenOffice.org.  If not, see
      25                 :            :  * <http://www.openoffice.org/license.html>
      26                 :            :  * for a copy of the LGPLv3 License.
      27                 :            :  *
      28                 :            :  ************************************************************************/
      29                 :            : 
      30                 :            : #include "vbafilesearch.hxx"
      31                 :            : #include "vbaapplication.hxx"
      32                 :            : #include "vbafoundfiles.hxx"
      33                 :            : #include <comphelper/processfactory.hxx>
      34                 :            : #include <tools/urlobj.hxx>
      35                 :            : #include <tools/wldcrd.hxx>
      36                 :            : #include <com/sun/star/ucb/XSimpleFileAccess3.hpp>
      37                 :            : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      38                 :            : #include <com/sun/star/uno/Sequence.hxx>
      39                 :            : #include <vector>
      40                 :            : #include "unotools/viewoptions.hxx"
      41                 :            : #include <osl/file.hxx>
      42                 :            : 
      43                 :            : using namespace ::ooo::vba;
      44                 :            : using namespace ::com::sun::star;
      45                 :            : using namespace ::com::sun::star::uno;
      46                 :            : using namespace ::com::sun::star::ucb;
      47                 :            : using namespace ::com::sun::star::lang;
      48                 :            : using namespace comphelper;
      49                 :            : 
      50                 :          0 : static Reference< XSimpleFileAccess3 > getFileAccess( void )
      51                 :            : {
      52 [ #  # ][ #  # ]:          0 :     static Reference< XSimpleFileAccess3 > xSFI;
      53         [ #  # ]:          0 :     if( !xSFI.is() )
      54                 :            :     {
      55         [ #  # ]:          0 :         Reference< XMultiServiceFactory > xSMgr = getProcessServiceFactory();
      56         [ #  # ]:          0 :         if( xSMgr.is() )
      57                 :            :         {
      58         [ #  # ]:          0 :             xSFI = Reference< XSimpleFileAccess3 >( xSMgr->createInstance
      59 [ #  # ][ #  # ]:          0 :                 ( ::rtl::OUString( "com.sun.star.ucb.SimpleFileAccess" ) ), UNO_QUERY );
                 [ #  # ]
      60                 :          0 :         }
      61                 :            :     }
      62                 :          0 :     return xSFI;
      63                 :            : }
      64                 :            : 
      65                 :          0 : ScVbaFileSearch::ScVbaFileSearch( ScVbaApplication* pApp, const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext )
      66         [ #  # ]:          0 :         : ScVbaFileSearchImpl_BASE( xParent, xContext ), m_pApplication( pApp )
      67                 :            : {
      68         [ #  # ]:          0 :     NewSearch();
      69                 :          0 : }
      70                 :            : 
      71         [ #  # ]:          0 : ScVbaFileSearch::~ScVbaFileSearch()
      72                 :            : {
      73         [ #  # ]:          0 : }
      74                 :            : 
      75                 :          0 : ::rtl::OUString SAL_CALL ScVbaFileSearch::getFileName() throw (css::uno::RuntimeException)
      76                 :            : {
      77                 :          0 :     return m_sFileName;
      78                 :            : }
      79                 :            : 
      80                 :          0 : void SAL_CALL ScVbaFileSearch::setFileName(const ::rtl::OUString& _fileName ) throw (css::uno::RuntimeException)
      81                 :            : {
      82                 :          0 :     m_sFileName = _fileName;
      83                 :          0 : }
      84                 :            : 
      85                 :          0 : ::rtl::OUString SAL_CALL ScVbaFileSearch::getLookIn() throw (css::uno::RuntimeException)
      86                 :            : {
      87                 :          0 :     return m_sLookIn;
      88                 :            : }
      89                 :            : 
      90                 :          0 : void SAL_CALL ScVbaFileSearch::setLookIn( const ::rtl::OUString& _lookIn ) throw (css::uno::RuntimeException)
      91                 :            : {
      92                 :          0 :     m_sLookIn = _lookIn;
      93                 :          0 : }
      94                 :            : 
      95                 :          0 : sal_Bool SAL_CALL ScVbaFileSearch::getSearchSubFolders() throw (css::uno::RuntimeException)
      96                 :            : {
      97                 :          0 :     return m_bSearchSubFolders;
      98                 :            : }
      99                 :            : 
     100                 :          0 : void SAL_CALL ScVbaFileSearch::setSearchSubFolders( sal_Bool _searchSubFolders ) throw (css::uno::RuntimeException)
     101                 :            : {
     102                 :          0 :     m_bSearchSubFolders = _searchSubFolders;
     103                 :          0 : }
     104                 :            : 
     105                 :          0 : sal_Bool SAL_CALL ScVbaFileSearch::getMatchTextExactly() throw (css::uno::RuntimeException)
     106                 :            : {
     107                 :          0 :     return m_bMatchTextExactly;
     108                 :            : }
     109                 :            : 
     110                 :          0 : void SAL_CALL ScVbaFileSearch::setMatchTextExactly( sal_Bool _matchTextExactly ) throw (css::uno::RuntimeException)
     111                 :            : {
     112                 :          0 :     m_bMatchTextExactly = _matchTextExactly;
     113                 :          0 : }
     114                 :            : 
     115                 :          0 : static bool IsWildCard( const ::rtl::OUString& fileName )
     116                 :            : {
     117                 :            :     static sal_Char cWild1 = '*';
     118                 :            :     static sal_Char cWild2 = '?';
     119                 :            : 
     120                 :          0 :     return  ( ( fileName.indexOf( cWild1 ) >= 0 )
     121 [ #  # ][ #  # ]:          0 :             || ( fileName.indexOf( cWild2 ) >= 0 ) );
     122                 :            : }
     123                 :            : 
     124                 :          0 : static void SearchWildCard(const WildCard& wildCard, const ::rtl::OUString& aDir, bool bSearchSubFolders, css::uno::Sequence< rtl::OUString >& aSearchedFiles)
     125                 :            : {
     126         [ #  # ]:          0 :     Reference< XSimpleFileAccess3 > xSFI = getFileAccess();
     127         [ #  # ]:          0 :     Sequence< rtl::OUString > aDirSeq;
     128                 :            :     try
     129                 :            :     {
     130         [ #  # ]:          0 :         if ( xSFI.is() )
     131                 :            :         {
     132 [ #  # ][ #  # ]:          0 :             aDirSeq = xSFI->getFolderContents( aDir, bSearchSubFolders );
         [ #  # ][ #  # ]
                 [ #  # ]
     133                 :            :         }
     134                 :            :     }
     135         [ #  # ]:          0 :     catch( css::uno::Exception& )
     136                 :            :     {
     137                 :            :     }
     138                 :          0 :     sal_Int32 nLength = aDirSeq.getLength();
     139         [ #  # ]:          0 :     for ( sal_Int32 i = 0; i < nLength; i++ )
     140                 :            :     {
     141         [ #  # ]:          0 :         rtl::OUString aURLStr = aDirSeq[i];
     142 [ #  # ][ #  # ]:          0 :         if ( xSFI->isFolder( aURLStr ) )
                 [ #  # ]
     143                 :            :         {
     144         [ #  # ]:          0 :             if ( bSearchSubFolders )
     145                 :            :             {
     146         [ #  # ]:          0 :                 SearchWildCard( wildCard, aURLStr, true, aSearchedFiles );
     147                 :            :             }
     148                 :            :         }
     149                 :            :         else
     150                 :            :         {
     151         [ #  # ]:          0 :             INetURLObject aFileURL( aURLStr );
     152         [ #  # ]:          0 :             rtl::OUString aFileName = aFileURL.GetLastName( INetURLObject::DECODE_UNAMBIGUOUS );
     153 [ #  # ][ #  # ]:          0 :             if ( wildCard.Matches( aFileName.toAsciiLowerCase() ) )
         [ #  # ][ #  # ]
     154                 :            :             {
     155                 :          0 :                 sal_Int32 nFilesLength = aSearchedFiles.getLength();
     156         [ #  # ]:          0 :                 aSearchedFiles.realloc( nFilesLength + 1 );
     157                 :          0 :                 rtl::OUString sSystemPath;
     158         [ #  # ]:          0 :                 ::osl::File::getSystemPathFromFileURL( aURLStr, sSystemPath );
     159         [ #  # ]:          0 :                 aSearchedFiles[nFilesLength] = sSystemPath;
     160         [ #  # ]:          0 :             }
     161                 :            :         }
     162         [ #  # ]:          0 :     }
     163                 :          0 : }
     164                 :            : 
     165                 :          0 : sal_Int32 SAL_CALL ScVbaFileSearch::Execute( )  throw (css::uno::RuntimeException)
     166                 :            : {
     167         [ #  # ]:          0 :     m_aSearchedFiles.realloc(0);
     168         [ #  # ]:          0 :     Reference< XSimpleFileAccess3 > xSFI = getFileAccess();
     169 [ #  # ][ #  # ]:          0 :     if ( !xSFI.is() || !xSFI->isFolder( m_sLookIn ) )
         [ #  # ][ #  # ]
                 [ #  # ]
     170                 :            :     {
     171                 :          0 :         return 0;
     172                 :            :     }
     173                 :            : 
     174         [ #  # ]:          0 :     if ( m_sFileName.isEmpty() )
     175                 :            :     {
     176                 :          0 :         return 1;
     177                 :            :     }
     178                 :            : 
     179                 :          0 :     ::rtl::OUString aTempFileName = m_sFileName.toAsciiLowerCase();
     180         [ #  # ]:          0 :     if ( IsWildCard( aTempFileName ) )
     181                 :            :     {
     182                 :          0 :         bool bEndWithAsterisk = aTempFileName.endsWithAsciiL("*", 1);
     183                 :          0 :         bool bStartWithAsterisk = (aTempFileName.indexOf('*') == 0);
     184 [ #  # ][ #  # ]:          0 :         if ( !bEndWithAsterisk && !bStartWithAsterisk )
     185                 :            :         {
     186                 :          0 :             aTempFileName = ::rtl::OUString("*") + aTempFileName + ::rtl::OUString("*");
     187                 :            :         }
     188                 :            :     }
     189                 :            :     else
     190                 :            :     {
     191                 :          0 :         aTempFileName = ::rtl::OUString("*") + aTempFileName + ::rtl::OUString("*");
     192                 :            :     }
     193         [ #  # ]:          0 :     WildCard wildCard( aTempFileName );
     194         [ #  # ]:          0 :     SearchWildCard( wildCard, m_sLookIn, m_bSearchSubFolders, m_aSearchedFiles );
     195                 :            : 
     196         [ #  # ]:          0 :     return m_aSearchedFiles.getLength();
     197                 :            : }
     198                 :            : 
     199                 :            : // set ScVbaApplication::getDefaultFilePath(  ) as the InitPath for FileSearch
     200                 :          0 :  ::rtl::OUString ScVbaFileSearch::getInitPath() throw (css::uno::RuntimeException)
     201                 :            : {
     202         [ #  # ]:          0 :     String aPath;
     203                 :            : 
     204         [ #  # ]:          0 :     if (m_pApplication != NULL)
     205                 :            :     {
     206 [ #  # ][ #  # ]:          0 :         aPath = m_pApplication->getDefaultFilePath();
     207                 :            :     }
     208                 :            : 
     209 [ #  # ][ #  # ]:          0 :     return aPath;
     210                 :            : }
     211                 :            : 
     212                 :          0 : void SAL_CALL ScVbaFileSearch::NewSearch( )  throw (css::uno::RuntimeException)
     213                 :            : {
     214                 :          0 :     m_sFileName = ::rtl::OUString();
     215                 :          0 :     m_sLookIn = getInitPath();
     216                 :          0 :     m_bSearchSubFolders = false;
     217                 :          0 :     m_bMatchTextExactly = false;
     218                 :          0 :     m_aSearchedFiles.realloc(0);
     219                 :          0 : }
     220                 :            : 
     221                 :          0 : Reference< XFoundFiles > SAL_CALL ScVbaFileSearch::getFoundFiles() throw (css::uno::RuntimeException)
     222                 :            : {
     223                 :            :     css::uno::Reference< ov::XFoundFiles > xFoundFiles = new VbaFoundFiles(
     224 [ #  # ][ #  # ]:          0 :         mxParent, mxContext, (css::container::XIndexAccess *) new VbaFoundFilesEnum(m_aSearchedFiles) );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     225                 :          0 :     return xFoundFiles;
     226                 :            : }
     227                 :            : 
     228                 :          0 : rtl::OUString ScVbaFileSearch::getServiceImplName()
     229                 :            : {
     230                 :          0 :     return rtl::OUString("VbaFileSearch");
     231                 :            : }
     232                 :            : 
     233                 :          0 : css::uno::Sequence< rtl::OUString > ScVbaFileSearch::getServiceNames()
     234                 :            : {
     235 [ #  # ][ #  # ]:          0 :     static css::uno::Sequence< rtl::OUString > aServiceNames;
         [ #  # ][ #  # ]
     236         [ #  # ]:          0 :     if ( aServiceNames.getLength() == 0 )
     237                 :            :     {
     238                 :          0 :         aServiceNames.realloc( 1 );
     239         [ #  # ]:          0 :         aServiceNames[ 0 ] = rtl::OUString( "ooo.vba.FileSearch" );
     240                 :            :     }
     241                 :          0 :     return aServiceNames;
     242                 :            : }
     243                 :            : 
     244                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10