1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: filenotation.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svtools.hxx"
33 #include "filenotation.hxx"
35 #include <osl/diagnose.h>
36 #include <tools/urlobj.hxx>
38 //.........................................................................
41 //.........................................................................
43 //=====================================================================
45 //=====================================================================
46 //---------------------------------------------------------------------
47 OFileNotation::OFileNotation( const ::rtl::OUString
& _rUrlOrPath
)
49 construct( _rUrlOrPath
);
52 //---------------------------------------------------------------------
53 OFileNotation::OFileNotation( const ::rtl::OUString
& _rUrlOrPath
, NOTATION _eInputNotation
)
55 if ( _eInputNotation
== N_URL
)
57 INetURLObject
aParser( _rUrlOrPath
);
58 if ( aParser
.GetProtocol() == INET_PROT_FILE
)
59 implInitWithURLNotation( _rUrlOrPath
);
61 m_sSystem
= m_sFileURL
= _rUrlOrPath
;
64 implInitWithSystemNotation( _rUrlOrPath
);
67 //---------------------------------------------------------------------
68 bool OFileNotation::implInitWithSystemNotation( const ::rtl::OUString
& _rSystemPath
)
70 bool bSuccess
= false;
72 m_sSystem
= _rSystemPath
;
73 if ( ( osl_File_E_None
!= osl_getFileURLFromSystemPath( m_sSystem
.pData
, &m_sFileURL
.pData
) )
74 && ( 0 == m_sFileURL
.getLength() )
77 if ( _rSystemPath
.getLength() )
79 INetURLObject aSmartParser
;
80 aSmartParser
.SetSmartProtocol( INET_PROT_FILE
);
81 if ( aSmartParser
.SetSmartURL( _rSystemPath
) )
83 m_sFileURL
= aSmartParser
.GetMainURL( INetURLObject::NO_DECODE
);
84 osl_getSystemPathFromFileURL( m_sFileURL
.pData
, &m_sSystem
.pData
);
94 //---------------------------------------------------------------------
95 bool OFileNotation::implInitWithURLNotation( const ::rtl::OUString
& _rURL
)
98 osl_getSystemPathFromFileURL( _rURL
.pData
, &m_sSystem
.pData
);
102 //---------------------------------------------------------------------
103 void OFileNotation::construct( const ::rtl::OUString
& _rUrlOrPath
)
105 bool bSuccess
= false;
107 INetURLObject
aParser( _rUrlOrPath
);
108 switch ( aParser
.GetProtocol() )
112 bSuccess
= implInitWithURLNotation( _rUrlOrPath
);
115 case INET_PROT_NOT_VALID
:
116 // assume system notation
117 bSuccess
= implInitWithSystemNotation( _rUrlOrPath
);
121 // it's a known scheme, but no file-URL -> assume that bothe the URL representation and the
122 // system representation are the URL itself
123 m_sSystem
= m_sFileURL
= _rUrlOrPath
;
128 OSL_ENSURE( bSuccess
, "OFileNotation::OFileNotation: could not detect the format!" );
131 //---------------------------------------------------------------------
132 ::rtl::OUString
OFileNotation::get(NOTATION _eOutputNotation
)
134 switch (_eOutputNotation
)
136 case N_SYSTEM
: return m_sSystem
;
137 case N_URL
: return m_sFileURL
;
140 OSL_ENSURE(sal_False
, "OFileNotation::get: inavlid enum value!");
141 return ::rtl::OUString();
144 //.........................................................................
146 //.........................................................................