LCOV - code coverage report
Current view: top level - unotools/source/ucbhelper - localfilehelper.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 70 0.0 %
Date: 2014-04-14 Functions: 0 7 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             : #include <com/sun/star/sdbc/XResultSet.hpp>
      21             : #include <com/sun/star/ucb/XContentAccess.hpp>
      22             : #include <com/sun/star/ucb/CommandAbortedException.hpp>
      23             : #include <com/sun/star/ucb/UniversalContentBroker.hpp>
      24             : #include <comphelper/processfactory.hxx>
      25             : #include <unotools/localfilehelper.hxx>
      26             : #include <ucbhelper/fileidentifierconverter.hxx>
      27             : #include <rtl/ustring.hxx>
      28             : #include <osl/file.hxx>
      29             : #include <tools/urlobj.hxx>
      30             : #include <ucbhelper/content.hxx>
      31             : #include <vector>
      32             : 
      33             : using namespace ::osl;
      34             : using namespace ::com::sun::star::uno;
      35             : using namespace ::com::sun::star::ucb;
      36             : 
      37             : namespace utl
      38             : {
      39             : 
      40           0 : bool LocalFileHelper::ConvertSystemPathToURL( const OUString& rName, const OUString& rBaseURL, OUString& rReturn )
      41             : {
      42           0 :     rReturn = "";
      43             : 
      44             :     Reference< XUniversalContentBroker > pBroker(
      45             :         UniversalContentBroker::create(
      46           0 :             comphelper::getProcessComponentContext() ) );
      47             :     try
      48             :     {
      49           0 :         rReturn = ::ucbhelper::getFileURLFromSystemPath( pBroker, rBaseURL, rName );
      50             :     }
      51           0 :     catch ( ::com::sun::star::uno::RuntimeException& )
      52             :     {
      53           0 :         return false;
      54             :     }
      55             : 
      56           0 :     return !rReturn.isEmpty();
      57             : }
      58             : 
      59           0 : bool LocalFileHelper::ConvertURLToSystemPath( const OUString& rName, OUString& rReturn )
      60             : {
      61           0 :     rReturn = "";
      62             :     Reference< XUniversalContentBroker > pBroker(
      63             :         UniversalContentBroker::create(
      64           0 :             comphelper::getProcessComponentContext() ) );
      65             :     try
      66             :     {
      67           0 :         rReturn = ::ucbhelper::getSystemPathFromFileURL( pBroker, rName );
      68             :     }
      69           0 :     catch ( ::com::sun::star::uno::RuntimeException& )
      70             :     {
      71             :     }
      72             : 
      73           0 :     return !rReturn.isEmpty();
      74             : }
      75             : 
      76           0 : bool LocalFileHelper::ConvertPhysicalNameToURL(const OUString& rName, OUString& rReturn)
      77             : {
      78           0 :     rReturn = OUString();
      79             :     Reference< XUniversalContentBroker > pBroker(
      80             :         UniversalContentBroker::create(
      81           0 :             comphelper::getProcessComponentContext() ) );
      82             :     try
      83             :     {
      84           0 :         OUString aBase( ::ucbhelper::getLocalFileURL() );
      85           0 :         rReturn = ::ucbhelper::getFileURLFromSystemPath( pBroker, aBase, rName );
      86             :     }
      87           0 :     catch (const ::com::sun::star::uno::RuntimeException&)
      88             :     {
      89             :     }
      90             : 
      91           0 :     return !rReturn.isEmpty();
      92             : }
      93             : 
      94           0 : bool LocalFileHelper::ConvertURLToPhysicalName(const OUString& rName, OUString& rReturn)
      95             : {
      96           0 :     rReturn = "";
      97             :     Reference< XUniversalContentBroker > pBroker(
      98             :         UniversalContentBroker::create(
      99           0 :             comphelper::getProcessComponentContext() ) );
     100             :     try
     101             :     {
     102           0 :         INetURLObject aObj( rName );
     103           0 :         INetURLObject aLocal( ::ucbhelper::getLocalFileURL() );
     104           0 :         if ( aObj.GetProtocol() == aLocal.GetProtocol() )
     105           0 :             rReturn = ::ucbhelper::getSystemPathFromFileURL( pBroker, rName );
     106             :     }
     107           0 :     catch (const ::com::sun::star::uno::RuntimeException&)
     108             :     {
     109             :     }
     110             : 
     111           0 :     return !rReturn.isEmpty();
     112             : }
     113             : 
     114           0 : bool LocalFileHelper::IsLocalFile(const OUString& rName)
     115             : {
     116           0 :     OUString aTmp;
     117           0 :     return ConvertURLToPhysicalName(rName, aTmp);
     118             : }
     119             : 
     120           0 : bool LocalFileHelper::IsFileContent(const OUString& rName)
     121             : {
     122           0 :     OUString aTmp;
     123           0 :     return ConvertURLToSystemPath(rName, aTmp);
     124             : }
     125             : 
     126             : typedef ::std::vector< OUString* > StringList_Impl;
     127             : 
     128           0 : ::com::sun::star::uno::Sequence < OUString > LocalFileHelper::GetFolderContents( const OUString& rFolder, bool bFolder )
     129             : {
     130           0 :     StringList_Impl* pFiles = NULL;
     131             :     try
     132             :     {
     133             :         ::ucbhelper::Content aCnt(
     134             :             rFolder, Reference< XCommandEnvironment >(),
     135           0 :             comphelper::getProcessComponentContext() );
     136           0 :         Reference< ::com::sun::star::sdbc::XResultSet > xResultSet;
     137           0 :         ::com::sun::star::uno::Sequence< OUString > aProps(1);
     138           0 :         OUString* pProps = aProps.getArray();
     139           0 :         pProps[0] = "Url";
     140             : 
     141             :         try
     142             :         {
     143           0 :             ::ucbhelper::ResultSetInclude eInclude = bFolder ? ::ucbhelper::INCLUDE_FOLDERS_AND_DOCUMENTS : ::ucbhelper::INCLUDE_DOCUMENTS_ONLY;
     144           0 :             xResultSet = aCnt.createCursor( aProps, eInclude );
     145             :         }
     146           0 :         catch( ::com::sun::star::ucb::CommandAbortedException& )
     147             :         {
     148             :         }
     149           0 :         catch( Exception& )
     150             :         {
     151             :         }
     152             : 
     153           0 :         if ( xResultSet.is() )
     154             :         {
     155           0 :             pFiles = new StringList_Impl;
     156           0 :             Reference< XContentAccess > xContentAccess( xResultSet, UNO_QUERY );
     157             :             try
     158             :             {
     159           0 :                 while ( xResultSet->next() )
     160             :                 {
     161           0 :                     OUString aId = xContentAccess->queryContentIdentifierString();
     162           0 :                     OUString* pFile = new OUString( aId );
     163           0 :                     pFiles->push_back( pFile );
     164           0 :                 }
     165             :             }
     166           0 :             catch( ::com::sun::star::ucb::CommandAbortedException& )
     167             :             {
     168             :             }
     169           0 :             catch( Exception& )
     170             :             {
     171           0 :             }
     172           0 :         }
     173             :     }
     174           0 :     catch( Exception& )
     175             :     {
     176             :     }
     177             : 
     178           0 :     if ( pFiles )
     179             :     {
     180           0 :         size_t nCount = pFiles->size();
     181           0 :         Sequence < OUString > aRet( nCount );
     182           0 :         OUString* pRet = aRet.getArray();
     183           0 :         for ( size_t i = 0; i < nCount; ++i )
     184             :         {
     185           0 :             OUString* pFile = (*pFiles)[ i ];
     186           0 :             pRet[i] = *( pFile );
     187           0 :             delete pFile;
     188             :         }
     189           0 :         delete pFiles;
     190           0 :         return aRet;
     191             :     }
     192             :     else
     193           0 :         return Sequence < OUString > ();
     194             : }
     195             : 
     196             : }
     197             : 
     198             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10