aeDesc = null; // Encourage it to get disposed if it was created
browser = null; // Ditto
}
break;
case MRJ_2_1:
new ExecutionHandler(new String[] { (String) browser, url }).execute();
break;
case MRJ_3_0:
int[] instance = new int[1];
int result = ICStart(instance, 0);
if (result == 0) {
int[] selectionStart = new int[] { 0 };
byte[] urlBytes = url.getBytes();
int[] selectionEnd = new int[] { urlBytes.length };
result = ICLaunchURL(instance[0], new byte[] { 0 }, urlBytes,
urlBytes.length, selectionStart,
selectionEnd);
if (result == 0) {
// Ignore the return value; the URL was launched successfully
// regardless of what happens here.
ICStop(instance);
} else {
throw new IOException("Unable to launch URL: " + result);
}
} else {
throw new IOException("Unable to create an Internet Config instance: " + result);
}
break;
case MRJ_3_1:
case MRJ_COCOA:
try {
openURL.invoke(null, new Object[] { url });
} catch (InvocationTargetException ite) {
throw new IOException("InvocationTargetException while calling openURL: " + ite.getMessage());
} catch (IllegalAccessException iae) {
throw new IOException("IllegalAccessException while calling openURL: " + iae.getMessage());
}
break;
case WINDOWS_NT:
case WINDOWS_9x:
// Add quotes around the URL to allow ampersands and other special
// characters to work.
String[] arguments;
if (jvm == WINDOWS_9x) {
arguments = new String[] { (String) browser,
FIRST_WINDOWS_PARAMETER,
SECOND_WINDOWS_PARAMETER,
null };
} else {
arguments = new String[] { (String) browser,
FIRST_WINDOWS_PARAMETER,
SECOND_WINDOWS_PARAMETER,
THIRD_WINDOWS_PARAMETER,
null };
}
arguments[arguments.length - 1] = '"' + url + '"';
ExecutionHandler executionHandler = new ExecutionHandler(arguments);
executionHandler.execute();
// This avoids a memory leak on some versions of Java on Windows.
// That's hinted at in <http://developer.java.sun.com/developer/qow/archive/68/>.
try {
executionHandler.getProcess().waitFor();
executionHandler.exitValue();
} catch (InterruptedException ie) {
throw new IOException("InterruptedException while launching browser: " + ie.getMessage());
}
break;
case OTHER:
// Assume that we're on Unix and that Netscape is installed
// Attempt to open the URL in a currently running session of Netscape
executionHandler = new ExecutionHandler(new String[] { (String) browser,
NETSCAPE_REMOTE_PARAMETER,
NETSCAPE_OPEN_PARAMETER_START +
url +
NETSCAPE_OPEN_PARAMETER_END });
executionHandler.execute();
try {
int exitCode = executionHandler.getProcess().waitFor();
if (exitCode != 0) { // if Netscape was not open
new ExecutionHandler(new String[] { (String) browser, url }).execute();
}
} catch (InterruptedException ie) {
throw new IOException("InterruptedException while launching browser: " + ie.getMessage());
}
break;
default:
// This should never occur, but if it does, we'll try the simplest thing possible
new ExecutionHandler(new String[] { (String) browser, url }).execute();
break;
}
}