2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * Copyright 2009 by Sun Microsystems, Inc.
6 * OpenOffice.org - a multi-platform office productivity suite
8 * This file is part of OpenOffice.org.
10 * OpenOffice.org is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License version 3
12 * only, as published by the Free Software Foundation.
14 * OpenOffice.org is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Lesser General Public License version 3 for more details
18 * (a copy is included in the LICENSE file that accompanied this code).
20 * You should have received a copy of the GNU Lesser General Public License
21 * version 3 along with OpenOffice.org. If not, see
22 * <http://www.openoffice.org/license.html>
23 * for a copy of the LGPLv3 License.
27 import java
.net
.MalformedURLException
;
29 public class URLHelper
32 * Because the office need URLs for loading/saving documents
33 * we must convert used system pathes.
34 * And java use another notation for file URLs ... correct it.
37 * represent the file in system notation
40 * a file url which represent the given system path
42 @SuppressWarnings("deprecation")
43 public static String
getFileURLFromSystemPath( File aSystemPath
)
45 String sFileURL
= null;
48 sFileURL
= aSystemPath
.toURL().toString();
50 catch( MalformedURLException exWrong
)
55 // problem of java: file URL's are coded with 1 slash instead of 2 or 3 ones!
56 // => correct this problem first, otherwise office can't use these URL's
58 (sFileURL
!= null ) &&
59 (sFileURL
.startsWith("file:/") == true ) &&
60 (sFileURL
.startsWith("file://") == false)
63 StringBuffer sWorkBuffer
= new StringBuffer(sFileURL
);
64 sWorkBuffer
.insert(6,"//");
65 sFileURL
= sWorkBuffer
.toString();