1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
22 #include <osl/diagnose.h>
23 #include <tools/urlobj.hxx>
25 //.........................................................................
28 //.........................................................................
30 //=====================================================================
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
);
48 m_sSystem
= m_sFileURL
= _rUrlOrPath
;
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
);
81 //---------------------------------------------------------------------
82 bool OFileNotation::implInitWithURLNotation( const OUString
& _rURL
)
85 osl_getSystemPathFromFileURL( _rURL
.pData
, &m_sSystem
.pData
);
89 //---------------------------------------------------------------------
90 void OFileNotation::construct( const OUString
& _rUrlOrPath
)
92 bool bSuccess
= false;
94 INetURLObject
aParser( _rUrlOrPath
);
95 switch ( aParser
.GetProtocol() )
99 bSuccess
= implInitWithURLNotation( _rUrlOrPath
);
102 case INET_PROT_NOT_VALID
:
103 // assume system notation
104 bSuccess
= implInitWithSystemNotation( _rUrlOrPath
);
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
;
115 OSL_ENSURE( bSuccess
, "OFileNotation::OFileNotation: could not detect the format!" );
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!");
132 //.........................................................................
134 //.........................................................................
136 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */