KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > zirc > base > BrowserLauncher


1 package zirc.base ;
2
3 import java.io.* ;
4 import java.util.* ;
5
6 //zIrc, irc client.
7
// Copyright (C) 2004 CoolBytes(Stephane claret, Andre Aymon, Alban Zumofen) coolbytes@hotmail.com
8
//
9
// This program is free software; you can redistribute it and/or
10
// modify it under the terms of the GNU General Public License
11
// as published by the Free Software Foundation; either version 2
12
// of the License, or (at your option) any later version.
13
//
14
// This program is distributed in the hope that it will be useful,
15
// but WITHOUT ANY WARRANTY; without even the implied warranty of
16
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
// GNU General Public License for more details.
18

19 /**
20  * <p>Title: BrowserLauncher</p>
21  * <p>Description: classe qui sert a lancer un navigateur html</p>
22  * <p>Copyright: Copyright (c) 2004</p>
23  * <p>Company: CoolBytes(Stephane claret, Andre Aymon, Alban Zumofen) coolbytes@hotmail.com</p>
24  * @version 1.0
25  */

26
27
28 /*
29  "browser",
30     "browser.vendor", "browser.version"
31  java.version Java version number
32  java.vendor Java vendor-specific string
33  java.vendor.url Java vendor URL
34  os.name Operating system name
35  os.arch Operating system architecture
36  file.separator File separator (eg, "/")
37  path.separator Path separator (eg, ":")
38  line.separator Line separator
39  java.class.version Java class version number
40  java.home Java installation directory
41  java.class.path Java classpath
42  user.name User account name
43  user.home User home directory
44  user.dir User's current working directory
45
46
47  */

48
49 public class BrowserLauncher
50 {
51
52   final String JavaDoc WIN_PATH = "rundll32" ;
53   final String JavaDoc WIN_FLAG = "url.dll,FileProtocolHandler" ;
54   final String JavaDoc UNIX_PATH = "netscape" ;
55   final String JavaDoc UNIX_FLAG = "-remote openURL" ;
56
57   public BrowserLauncher()
58   {
59   }
60
61   public void launchBrowserForLocalFiles(String JavaDoc url)
62   {
63     String JavaDoc os = System.getProperty("os.name") ;
64     StringTokenizer str = new StringTokenizer(os, " ") ;
65     os = str.nextElement().toString() ;
66     System.err.println(os) ;
67
68     if (os.equalsIgnoreCase("windows"))
69     {
70       String JavaDoc cmd = WIN_PATH + " " + WIN_FLAG + " " + url ;
71       try
72       {
73         Process JavaDoc p = Runtime.getRuntime().exec(cmd) ;
74       }
75       catch (IOException ex)
76       {
77
78       }
79     }
80     else //tester pour nunux...
81
{
82       if (os.equalsIgnoreCase("linux"))
83       {
84         String JavaDoc cmd = UNIX_PATH + " " + UNIX_FLAG + " " + url ;
85         try
86         {
87           Process JavaDoc p = Runtime.getRuntime().exec(cmd) ;
88         }
89         catch (IOException ex)
90         {
91           cmd = "konqueror " + url ;
92           try
93           {
94             Process JavaDoc p = Runtime.getRuntime().exec(cmd) ;
95           }
96           catch (IOException ex1)
97           {
98           }
99         }
100       }
101
102     }
103
104   }
105
106   public void launchBrowserForInternet(String JavaDoc url)
107   {
108     String JavaDoc os = System.getProperty("os.name") ;
109     StringTokenizer str = new StringTokenizer(os, " ") ;
110     os = str.nextElement().toString() ;
111     System.err.println(os) ;
112
113     if (os.equalsIgnoreCase("windows"))
114     {
115       String JavaDoc cmd = WIN_PATH + " " + WIN_FLAG + " " + url ;
116       try
117       {
118         Process JavaDoc p = Runtime.getRuntime().exec(cmd) ;
119       }
120       catch (IOException ex)
121       {
122         ex.printStackTrace() ;
123       }
124     }
125     else //tester pour nunux...
126
{
127       if (os.equalsIgnoreCase("linux"))
128       {
129         String JavaDoc cmd = UNIX_PATH + " " + UNIX_FLAG + " " + url ;
130         try
131         {
132           Process JavaDoc p = Runtime.getRuntime().exec(cmd) ;
133         }
134         catch (IOException ex)
135         {
136           cmd = "konqueror " + url ;
137           try
138           {
139             Process JavaDoc p = Runtime.getRuntime().exec(cmd) ;
140           }
141           catch (IOException ex1)
142           {
143           }
144         }
145
146       }
147     }
148
149   }
150
151 }
152
Popular Tags