X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Futil%2FBrowserLauncher.java;h=a55a65ccadc09138ae66689471a115c3f65c7472;hb=d5bc056b7dff2e83166c0a25df7d52082954297a;hp=5ea4588c139a7401d1d8edc9930b10eb51071fc4;hpb=2de8acfae59aced665e4c37ad0f7dcc2ed68818e;p=jalview.git
diff --git a/src/jalview/util/BrowserLauncher.java b/src/jalview/util/BrowserLauncher.java
index 5ea4588..a55a65c 100755
--- a/src/jalview/util/BrowserLauncher.java
+++ b/src/jalview/util/BrowserLauncher.java
@@ -1,25 +1,31 @@
/*
- * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1)
- * Copyright (C) 2009 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This file is part of Jalview.
*
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ * along with Jalview. If not, see
* 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
@@ -89,8 +95,8 @@ public class BrowserLauncher
* Caches whether any classes, methods, and fields that are not part of the
* JDK and need to be dynamically loaded at runtime loaded successfully.
*
- * Note that if this is false
, openURL()
will
- * always return an IOException.
+ * Note that if this is false
, openURL()
will always
+ * return an IOException.
*/
private static boolean loadedWithoutErrors;
@@ -227,14 +233,30 @@ public class BrowserLauncher
*/
static
{
+
loadedWithoutErrors = true;
+ /**
+ *
+ * @j2sNative
+ *
+ */
+ {
String osName = System.getProperty("os.name");
if (osName.startsWith("Mac OS"))
{
String mrjVersion = System.getProperty("mrj.version");
- String majorMRJVersion = mrjVersion.substring(0, 3);
+ String majorMRJVersion;
+ if (mrjVersion == null)
+ {
+ // must be on some later build with mrj support
+ majorMRJVersion = "3.1";
+ }
+ else
+ {
+ majorMRJVersion = mrjVersion.substring(0, 3);
+ }
try
{
@@ -292,6 +314,7 @@ public class BrowserLauncher
{ // if we haven't hit any errors yet
loadedWithoutErrors = loadClasses();
}
+ }
}
/**
@@ -305,11 +328,17 @@ public class BrowserLauncher
* Called by a static initializer to load any classes, fields, and methods
* required at runtime to locate the user's web browser.
*
- * @return true
if all intialization succeeded
- * false
if any portion of the initialization failed
+ * @return true
if all intialization succeeded false
+ * if any portion of the initialization failed
*/
private static boolean loadClasses()
{
+
+ /**
+ * @j2sNative
+ *
+ */
+ {
switch (jvm)
{
case MRJ_2_0:
@@ -327,9 +356,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[]
@@ -338,8 +369,7 @@ public class BrowserLauncher
new Class[]
{ int.class, aeDescClass });
sendNoReply = appleEventClass.getDeclaredMethod("sendNoReply",
- new Class[]
- {});
+ new Class[] {});
Field keyDirectObjectField = aeClass
.getDeclaredField("keyDirectObject");
@@ -390,8 +420,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[]
@@ -430,10 +460,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();
@@ -489,6 +521,7 @@ public class BrowserLauncher
break;
}
+ }
return true;
}
@@ -505,6 +538,11 @@ public class BrowserLauncher
*/
private static Object locateBrowser()
{
+ /**
+ * @j2sNative
+ *
+ */
+ {
if (browser != null)
{
return browser;
@@ -519,13 +557,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
@@ -562,8 +603,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;
@@ -604,13 +646,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()))
{
@@ -667,7 +709,10 @@ public class BrowserLauncher
break;
}
+ }
+
return browser;
+
}
/**
@@ -683,22 +728,37 @@ public class BrowserLauncher
* Attempts to open the default web browser to the given URL.
*
* @param url
- * The URL to open
+ * The URL to open
* @throws IOException
- * If the web browser could not be located or does not run
+ * If the web browser could not be located or does not run
*/
public static void openURL(String url) throws IOException
{
+
+ /**
+ * @j2sNative
+ *
+ * window.open(url);
+ *
+ *
+ */
+
+ {
+
if (!loadedWithoutErrors)
{
- throw new IOException("Exception in finding browser: " + errorMessage);
+ throw new IOException(MessageManager
+ .formatMessage("exception.browser_not_found", new String[]
+ { errorMessage }));
}
Object browser = locateBrowser();
if (browser == null)
{
- throw new IOException("Unable to locate browser: " + errorMessage);
+ throw new IOException(MessageManager.formatMessage(
+ "exception.browser_unable_to_locate", new String[]
+ { errorMessage }));
}
switch (jvm)
@@ -709,27 +769,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(
- "InvocationTargetException while creating AEDesc: "
- + ite.getMessage());
+ throw new IOException(MessageManager.formatMessage(
+ "exception.invocation_target_exception_creating_aedesc",
+ new String[]
+ { ite.getMessage() }));
} catch (IllegalAccessException iae)
{
- throw new IOException(
- "IllegalAccessException while building AppleEvent: "
- + iae.getMessage());
+ throw new IOException(MessageManager.formatMessage(
+ "exception.illegal_access_building_apple_evt", new String[]
+ { iae.getMessage() }));
} catch (InstantiationException ie)
{
- throw new IOException(
- "InstantiationException while creating AEDesc: "
- + 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
@@ -739,8 +799,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;
@@ -751,13 +810,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)
{
@@ -767,13 +824,16 @@ public class BrowserLauncher
}
else
{
- throw new IOException("Unable to launch URL: " + result);
+ throw new IOException(MessageManager.formatMessage(
+ "exception.unable_to_launch_url", new String[]
+ { Integer.valueOf(result).toString() }));
}
}
else
{
- throw new IOException(
- "Unable to create an Internet Config instance: " + result);
+ throw new IOException(MessageManager.formatMessage(
+ "exception.unable_to_create_internet_config", new String[]
+ { Integer.valueOf(result).toString() }));
}
break;
@@ -782,18 +842,17 @@ public class BrowserLauncher
try
{
- openURL.invoke(null, new Object[]
- { url });
+ openURL.invoke(null, new Object[] { url });
} catch (InvocationTargetException ite)
{
- throw new IOException(
- "InvocationTargetException while calling openURL: "
- + ite.getMessage());
+ throw new IOException(MessageManager.formatMessage(
+ "exception.invocation_target_calling_url", new String[]
+ { ite.getMessage() }));
} catch (IllegalAccessException iae)
{
- throw new IOException(
- "IllegalAccessException while calling openURL: "
- + iae.getMessage());
+ throw new IOException(MessageManager.formatMessage(
+ "exception.illegal_access_calling_url", new String[]
+ { iae.getMessage() }));
}
break;
@@ -803,8 +862,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,9 +877,9 @@ public class BrowserLauncher
process.exitValue();
} catch (InterruptedException ie)
{
- throw new IOException(
- "InterruptedException while launching browser: "
- + ie.getMessage());
+ throw new IOException(MessageManager.formatMessage(
+ "exception.interrupted_launching_browser", new String[]
+ { ie.getMessage() }));
}
break;
@@ -838,11 +897,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
@@ -854,14 +911,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(
- "InterruptedException while launching browser: "
- + ie.getMessage());
+ throw new IOException(MessageManager.formatMessage(
+ "exception.interrupted_launching_browser", new String[]
+ { ie.getMessage() }));
}
break;
@@ -870,13 +926,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.