KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfox > ioc > util > Systems


1 /* JFox, the OpenSource J2EE Application Server
2  *
3  * Distributable under GNU LGPL license by gun.org
4  * more details please visit http://www.huihoo.org/jfox
5  */

6
7 package org.jfox.ioc.util;
8
9 import java.io.File JavaDoc;
10
11 /**
12  * @author <a HREF="mailto:young_yy@hotmail.com">Young Yang</a>
13  */

14
15 public class Systems {
16
17     /**
18      * The System property key for the user home directory.
19      */

20     private static final String JavaDoc USER_HOME_KEY = "user.home";
21
22     /**
23      * The System property key for the user directory.
24      */

25     private static final String JavaDoc USER_DIR_KEY = "user.dir";
26
27     /**
28      * The System property key for the Java IO temporary directory.
29      */

30     private static final String JavaDoc JAVA_IO_TMPDIR_KEY = "java.io.tmpdir";
31
32     /**
33      * The System property key for the Java home directory.
34      */

35     private static final String JavaDoc JAVA_HOME_KEY = "java.home";
36
37     /**
38      * <p>The <code>file.encoding</code> System Property.</p>
39      * <p>File encoding, such as <code>Cp1252</code>.</p>
40      * <p/>
41      * <p>Defaults to <code>null</code> if the runtime does not have
42      * security access to read this property or the property does not exist.</p>
43      * <p/>
44      * <p/>
45      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
46      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
47      * will be out of sync with that System property.
48      * </p>
49      *
50      * @since Java 1.2
51      */

52     public static final String JavaDoc FILE_ENCODING = getSystemProperty("file.encoding");
53
54     /**
55      * <p>The <code>file.separator</code> System Property.
56      * File separator (<code>&quot;/&quot;</code> on UNIX).</p>
57      * <p/>
58      * <p>Defaults to <code>null</code> if the runtime does not have
59      * security access to read this property or the property does not exist.</p>
60      * <p/>
61      * <p/>
62      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
63      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
64      * will be out of sync with that System property.
65      * </p>
66      *
67      * @since Java 1.1
68      */

69     public static final String JavaDoc FILE_SEPARATOR = getSystemProperty("file.separator");
70
71     /**
72      * <p>The <code>java.awt.fonts</code> System Property.</p>
73      * <p/>
74      * <p>Defaults to <code>null</code> if the runtime does not have
75      * security access to read this property or the property does not exist.</p>
76      * <p/>
77      * <p/>
78      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
79      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
80      * will be out of sync with that System property.
81      * </p>
82      *
83      * @since 2.1
84      */

85     public static final String JavaDoc JAVA_AWT_FONTS = getSystemProperty("java.awt.fonts");
86
87     /**
88      * <p>The <code>java.class.path</code> System Property. Java class path.</p>
89      * <p/>
90      * <p>Defaults to <code>null</code> if the runtime does not have
91      * security access to read this property or the property does not exist.</p>
92      * <p/>
93      * <p/>
94      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
95      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
96      * will be out of sync with that System property.
97      * </p>
98      *
99      * @since Java 1.1
100      */

101     public static final String JavaDoc JAVA_CLASS_PATH = getSystemProperty("java.class.path");
102
103     /**
104      * <p>The <code>java.class.version</code> System Property.
105      * Java class format version number.</p>
106      * <p/>
107      * <p>Defaults to <code>null</code> if the runtime does not have
108      * security access to read this property or the property does not exist.</p>
109      * <p/>
110      * <p/>
111      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
112      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
113      * will be out of sync with that System property.
114      * </p>
115      *
116      * @since Java 1.1
117      */

118     public static final String JavaDoc JAVA_CLASS_VERSION = getSystemProperty("java.class.version");
119
120     /**
121      * <p>The <code>java.compiler</code> System Property. Name of JIT compiler to use.
122      * First in JDK version 1.2. Not used in Sun JDKs after 1.2.</p>
123      * <p/>
124      * <p>Defaults to <code>null</code> if the runtime does not have
125      * security access to read this property or the property does not exist.</p>
126      * <p/>
127      * <p/>
128      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
129      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
130      * will be out of sync with that System property.
131      * </p>
132      *
133      * @since Java 1.2. Not used in Sun versions after 1.2.
134      */

135     public static final String JavaDoc JAVA_COMPILER = getSystemProperty("java.compiler");
136
137     /**
138      * <p>The <code>java.endorsed.dirs</code> System Property. Path of endorsed directory
139      * or directories.</p>
140      * <p/>
141      * <p>Defaults to <code>null</code> if the runtime does not have
142      * security access to read this property or the property does not exist.</p>
143      * <p/>
144      * <p/>
145      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
146      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
147      * will be out of sync with that System property.
148      * </p>
149      *
150      * @since Java 1.4
151      */

152     public static final String JavaDoc JAVA_ENDORSED_DIRS = getSystemProperty("java.endorsed.dirs");
153
154     /**
155      * <p>The <code>java.ext.dirs</code> System Property. Path of extension directory
156      * or directories.</p>
157      * <p/>
158      * <p>Defaults to <code>null</code> if the runtime does not have
159      * security access to read this property or the property does not exist.</p>
160      * <p/>
161      * <p/>
162      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
163      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
164      * will be out of sync with that System property.
165      * </p>
166      *
167      * @since Java 1.3
168      */

169     public static final String JavaDoc JAVA_EXT_DIRS = getSystemProperty("java.ext.dirs");
170
171     /**
172      * <p>The <code>java.home</code> System Property. Java installation directory.</p>
173      * <p/>
174      * <p>Defaults to <code>null</code> if the runtime does not have
175      * security access to read this property or the property does not exist.</p>
176      * <p/>
177      * <p/>
178      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
179      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
180      * will be out of sync with that System property.
181      * </p>
182      *
183      * @since Java 1.1
184      */

185     public static final String JavaDoc JAVA_HOME = getSystemProperty(JAVA_HOME_KEY);
186
187     /**
188      * <p>The <code>java.io.tmpdir</code> System Property. Default temp file path.</p>
189      * <p/>
190      * <p>Defaults to <code>null</code> if the runtime does not have
191      * security access to read this property or the property does not exist.</p>
192      * <p/>
193      * <p/>
194      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
195      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
196      * will be out of sync with that System property.
197      * </p>
198      *
199      * @since Java 1.2
200      */

201     public static final String JavaDoc JAVA_IO_TMPDIR = getSystemProperty(JAVA_IO_TMPDIR_KEY);
202
203     /**
204      * <p>The <code>java.library.path</code> System Property. List of paths to search
205      * when loading libraries.</p>
206      * <p/>
207      * <p>Defaults to <code>null</code> if the runtime does not have
208      * security access to read this property or the property does not exist.</p>
209      * <p/>
210      * <p/>
211      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
212      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
213      * will be out of sync with that System property.
214      * </p>
215      *
216      * @since Java 1.2
217      */

218     public static final String JavaDoc JAVA_LIBRARY_PATH = getSystemProperty("java.library.path");
219
220     /**
221      * <p>The <code>java.runtime.name</code> System Property. Java Runtime Environment
222      * name.</p>
223      * <p/>
224      * <p>Defaults to <code>null</code> if the runtime does not have
225      * security access to read this property or the property does not exist.</p>
226      * <p/>
227      * <p/>
228      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
229      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
230      * will be out of sync with that System property.
231      * </p>
232      *
233      * @since Java 1.3
234      */

235     public static final String JavaDoc JAVA_RUNTIME_NAME = getSystemProperty("java.runtime.name");
236
237     /**
238      * <p>The <code>java.runtime.version</code> System Property. Java Runtime Environment
239      * version.</p>
240      * <p/>
241      * <p>Defaults to <code>null</code> if the runtime does not have
242      * security access to read this property or the property does not exist.</p>
243      * <p/>
244      * <p/>
245      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
246      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
247      * will be out of sync with that System property.
248      * </p>
249      *
250      * @since Java 1.3
251      */

252     public static final String JavaDoc JAVA_RUNTIME_VERSION = getSystemProperty("java.runtime.version");
253
254     /**
255      * <p>The <code>java.specification.name</code> System Property. Java Runtime Environment
256      * specification name.</p>
257      * <p/>
258      * <p>Defaults to <code>null</code> if the runtime does not have
259      * security access to read this property or the property does not exist.</p>
260      * <p/>
261      * <p/>
262      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
263      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
264      * will be out of sync with that System property.
265      * </p>
266      *
267      * @since Java 1.2
268      */

269     public static final String JavaDoc JAVA_SPECIFICATION_NAME = getSystemProperty("java.specification.name");
270
271     /**
272      * <p>The <code>java.specification.vendor</code> System Property. Java Runtime Environment
273      * specification vendor.</p>
274      * <p/>
275      * <p>Defaults to <code>null</code> if the runtime does not have
276      * security access to read this property or the property does not exist.</p>
277      * <p/>
278      * <p/>
279      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
280      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
281      * will be out of sync with that System property.
282      * </p>
283      *
284      * @since Java 1.2
285      */

286     public static final String JavaDoc JAVA_SPECIFICATION_VENDOR = getSystemProperty("java.specification.vendor");
287
288     /**
289      * <p>The <code>java.specification.version</code> System Property. Java Runtime Environment
290      * specification version.</p>
291      * <p/>
292      * <p>Defaults to <code>null</code> if the runtime does not have
293      * security access to read this property or the property does not exist.</p>
294      * <p/>
295      * <p/>
296      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
297      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
298      * will be out of sync with that System property.
299      * </p>
300      *
301      * @since Java 1.3
302      */

303     public static final String JavaDoc JAVA_SPECIFICATION_VERSION = getSystemProperty("java.specification.version");
304
305     /**
306      * <p>The <code>java.util.prefs.PreferencesFactory</code> System Property. A class name.</p>
307      * <p/>
308      * <p>Defaults to <code>null</code> if the runtime does not have
309      * security access to read this property or the property does not exist.</p>
310      * <p/>
311      * <p/>
312      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
313      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
314      * will be out of sync with that System property.
315      * </p>
316      *
317      * @since Java 1.4
318      */

319     public static final String JavaDoc JAVA_UTIL_PREFS_PREFERENCES_FACTORY = getSystemProperty("java.util.prefs.PreferencesFactory");
320
321     /**
322      * <p>The <code>java.vendor</code> System Property. Java vendor-specific string.</p>
323      * <p/>
324      * <p>Defaults to <code>null</code> if the runtime does not have
325      * security access to read this property or the property does not exist.</p>
326      * <p/>
327      * <p/>
328      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
329      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
330      * will be out of sync with that System property.
331      * </p>
332      *
333      * @since Java 1.1
334      */

335     public static final String JavaDoc JAVA_VENDOR = getSystemProperty("java.vendor");
336
337     /**
338      * <p>The <code>java.vendor.url</code> System Property. Java vendor URL.</p>
339      * <p/>
340      * <p>Defaults to <code>null</code> if the runtime does not have
341      * security access to read this property or the property does not exist.</p>
342      * <p/>
343      * <p/>
344      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
345      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
346      * will be out of sync with that System property.
347      * </p>
348      *
349      * @since Java 1.1
350      */

351     public static final String JavaDoc JAVA_VENDOR_URL = getSystemProperty("java.vendor.url");
352
353     /**
354      * <p>The <code>java.version</code> System Property. Java version number.</p>
355      * <p/>
356      * <p>Defaults to <code>null</code> if the runtime does not have
357      * security access to read this property or the property does not exist.</p>
358      * <p/>
359      * <p/>
360      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
361      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
362      * will be out of sync with that System property.
363      * </p>
364      *
365      * @since Java 1.1
366      */

367     public static final String JavaDoc JAVA_VERSION = getSystemProperty("java.version");
368
369     /**
370      * <p>The <code>java.vm.info</code> System Property. Java Virtual Machine implementation
371      * info.</p>
372      * <p/>
373      * <p>Defaults to <code>null</code> if the runtime does not have
374      * security access to read this property or the property does not exist.</p>
375      * <p/>
376      * <p/>
377      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
378      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
379      * will be out of sync with that System property.
380      * </p>
381      *
382      * @since Java 1.2
383      */

384     public static final String JavaDoc JAVA_VM_INFO = getSystemProperty("java.vm.info");
385
386     /**
387      * <p>The <code>java.vm.name</code> System Property. Java Virtual Machine implementation
388      * name.</p>
389      * <p/>
390      * <p>Defaults to <code>null</code> if the runtime does not have
391      * security access to read this property or the property does not exist.</p>
392      * <p/>
393      * <p/>
394      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
395      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
396      * will be out of sync with that System property.
397      * </p>
398      *
399      * @since Java 1.2
400      */

401     public static final String JavaDoc JAVA_VM_NAME = getSystemProperty("java.vm.name");
402
403     /**
404      * <p>The <code>java.vm.specification.name</code> System Property. Java Virtual Machine
405      * specification name.</p>
406      * <p/>
407      * <p>Defaults to <code>null</code> if the runtime does not have
408      * security access to read this property or the property does not exist.</p>
409      * <p/>
410      * <p/>
411      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
412      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
413      * will be out of sync with that System property.
414      * </p>
415      *
416      * @since Java 1.2
417      */

418     public static final String JavaDoc JAVA_VM_SPECIFICATION_NAME = getSystemProperty("java.vm.specification.name");
419
420     /**
421      * <p>The <code>java.vm.specification.vendor</code> System Property. Java Virtual
422      * Machine specification vendor.</p>
423      * <p/>
424      * <p>Defaults to <code>null</code> if the runtime does not have
425      * security access to read this property or the property does not exist.</p>
426      * <p/>
427      * <p/>
428      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
429      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
430      * will be out of sync with that System property.
431      * </p>
432      *
433      * @since Java 1.2
434      */

435     public static final String JavaDoc JAVA_VM_SPECIFICATION_VENDOR = getSystemProperty("java.vm.specification.vendor");
436
437     /**
438      * <p>The <code>java.vm.specification.version</code> System Property. Java Virtual Machine
439      * specification version.</p>
440      * <p/>
441      * <p>Defaults to <code>null</code> if the runtime does not have
442      * security access to read this property or the property does not exist.</p>
443      * <p/>
444      * <p/>
445      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
446      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
447      * will be out of sync with that System property.
448      * </p>
449      *
450      * @since Java 1.2
451      */

452     public static final String JavaDoc JAVA_VM_SPECIFICATION_VERSION = getSystemProperty("java.vm.specification.version");
453
454     /**
455      * <p>The <code>java.vm.vendor</code> System Property. Java Virtual Machine implementation
456      * vendor.</p>
457      * <p/>
458      * <p>Defaults to <code>null</code> if the runtime does not have
459      * security access to read this property or the property does not exist.</p>
460      * <p/>
461      * <p/>
462      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
463      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
464      * will be out of sync with that System property.
465      * </p>
466      *
467      * @since Java 1.2
468      */

469     public static final String JavaDoc JAVA_VM_VENDOR = getSystemProperty("java.vm.vendor");
470
471     /**
472      * <p>The <code>java.vm.version</code> System Property. Java Virtual Machine
473      * implementation version.</p>
474      * <p/>
475      * <p>Defaults to <code>null</code> if the runtime does not have
476      * security access to read this property or the property does not exist.</p>
477      * <p/>
478      * <p/>
479      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
480      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
481      * will be out of sync with that System property.
482      * </p>
483      *
484      * @since Java 1.2
485      */

486     public static final String JavaDoc JAVA_VM_VERSION = getSystemProperty("java.vm.version");
487
488     /**
489      * <p>The <code>line.separator</code> System Property. Line separator
490      * (<code>&quot;\n<&quot;</code> on UNIX).</p>
491      * <p/>
492      * <p>Defaults to <code>null</code> if the runtime does not have
493      * security access to read this property or the property does not exist.</p>
494      * <p/>
495      * <p/>
496      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
497      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
498      * will be out of sync with that System property.
499      * </p>
500      *
501      * @since Java 1.1
502      */

503     public static final String JavaDoc LINE_SEPARATOR = getSystemProperty("line.separator");
504
505     /**
506      * <p>The <code>os.arch</code> System Property. Operating system architecture.</p>
507      * <p/>
508      * <p>Defaults to <code>null</code> if the runtime does not have
509      * security access to read this property or the property does not exist.</p>
510      * <p/>
511      * <p/>
512      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
513      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
514      * will be out of sync with that System property.
515      * </p>
516      *
517      * @since Java 1.1
518      */

519     public static final String JavaDoc OS_ARCH = getSystemProperty("os.arch");
520
521     /**
522      * <p>The <code>os.name</code> System Property. Operating system name.</p>
523      * <p/>
524      * <p>Defaults to <code>null</code> if the runtime does not have
525      * security access to read this property or the property does not exist.</p>
526      * <p/>
527      * <p/>
528      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
529      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
530      * will be out of sync with that System property.
531      * </p>
532      *
533      * @since Java 1.1
534      */

535     public static final String JavaDoc OS_NAME = getSystemProperty("os.name");
536
537     /**
538      * <p>The <code>os.version</code> System Property. Operating system version.</p>
539      * <p/>
540      * <p>Defaults to <code>null</code> if the runtime does not have
541      * security access to read this property or the property does not exist.</p>
542      * <p/>
543      * <p/>
544      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
545      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
546      * will be out of sync with that System property.
547      * </p>
548      *
549      * @since Java 1.1
550      */

551     public static final String JavaDoc OS_VERSION = getSystemProperty("os.version");
552
553     /**
554      * <p>The <code>path.separator</code> System Property. Path separator
555      * (<code>&quot;:&quot;</code> on UNIX).</p>
556      * <p/>
557      * <p>Defaults to <code>null</code> if the runtime does not have
558      * security access to read this property or the property does not exist.</p>
559      * <p/>
560      * <p/>
561      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
562      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
563      * will be out of sync with that System property.
564      * </p>
565      *
566      * @since Java 1.1
567      */

568     public static final String JavaDoc PATH_SEPARATOR = getSystemProperty("path.separator");
569
570     /**
571      * <p>The <code>user.country</code> or <code>user.region</code> System Property.
572      * User's country code, such as <code>GB</code>. First in JDK version 1.2 as
573      * <code>user.region</code>. Renamed to <code>user.country</code> in 1.4</p>
574      * <p/>
575      * <p>Defaults to <code>null</code> if the runtime does not have
576      * security access to read this property or the property does not exist.</p>
577      * <p/>
578      * <p/>
579      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
580      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
581      * will be out of sync with that System property.
582      * </p>
583      *
584      * @since Java 1.2
585      */

586     public static final String JavaDoc USER_COUNTRY =
587             (getSystemProperty("user.country") == null ?
588             getSystemProperty("user.region") : getSystemProperty("user.country"));
589
590     /**
591      * <p>The <code>user.dir</code> System Property. User's current working
592      * directory.</p>
593      * <p/>
594      * <p>Defaults to <code>null</code> if the runtime does not have
595      * security access to read this property or the property does not exist.</p>
596      * <p/>
597      * <p/>
598      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
599      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
600      * will be out of sync with that System property.
601      * </p>
602      *
603      * @since Java 1.1
604      */

605     public static final String JavaDoc USER_DIR = getSystemProperty(USER_DIR_KEY);
606
607     /**
608      * <p>The <code>user.home</code> System Property. User's home directory.</p>
609      * <p/>
610      * <p>Defaults to <code>null</code> if the runtime does not have
611      * security access to read this property or the property does not exist.</p>
612      * <p/>
613      * <p/>
614      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
615      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
616      * will be out of sync with that System property.
617      * </p>
618      *
619      * @since Java 1.1
620      */

621     public static final String JavaDoc USER_HOME = getSystemProperty(USER_HOME_KEY);
622
623     /**
624      * <p>The <code>user.language</code> System Property. User's language code,
625      * such as <code>"en"</code>.</p>
626      * <p/>
627      * <p>Defaults to <code>null</code> if the runtime does not have
628      * security access to read this property or the property does not exist.</p>
629      * <p/>
630      * <p/>
631      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
632      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
633      * will be out of sync with that System property.
634      * </p>
635      *
636      * @since Java 1.2
637      */

638     public static final String JavaDoc USER_LANGUAGE = getSystemProperty("user.language");
639
640     /**
641      * <p>The <code>user.name</code> System Property. User's account name.</p>
642      * <p/>
643      * <p>Defaults to <code>null</code> if the runtime does not have
644      * security access to read this property or the property does not exist.</p>
645      * <p/>
646      * <p/>
647      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
648      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
649      * will be out of sync with that System property.
650      * </p>
651      *
652      * @since Java 1.1
653      */

654     public static final String JavaDoc USER_NAME = getSystemProperty("user.name");
655
656     /**
657      * <p>The <code>user.timezone</code> System Property.
658      * For example: <code>"America/Los_Angeles"</code>.</p>
659      * <p/>
660      * <p>Defaults to <code>null</code> if the runtime does not have
661      * security access to read this property or the property does not exist.</p>
662      * <p/>
663      * <p/>
664      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
665      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
666      * will be out of sync with that System property.
667      * </p>
668      *
669      * @since 2.1
670      */

671     public static final String JavaDoc USER_TIMEZONE = getSystemProperty("user.timezone");
672
673     // Java version
674
//-----------------------------------------------------------------------
675
// These MUST be declared after those above as they depend on the
676
// values being set up
677

678     /**
679      * <p>Gets the Java version as a <code>float</code>.</p>
680      * <p/>
681      * <p>Example return values:</p>
682      * <ul>
683      * <li><code>1.2f</code> for JDK 1.2
684      * <li><code>1.31f</code> for JDK 1.3.1
685      * </ul>
686      * <p/>
687      * <p>The field will return zero if {@link #JAVA_VERSION} is <code>null</code>.</p>
688      *
689      * @since 2.0
690      */

691     public static final float JAVA_VERSION_FLOAT = getJavaVersionAsFloat();
692
693     /**
694      * <p>Gets the Java version as an <code>int</code>.</p>
695      * <p/>
696      * <p>Example return values:</p>
697      * <ul>
698      * <li><code>120</code> for JDK 1.2
699      * <li><code>131</code> for JDK 1.3.1
700      * </ul>
701      * <p/>
702      * <p>The field will return zero if {@link #JAVA_VERSION} is <code>null</code>.</p>
703      *
704      * @since 2.0
705      */

706     public static final int JAVA_VERSION_INT = getJavaVersionAsInt();
707
708     // Java version checks
709
//-----------------------------------------------------------------------
710
// These MUST be declared after those above as they depend on the
711
// values being set up
712

713     /**
714      * <p>Is <code>true</code> if this is Java version 1.1 (also 1.1.x versions).</p>
715      * <p/>
716      * <p>The field will return <code>false</code> if {@link #JAVA_VERSION} is
717      * <code>null</code>.</p>
718      */

719     public static final boolean IS_JAVA_1_1 = getJavaVersionMatches("1.1");
720
721     /**
722      * <p>Is <code>true</code> if this is Java version 1.2 (also 1.2.x versions).</p>
723      * <p/>
724      * <p>The field will return <code>false</code> if {@link #JAVA_VERSION} is
725      * <code>null</code>.</p>
726      */

727     public static final boolean IS_JAVA_1_2 = getJavaVersionMatches("1.2");
728
729     /**
730      * <p>Is <code>true</code> if this is Java version 1.3 (also 1.3.x versions).</p>
731      * <p/>
732      * <p>The field will return <code>false</code> if {@link #JAVA_VERSION} is
733      * <code>null</code>.</p>
734      */

735     public static final boolean IS_JAVA_1_3 = getJavaVersionMatches("1.3");
736
737     /**
738      * <p>Is <code>true</code> if this is Java version 1.4 (also 1.4.x versions).</p>
739      * <p/>
740      * <p>The field will return <code>false</code> if {@link #JAVA_VERSION} is
741      * <code>null</code>.</p>
742      */

743     public static final boolean IS_JAVA_1_4 = getJavaVersionMatches("1.4");
744
745     /**
746      * <p>Is <code>true</code> if this is Java version 1.5 (also 1.5.x versions).</p>
747      * <p/>
748      * <p>The field will return <code>false</code> if {@link #JAVA_VERSION} is
749      * <code>null</code>.</p>
750      */

751     public static final boolean IS_JAVA_1_5 = getJavaVersionMatches("1.5");
752
753     // Operating system checks
754
//-----------------------------------------------------------------------
755
// These MUST be declared after those above as they depend on the
756
// values being set up
757
// OS names from http://www.vamphq.com/os.html
758
// Selected ones included - please advise commons-dev@jakarta.apache.org
759
// if you want another added or a mistake corrected
760

761     /**
762      * <p>Is <code>true</code> if this is AIX.</p>
763      * <p/>
764      * <p>The field will return <code>false</code> if <code>OS_NAME</code> is
765      * <code>null</code>.</p>
766      *
767      * @since 2.0
768      */

769     public static final boolean IS_OS_AIX = getOSMatches("AIX");
770
771     /**
772      * <p>Is <code>true</code> if this is HP-UX.</p>
773      * <p/>
774      * <p>The field will return <code>false</code> if <code>OS_NAME</code> is
775      * <code>null</code>.</p>
776      *
777      * @since 2.0
778      */

779     public static final boolean IS_OS_HP_UX = getOSMatches("HP-UX");
780
781     /**
782      * <p>Is <code>true</code> if this is Irix.</p>
783      * <p/>
784      * <p>The field will return <code>false</code> if <code>OS_NAME</code> is
785      * <code>null</code>.</p>
786      *
787      * @since 2.0
788      */

789     public static final boolean IS_OS_IRIX = getOSMatches("Irix");
790
791     /**
792      * <p>Is <code>true</code> if this is Linux.</p>
793      * <p/>
794      * <p>The field will return <code>false</code> if <code>OS_NAME</code> is
795      * <code>null</code>.</p>
796      *
797      * @since 2.0
798      */

799     public static final boolean IS_OS_LINUX = getOSMatches("Linux") || getOSMatches("LINUX");
800
801     /**
802      * <p>Is <code>true</code> if this is Mac.</p>
803      * <p/>
804      * <p>The field will return <code>false</code> if <code>OS_NAME</code> is
805      * <code>null</code>.</p>
806      *
807      * @since 2.0
808      */

809     public static final boolean IS_OS_MAC = getOSMatches("Mac");
810
811     /**
812      * <p>Is <code>true</code> if this is Mac.</p>
813      * <p/>
814      * <p>The field will return <code>false</code> if <code>OS_NAME</code> is
815      * <code>null</code>.</p>
816      *
817      * @since 2.0
818      */

819     public static final boolean IS_OS_MAC_OSX = getOSMatches("Mac OS X");
820
821     /**
822      * <p>Is <code>true</code> if this is OS/2.</p>
823      * <p/>
824      * <p>The field will return <code>false</code> if <code>OS_NAME</code> is
825      * <code>null</code>.</p>
826      *
827      * @since 2.0
828      */

829     public static final boolean IS_OS_OS2 = getOSMatches("OS/2");
830
831     /**
832      * <p>Is <code>true</code> if this is Solaris.</p>
833      * <p/>
834      * <p>The field will return <code>false</code> if <code>OS_NAME</code> is
835      * <code>null</code>.</p>
836      *
837      * @since 2.0
838      */

839     public static final boolean IS_OS_SOLARIS = getOSMatches("Solaris");
840
841     /**
842      * <p>Is <code>true</code> if this is SunOS.</p>
843      * <p/>
844      * <p>The field will return <code>false</code> if <code>OS_NAME</code> is
845      * <code>null</code>.</p>
846      *
847      * @since 2.0
848      */

849     public static final boolean IS_OS_SUN_OS = getOSMatches("SunOS");
850
851     /**
852      * <p>Is <code>true</code> if this is a POSIX compilant system,
853      * as in any of AIX, HP-UX, Irix, Linux, MacOSX, Solaris or SUN OS.</p>
854      * <p/>
855      * <p>The field will return <code>false</code> if <code>OS_NAME</code> is
856      * <code>null</code>.</p>
857      *
858      * @since 2.1
859      */

860     public static final boolean IS_OS_UNIX =
861             IS_OS_AIX || IS_OS_HP_UX || IS_OS_IRIX || IS_OS_LINUX ||
862             IS_OS_MAC_OSX || IS_OS_SOLARIS || IS_OS_SUN_OS;
863
864     /**
865      * <p>Is <code>true</code> if this is Windows.</p>
866      * <p/>
867      * <p>The field will return <code>false</code> if <code>OS_NAME</code> is
868      * <code>null</code>.</p>
869      *
870      * @since 2.0
871      */

872     public static final boolean IS_OS_WINDOWS = getOSMatches("Windows");
873
874     /**
875      * <p>Is <code>true</code> if this is Windows 2000.</p>
876      * <p/>
877      * <p>The field will return <code>false</code> if <code>OS_NAME</code> is
878      * <code>null</code>.</p>
879      *
880      * @since 2.0
881      */

882     public static final boolean IS_OS_WINDOWS_2000 = getOSMatches("Windows", "5.0");
883
884     /**
885      * <p>Is <code>true</code> if this is Windows 95.</p>
886      * <p/>
887      * <p>The field will return <code>false</code> if <code>OS_NAME</code> is
888      * <code>null</code>.</p>
889      *
890      * @since 2.0
891      */

892     public static final boolean IS_OS_WINDOWS_95 = getOSMatches("Windows 9", "4.0");
893     // JDK 1.2 running on Windows98 returns 'Windows 95', hence the above
894

895     /**
896      * <p>Is <code>true</code> if this is Windows 98.</p>
897      * <p/>
898      * <p>The field will return <code>false</code> if <code>OS_NAME</code> is
899      * <code>null</code>.</p>
900      *
901      * @since 2.0
902      */

903     public static final boolean IS_OS_WINDOWS_98 = getOSMatches("Windows 9", "4.1");
904     // JDK 1.2 running on Windows98 returns 'Windows 95', hence the above
905

906     /**
907      * <p>Is <code>true</code> if this is Windows ME.</p>
908      * <p/>
909      * <p>The field will return <code>false</code> if <code>OS_NAME</code> is
910      * <code>null</code>.</p>
911      *
912      * @since 2.0
913      */

914     public static final boolean IS_OS_WINDOWS_ME = getOSMatches("Windows", "4.9");
915     // JDK 1.2 running on WindowsME may return 'Windows 95', hence the above
916

917     /**
918      * <p>Is <code>true</code> if this is Windows NT.</p>
919      * <p/>
920      * <p>The field will return <code>false</code> if <code>OS_NAME</code> is
921      * <code>null</code>.</p>
922      *
923      * @since 2.0
924      */

925     public static final boolean IS_OS_WINDOWS_NT = getOSMatches("Windows NT");
926     // Windows 2000 returns 'Windows 2000' but may suffer from same JDK1.2 problem
927

928     /**
929      * <p>Is <code>true</code> if this is Windows XP.</p>
930      * <p/>
931      * <p>The field will return <code>false</code> if <code>OS_NAME</code> is
932      * <code>null</code>.</p>
933      *
934      * @since 2.0
935      */

936     public static final boolean IS_OS_WINDOWS_XP = getOSMatches("Windows", "5.1");
937     // Windows XP returns 'Windows 2000' just for fun...
938

939     //-----------------------------------------------------------------------
940
/**
941      * <p>SystemUtils instances should NOT be constructed in standard
942      * programming. Instead, the class should be used as
943      * <code>SystemUtils.FILE_SEPARATOR</code>.</p>
944      * <p/>
945      * <p>This constructor is public to permit tools that require a JavaBean
946      * instance to operate.</p>
947      */

948     public Systems() {
949         // no init.
950
}
951
952     //-----------------------------------------------------------------------
953
/**
954      * <p>Gets the Java version number as a <code>float</code>.</p>
955      * <p/>
956      * <p>Example return values:</p>
957      * <ul>
958      * <li><code>1.2f</code> for JDK 1.2
959      * <li><code>1.31f</code> for JDK 1.3.1
960      * </ul>
961      *
962      * @return the version, for example 1.31f for JDK 1.3.1
963      * @deprecated Use {@link #JAVA_VERSION_FLOAT} instead.
964      * Method will be removed in Commons Lang 3.0.
965      */

966     public static float getJavaVersion() {
967         return JAVA_VERSION_FLOAT;
968     }
969
970     /**
971      * <p>Gets the Java version number as a <code>float</code>.</p>
972      * <p/>
973      * <p>Example return values:</p>
974      * <ul>
975      * <li><code>1.2f</code> for JDK 1.2
976      * <li><code>1.31f</code> for JDK 1.3.1
977      * </ul>
978      * <p/>
979      * <p>Patch releases are not reported.
980      * Zero is returned if {@link #JAVA_VERSION} is <code>null</code>.</p>
981      *
982      * @return the version, for example 1.31f for JDK 1.3.1
983      */

984     private static float getJavaVersionAsFloat() {
985         if(JAVA_VERSION == null) {
986             return 0f;
987         }
988         String JavaDoc str = JAVA_VERSION.substring(0, 3);
989         if(JAVA_VERSION.length() >= 5) {
990             str = str + JAVA_VERSION.substring(4, 5);
991         }
992         return Float.parseFloat(str);
993     }
994
995     /**
996      * <p>Gets the Java version number as an <code>int</code>.</p>
997      * <p/>
998      * <p>Example return values:</p>
999      * <ul>
1000     * <li><code>120</code> for JDK 1.2
1001     * <li><code>131</code> for JDK 1.3.1
1002     * </ul>
1003     * <p/>
1004     * <p>Patch releases are not reported.
1005     * Zero is returned if {@link #JAVA_VERSION} is <code>null</code>.</p>
1006     *
1007     * @return the version, for example 131 for JDK 1.3.1
1008     */

1009    private static int getJavaVersionAsInt() {
1010        if(JAVA_VERSION == null) {
1011            return 0;
1012        }
1013        String JavaDoc str = JAVA_VERSION.substring(0, 1);
1014        str = str + JAVA_VERSION.substring(2, 3);
1015        if(JAVA_VERSION.length() >= 5) {
1016            str = str + JAVA_VERSION.substring(4, 5);
1017        }
1018        else {
1019            str = str + "0";
1020        }
1021        return Integer.parseInt(str);
1022    }
1023
1024    /**
1025     * <p>Decides if the java version matches.</p>
1026     *
1027     * @param versionPrefix the prefix for the java version
1028     * @return true if matches, or false if not or can't determine
1029     */

1030    private static boolean getJavaVersionMatches(String JavaDoc versionPrefix) {
1031        if(JAVA_VERSION == null) {
1032            return false;
1033        }
1034        return JAVA_VERSION.startsWith(versionPrefix);
1035    }
1036
1037    /**
1038     * <p>Decides if the operating system matches.</p>
1039     *
1040     * @param osNamePrefix the prefix for the os name
1041     * @return true if matches, or false if not or can't determine
1042     */

1043    private static boolean getOSMatches(String JavaDoc osNamePrefix) {
1044        if(OS_NAME == null) {
1045            return false;
1046        }
1047        return OS_NAME.startsWith(osNamePrefix);
1048    }
1049
1050    /**
1051     * <p>Decides if the operating system matches.</p>
1052     *
1053     * @param osNamePrefix the prefix for the os name
1054     * @param osVersionPrefix the prefix for the version
1055     * @return true if matches, or false if not or can't determine
1056     */

1057    private static boolean getOSMatches(String JavaDoc osNamePrefix, String JavaDoc osVersionPrefix) {
1058        if(OS_NAME == null || OS_VERSION == null) {
1059            return false;
1060        }
1061        return OS_NAME.startsWith(osNamePrefix) && OS_VERSION.startsWith(osVersionPrefix);
1062    }
1063
1064    //-----------------------------------------------------------------------
1065
/**
1066     * <p>Gets a System property, defaulting to <code>null</code> if the property
1067     * cannot be read.</p>
1068     * <p/>
1069     * <p>If a <code>SecurityException</code> is caught, the return
1070     * value is <code>null</code> and a message is written to <code>System.err</code>.</p>
1071     *
1072     * @param property the system property name
1073     * @return the system property value or <code>null</code> if a security problem occurs
1074     */

1075    private static String JavaDoc getSystemProperty(String JavaDoc property) {
1076        try {
1077            return System.getProperty(property);
1078        }
1079        catch(SecurityException JavaDoc ex) {
1080            // we are not allowed to look at this property
1081
System.err.println("Caught a SecurityException reading the system property '" + property
1082                    + "'; the SystemUtils property value will default to null.");
1083            return null;
1084        }
1085    }
1086
1087    /**
1088     * <p>Is the Java version at least the requested version.</p>
1089     * <p/>
1090     * <p>Example input:</p>
1091     * <ul>
1092     * <li><code>1.2f</code> to test for JDK 1.2</li>
1093     * <li><code>1.31f</code> to test for JDK 1.3.1</li>
1094     * </ul>
1095     *
1096     * @param requiredVersion the required version, for example 1.31f
1097     * @return <code>true</code> if the actual version is equal or greater
1098     * than the required version
1099     */

1100    public static boolean isJavaVersionAtLeast(float requiredVersion) {
1101        return (JAVA_VERSION_FLOAT >= requiredVersion);
1102    }
1103
1104    /**
1105     * <p>Is the Java version at least the requested version.</p>
1106     * <p/>
1107     * <p>Example input:</p>
1108     * <ul>
1109     * <li><code>120</code> to test for JDK 1.2 or greater</li>
1110     * <li><code>131</code> to test for JDK 1.3.1 or greater</li>
1111     * </ul>
1112     *
1113     * @param requiredVersion the required version, for example 131
1114     * @return <code>true</code> if the actual version is equal or greater
1115     * than the required version
1116     * @since 2.0
1117     */

1118    public static boolean isJavaVersionAtLeast(int requiredVersion) {
1119        return (JAVA_VERSION_INT >= requiredVersion);
1120    }
1121
1122    /**
1123     * <p>Gets the Java home directory as a <code>File</code>.</p>
1124     *
1125     * @return a directory
1126     * @throws SecurityException if a security manager exists and its
1127     * <code>checkPropertyAccess</code> method doesn't allow
1128     * access to the specified system property.
1129     * @see System#getProperty(String)
1130     */

1131    public static File JavaDoc getJavaHome() {
1132        return new File JavaDoc(System.getProperty(JAVA_HOME_KEY));
1133    }
1134
1135    /**
1136     * <p>Gets the Java IO temporary directory as a <code>File</code>.</p>
1137     *
1138     * @return a directory
1139     * @throws SecurityException if a security manager exists and its
1140     * <code>checkPropertyAccess</code> method doesn't allow
1141     * access to the specified system property.
1142     * @see System#getProperty(String)
1143     */

1144    public static File JavaDoc getJavaIoTmpDir() {
1145        return new File JavaDoc(System.getProperty(JAVA_IO_TMPDIR_KEY));
1146    }
1147
1148    /**
1149     * <p>Gets the user directory as a <code>File</code>.</p>
1150     *
1151     * @return a directory
1152     * @throws SecurityException if a security manager exists and its
1153     * <code>checkPropertyAccess</code> method doesn't allow
1154     * access to the specified system property.
1155     * @see System#getProperty(String)
1156     */

1157    public static File JavaDoc getUserDir() {
1158        return new File JavaDoc(System.getProperty(USER_DIR_KEY));
1159    }
1160
1161    /**
1162     * <p>Gets the user home directory as a <code>File</code>.</p>
1163     *
1164     * @return a directory
1165     * @throws SecurityException if a security manager exists and its
1166     * <code>checkPropertyAccess</code> method doesn't allow
1167     * access to the specified system property.
1168     * @see System#getProperty(String)
1169     */

1170    public static File JavaDoc getUserHome() {
1171        return new File JavaDoc(System.getProperty(USER_HOME_KEY));
1172    }
1173
1174    public static void main(String JavaDoc[] args) {
1175
1176    }
1177}
1178
1179
Popular Tags