com.limegroup.gnutella.util
Class Launcher

java.lang.Object
  extended bycom.limegroup.gnutella.util.Launcher

public final class Launcher
extends java.lang.Object

This class launches files in their associated applications and opens urls in the default browser for different operating systems. This really only works meaningfully for the Mac and Windows.

Acknowledgement goes to Eric Albert for demonstrating the general technique for loading the MRJ classes in his frequently-used "BrowserLauncher" code.

This code is Copyright 1999-2001 by Eric Albert (ejalbert@cs.stanford.edu) and may be redistributed or modified in any form without restrictions as long as the portion of this comment from this paragraph through the end of the comment is not removed. The author requests that he be notified of any application, applet, or other binary that makes use of this code, but that's more out of curiosity than anything and is not required. This software includes no warranty. The author is not repsonsible for any loss of data or functionality or any adverse or unexpected effects of using this software.

Credits:
Steven Spencer, JavaWorld magazine (Java Tip 66)
Thanks also to Ron B. Yeh, Eric Shapiro, Ben Engber, Paul Teitlebaum, Andrea Cantatore, Larry Barowski, Trevor Bedzek, Frank Miedrich, and Ron Rabakukk


Method Summary
static int launchFile(java.io.File file)
          Launches the file whose abstract path is specified in the File parameter.
static int openURL(java.lang.String url)
          Opens the specified url in a browser.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

openURL

public static int openURL(java.lang.String url)
                   throws java.io.IOException
Opens the specified url in a browser.

A browser will only be opened if the underlying operating system recognizes the url as one that should be opened in a browser, namely a url that ends in .htm or .html.

Parameters:
url - The url to open
Returns:
An int indicating the success of the browser launch
Throws:
java.io.IOException - if the url cannot be loaded do to an IO problem

launchFile

public static int launchFile(java.io.File file)
                      throws java.io.IOException,
                             java.lang.SecurityException
Launches the file whose abstract path is specified in the File parameter. This method will not launch any file with .exe, .vbs, .lnk, .bat, .sys, or .com extensions, diplaying an error if one of the file is of one of these types.

Returns:
An int indicating the success of the browser launch
Throws:
java.io.IOException - if the file cannot be launched do to an IO problem
java.lang.SecurityException