KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > browser > SystemBrowserInstance


1 /*******************************************************************************
2  * Copyright (c) 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - Initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.internal.browser;
12
13 import java.net.URL JavaDoc;
14
15 import org.eclipse.osgi.util.NLS;
16 import org.eclipse.swt.program.Program;
17 import org.eclipse.ui.PartInitException;
18 import org.eclipse.ui.browser.AbstractWebBrowser;
19
20 /**
21  * An instance of a running system Web browser.
22  */

23 public class SystemBrowserInstance extends AbstractWebBrowser {
24     public SystemBrowserInstance(String JavaDoc id) {
25         super(id);
26     }
27
28     public void openURL(URL JavaDoc url) throws PartInitException {
29         String JavaDoc urlText = null;
30
31         if (url != null)
32             urlText = url.toExternalForm();
33
34         // change spaces to "%20"
35
if (urlText != null && !WebBrowserUtil.isWindows()) {
36             int index = urlText.indexOf(" "); //$NON-NLS-1$
37
while (index >= 0) {
38                 urlText = urlText.substring(0, index) + "%20" //$NON-NLS-1$
39
+ urlText.substring(index + 1);
40                 index = urlText.indexOf(" "); //$NON-NLS-1$
41
}
42         }
43         Trace.trace(Trace.FINEST, "Launching system Web browser: " + urlText); //$NON-NLS-1$
44
Program program = Program.findProgram("html"); //$NON-NLS-1$
45
if (program != null) {
46             if (program.execute(urlText))
47                 return;
48         }
49         if (!Program.launch(urlText))
50             throw new PartInitException(NLS.bind(Messages.errorCouldNotLaunchWebBrowser, url.toExternalForm()));
51     }
52 }
Popular Tags