X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Futil%2FBrowserLauncher.java;h=8119daa8edbefac5d9b24f6437d378ef00d7e06a;hb=afffa24481a7d3cb65ae41e0948c16a5f490f302;hp=60e2fed937ec4e8d7ab16eee6d6ccec956195693;hpb=aced09c4feeaf3406269442c14e54abeeb4cad81;p=jalview.git diff --git a/src/jalview/util/BrowserLauncher.java b/src/jalview/util/BrowserLauncher.java index 60e2fed..8119daa 100755 --- a/src/jalview/util/BrowserLauncher.java +++ b/src/jalview/util/BrowserLauncher.java @@ -1,6 +1,6 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2) - * Copyright (C) 2014 The Jalview Authors + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors * * This file is part of Jalview. * @@ -20,8 +20,12 @@ */ package jalview.util; -import java.io.*; -import java.lang.reflect.*; +import java.io.File; +import java.io.IOException; +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; /** * BrowserLauncher is a class that provides one static method, openURL, which @@ -65,14 +69,14 @@ import java.lang.reflect.*; * functionality or any adverse or unexpected effects of using this software. *
* Credits:
- * Steven Spencer, JavaWorld magazine (Java Tip
- * 66)
+ * 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
*
- * @author Eric Albert (ejalbert@cs.stanford.edu)
+ * @author Eric Albert (ejalbert@cs.stanford.edu)
* @version 1.4b1 (Released June 20, 2001)
*/
public class BrowserLauncher
@@ -229,8 +233,17 @@ public class BrowserLauncher
*/
static
{
+
loadedWithoutErrors = true;
+ if (!Platform.isJS())
+ /**
+ * Java only
+ *
+ * @j2sIgnore
+ *
+ */
+ {
String osName = System.getProperty("os.name");
if (osName.startsWith("Mac OS"))
@@ -303,6 +316,7 @@ public class BrowserLauncher
{ // if we haven't hit any errors yet
loadedWithoutErrors = loadClasses();
}
+ }
}
/**
@@ -321,6 +335,15 @@ public class BrowserLauncher
*/
private static boolean loadClasses()
{
+
+ if (!Platform.isJS())
+ /**
+ * Java only
+ *
+ * @j2sIgnore
+ *
+ */
+ {
switch (jvm)
{
case MRJ_2_0:
@@ -338,9 +361,11 @@ public class BrowserLauncher
{ int.class });
appleEventConstructor = appleEventClass
.getDeclaredConstructor(new Class[]
- { int.class, int.class, aeTargetClass, int.class, int.class });
- aeDescConstructor = aeDescClass.getDeclaredConstructor(new Class[]
- { String.class });
+ { int.class, int.class, aeTargetClass, int.class,
+ int.class });
+ aeDescConstructor = aeDescClass
+ .getDeclaredConstructor(new Class[]
+ { String.class });
makeOSType = osUtilsClass.getDeclaredMethod("makeOSType",
new Class[]
@@ -349,8 +374,7 @@ public class BrowserLauncher
new Class[]
{ int.class, aeDescClass });
sendNoReply = appleEventClass.getDeclaredMethod("sendNoReply",
- new Class[]
- {});
+ new Class[] {});
Field keyDirectObjectField = aeClass
.getDeclaredField("keyDirectObject");
@@ -401,8 +425,8 @@ public class BrowserLauncher
findFolder = mrjFileUtilsClass.getDeclaredMethod("findFolder",
new Class[]
{ mrjOSTypeClass });
- getFileCreator = mrjFileUtilsClass.getDeclaredMethod(
- "getFileCreator", new Class[]
+ getFileCreator = mrjFileUtilsClass
+ .getDeclaredMethod("getFileCreator", new Class[]
{ File.class });
getFileType = mrjFileUtilsClass.getDeclaredMethod("getFileType",
new Class[]
@@ -441,10 +465,12 @@ public class BrowserLauncher
try
{
Class linker = Class.forName("com.apple.mrj.jdirect.Linker");
- Constructor constructor = linker.getConstructor(new Class[]
- { Class.class });
- linkage = constructor.newInstance(new Object[]
- { BrowserLauncher.class });
+ Constructor constructor = linker
+ .getConstructor(new Class[]
+ { Class.class });
+ linkage = constructor
+ .newInstance(new Object[]
+ { BrowserLauncher.class });
} catch (ClassNotFoundException cnfe)
{
errorMessage = cnfe.getMessage();
@@ -500,6 +526,7 @@ public class BrowserLauncher
break;
}
+ }
return true;
}
@@ -516,6 +543,14 @@ public class BrowserLauncher
*/
private static Object locateBrowser()
{
+ if (!Platform.isJS())
+ /**
+ * Java only
+ *
+ * @j2sIgnore
+ *
+ */
+ {
if (browser != null)
{
return browser;
@@ -530,13 +565,16 @@ public class BrowserLauncher
Integer finderCreatorCode = (Integer) makeOSType.invoke(null,
new Object[]
{ FINDER_CREATOR });
- Object aeTarget = aeTargetConstructor.newInstance(new Object[]
- { finderCreatorCode });
- Integer gurlType = (Integer) makeOSType.invoke(null, new Object[]
- { GURL_EVENT });
- Object appleEvent = appleEventConstructor.newInstance(new Object[]
- { gurlType, gurlType, aeTarget, kAutoGenerateReturnID,
- kAnyTransactionID });
+ Object aeTarget = aeTargetConstructor
+ .newInstance(new Object[]
+ { finderCreatorCode });
+ Integer gurlType = (Integer) makeOSType.invoke(null,
+ new Object[]
+ { GURL_EVENT });
+ Object appleEvent = appleEventConstructor
+ .newInstance(new Object[]
+ { gurlType, gurlType, aeTarget, kAutoGenerateReturnID,
+ kAnyTransactionID });
// Don't set browser = appleEvent because then the next time we call
// locateBrowser(), we'll get the same AppleEvent, to which we'll
@@ -573,8 +611,9 @@ public class BrowserLauncher
try
{
- systemFolder = (File) findFolder.invoke(null, new Object[]
- { kSystemFolderType });
+ systemFolder = (File) findFolder.invoke(null,
+ new Object[]
+ { kSystemFolderType });
} catch (IllegalArgumentException iare)
{
browser = null;
@@ -615,13 +654,13 @@ public class BrowserLauncher
// applications being picked up on certain Mac OS 9 systems,
// especially German ones, and sending a GURL event to those
// applications results in a logout under Multiple Users.
- Object fileType = getFileType.invoke(null, new Object[]
- { file });
+ Object fileType = getFileType.invoke(null, new Object[] { file });
if (FINDER_TYPE.equals(fileType.toString()))
{
- Object fileCreator = getFileCreator.invoke(null, new Object[]
- { file });
+ Object fileCreator = getFileCreator.invoke(null,
+ new Object[]
+ { file });
if (FINDER_CREATOR.equals(fileCreator.toString()))
{
@@ -678,7 +717,10 @@ public class BrowserLauncher
break;
}
+ }
+
return browser;
+
}
/**
@@ -700,16 +742,34 @@ public class BrowserLauncher
*/
public static void openURL(String url) throws IOException
{
+
+ if (Platform.isJS())
+ {
+ Platform.openURL(url);
+ return;
+ }
+ else
+ /**
+ * Java only
+ *
+ * @j2sIgnore
+ */
+ {
+
if (!loadedWithoutErrors)
{
- throw new IOException(MessageManager.formatMessage("exception.browser_not_found", new String[]{errorMessage}));
+ throw new IOException(MessageManager
+ .formatMessage("exception.browser_not_found", new String[]
+ { errorMessage }));
}
Object browser = locateBrowser();
if (browser == null)
{
- throw new IOException(MessageManager.formatMessage("exception.browser_unable_to_locate", new String[]{errorMessage}));
+ throw new IOException(MessageManager.formatMessage(
+ "exception.browser_unable_to_locate", new String[]
+ { errorMessage }));
}
switch (jvm)
@@ -720,21 +780,27 @@ public class BrowserLauncher
try
{
- aeDesc = aeDescConstructor.newInstance(new Object[]
- { url });
- putParameter.invoke(browser, new Object[]
- { keyDirectObject, aeDesc });
- sendNoReply.invoke(browser, new Object[]
- {});
+ aeDesc = aeDescConstructor.newInstance(new Object[] { url });
+ putParameter.invoke(browser,
+ new Object[]
+ { keyDirectObject, aeDesc });
+ sendNoReply.invoke(browser, new Object[] {});
} catch (InvocationTargetException ite)
{
- throw new IOException(MessageManager.formatMessage("exception.invocation_target_exception_creating_aedesc", new String[]{ite.getMessage()}));
+ throw new IOException(MessageManager.formatMessage(
+ "exception.invocation_target_exception_creating_aedesc",
+ new String[]
+ { ite.getMessage() }));
} catch (IllegalAccessException iae)
{
- throw new IOException(MessageManager.formatMessage("exception.illegal_access_building_apple_evt", new String[]{iae.getMessage()}));
+ throw new IOException(MessageManager.formatMessage(
+ "exception.illegal_access_building_apple_evt", new String[]
+ { iae.getMessage() }));
} catch (InstantiationException ie)
{
- throw new IOException(MessageManager.formatMessage("exception.illegal_access_building_apple_evt", new String[]{ie.getMessage()}));
+ throw new IOException(MessageManager.formatMessage(
+ "exception.illegal_access_building_apple_evt", new String[]
+ { ie.getMessage() }));
} finally
{
aeDesc = null; // Encourage it to get disposed if it was created
@@ -744,8 +810,7 @@ public class BrowserLauncher
break;
case MRJ_2_1:
- Runtime.getRuntime().exec(new String[]
- { (String) browser, url });
+ Runtime.getRuntime().exec(new String[] { (String) browser, url });
break;
@@ -756,13 +821,11 @@ public class BrowserLauncher
if (result == 0)
{
- int[] selectionStart = new int[]
- { 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);
+ int[] selectionEnd = new int[] { urlBytes.length };
+ result = ICLaunchURL(instance[0], new byte[] { 0 }, urlBytes,
+ urlBytes.length, selectionStart, selectionEnd);
if (result == 0)
{
@@ -772,12 +835,16 @@ public class BrowserLauncher
}
else
{
- throw new IOException(MessageManager.formatMessage("exception.unable_to_launch_url", new String[]{Integer.valueOf(result).toString()}));
+ throw new IOException(MessageManager.formatMessage(
+ "exception.unable_to_launch_url", new String[]
+ { Integer.valueOf(result).toString() }));
}
}
else
{
- throw new IOException(MessageManager.formatMessage("exception.unable_to_create_internet_config", new String[]{Integer.valueOf(result).toString()}));
+ throw new IOException(MessageManager.formatMessage(
+ "exception.unable_to_create_internet_config", new String[]
+ { Integer.valueOf(result).toString() }));
}
break;
@@ -786,14 +853,17 @@ public class BrowserLauncher
try
{
- openURL.invoke(null, new Object[]
- { url });
+ openURL.invoke(null, new Object[] { url });
} catch (InvocationTargetException ite)
{
- throw new IOException(MessageManager.formatMessage("exception.invocation_target_calling_url", new String[]{ite.getMessage()}));
+ throw new IOException(MessageManager.formatMessage(
+ "exception.invocation_target_calling_url", new String[]
+ { ite.getMessage() }));
} catch (IllegalAccessException iae)
{
- throw new IOException(MessageManager.formatMessage("exception.illegal_access_calling_url", new String[]{iae.getMessage()}));
+ throw new IOException(MessageManager.formatMessage(
+ "exception.illegal_access_calling_url", new String[]
+ { iae.getMessage() }));
}
break;
@@ -803,8 +873,8 @@ public class BrowserLauncher
// Add quotes around the URL to allow ampersands and other special
// characters to work.
- Process process = Runtime.getRuntime().exec(
- new String[]
+ Process process = Runtime.getRuntime()
+ .exec(new String[]
{ (String) browser, FIRST_WINDOWS_PARAMETER,
SECOND_WINDOWS_PARAMETER, THIRD_WINDOWS_PARAMETER,
'"' + url + '"' });
@@ -818,7 +888,9 @@ public class BrowserLauncher
process.exitValue();
} catch (InterruptedException ie)
{
- throw new IOException(MessageManager.formatMessage("exception.interrupted_launching_browser", new String[]{ie.getMessage()}));
+ throw new IOException(MessageManager.formatMessage(
+ "exception.interrupted_launching_browser", new String[]
+ { ie.getMessage() }));
}
break;
@@ -836,11 +908,9 @@ public class BrowserLauncher
* NETSCAPE_REMOTE_PARAMETER+" "+ NETSCAPE_OPEN_PARAMETER_START + url +
* NETSCAPE_OPEN_NEW_WINDOW + NETSCAPE_OPEN_PARAMETER_END);
*/
- process = Runtime.getRuntime().exec(
- new String[]
- {
- (String) browser,
- NETSCAPE_REMOTE_PARAMETER,
+ process = Runtime.getRuntime()
+ .exec(new String[]
+ { (String) browser, NETSCAPE_REMOTE_PARAMETER,
NETSCAPE_OPEN_PARAMETER_START + url
+ NETSCAPE_OPEN_NEW_WINDOW
@@ -852,12 +922,13 @@ public class BrowserLauncher
if (exitCode != 0)
{ // if Netscape was not open
- Runtime.getRuntime().exec(new String[]
- { (String) browser, url });
+ Runtime.getRuntime().exec(new String[] { (String) browser, url });
}
} catch (InterruptedException ie)
{
- throw new IOException(MessageManager.formatMessage("exception.interrupted_launching_browser", new String[]{ie.getMessage()}));
+ throw new IOException(MessageManager.formatMessage(
+ "exception.interrupted_launching_browser", new String[]
+ { ie.getMessage() }));
}
break;
@@ -866,13 +937,14 @@ public class BrowserLauncher
// This should never occur, but if it does, we'll try the simplest thing
// possible
- Runtime.getRuntime().exec(new String[]
- { (String) browser, url });
+ Runtime.getRuntime().exec(new String[] { (String) browser, url });
break;
}
+ }
}
+
/**
* Methods required for Mac OS X. The presence of native methods does not
* cause any problems on other platforms.