2005-12-02 15:39  orrisroot

	* SGBrowserLauncher.java: fixed static asscess warnings.

2004-11-30 14:06  kuromaru

	* SGBrowserLauncher.java: Organized import lines.

2004-11-08 12:58  kuromaru

	* SGBrowserLauncher.java: Default browser is changed from netscape
	  to mozilla.

2004-10-10 22:31  kuromaru

	* SGBrowserLauncher.java: Removed a meaningless line.

2004-09-27 12:59  kuromaru

	* SGBrowserLauncher.java: Added a new class to launch the web
	  browser.

--- BrowserLauncher.java	Fri Dec 16 11:14:23 2005
+++ SGBrowserLauncher.java	Fri Dec 16 11:14:23 2005
@@ -1,13 +1,14 @@
-package edu.stanford.ejalbert;
+
+package jp.riken.brain.ni.samuraigraph.base;
 
 import java.io.File;
-import java.io.FileNotFoundException;
 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 opens the default
  * web browser for the current user of the system to the given URL.  It may support other
@@ -52,7 +53,7 @@
  * @author Eric Albert (<a href="mailto:ejalbert@cs.stanford.edu">ejalbert@cs.stanford.edu</a>)
  * @version 1.4b1 (Released June 20, 2001)
  */
-public class BrowserLauncher {
+public class SGBrowserLauncher {
 
 	/**
 	 * The Java virtual machine that we are running on.  Actually, in most cases we only care
@@ -168,17 +169,17 @@
 	 * The first parameter that needs to be passed into Runtime.exec() to open the default web
 	 * browser on Windows.
 	 */
-    private static final String FIRST_WINDOWS_PARAMETER = "/c";
+	private static final String FIRST_WINDOWS_PARAMETER = "/c";
     
-    /** The second parameter for Runtime.exec() on Windows. */
-    private static final String SECOND_WINDOWS_PARAMETER = "start";
+	/** The second parameter for Runtime.exec() on Windows. */
+	private static final String SECOND_WINDOWS_PARAMETER = "start";
     
-    /**
-     * The third parameter for Runtime.exec() on Windows.  This is a "title"
-     * parameter that the command line expects.  Setting this parameter allows
-     * URLs containing spaces to work.
-     */
-    private static final String THIRD_WINDOWS_PARAMETER = "\"\"";
+	/**
+	 * The third parameter for Runtime.exec() on Windows.  This is a "title"
+	 * parameter that the command line expects.  Setting this parameter allows
+	 * URLs containing spaces to work.
+	 */
+	private static final String THIRD_WINDOWS_PARAMETER = "\"\"";
 	
 	/**
 	 * The shell parameters for Netscape that opens a given URL in an already-open copy of Netscape
@@ -243,7 +244,7 @@
 	/**
 	 * This class should be never be instantiated; this just ensures so.
 	 */
-	private BrowserLauncher() { }
+	private SGBrowserLauncher() { }
 	
 	/**
 	 * Called by a static initializer to load any classes, fields, and methods required at runtime
@@ -316,10 +317,10 @@
 				}
 				break;
 			case MRJ_3_0:
-			    try {
+				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 });
+					linkage = constructor.newInstance(new Object[] { SGBrowserLauncher.class });
 				} catch (ClassNotFoundException cnfe) {
 					errorMessage = cnfe.getMessage();
 					return false;
@@ -350,7 +351,7 @@
 				}
 				break;
 			default:
-			    break;
+				break;
 		}
 		return true;
 	}
@@ -432,7 +433,6 @@
 							}
 						}
 					} catch (IllegalArgumentException iare) {
-						browser = browser;
 						errorMessage = iare.getMessage();
 						return null;
 					} catch (IllegalAccessException iae) {
@@ -459,7 +459,8 @@
 				break;
 			case OTHER:
 			default:
-				browser = "netscape";
+//				browser = "netscape";
+				browser = "mozilla";
 				break;
 		}
 		return browser;
@@ -474,18 +475,17 @@
 		if (!loadedWithoutErrors) {
 			throw new IOException("Exception in finding browser: " + errorMessage);
 		}
-		Object browser = locateBrowser();
-		if (browser == null) {
+		Object _browser = locateBrowser();
+		if (_browser == null) {
 			throw new IOException("Unable to locate browser: " + errorMessage);
 		}
-		
 		switch (jvm) {
 			case MRJ_2_0:
 				Object aeDesc = null;
 				try {
 					aeDesc = aeDescConstructor.newInstance(new Object[] { url });
-					putParameter.invoke(browser, new Object[] { keyDirectObject, aeDesc });
-					sendNoReply.invoke(browser, new Object[] { });
+					putParameter.invoke(_browser, new Object[] { keyDirectObject, aeDesc });
+					sendNoReply.invoke(_browser, new Object[] { });
 				} catch (InvocationTargetException ite) {
 					throw new IOException("InvocationTargetException while creating AEDesc: " + ite.getMessage());
 				} catch (IllegalAccessException iae) {
@@ -494,11 +494,11 @@
 					throw new IOException("InstantiationException while creating AEDesc: " + ie.getMessage());
 				} finally {
 					aeDesc = null;	// Encourage it to get disposed if it was created
-					browser = null;	// Ditto
+					_browser = null;	// Ditto
 				}
 				break;
 			case MRJ_2_1:
-				Runtime.getRuntime().exec(new String[] { (String) browser, url } );
+				Runtime.getRuntime().exec(new String[] { (String) _browser, url } );
 				break;
 			case MRJ_3_0:
 				int[] instance = new int[1];
@@ -530,11 +530,11 @@
 					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.
-				Process process = Runtime.getRuntime().exec(new String[] { (String) browser,
+			case WINDOWS_NT:
+			case WINDOWS_9x:
+				// 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,
 																SECOND_WINDOWS_PARAMETER,
 																THIRD_WINDOWS_PARAMETER,
@@ -550,17 +550,18 @@
 				break;
 			case OTHER:
 				// Assume that we're on Unix and that Netscape is installed
-				
 				// First, attempt to open the URL in a currently running session of Netscape
-				process = Runtime.getRuntime().exec(new String[] { (String) browser,
-													NETSCAPE_REMOTE_PARAMETER,
-													NETSCAPE_OPEN_PARAMETER_START +
-													url +
-													NETSCAPE_OPEN_PARAMETER_END });
+//				process = Runtime.getRuntime().exec(new String[] { (String) browser,
+//													NETSCAPE_REMOTE_PARAMETER,
+//													NETSCAPE_OPEN_PARAMETER_START +
+//													url +
+//													NETSCAPE_OPEN_PARAMETER_END });
+				process = Runtime.getRuntime().exec(new String[] { (String) _browser, url });
+
 				try {
 					int exitCode = process.waitFor();
 					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());
@@ -568,7 +569,7 @@
 				break;
 			default:
 				// 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;
 		}
 	}
@@ -582,3 +583,4 @@
 	private native static int ICLaunchURL(int instance, byte[] hint, byte[] data, int len,
 											int[] selectionStart, int[] selectionEnd);
 }
+
