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

Generated by: LCOV version 1.10