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

Generated by: LCOV version 1.10