X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Futil%2FBrowserLauncher.java;h=dbd9177631816dcafedfebd87c8d447023e388c9;hb=caa5930cf71ef14a4af891f2c17aa4a6e0f72bcf;hp=1da860be1054099b10d52aa3a61357cb1d0b08bf;hpb=838e4f91d4a53dd315640dbc9ff6ef7a815ee576;p=jalview.git diff --git a/src/jalview/util/BrowserLauncher.java b/src/jalview/util/BrowserLauncher.java index 1da860b..dbd9177 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.9.0b1) - * Copyright (C) 2015 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,6 +20,8 @@ */ package jalview.util; +import jalview.bin.Cache; + import java.io.File; import java.io.IOException; import java.lang.reflect.Constructor; @@ -69,14 +71,14 @@ import java.lang.reflect.Method; * 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 @@ -233,8 +235,17 @@ public class BrowserLauncher */ static { + loadedWithoutErrors = true; + if (!Platform.isJS()) + /** + * Java only + * + * @j2sIgnore + * + */ + { String osName = System.getProperty("os.name"); if (osName.startsWith("Mac OS")) @@ -307,6 +318,7 @@ public class BrowserLauncher { // if we haven't hit any errors yet loadedWithoutErrors = loadClasses(); } + } } /** @@ -325,6 +337,15 @@ public class BrowserLauncher */ private static boolean loadClasses() { + + if (!Platform.isJS()) + /** + * Java only + * + * @j2sIgnore + * + */ + { switch (jvm) { case MRJ_2_0: @@ -338,17 +359,22 @@ public class BrowserLauncher aeDescClass = Class.forName("com.apple.MacOS.AEDesc"); aeTargetConstructor = aeTargetClass - .getDeclaredConstructor(new Class[] { int.class }); + .getDeclaredConstructor(new Class[] + { int.class }); appleEventConstructor = appleEventClass - .getDeclaredConstructor(new Class[] { int.class, int.class, - aeTargetClass, int.class, int.class }); + .getDeclaredConstructor(new Class[] + { int.class, int.class, aeTargetClass, int.class, + int.class }); aeDescConstructor = aeDescClass - .getDeclaredConstructor(new Class[] { String.class }); + .getDeclaredConstructor(new Class[] + { String.class }); makeOSType = osUtilsClass.getDeclaredMethod("makeOSType", - new Class[] { String.class }); + new Class[] + { String.class }); putParameter = appleEventClass.getDeclaredMethod("putParameter", - new Class[] { int.class, aeDescClass }); + new Class[] + { int.class, aeDescClass }); sendNoReply = appleEventClass.getDeclaredMethod("sendNoReply", new Class[] {}); @@ -399,11 +425,14 @@ public class BrowserLauncher .getDeclaredField("kSystemFolderType"); kSystemFolderType = systemFolderField.get(null); findFolder = mrjFileUtilsClass.getDeclaredMethod("findFolder", - new Class[] { mrjOSTypeClass }); - getFileCreator = mrjFileUtilsClass.getDeclaredMethod( - "getFileCreator", new Class[] { File.class }); + new Class[] + { mrjOSTypeClass }); + getFileCreator = mrjFileUtilsClass + .getDeclaredMethod("getFileCreator", new Class[] + { File.class }); getFileType = mrjFileUtilsClass.getDeclaredMethod("getFileType", - new Class[] { File.class }); + new Class[] + { File.class }); } catch (ClassNotFoundException cnfe) { errorMessage = cnfe.getMessage(); @@ -439,9 +468,11 @@ public class BrowserLauncher { Class linker = Class.forName("com.apple.mrj.jdirect.Linker"); Constructor constructor = linker - .getConstructor(new Class[] { Class.class }); + .getConstructor(new Class[] + { Class.class }); linkage = constructor - .newInstance(new Object[] { BrowserLauncher.class }); + .newInstance(new Object[] + { BrowserLauncher.class }); } catch (ClassNotFoundException cnfe) { errorMessage = cnfe.getMessage(); @@ -477,7 +508,8 @@ public class BrowserLauncher { mrjFileUtilsClass = Class.forName("com.apple.mrj.MRJFileUtils"); openURL = mrjFileUtilsClass.getDeclaredMethod("openURL", - new Class[] { String.class }); + new Class[] + { String.class }); } catch (ClassNotFoundException cnfe) { errorMessage = cnfe.getMessage(); @@ -496,6 +528,7 @@ public class BrowserLauncher break; } + } return true; } @@ -512,6 +545,14 @@ public class BrowserLauncher */ private static Object locateBrowser() { + if (!Platform.isJS()) + /** + * Java only + * + * @j2sIgnore + * + */ + { if (browser != null) { return browser; @@ -524,14 +565,18 @@ public class BrowserLauncher try { Integer finderCreatorCode = (Integer) makeOSType.invoke(null, - new Object[] { FINDER_CREATOR }); + new Object[] + { FINDER_CREATOR }); Object aeTarget = aeTargetConstructor - .newInstance(new Object[] { finderCreatorCode }); + .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 }); + 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 @@ -569,7 +614,8 @@ public class BrowserLauncher try { systemFolder = (File) findFolder.invoke(null, - new Object[] { kSystemFolderType }); + new Object[] + { kSystemFolderType }); } catch (IllegalArgumentException iare) { browser = null; @@ -615,7 +661,8 @@ public class BrowserLauncher if (FINDER_TYPE.equals(fileType.toString())) { Object fileCreator = getFileCreator.invoke(null, - new Object[] { file }); + new Object[] + { file }); if (FINDER_CREATOR.equals(fileCreator.toString())) { @@ -667,12 +714,15 @@ public class BrowserLauncher case OTHER: default: - browser = jalview.bin.Cache.getDefault("DEFAULT_BROWSER", "firefox"); + browser = Cache.getDefault("DEFAULT_BROWSER", "firefox"); break; } + } + return browser; + } /** @@ -694,10 +744,25 @@ 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(); @@ -705,8 +770,8 @@ public class BrowserLauncher if (browser == null) { throw new IOException(MessageManager.formatMessage( - "exception.browser_unable_to_locate", - new String[] { errorMessage })); + "exception.browser_unable_to_locate", new String[] + { errorMessage })); } switch (jvm) @@ -719,13 +784,15 @@ public class BrowserLauncher { aeDesc = aeDescConstructor.newInstance(new Object[] { url }); putParameter.invoke(browser, - new Object[] { keyDirectObject, aeDesc }); + 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() })); + new String[] + { ite.getMessage() })); } catch (IllegalAccessException iae) { throw new IOException(MessageManager.formatMessage( @@ -771,15 +838,15 @@ public class BrowserLauncher else { throw new IOException(MessageManager.formatMessage( - "exception.unable_to_launch_url", new String[] { Integer - .valueOf(result).toString() })); + "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() })); + "exception.unable_to_create_internet_config", new String[] + { Integer.valueOf(result).toString() })); } break; @@ -792,13 +859,13 @@ public class BrowserLauncher } catch (InvocationTargetException ite) { throw new IOException(MessageManager.formatMessage( - "exception.invocation_target_calling_url", - new String[] { ite.getMessage() })); + "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() })); + "exception.illegal_access_calling_url", new String[] + { iae.getMessage() })); } break; @@ -808,8 +875,9 @@ public class BrowserLauncher // Add quotes around the URL to allow ampersands and other special // characters to work. - Process process = Runtime.getRuntime().exec( - new String[] { (String) browser, FIRST_WINDOWS_PARAMETER, + Process process = Runtime.getRuntime() + .exec(new String[] + { (String) browser, FIRST_WINDOWS_PARAMETER, SECOND_WINDOWS_PARAMETER, THIRD_WINDOWS_PARAMETER, '"' + url + '"' }); @@ -823,8 +891,8 @@ public class BrowserLauncher } catch (InterruptedException ie) { throw new IOException(MessageManager.formatMessage( - "exception.interrupted_launching_browser", - new String[] { ie.getMessage() })); + "exception.interrupted_launching_browser", new String[] + { ie.getMessage() })); } break; @@ -842,10 +910,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 @@ -862,8 +929,8 @@ public class BrowserLauncher } catch (InterruptedException ie) { throw new IOException(MessageManager.formatMessage( - "exception.interrupted_launching_browser", - new String[] { ie.getMessage() })); + "exception.interrupted_launching_browser", new String[] + { ie.getMessage() })); } break; @@ -876,8 +943,10 @@ public class BrowserLauncher break; } + } } + /** * Methods required for Mac OS X. The presence of native methods does not * cause any problems on other platforms.