/*******************************************************************************
* Copyright (c) 2000, 2006 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.locationtech.udig.ui;
import java.net.MalformedURLException;
import java.net.URL;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.browser.IWebBrowser;
import org.eclipse.ui.browser.IWorkbenchBrowserSupport;
public class UIUtilities {
/**
* Copied from org.eclipse.ui.internal.dialogs.AboutDialog
*
* Open a link
*/
public static void openLink(String href) {
// format the href for an html file (file:///<filename.html>
// required for Mac only.
if (href.startsWith("file:")) { //$NON-NLS-1$
href = href.substring(5);
while (href.startsWith("/")) { //$NON-NLS-1$
href = href.substring(1);
}
href = "file:///" + href; //$NON-NLS-1$
}
IWorkbenchBrowserSupport support = PlatformUI.getWorkbench()
.getBrowserSupport();
try {
IWebBrowser browser = support.getExternalBrowser();
browser.openURL(new URL(UIUtilities.urlEncodeForSpaces(href.toCharArray())));
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (PartInitException e) {
e.printStackTrace();
}
}
/**
* Copied from org.eclipse.ui.internal.dialogs.AboutDialog
*
* This method encodes the url, removes the spaces from the url and replaces
* the same with <code>"%20"</code>. This method is required to fix Bug
* 77840.
*
* @since 3.0.2
*/
public static String urlEncodeForSpaces(char[] input) {
StringBuffer retu = new StringBuffer(input.length);
for (int i = 0; i < input.length; i++) {
if (input[i] == ' ') {
retu.append("%20"); //$NON-NLS-1$
} else {
retu.append(input[i]);
}
}
return retu.toString();
}
}