/*
* Copyright (c) 2006 Mirko Dietrich
*
* E-Mail : mirkodietrich@hrz.uni-kassel.de
* Creation Date : Jul 20, 2006 11:58:56 AM
* Original Filename: org.dgpf.gui.DGPFBrowserLaunch.java
* Version : 1.0
* Last modification: Jul 20, 2006
* Last modified by : Mirko Dietrich
*
* License : GNU LESSER GENERAL PUBLIC LICENSE
* Version 2.1, February 1999
* You should have received a copy of this license along
* with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307, USA or download the license under
* http://www.gnu.org/copyleft/lesser.html.
*
* Warranty : This software is provided "as is" without any
* warranty; without even the implied warranty of
* merchantability or fitness for a particular purpose.
* See the Gnu Lesser General Public License for more
* details.
*/
package org.dgpf.gui.utils;
import java.lang.reflect.Method;
import javax.swing.JOptionPane;
/**
* Launch a browser and open an URL. This class is intended to work with
* the following operating systems:
*
* - Mac OS X
* - Microsoft Windows
* - GNU/Linux
* - other Unix flavors
*
*
* @author Mirko Dietrich
*/
public class BrowserLaunch
{
/**
* Browsers to try on GNU/Linux or other unices.
*/
private static final String[] BROWSERS = { "firefox", "mozilla",
"opera", "konqueror", "epiphany", "netscape" };
/**
* Open the specified URL in a browser.
*
* @param p_url
* to open.
*/
public static void openURL(String p_url)
{
String l_osName = System.getProperty("os.name");
try
{
if(l_osName.startsWith("Mac OS"))
{
Class l_fileMgr = Class.forName("com.apple.eio.FileManager");
Method l_openURL = l_fileMgr.getDeclaredMethod("openURL",
new Class[] { String.class });
l_openURL.invoke(null, new Object[] { p_url });
}
else
if(l_osName.startsWith("Windows"))
Runtime.getRuntime().exec(
"rundll32 url.dll,FileProtocolHandler " + p_url);
else
{ // assume Unix or Linux
String l_browser = null;
for(int count = 0; count < BROWSERS.length && l_browser == null; count++)
if(Runtime.getRuntime().exec(
new String[] { "which", BROWSERS[count] }).waitFor() == 0)
l_browser = BROWSERS[count];
if(l_browser == null){
throw new Exception(LanguageSwitcher
.getString("msgb_no_browser_found"));
}
Runtime.getRuntime().exec(new String[] { l_browser, p_url });
}
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, e.getLocalizedMessage());
}
}
}