LCOV - code coverage report
Current view: top level - svl/source/misc - filenotation.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 28 48 58.3 %
Date: 2015-06-13 12:38:46 Functions: 5 6 83.3 %
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          89 :     OFileNotation::OFileNotation( const OUString& _rUrlOrPath )
      29             :     {
      30          89 :         construct( _rUrlOrPath );
      31          89 :     }
      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() == INetProtocol::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           1 :     bool OFileNotation::implInitWithSystemNotation( const OUString& _rSystemPath )
      48             :     {
      49           1 :         bool bSuccess = false;
      50             : 
      51           1 :         m_sSystem = _rSystemPath;
      52           2 :         if  (  ( osl_File_E_None != osl_getFileURLFromSystemPath( m_sSystem.pData, &m_sFileURL.pData ) )
      53           1 :             && ( m_sFileURL.isEmpty() )
      54             :             )
      55             :         {
      56           0 :             if ( !_rSystemPath.isEmpty() )
      57             :             {
      58           0 :                 INetURLObject aSmartParser;
      59           0 :                 aSmartParser.SetSmartProtocol( INetProtocol::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           1 :             bSuccess = true;
      70           1 :         return bSuccess;
      71             :     }
      72             : 
      73          88 :     bool OFileNotation::implInitWithURLNotation( const OUString& _rURL )
      74             :     {
      75          88 :         m_sFileURL = _rURL;
      76          88 :         osl_getSystemPathFromFileURL( _rURL.pData, &m_sSystem.pData );
      77          88 :         return true;
      78             :     }
      79             : 
      80          89 :     void OFileNotation::construct( const OUString& _rUrlOrPath )
      81             :     {
      82          89 :         bool bSuccess = false;
      83             :         // URL notation?
      84          89 :         INetURLObject aParser( _rUrlOrPath );
      85          89 :         switch ( aParser.GetProtocol() )
      86             :         {
      87             :             case INetProtocol::File:
      88             :                 // file URL
      89          88 :                 bSuccess = implInitWithURLNotation( _rUrlOrPath );
      90          88 :                 break;
      91             : 
      92             :             case INetProtocol::NotValid:
      93             :                 // assume system notation
      94           1 :                 bSuccess = implInitWithSystemNotation( _rUrlOrPath );
      95           1 :                 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          89 :         (void)bSuccess;
     107          89 :     }
     108             : 
     109          89 :     OUString OFileNotation::get(NOTATION _eOutputNotation)
     110             :     {
     111          89 :         switch (_eOutputNotation)
     112             :         {
     113           2 :             case N_SYSTEM: return m_sSystem;
     114          87 :             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.11