KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lobobrowser > util > OS


1 /*
2     GNU LESSER GENERAL PUBLIC LICENSE
3     Copyright (C) 2006 The Lobo Project
4
5     This library is free software; you can redistribute it and/or
6     modify it under the terms of the GNU Lesser General Public
7     License as published by the Free Software Foundation; either
8     version 2.1 of the License, or (at your option) any later version.
9
10     This library is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13     Lesser General Public License for more details.
14
15     You should have received a copy of the GNU Lesser General Public
16     License along with this library; if not, write to the Free Software
17     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19     Contact info: xamjadmin@users.sourceforge.net
20 */

21 /*
22  * Created on May 14, 2005
23  */

24 package org.lobobrowser.util;
25
26 /**
27  * @author J. H. S.
28  */

29 public class OS {
30     /**
31      *
32      */

33     private OS() {
34         super();
35     }
36
37     public static boolean isWindows() {
38         String JavaDoc osName = System.getProperty("os.name");
39         return osName.indexOf("Windows") != -1;
40     }
41     
42     public static void launchBrowser(String JavaDoc url) throws java.io.IOException JavaDoc {
43         String JavaDoc cmdLine;
44         if(isWindows()) {
45             cmdLine = "rundll32 url.dll,FileProtocolHandler " + url;
46         }
47         else {
48             cmdLine = "firefox " + url;
49         }
50         try {
51             Runtime.getRuntime().exec(cmdLine);
52         } catch(java.io.IOException JavaDoc ioe) {
53             Runtime.getRuntime().exec("netscape " + url);
54         }
55     }
56
57     /**
58      * Opens a file a directory with an appropriate program.
59      */

60     public static void launchPath(String JavaDoc path) throws java.io.IOException JavaDoc {
61         if(isWindows()) {
62             Runtime.getRuntime().exec(new String JavaDoc[] { "cmd.exe", "/c", "start", "\"title\"", path });
63         }
64         else {
65             throw new UnsupportedOperationException JavaDoc("Unsupported");
66         }
67     }
68     
69     public static boolean supportsLaunchPath() {
70         return isWindows();
71     }
72 }
73
Popular Tags