merge the formfield patch from ooo-build
[ooovba.git] / odk / examples / DevelopersGuide / Forms / URLHelper.java
blobaa9c6e2b3d50d02602611cf799d2ec90a1f63b29
1 /*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3 *
4 * Copyright 2009 by Sun Microsystems, Inc.
5 *
6 * OpenOffice.org - a multi-platform office productivity suite
7 *
8 * This file is part of OpenOffice.org.
9 *
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.
26 import java.io.File;
27 import java.net.MalformedURLException;
29 public class URLHelper
31 /**
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.
36 * @param aSystemPath
37 * represent the file in system notation
39 * @return [String]
40 * a file url which represent the given system path
42 @SuppressWarnings("deprecation")
43 public static String getFileURLFromSystemPath( File aSystemPath )
45 String sFileURL = null;
46 try
48 sFileURL = aSystemPath.toURL().toString();
50 catch( MalformedURLException exWrong )
52 sFileURL = null;
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
57 if(
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();
68 return sFileURL;