01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package net.refractions.udig.ui;
11:
12: import java.net.MalformedURLException;
13: import java.net.URL;
14:
15: import org.eclipse.ui.PartInitException;
16: import org.eclipse.ui.PlatformUI;
17: import org.eclipse.ui.browser.IWebBrowser;
18: import org.eclipse.ui.browser.IWorkbenchBrowserSupport;
19:
20: public class UIUtilities {
21:
22: /**
23: * Copied from org.eclipse.ui.internal.dialogs.AboutDialog
24: *
25: * Open a link
26: */
27: public static void openLink(String href) {
28: // format the href for an html file (file:///<filename.html>
29: // required for Mac only.
30: if (href.startsWith("file:")) { //$NON-NLS-1$
31: href = href.substring(5);
32: while (href.startsWith("/")) { //$NON-NLS-1$
33: href = href.substring(1);
34: }
35: href = "file:///" + href; //$NON-NLS-1$
36: }
37: IWorkbenchBrowserSupport support = PlatformUI.getWorkbench()
38: .getBrowserSupport();
39: try {
40: IWebBrowser browser = support.getExternalBrowser();
41: browser.openURL(new URL(UIUtilities.urlEncodeForSpaces(href
42: .toCharArray())));
43: } catch (MalformedURLException e) {
44: e.printStackTrace();
45: } catch (PartInitException e) {
46: e.printStackTrace();
47: }
48: }
49:
50: /**
51: * Copied from org.eclipse.ui.internal.dialogs.AboutDialog
52: *
53: * This method encodes the url, removes the spaces from the url and replaces
54: * the same with <code>"%20"</code>. This method is required to fix Bug
55: * 77840.
56: *
57: * @since 3.0.2
58: */
59: public static String urlEncodeForSpaces(char[] input) {
60: StringBuffer retu = new StringBuffer(input.length);
61: for (int i = 0; i < input.length; i++) {
62: if (input[i] == ' ') {
63: retu.append("%20"); //$NON-NLS-1$
64: } else {
65: retu.append(input[i]);
66: }
67: }
68: return retu.toString();
69: }
70:
71: }
|