KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > core > base > OSInfo


1 //The contents of this file are subject to the Mozilla Public License Version 1.1
2
//(the "License"); you may not use this file except in compliance with the
3
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
4
//
5
//Software distributed under the License is distributed on an "AS IS" basis,
6
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
7
//for the specific language governing rights and
8
//limitations under the License.
9
//
10
//The Original Code is "The Columba Project"
11
//
12
//The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
13
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
14
//
15
//All Rights Reserved.
16

17 package org.columba.core.base;
18
19 /**
20  * This is a helper class providing a quick and easy way to obtain useful
21  * information about the operating system Columba is running on.
22  *
23  * @author Hrk (Luca Santarelli) <hrk@users.sourceforge.net>
24  */

25 public class OSInfo {
26     private static final String JavaDoc OS_NAME = "os.name"; //$NON-NLS-1$
27

28     private static final String JavaDoc OS_ARCH = "os.arch"; //$NON-NLS-1$
29

30     // Platform identifiers: Windows, Linux, Mac OS, ...
31

32     /**
33      * Returns whether the underlying operating system is a Windows or Windows
34      * NT platform.
35      *
36      * @return isWindows32Platform
37      *
38      * @see #org.columba.core.base.OSInfo.isWindowsPlatform()
39      * @see #org.columba.core.base.OSInfo.isWinNTPlatform()
40      */

41     public static boolean isWin32Platform() {
42         return (isWindowsPlatform() || isWinNTPlatform());
43     }
44
45     /**
46      * Returns whether the underlying operating system is a Windows NT platform.
47      *
48      * @return isWinNTPlatform
49      *
50      * @see #org.columba.core.base.OSInfo.isWinNT()
51      * @see #org.columba.core.base.OSInfo.isWin2K()
52      * @see #org.columba.core.base.OSInfo.isWin2K3()
53      * @see #org.columba.core.base.OSInfo.isWinXP()
54      */

55     public static boolean isWinNTPlatform() {
56         return (isWinNT() || isWin2K() || isWin2K3() || isWinXP());
57     }
58
59     /**
60      * Returns whether the underlying operating system is a Windows platform.
61      *
62      * @return isWindowsPlatform
63      *
64      * @see #org.columba.core.base.OSInfo.isWin95()
65      * @see #org.columba.core.base.OSInfo.isWin98()
66      * @see #org.columba.core.base.OSInfo.isWinME()
67      */

68     public static boolean isWindowsPlatform() {
69         return (isWin95() || isWin98() || isWinME());
70     }
71
72     // Single OS identifiers: Window 95, Window 98, ...
73

74     /**
75      * Returns whether the underlying operating system is Windows 95.
76      *
77      * @return isWin95
78      */

79     public static boolean isWin95() {
80         return "Windows 95".equalsIgnoreCase(System.getProperty(OS_NAME)); //$NON-NLS-1$
81
}
82
83     /**
84      * Returns whether the underlying operating system is Windows 98.
85      *
86      * @return isWin98
87      */

88     public static boolean isWin98() {
89         return "Windows 98".equalsIgnoreCase(System.getProperty(OS_NAME)); //$NON-NLS-1$
90
}
91
92     /**
93      * Returns whether the underlying operating system is Windows ME.
94      *
95      * @return isWinME
96      */

97     public static boolean isWinME() {
98         return "Windows ME".equalsIgnoreCase(System.getProperty(OS_NAME)); //$NON-NLS-1$
99
}
100
101     /**
102      * Returns whether the underlying operating system is Windows NT.
103      *
104      * @return isWinNT
105      */

106     public static boolean isWinNT() {
107         return "Windows NT".equalsIgnoreCase(System.getProperty(OS_NAME)); //$NON-NLS-1$
108
}
109
110     /**
111      * Returns whether the underlying operating system is Windows 2000.
112      *
113      * @return isWin2K
114      */

115     public static boolean isWin2K() {
116         return "Windows 2000".equalsIgnoreCase(System.getProperty(OS_NAME)); //$NON-NLS-1$
117
}
118
119     /**
120      * Returns whether the underlying operating system is Windows 2003.
121      *
122      * @return isWin2K3
123      */

124     public static boolean isWin2K3() {
125         return "Windows 2003".equalsIgnoreCase(System.getProperty(OS_NAME)); //$NON-NLS-1$
126
}
127
128     /**
129      * Returns whether the underlying operating system is Windows XP.
130      *
131      * @return isWinXP
132      */

133     public static boolean isWinXP() {
134         return "Windows XP".equalsIgnoreCase(System.getProperty(OS_NAME)); //$NON-NLS-1$
135
}
136
137     /**
138      * Returns whether the underlying operating system is Linux.
139      *
140      * @return isLinux
141      */

142     public static boolean isLinux() {
143         return "Linux".equalsIgnoreCase(System.getProperty(OS_NAME)); //$NON-NLS-1$
144
}
145
146     /**
147      * Returns whether the underlying operating system is Solaris.
148      *
149      * @return isSolaris
150      */

151     public static boolean isSolaris() {
152         return "Solaris".equalsIgnoreCase(System.getProperty(OS_NAME)); //$NON-NLS-1$
153
}
154
155     /**
156      * Returns whether the underlying operating system is some MacOS.
157      *
158      * @return isMac
159      */

160     public static boolean isMac() {
161         return System.getProperty(OS_NAME).toLowerCase().indexOf("mac") != -1; //$NON-NLS-1$
162
}
163
164     public static boolean isAMD64Bit() {
165         return System.getProperty(OS_ARCH).toLowerCase().indexOf("amd64") != -1; //$NON-NLS-1$
166
}
167 }
168
Popular Tags