LCOV - code coverage report
Current view: top level - svl/source/misc - filenotation.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 19 48 39.6 %
Date: 2014-11-03 Functions: 4 6 66.7 %
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 <svl/filenotation.hxx>
      21             : #include <osl/file.h>
      22             : #include <osl/diagnose.h>
      23             : #include <tools/urlobj.hxx>
      24             : 
      25             : namespace svt
      26             : {
      27             : 
      28         180 :     OFileNotation::OFileNotation( const OUString& _rUrlOrPath )
      29             :     {
      30         180 :         construct( _rUrlOrPath );
      31         180 :     }
      32             : 
      33           0 :     OFileNotation::OFileNotation( const OUString& _rUrlOrPath, NOTATION _eInputNotation )
      34             :     {
      35           0 :         if ( _eInputNotation == N_URL )
      36             :         {
      37           0 :             INetURLObject aParser( _rUrlOrPath );
      38           0 :             if ( aParser.GetProtocol() == INET_PROT_FILE )
      39           0 :                 implInitWithURLNotation( _rUrlOrPath );
      40             :             else
      41           0 :                 m_sSystem = m_sFileURL = _rUrlOrPath;
      42             :         }
      43             :         else
      44           0 :             implInitWithSystemNotation( _rUrlOrPath );
      45           0 :     }
      46             : 
      47           0 :     bool OFileNotation::implInitWithSystemNotation( const OUString& _rSystemPath )
      48             :     {
      49           0 :         bool bSuccess = false;
      50             : 
      51           0 :         m_sSystem = _rSystemPath;
      52           0 :         if  (  ( osl_File_E_None != osl_getFileURLFromSystemPath( m_sSystem.pData, &m_sFileURL.pData ) )
      53           0 :             && ( m_sFileURL.isEmpty() )
      54             :             )
      55             :         {
      56           0 :             if ( !_rSystemPath.isEmpty() )
      57             :             {
      58           0 :                 INetURLObject aSmartParser;
      59           0 :                 aSmartParser.SetSmartProtocol( INET_PROT_FILE );
      60           0 :                 if ( aSmartParser.SetSmartURL( _rSystemPath ) )
      61             :                 {
      62           0 :                     m_sFileURL = aSmartParser.GetMainURL( INetURLObject::NO_DECODE );
      63           0 :                     osl_getSystemPathFromFileURL( m_sFileURL.pData, &m_sSystem.pData );
      64           0 :                     bSuccess = true;
      65           0 :                 }
      66             :             }
      67             :         }
      68             :         else
      69           0 :             bSuccess = true;
      70           0 :         return bSuccess;
      71             :     }
      72             : 
      73         180 :     bool OFileNotation::implInitWithURLNotation( const OUString& _rURL )
      74             :     {
      75         180 :         m_sFileURL = _rURL;
      76         180 :         osl_getSystemPathFromFileURL( _rURL.pData, &m_sSystem.pData );
      77         180 :         return true;
      78             :     }
      79             : 
      80         180 :     void OFileNotation::construct( const OUString& _rUrlOrPath )
      81             :     {
      82         180 :         bool bSuccess = false;
      83             :         // URL notation?
      84         180 :         INetURLObject aParser( _rUrlOrPath );
      85         180 :         switch ( aParser.GetProtocol() )
      86             :         {
      87             :             case INET_PROT_FILE:
      88             :                 // file URL
      89         180 :                 bSuccess = implInitWithURLNotation( _rUrlOrPath );
      90         180 :                 break;
      91             : 
      92             :             case INET_PROT_NOT_VALID:
      93             :                 // assume system notation
      94           0 :                 bSuccess = implInitWithSystemNotation( _rUrlOrPath );
      95           0 :                 break;
      96             : 
      97             :             default:
      98             :                 // it's a known scheme, but no file-URL -> assume that bothe the URL representation and the
      99             :                 // system representation are the URL itself
     100           0 :                 m_sSystem = m_sFileURL = _rUrlOrPath;
     101           0 :                 bSuccess = true;
     102           0 :                 break;
     103             :         }
     104             : 
     105             :         OSL_ENSURE( bSuccess, "OFileNotation::OFileNotation: could not detect the format!" );
     106         180 :         (void)bSuccess;
     107         180 :     }
     108             : 
     109         180 :     OUString OFileNotation::get(NOTATION _eOutputNotation)
     110             :     {
     111         180 :         switch (_eOutputNotation)
     112             :         {
     113           2 :             case N_SYSTEM: return m_sSystem;
     114         178 :             case N_URL: return m_sFileURL;
     115             :         }
     116             : 
     117             :         OSL_FAIL("OFileNotation::get: invalid enum value!");
     118           0 :         return OUString();
     119             :     }
     120             : 
     121             : }   // namespace svt
     122             : 
     123             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10