bump product version to 4.1.6.2
[LibreOffice.git] / svl / source / misc / filenotation.cxx
blobb7b40144004aa473d03a03f444f38cdceb541af9
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <svl/filenotation.hxx>
21 #include <osl/file.h>
22 #include <osl/diagnose.h>
23 #include <tools/urlobj.hxx>
25 //.........................................................................
26 namespace svt
28 //.........................................................................
30 //=====================================================================
31 //= OFileNotation
32 //=====================================================================
33 //---------------------------------------------------------------------
34 OFileNotation::OFileNotation( const OUString& _rUrlOrPath )
36 construct( _rUrlOrPath );
39 //---------------------------------------------------------------------
40 OFileNotation::OFileNotation( const OUString& _rUrlOrPath, NOTATION _eInputNotation )
42 if ( _eInputNotation == N_URL )
44 INetURLObject aParser( _rUrlOrPath );
45 if ( aParser.GetProtocol() == INET_PROT_FILE )
46 implInitWithURLNotation( _rUrlOrPath );
47 else
48 m_sSystem = m_sFileURL = _rUrlOrPath;
50 else
51 implInitWithSystemNotation( _rUrlOrPath );
54 //---------------------------------------------------------------------
55 bool OFileNotation::implInitWithSystemNotation( const OUString& _rSystemPath )
57 bool bSuccess = false;
59 m_sSystem = _rSystemPath;
60 if ( ( osl_File_E_None != osl_getFileURLFromSystemPath( m_sSystem.pData, &m_sFileURL.pData ) )
61 && ( m_sFileURL.isEmpty() )
64 if ( !_rSystemPath.isEmpty() )
66 INetURLObject aSmartParser;
67 aSmartParser.SetSmartProtocol( INET_PROT_FILE );
68 if ( aSmartParser.SetSmartURL( _rSystemPath ) )
70 m_sFileURL = aSmartParser.GetMainURL( INetURLObject::NO_DECODE );
71 osl_getSystemPathFromFileURL( m_sFileURL.pData, &m_sSystem.pData );
72 bSuccess = true;
76 else
77 bSuccess = true;
78 return bSuccess;
81 //---------------------------------------------------------------------
82 bool OFileNotation::implInitWithURLNotation( const OUString& _rURL )
84 m_sFileURL = _rURL;
85 osl_getSystemPathFromFileURL( _rURL.pData, &m_sSystem.pData );
86 return true;
89 //---------------------------------------------------------------------
90 void OFileNotation::construct( const OUString& _rUrlOrPath )
92 bool bSuccess = false;
93 // URL notation?
94 INetURLObject aParser( _rUrlOrPath );
95 switch ( aParser.GetProtocol() )
97 case INET_PROT_FILE:
98 // file URL
99 bSuccess = implInitWithURLNotation( _rUrlOrPath );
100 break;
102 case INET_PROT_NOT_VALID:
103 // assume system notation
104 bSuccess = implInitWithSystemNotation( _rUrlOrPath );
105 break;
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 m_sSystem = m_sFileURL = _rUrlOrPath;
111 bSuccess = true;
112 break;
115 OSL_ENSURE( bSuccess, "OFileNotation::OFileNotation: could not detect the format!" );
116 (void)bSuccess;
119 //---------------------------------------------------------------------
120 OUString OFileNotation::get(NOTATION _eOutputNotation)
122 switch (_eOutputNotation)
124 case N_SYSTEM: return m_sSystem;
125 case N_URL: return m_sFileURL;
128 OSL_FAIL("OFileNotation::get: invalid enum value!");
129 return OUString();
132 //.........................................................................
133 } // namespace svt
134 //.........................................................................
136 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */