Source Code Cross Referenced for SystemUtils.java in  » Library » Apache-common-lang » org » apache » commons » lang » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Library » Apache common lang » org.apache.commons.lang 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * Licensed to the Apache Software Foundation (ASF) under one or more
0003:         * contributor license agreements.  See the NOTICE file distributed with
0004:         * this work for additional information regarding copyright ownership.
0005:         * The ASF licenses this file to You under the Apache License, Version 2.0
0006:         * (the "License"); you may not use this file except in compliance with
0007:         * the License.  You may obtain a copy of the License at
0008:         * 
0009:         *      http://www.apache.org/licenses/LICENSE-2.0
0010:         * 
0011:         * Unless required by applicable law or agreed to in writing, software
0012:         * distributed under the License is distributed on an "AS IS" BASIS,
0013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014:         * See the License for the specific language governing permissions and
0015:         * limitations under the License.
0016:         */
0017:        package org.apache.commons.lang;
0018:
0019:        import java.io.File;
0020:
0021:        /**
0022:         * <p>Helpers for <code>java.lang.System</code>.</p>
0023:         * 
0024:         * <p>If a system property cannot be read due to security restrictions, 
0025:         * the corresponding field in this class will be set to <code>null</code>
0026:         * and a message will be written to <code>System.err</code>.</p>
0027:         *
0028:         * @author Based on code from Avalon Excalibur
0029:         * @author Based on code from Lucene
0030:         * @author Stephen Colebourne
0031:         * @author <a href="mailto:sdowney@panix.com">Steve Downey</a>
0032:         * @author Gary Gregory
0033:         * @author Michael Becke
0034:         * @author Tetsuya Kaneuchi
0035:         * @author Rafal Krupinski
0036:         * @author Jason Gritman
0037:         * @since 1.0
0038:         * @version $Id: SystemUtils.java 437554 2006-08-28 06:21:41Z bayard $
0039:         */
0040:        public class SystemUtils {
0041:
0042:            /**
0043:             * The prefix String for all Windows OS.
0044:             */
0045:            private static final String OS_NAME_WINDOWS_PREFIX = "Windows";
0046:
0047:            // System property constants
0048:            //-----------------------------------------------------------------------
0049:            // These MUST be declared first. Other constants depend on this.
0050:
0051:            /**
0052:             * The System property key for the user home directory.
0053:             */
0054:            private static final String USER_HOME_KEY = "user.home";
0055:
0056:            /**
0057:             * The System property key for the user directory.
0058:             */
0059:            private static final String USER_DIR_KEY = "user.dir";
0060:
0061:            /**
0062:             * The System property key for the Java IO temporary directory.
0063:             */
0064:            private static final String JAVA_IO_TMPDIR_KEY = "java.io.tmpdir";
0065:
0066:            /**
0067:             * The System property key for the Java home directory.
0068:             */
0069:            private static final String JAVA_HOME_KEY = "java.home";
0070:
0071:            /**
0072:             * <p>The <code>awt.toolkit</code> System Property.</p>
0073:             * <p>Holds a class name, on Windows XP this is <code>sun.awt.windows.WToolkit</code>.</p>
0074:             * <p><b>On platforms without a GUI, this value is <code>null</code>.</b></p>
0075:             * 
0076:             * <p>Defaults to <code>null</code> if the runtime does not have
0077:             * security access to read this property or the property does not exist.</p>
0078:             * 
0079:             * <p>
0080:             * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
0081:             * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
0082:             * will be out of sync with that System property.
0083:             * </p>
0084:             * 
0085:             * @since 2.1
0086:             */
0087:            public static final String AWT_TOOLKIT = getSystemProperty("awt.toolkit");
0088:
0089:            /**
0090:             * <p>The <code>file.encoding</code> System Property.</p>
0091:             * <p>File encoding, such as <code>Cp1252</code>.</p>
0092:             * 
0093:             * <p>Defaults to <code>null</code> if the runtime does not have
0094:             * security access to read this property or the property does not exist.</p>
0095:             * 
0096:             * <p>
0097:             * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
0098:             * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
0099:             * will be out of sync with that System property.
0100:             * </p>
0101:             * 
0102:             * @since 2.0
0103:             * @since Java 1.2
0104:             */
0105:            public static final String FILE_ENCODING = getSystemProperty("file.encoding");
0106:
0107:            /**
0108:             * <p>The <code>file.separator</code> System Property.
0109:             * File separator (<code>&quot;/&quot;</code> on UNIX).</p>
0110:             *
0111:             * <p>Defaults to <code>null</code> if the runtime does not have
0112:             * security access to read this property or the property does not exist.</p>
0113:             * 
0114:             * <p>
0115:             * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
0116:             * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
0117:             * will be out of sync with that System property.
0118:             * </p>
0119:             * 
0120:             * @since Java 1.1
0121:             */
0122:            public static final String FILE_SEPARATOR = getSystemProperty("file.separator");
0123:
0124:            /**
0125:             * <p>The <code>java.awt.fonts</code> System Property.</p>
0126:             *
0127:             * <p>Defaults to <code>null</code> if the runtime does not have
0128:             * security access to read this property or the property does not exist.</p>
0129:             * 
0130:             * <p>
0131:             * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
0132:             * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
0133:             * will be out of sync with that System property.
0134:             * </p>
0135:             * 
0136:             * @since 2.1
0137:             */
0138:            public static final String JAVA_AWT_FONTS = getSystemProperty("java.awt.fonts");
0139:
0140:            /**
0141:             * <p>The <code>java.awt.graphicsenv</code> System Property.</p>
0142:             *
0143:             * <p>Defaults to <code>null</code> if the runtime does not have
0144:             * security access to read this property or the property does not exist.</p>
0145:             * 
0146:             * <p>
0147:             * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
0148:             * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
0149:             * will be out of sync with that System property.
0150:             * </p>
0151:             * 
0152:             * @since 2.1
0153:             */
0154:            public static final String JAVA_AWT_GRAPHICSENV = getSystemProperty("java.awt.graphicsenv");
0155:
0156:            /**
0157:             * <p>
0158:             * The <code>java.awt.headless</code> System Property.
0159:             * The value of this property is the String <code>"true"</code> or <code>"false"</code>. 
0160:             * </p>
0161:             *
0162:             * <p>Defaults to <code>null</code> if the runtime does not have
0163:             * security access to read this property or the property does not exist.</p>
0164:             * 
0165:             * <p>
0166:             * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
0167:             * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
0168:             * will be out of sync with that System property.
0169:             * </p>
0170:             * 
0171:             * @see #isJavaAwtHeadless()
0172:             * @since 2.1
0173:             * @since Java 1.4
0174:             */
0175:            public static final String JAVA_AWT_HEADLESS = getSystemProperty("java.awt.headless");
0176:
0177:            /**
0178:             * <p>The <code>java.awt.printerjob</code> System Property.</p>
0179:             *
0180:             * <p>Defaults to <code>null</code> if the runtime does not have
0181:             * security access to read this property or the property does not exist.</p>
0182:             * 
0183:             * <p>
0184:             * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
0185:             * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
0186:             * will be out of sync with that System property.
0187:             * </p>
0188:             * 
0189:             * @since 2.1
0190:             */
0191:            public static final String JAVA_AWT_PRINTERJOB = getSystemProperty("java.awt.printerjob");
0192:
0193:            /**
0194:             * <p>The <code>java.class.path</code> System Property. Java class path.</p>
0195:             *
0196:             * <p>Defaults to <code>null</code> if the runtime does not have
0197:             * security access to read this property or the property does not exist.</p>
0198:             * 
0199:             * <p>
0200:             * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
0201:             * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
0202:             * will be out of sync with that System property.
0203:             * </p>
0204:             * 
0205:             * @since Java 1.1
0206:             */
0207:            public static final String JAVA_CLASS_PATH = getSystemProperty("java.class.path");
0208:
0209:            /**
0210:             * <p>The <code>java.class.version</code> System Property.
0211:             * Java class format version number.</p>
0212:             *
0213:             * <p>Defaults to <code>null</code> if the runtime does not have
0214:             * security access to read this property or the property does not exist.</p>
0215:             * 
0216:             * <p>
0217:             * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
0218:             * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
0219:             * will be out of sync with that System property.
0220:             * </p>
0221:             * 
0222:             * @since Java 1.1
0223:             */
0224:            public static final String JAVA_CLASS_VERSION = getSystemProperty("java.class.version");
0225:
0226:            /**
0227:             * <p>The <code>java.compiler</code> System Property. Name of JIT compiler to use.
0228:             * First in JDK version 1.2. Not used in Sun JDKs after 1.2.</p>
0229:             *
0230:             * <p>Defaults to <code>null</code> if the runtime does not have
0231:             * security access to read this property or the property does not exist.</p>
0232:             * 
0233:             * <p>
0234:             * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
0235:             * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
0236:             * will be out of sync with that System property.
0237:             * </p>
0238:             * 
0239:             * @since Java 1.2. Not used in Sun versions after 1.2.
0240:             */
0241:            public static final String JAVA_COMPILER = getSystemProperty("java.compiler");
0242:
0243:            /**
0244:             * <p>The <code>java.endorsed.dirs</code> System Property. Path of endorsed directory
0245:             * or directories.</p>
0246:             *
0247:             * <p>Defaults to <code>null</code> if the runtime does not have
0248:             * security access to read this property or the property does not exist.</p>
0249:             * 
0250:             * <p>
0251:             * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
0252:             * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
0253:             * will be out of sync with that System property.
0254:             * </p>
0255:             * 
0256:             * @since Java 1.4
0257:             */
0258:            public static final String JAVA_ENDORSED_DIRS = getSystemProperty("java.endorsed.dirs");
0259:
0260:            /**
0261:             * <p>The <code>java.ext.dirs</code> System Property. Path of extension directory
0262:             * or directories.</p>
0263:             *
0264:             * <p>Defaults to <code>null</code> if the runtime does not have
0265:             * security access to read this property or the property does not exist.</p>
0266:             * 
0267:             * <p>
0268:             * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
0269:             * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
0270:             * will be out of sync with that System property.
0271:             * </p>
0272:             * 
0273:             * @since Java 1.3
0274:             */
0275:            public static final String JAVA_EXT_DIRS = getSystemProperty("java.ext.dirs");
0276:
0277:            /**
0278:             * <p>The <code>java.home</code> System Property. Java installation directory.</p>
0279:             *
0280:             * <p>Defaults to <code>null</code> if the runtime does not have
0281:             * security access to read this property or the property does not exist.</p>
0282:             * 
0283:             * <p>
0284:             * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
0285:             * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
0286:             * will be out of sync with that System property.
0287:             * </p>
0288:             * 
0289:             * @since Java 1.1
0290:             */
0291:            public static final String JAVA_HOME = getSystemProperty(JAVA_HOME_KEY);
0292:
0293:            /**
0294:             * <p>The <code>java.io.tmpdir</code> System Property. Default temp file path.</p>
0295:             *
0296:             * <p>Defaults to <code>null</code> if the runtime does not have
0297:             * security access to read this property or the property does not exist.</p>
0298:             * 
0299:             * <p>
0300:             * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
0301:             * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
0302:             * will be out of sync with that System property.
0303:             * </p>
0304:             * 
0305:             * @since Java 1.2
0306:             */
0307:            public static final String JAVA_IO_TMPDIR = getSystemProperty(JAVA_IO_TMPDIR_KEY);
0308:
0309:            /**
0310:             * <p>The <code>java.library.path</code> System Property. List of paths to search
0311:             * when loading libraries.</p>
0312:             *
0313:             * <p>Defaults to <code>null</code> if the runtime does not have
0314:             * security access to read this property or the property does not exist.</p>
0315:             * 
0316:             * <p>
0317:             * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
0318:             * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
0319:             * will be out of sync with that System property.
0320:             * </p>
0321:             * 
0322:             * @since Java 1.2
0323:             */
0324:            public static final String JAVA_LIBRARY_PATH = getSystemProperty("java.library.path");
0325:
0326:            /**
0327:             * <p>The <code>java.runtime.name</code> System Property. Java Runtime Environment
0328:             * name.</p>
0329:             *
0330:             * <p>Defaults to <code>null</code> if the runtime does not have
0331:             * security access to read this property or the property does not exist.</p>
0332:             * 
0333:             * <p>
0334:             * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
0335:             * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
0336:             * will be out of sync with that System property.
0337:             * </p>
0338:             * 
0339:             * @since 2.0
0340:             * @since Java 1.3
0341:             */
0342:            public static final String JAVA_RUNTIME_NAME = getSystemProperty("java.runtime.name");
0343:
0344:            /**
0345:             * <p>The <code>java.runtime.version</code> System Property. Java Runtime Environment
0346:             * version.</p>
0347:             *
0348:             * <p>Defaults to <code>null</code> if the runtime does not have
0349:             * security access to read this property or the property does not exist.</p>
0350:             * 
0351:             * <p>
0352:             * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
0353:             * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
0354:             * will be out of sync with that System property.
0355:             * </p>
0356:             * 
0357:             * @since 2.0
0358:             * @since Java 1.3
0359:             */
0360:            public static final String JAVA_RUNTIME_VERSION = getSystemProperty("java.runtime.version");
0361:
0362:            /**
0363:             * <p>The <code>java.specification.name</code> System Property. Java Runtime Environment
0364:             * specification name.</p>
0365:             *
0366:             * <p>Defaults to <code>null</code> if the runtime does not have
0367:             * security access to read this property or the property does not exist.</p>
0368:             * 
0369:             * <p>
0370:             * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
0371:             * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
0372:             * will be out of sync with that System property.
0373:             * </p>
0374:             * 
0375:             * @since Java 1.2
0376:             */
0377:            public static final String JAVA_SPECIFICATION_NAME = getSystemProperty("java.specification.name");
0378:
0379:            /**
0380:             * <p>The <code>java.specification.vendor</code> System Property. Java Runtime Environment
0381:             * specification vendor.</p>
0382:             *
0383:             * <p>Defaults to <code>null</code> if the runtime does not have
0384:             * security access to read this property or the property does not exist.</p>
0385:             * 
0386:             * <p>
0387:             * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
0388:             * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
0389:             * will be out of sync with that System property.
0390:             * </p>
0391:             * 
0392:             * @since Java 1.2
0393:             */
0394:            public static final String JAVA_SPECIFICATION_VENDOR = getSystemProperty("java.specification.vendor");
0395:
0396:            /**
0397:             * <p>The <code>java.specification.version</code> System Property. Java Runtime Environment
0398:             * specification version.</p>
0399:             *
0400:             * <p>Defaults to <code>null</code> if the runtime does not have
0401:             * security access to read this property or the property does not exist.</p>
0402:             * 
0403:             * <p>
0404:             * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
0405:             * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
0406:             * will be out of sync with that System property.
0407:             * </p>
0408:             * 
0409:             * @since Java 1.3
0410:             */
0411:            public static final String JAVA_SPECIFICATION_VERSION = getSystemProperty("java.specification.version");
0412:
0413:            /**
0414:             * <p>The <code>java.util.prefs.PreferencesFactory</code> System Property. A class name.</p>
0415:             *
0416:             * <p>Defaults to <code>null</code> if the runtime does not have
0417:             * security access to read this property or the property does not exist.</p>
0418:             * 
0419:             * <p>
0420:             * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
0421:             * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
0422:             * will be out of sync with that System property.
0423:             * </p>
0424:             * 
0425:             * @since 2.1
0426:             * @since Java 1.4
0427:             */
0428:            public static final String JAVA_UTIL_PREFS_PREFERENCES_FACTORY = getSystemProperty("java.util.prefs.PreferencesFactory");
0429:
0430:            /**
0431:             * <p>The <code>java.vendor</code> System Property. Java vendor-specific string.</p>
0432:             *
0433:             * <p>Defaults to <code>null</code> if the runtime does not have
0434:             * security access to read this property or the property does not exist.</p>
0435:             * 
0436:             * <p>
0437:             * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
0438:             * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
0439:             * will be out of sync with that System property.
0440:             * </p>
0441:             * 
0442:             * @since Java 1.1
0443:             */
0444:            public static final String JAVA_VENDOR = getSystemProperty("java.vendor");
0445:
0446:            /**
0447:             * <p>The <code>java.vendor.url</code> System Property. Java vendor URL.</p>
0448:             *
0449:             * <p>Defaults to <code>null</code> if the runtime does not have
0450:             * security access to read this property or the property does not exist.</p>
0451:             * 
0452:             * <p>
0453:             * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
0454:             * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
0455:             * will be out of sync with that System property.
0456:             * </p>
0457:             * 
0458:             * @since Java 1.1
0459:             */
0460:            public static final String JAVA_VENDOR_URL = getSystemProperty("java.vendor.url");
0461:
0462:            /**
0463:             * <p>The <code>java.version</code> System Property. Java version number.</p>
0464:             *
0465:             * <p>Defaults to <code>null</code> if the runtime does not have
0466:             * security access to read this property or the property does not exist.</p>
0467:             * 
0468:             * <p>
0469:             * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
0470:             * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
0471:             * will be out of sync with that System property.
0472:             * </p>
0473:             * 
0474:             * @since Java 1.1
0475:             */
0476:            public static final String JAVA_VERSION = getSystemProperty("java.version");
0477:
0478:            /**
0479:             * <p>The <code>java.vm.info</code> System Property. Java Virtual Machine implementation
0480:             * info.</p>
0481:             *
0482:             * <p>Defaults to <code>null</code> if the runtime does not have
0483:             * security access to read this property or the property does not exist.</p>
0484:             * 
0485:             * <p>
0486:             * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
0487:             * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
0488:             * will be out of sync with that System property.
0489:             * </p>
0490:             * 
0491:             * @since 2.0
0492:             * @since Java 1.2
0493:             */
0494:            public static final String JAVA_VM_INFO = getSystemProperty("java.vm.info");
0495:
0496:            /**
0497:             * <p>The <code>java.vm.name</code> System Property. Java Virtual Machine implementation
0498:             * name.</p>
0499:             *
0500:             * <p>Defaults to <code>null</code> if the runtime does not have
0501:             * security access to read this property or the property does not exist.</p>
0502:             * 
0503:             * <p>
0504:             * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
0505:             * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
0506:             * will be out of sync with that System property.
0507:             * </p>
0508:             * 
0509:             * @since Java 1.2
0510:             */
0511:            public static final String JAVA_VM_NAME = getSystemProperty("java.vm.name");
0512:
0513:            /**
0514:             * <p>The <code>java.vm.specification.name</code> System Property. Java Virtual Machine
0515:             * specification name.</p>
0516:             *
0517:             * <p>Defaults to <code>null</code> if the runtime does not have
0518:             * security access to read this property or the property does not exist.</p>
0519:             * 
0520:             * <p>
0521:             * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
0522:             * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
0523:             * will be out of sync with that System property.
0524:             * </p>
0525:             * 
0526:             * @since Java 1.2
0527:             */
0528:            public static final String JAVA_VM_SPECIFICATION_NAME = getSystemProperty("java.vm.specification.name");
0529:
0530:            /**
0531:             * <p>The <code>java.vm.specification.vendor</code> System Property. Java Virtual
0532:             * Machine specification vendor.</p>
0533:             *
0534:             * <p>Defaults to <code>null</code> if the runtime does not have
0535:             * security access to read this property or the property does not exist.</p>
0536:             * 
0537:             * <p>
0538:             * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
0539:             * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
0540:             * will be out of sync with that System property.
0541:             * </p>
0542:             * 
0543:             * @since Java 1.2
0544:             */
0545:            public static final String JAVA_VM_SPECIFICATION_VENDOR = getSystemProperty("java.vm.specification.vendor");
0546:
0547:            /**
0548:             * <p>The <code>java.vm.specification.version</code> System Property. Java Virtual Machine
0549:             * specification version.</p>
0550:             *
0551:             * <p>Defaults to <code>null</code> if the runtime does not have
0552:             * security access to read this property or the property does not exist.</p>
0553:             * 
0554:             * <p>
0555:             * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
0556:             * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
0557:             * will be out of sync with that System property.
0558:             * </p>
0559:             * 
0560:             * @since Java 1.2
0561:             */
0562:            public static final String JAVA_VM_SPECIFICATION_VERSION = getSystemProperty("java.vm.specification.version");
0563:
0564:            /**
0565:             * <p>The <code>java.vm.vendor</code> System Property. Java Virtual Machine implementation
0566:             * vendor.</p>
0567:             *
0568:             * <p>Defaults to <code>null</code> if the runtime does not have
0569:             * security access to read this property or the property does not exist.</p>
0570:             * 
0571:             * <p>
0572:             * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
0573:             * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
0574:             * will be out of sync with that System property.
0575:             * </p>
0576:             * 
0577:             * @since Java 1.2
0578:             */
0579:            public static final String JAVA_VM_VENDOR = getSystemProperty("java.vm.vendor");
0580:
0581:            /**
0582:             * <p>The <code>java.vm.version</code> System Property. Java Virtual Machine
0583:             * implementation version.</p>
0584:             *
0585:             * <p>Defaults to <code>null</code> if the runtime does not have
0586:             * security access to read this property or the property does not exist.</p>
0587:             * 
0588:             * <p>
0589:             * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
0590:             * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
0591:             * will be out of sync with that System property.
0592:             * </p>
0593:             * 
0594:             * @since Java 1.2
0595:             */
0596:            public static final String JAVA_VM_VERSION = getSystemProperty("java.vm.version");
0597:
0598:            /**
0599:             * <p>The <code>line.separator</code> System Property. Line separator
0600:             * (<code>&quot;\n&quot;</code> on UNIX).</p>
0601:             *
0602:             * <p>Defaults to <code>null</code> if the runtime does not have
0603:             * security access to read this property or the property does not exist.</p>
0604:             * 
0605:             * <p>
0606:             * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
0607:             * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
0608:             * will be out of sync with that System property.
0609:             * </p>
0610:             * 
0611:             * @since Java 1.1
0612:             */
0613:            public static final String LINE_SEPARATOR = getSystemProperty("line.separator");
0614:
0615:            /**
0616:             * <p>The <code>os.arch</code> System Property. Operating system architecture.</p>
0617:             *
0618:             * <p>Defaults to <code>null</code> if the runtime does not have
0619:             * security access to read this property or the property does not exist.</p>
0620:             * 
0621:             * <p>
0622:             * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
0623:             * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
0624:             * will be out of sync with that System property.
0625:             * </p>
0626:             * 
0627:             * @since Java 1.1
0628:             */
0629:            public static final String OS_ARCH = getSystemProperty("os.arch");
0630:
0631:            /**
0632:             * <p>The <code>os.name</code> System Property. Operating system name.</p>
0633:             *
0634:             * <p>Defaults to <code>null</code> if the runtime does not have
0635:             * security access to read this property or the property does not exist.</p>
0636:             * 
0637:             * <p>
0638:             * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
0639:             * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
0640:             * will be out of sync with that System property.
0641:             * </p>
0642:             * 
0643:             * @since Java 1.1
0644:             */
0645:            public static final String OS_NAME = getSystemProperty("os.name");
0646:
0647:            /**
0648:             * <p>The <code>os.version</code> System Property. Operating system version.</p>
0649:             *
0650:             * <p>Defaults to <code>null</code> if the runtime does not have
0651:             * security access to read this property or the property does not exist.</p>
0652:             * 
0653:             * <p>
0654:             * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
0655:             * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
0656:             * will be out of sync with that System property.
0657:             * </p>
0658:             * 
0659:             * @since Java 1.1
0660:             */
0661:            public static final String OS_VERSION = getSystemProperty("os.version");
0662:
0663:            /**
0664:             * <p>The <code>path.separator</code> System Property. Path separator
0665:             * (<code>&quot;:&quot;</code> on UNIX).</p>
0666:             *
0667:             * <p>Defaults to <code>null</code> if the runtime does not have
0668:             * security access to read this property or the property does not exist.</p>
0669:             * 
0670:             * <p>
0671:             * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
0672:             * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
0673:             * will be out of sync with that System property.
0674:             * </p>
0675:             * 
0676:             * @since Java 1.1
0677:             */
0678:            public static final String PATH_SEPARATOR = getSystemProperty("path.separator");
0679:
0680:            /**
0681:             * <p>The <code>user.country</code> or <code>user.region</code> System Property.
0682:             * User's country code, such as <code>GB</code>. First in JDK version 1.2 as
0683:             * <code>user.region</code>. Renamed to <code>user.country</code> in 1.4</p>
0684:             *
0685:             * <p>Defaults to <code>null</code> if the runtime does not have
0686:             * security access to read this property or the property does not exist.</p>
0687:             * 
0688:             * <p>
0689:             * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
0690:             * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
0691:             * will be out of sync with that System property.
0692:             * </p>
0693:             * 
0694:             * @since 2.0
0695:             * @since Java 1.2
0696:             */
0697:            public static final String USER_COUNTRY = getSystemProperty("user.country") == null ? getSystemProperty("user.region")
0698:                    : getSystemProperty("user.country");
0699:
0700:            /**
0701:             * <p>The <code>user.dir</code> System Property. User's current working
0702:             * directory.</p>
0703:             *
0704:             * <p>Defaults to <code>null</code> if the runtime does not have
0705:             * security access to read this property or the property does not exist.</p>
0706:             * 
0707:             * <p>
0708:             * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
0709:             * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
0710:             * will be out of sync with that System property.
0711:             * </p>
0712:             * 
0713:             * @since Java 1.1
0714:             */
0715:            public static final String USER_DIR = getSystemProperty(USER_DIR_KEY);
0716:
0717:            /**
0718:             * <p>The <code>user.home</code> System Property. User's home directory.</p>
0719:             *
0720:             * <p>Defaults to <code>null</code> if the runtime does not have
0721:             * security access to read this property or the property does not exist.</p>
0722:             * 
0723:             * <p>
0724:             * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
0725:             * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
0726:             * will be out of sync with that System property.
0727:             * </p>
0728:             * 
0729:             * @since Java 1.1
0730:             */
0731:            public static final String USER_HOME = getSystemProperty(USER_HOME_KEY);
0732:
0733:            /**
0734:             * <p>The <code>user.language</code> System Property. User's language code,
0735:             * such as <code>"en"</code>.</p>
0736:             *
0737:             * <p>Defaults to <code>null</code> if the runtime does not have
0738:             * security access to read this property or the property does not exist.</p>
0739:             * 
0740:             * <p>
0741:             * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
0742:             * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
0743:             * will be out of sync with that System property.
0744:             * </p>
0745:             * 
0746:             * @since 2.0
0747:             * @since Java 1.2
0748:             */
0749:            public static final String USER_LANGUAGE = getSystemProperty("user.language");
0750:
0751:            /**
0752:             * <p>The <code>user.name</code> System Property. User's account name.</p>
0753:             *
0754:             * <p>Defaults to <code>null</code> if the runtime does not have
0755:             * security access to read this property or the property does not exist.</p>
0756:             * 
0757:             * <p>
0758:             * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
0759:             * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
0760:             * will be out of sync with that System property.
0761:             * </p>
0762:             * 
0763:             * @since Java 1.1
0764:             */
0765:            public static final String USER_NAME = getSystemProperty("user.name");
0766:
0767:            /**
0768:             * <p>The <code>user.timezone</code> System Property. 
0769:             * For example: <code>"America/Los_Angeles"</code>.</p>
0770:             *
0771:             * <p>Defaults to <code>null</code> if the runtime does not have
0772:             * security access to read this property or the property does not exist.</p>
0773:             * 
0774:             * <p>
0775:             * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
0776:             * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
0777:             * will be out of sync with that System property.
0778:             * </p>
0779:             * 
0780:             * @since 2.1
0781:             */
0782:            public static final String USER_TIMEZONE = getSystemProperty("user.timezone");
0783:
0784:            // Java version
0785:            //-----------------------------------------------------------------------
0786:            // This MUST be declared after those above as it depends on the
0787:            // values being set up
0788:
0789:            /**
0790:             * <p>Gets the Java version as a <code>String</code> trimming leading letters.</p>
0791:             *
0792:             * <p>The field will return <code>null</code> if {@link #JAVA_VERSION} is <code>null</code>.</p>
0793:             * 
0794:             * @since 2.1
0795:             */
0796:            public static final String JAVA_VERSION_TRIMMED = getJavaVersionTrimmed();
0797:
0798:            // Java version values
0799:            //-----------------------------------------------------------------------
0800:            // These MUST be declared after the trim above as they depend on the
0801:            // value being set up
0802:
0803:            /**
0804:             * <p>Gets the Java version as a <code>float</code>.</p>
0805:             *
0806:             * <p>Example return values:</p>
0807:             * <ul>
0808:             *  <li><code>1.2f</code> for JDK 1.2
0809:             *  <li><code>1.31f</code> for JDK 1.3.1
0810:             * </ul>
0811:             *
0812:             * <p>The field will return zero if {@link #JAVA_VERSION} is <code>null</code>.</p>
0813:             * 
0814:             * @since 2.0
0815:             */
0816:            public static final float JAVA_VERSION_FLOAT = getJavaVersionAsFloat();
0817:
0818:            /**
0819:             * <p>Gets the Java version as an <code>int</code>.</p>
0820:             *
0821:             * <p>Example return values:</p>
0822:             * <ul>
0823:             *  <li><code>120</code> for JDK 1.2
0824:             *  <li><code>131</code> for JDK 1.3.1
0825:             * </ul>
0826:             *
0827:             * <p>The field will return zero if {@link #JAVA_VERSION} is <code>null</code>.</p>
0828:             * 
0829:             * @since 2.0
0830:             */
0831:            public static final int JAVA_VERSION_INT = getJavaVersionAsInt();
0832:
0833:            // Java version checks
0834:            //-----------------------------------------------------------------------
0835:            // These MUST be declared after those above as they depend on the
0836:            // values being set up
0837:
0838:            /**
0839:             * <p>Is <code>true</code> if this is Java version 1.1 (also 1.1.x versions).</p>
0840:             *
0841:             * <p>The field will return <code>false</code> if {@link #JAVA_VERSION} is
0842:             * <code>null</code>.</p>
0843:             */
0844:            public static final boolean IS_JAVA_1_1 = getJavaVersionMatches("1.1");
0845:
0846:            /**
0847:             * <p>Is <code>true</code> if this is Java version 1.2 (also 1.2.x versions).</p>
0848:             *
0849:             * <p>The field will return <code>false</code> if {@link #JAVA_VERSION} is
0850:             * <code>null</code>.</p>
0851:             */
0852:            public static final boolean IS_JAVA_1_2 = getJavaVersionMatches("1.2");
0853:
0854:            /**
0855:             * <p>Is <code>true</code> if this is Java version 1.3 (also 1.3.x versions).</p>
0856:             *
0857:             * <p>The field will return <code>false</code> if {@link #JAVA_VERSION} is
0858:             * <code>null</code>.</p>
0859:             */
0860:            public static final boolean IS_JAVA_1_3 = getJavaVersionMatches("1.3");
0861:
0862:            /**
0863:             * <p>Is <code>true</code> if this is Java version 1.4 (also 1.4.x versions).</p>
0864:             *
0865:             * <p>The field will return <code>false</code> if {@link #JAVA_VERSION} is
0866:             * <code>null</code>.</p>
0867:             */
0868:            public static final boolean IS_JAVA_1_4 = getJavaVersionMatches("1.4");
0869:
0870:            /**
0871:             * <p>Is <code>true</code> if this is Java version 1.5 (also 1.5.x versions).</p>
0872:             *
0873:             * <p>The field will return <code>false</code> if {@link #JAVA_VERSION} is
0874:             * <code>null</code>.</p>
0875:             */
0876:            public static final boolean IS_JAVA_1_5 = getJavaVersionMatches("1.5");
0877:
0878:            /**
0879:             * <p>Is <code>true</code> if this is Java version 1.6 (also 1.6.x versions).</p>
0880:             *
0881:             * <p>The field will return <code>false</code> if {@link #JAVA_VERSION} is
0882:             * <code>null</code>.</p>
0883:             */
0884:            public static final boolean IS_JAVA_1_6 = getJavaVersionMatches("1.6");
0885:
0886:            // Operating system checks
0887:            //-----------------------------------------------------------------------
0888:            // These MUST be declared after those above as they depend on the
0889:            // values being set up
0890:            // OS names from http://www.vamphq.com/os.html
0891:            // Selected ones included - please advise commons-dev@jakarta.apache.org
0892:            // if you want another added or a mistake corrected
0893:
0894:            /**
0895:             * <p>Is <code>true</code> if this is AIX.</p>
0896:             *
0897:             * <p>The field will return <code>false</code> if <code>OS_NAME</code> is
0898:             * <code>null</code>.</p>
0899:             * 
0900:             * @since 2.0
0901:             */
0902:            public static final boolean IS_OS_AIX = getOSMatches("AIX");
0903:
0904:            /**
0905:             * <p>Is <code>true</code> if this is HP-UX.</p>
0906:             *
0907:             * <p>The field will return <code>false</code> if <code>OS_NAME</code> is
0908:             * <code>null</code>.</p>
0909:             * 
0910:             * @since 2.0
0911:             */
0912:            public static final boolean IS_OS_HP_UX = getOSMatches("HP-UX");
0913:
0914:            /**
0915:             * <p>Is <code>true</code> if this is Irix.</p>
0916:             *
0917:             * <p>The field will return <code>false</code> if <code>OS_NAME</code> is
0918:             * <code>null</code>.</p>
0919:             * 
0920:             * @since 2.0
0921:             */
0922:            public static final boolean IS_OS_IRIX = getOSMatches("Irix");
0923:
0924:            /**
0925:             * <p>Is <code>true</code> if this is Linux.</p>
0926:             *
0927:             * <p>The field will return <code>false</code> if <code>OS_NAME</code> is
0928:             * <code>null</code>.</p>
0929:             * 
0930:             * @since 2.0
0931:             */
0932:            public static final boolean IS_OS_LINUX = getOSMatches("Linux")
0933:                    || getOSMatches("LINUX");
0934:
0935:            /**
0936:             * <p>Is <code>true</code> if this is Mac.</p>
0937:             *
0938:             * <p>The field will return <code>false</code> if <code>OS_NAME</code> is
0939:             * <code>null</code>.</p>
0940:             * 
0941:             * @since 2.0
0942:             */
0943:            public static final boolean IS_OS_MAC = getOSMatches("Mac");
0944:
0945:            /**
0946:             * <p>Is <code>true</code> if this is Mac.</p>
0947:             *
0948:             * <p>The field will return <code>false</code> if <code>OS_NAME</code> is
0949:             * <code>null</code>.</p>
0950:             * 
0951:             * @since 2.0
0952:             */
0953:            public static final boolean IS_OS_MAC_OSX = getOSMatches("Mac OS X");
0954:
0955:            /**
0956:             * <p>Is <code>true</code> if this is OS/2.</p>
0957:             *
0958:             * <p>The field will return <code>false</code> if <code>OS_NAME</code> is
0959:             * <code>null</code>.</p>
0960:             * 
0961:             * @since 2.0
0962:             */
0963:            public static final boolean IS_OS_OS2 = getOSMatches("OS/2");
0964:
0965:            /**
0966:             * <p>Is <code>true</code> if this is Solaris.</p>
0967:             *
0968:             * <p>The field will return <code>false</code> if <code>OS_NAME</code> is
0969:             * <code>null</code>.</p>
0970:             * 
0971:             * @since 2.0
0972:             */
0973:            public static final boolean IS_OS_SOLARIS = getOSMatches("Solaris");
0974:
0975:            /**
0976:             * <p>Is <code>true</code> if this is SunOS.</p>
0977:             *
0978:             * <p>The field will return <code>false</code> if <code>OS_NAME</code> is
0979:             * <code>null</code>.</p>
0980:             * 
0981:             * @since 2.0
0982:             */
0983:            public static final boolean IS_OS_SUN_OS = getOSMatches("SunOS");
0984:
0985:            /**
0986:             * <p>Is <code>true</code> if this is a POSIX compilant system,
0987:             * as in any of AIX, HP-UX, Irix, Linux, MacOSX, Solaris or SUN OS.</p>
0988:             *
0989:             * <p>The field will return <code>false</code> if <code>OS_NAME</code> is
0990:             * <code>null</code>.</p>
0991:             * 
0992:             * @since 2.1
0993:             */
0994:            public static final boolean IS_OS_UNIX = IS_OS_AIX || IS_OS_HP_UX
0995:                    || IS_OS_IRIX || IS_OS_LINUX || IS_OS_MAC_OSX
0996:                    || IS_OS_SOLARIS || IS_OS_SUN_OS;
0997:
0998:            /**
0999:             * <p>Is <code>true</code> if this is Windows.</p>
1000:             *
1001:             * <p>The field will return <code>false</code> if <code>OS_NAME</code> is
1002:             * <code>null</code>.</p>
1003:             * 
1004:             * @since 2.0
1005:             */
1006:            public static final boolean IS_OS_WINDOWS = getOSMatches(OS_NAME_WINDOWS_PREFIX);
1007:
1008:            /**
1009:             * <p>Is <code>true</code> if this is Windows 2000.</p>
1010:             *
1011:             * <p>The field will return <code>false</code> if <code>OS_NAME</code> is
1012:             * <code>null</code>.</p>
1013:             * 
1014:             * @since 2.0
1015:             */
1016:            public static final boolean IS_OS_WINDOWS_2000 = getOSMatches(
1017:                    OS_NAME_WINDOWS_PREFIX, "5.0");
1018:
1019:            /**
1020:             * <p>Is <code>true</code> if this is Windows 95.</p>
1021:             *
1022:             * <p>The field will return <code>false</code> if <code>OS_NAME</code> is
1023:             * <code>null</code>.</p>
1024:             * 
1025:             * @since 2.0
1026:             */
1027:            public static final boolean IS_OS_WINDOWS_95 = getOSMatches(
1028:                    OS_NAME_WINDOWS_PREFIX + " 9", "4.0");
1029:            // JDK 1.2 running on Windows98 returns 'Windows 95', hence the above
1030:
1031:            /**
1032:             * <p>Is <code>true</code> if this is Windows 98.</p>
1033:             *
1034:             * <p>The field will return <code>false</code> if <code>OS_NAME</code> is
1035:             * <code>null</code>.</p>
1036:             * 
1037:             * @since 2.0
1038:             */
1039:            public static final boolean IS_OS_WINDOWS_98 = getOSMatches(
1040:                    OS_NAME_WINDOWS_PREFIX + " 9", "4.1");
1041:            // JDK 1.2 running on Windows98 returns 'Windows 95', hence the above
1042:
1043:            /**
1044:             * <p>Is <code>true</code> if this is Windows ME.</p>
1045:             *
1046:             * <p>The field will return <code>false</code> if <code>OS_NAME</code> is
1047:             * <code>null</code>.</p>
1048:             * 
1049:             * @since 2.0
1050:             */
1051:            public static final boolean IS_OS_WINDOWS_ME = getOSMatches(
1052:                    OS_NAME_WINDOWS_PREFIX, "4.9");
1053:            // JDK 1.2 running on WindowsME may return 'Windows 95', hence the above
1054:
1055:            /**
1056:             * <p>Is <code>true</code> if this is Windows NT.</p>
1057:             *
1058:             * <p>The field will return <code>false</code> if <code>OS_NAME</code> is
1059:             * <code>null</code>.</p>
1060:             * 
1061:             * @since 2.0
1062:             */
1063:            public static final boolean IS_OS_WINDOWS_NT = getOSMatches(OS_NAME_WINDOWS_PREFIX
1064:                    + " NT");
1065:            // Windows 2000 returns 'Windows 2000' but may suffer from same JDK1.2 problem
1066:
1067:            /**
1068:             * <p>Is <code>true</code> if this is Windows XP.</p>
1069:             *
1070:             * <p>The field will return <code>false</code> if <code>OS_NAME</code> is
1071:             * <code>null</code>.</p>
1072:             * 
1073:             * @since 2.0
1074:             */
1075:            public static final boolean IS_OS_WINDOWS_XP = getOSMatches(
1076:                    OS_NAME_WINDOWS_PREFIX, "5.1");
1077:
1078:            //-----------------------------------------------------------------------    
1079:            /**
1080:             * <p>SystemUtils instances should NOT be constructed in standard
1081:             * programming. Instead, the class should be used as
1082:             * <code>SystemUtils.FILE_SEPARATOR</code>.</p>
1083:             *
1084:             * <p>This constructor is public to permit tools that require a JavaBean
1085:             * instance to operate.</p>
1086:             */
1087:            public SystemUtils() {
1088:                super ();
1089:            }
1090:
1091:            //-----------------------------------------------------------------------    
1092:            /**
1093:             * <p>Gets the Java version number as a <code>float</code>.</p>
1094:             *
1095:             * <p>Example return values:</p>
1096:             * <ul>
1097:             *  <li><code>1.2f</code> for JDK 1.2
1098:             *  <li><code>1.31f</code> for JDK 1.3.1
1099:             * </ul>
1100:             * 
1101:             * @return the version, for example 1.31f for JDK 1.3.1
1102:             * @deprecated Use {@link #JAVA_VERSION_FLOAT} instead.
1103:             *             Method will be removed in Commons Lang 3.0.
1104:             */
1105:            public static float getJavaVersion() {
1106:                return JAVA_VERSION_FLOAT;
1107:            }
1108:
1109:            /**
1110:             * <p>Gets the Java version number as a <code>float</code>.</p>
1111:             *
1112:             * <p>Example return values:</p>
1113:             * <ul>
1114:             *  <li><code>1.2f</code> for JDK 1.2
1115:             *  <li><code>1.31f</code> for JDK 1.3.1
1116:             * </ul>
1117:             * 
1118:             * <p>Patch releases are not reported.
1119:             * Zero is returned if {@link #JAVA_VERSION_TRIMMED} is <code>null</code>.</p>
1120:             * 
1121:             * @return the version, for example 1.31f for JDK 1.3.1
1122:             */
1123:            private static float getJavaVersionAsFloat() {
1124:                if (JAVA_VERSION_TRIMMED == null) {
1125:                    return 0f;
1126:                }
1127:                String str = JAVA_VERSION_TRIMMED.substring(0, 3);
1128:                if (JAVA_VERSION_TRIMMED.length() >= 5) {
1129:                    str = str + JAVA_VERSION_TRIMMED.substring(4, 5);
1130:                }
1131:                try {
1132:                    return Float.parseFloat(str);
1133:                } catch (Exception ex) {
1134:                    return 0;
1135:                }
1136:            }
1137:
1138:            /**
1139:             * <p>Gets the Java version number as an <code>int</code>.</p>
1140:             *
1141:             * <p>Example return values:</p>
1142:             * <ul>
1143:             *  <li><code>120</code> for JDK 1.2
1144:             *  <li><code>131</code> for JDK 1.3.1
1145:             * </ul>
1146:             * 
1147:             * <p>Patch releases are not reported.
1148:             * Zero is returned if {@link #JAVA_VERSION_TRIMMED} is <code>null</code>.</p>
1149:             * 
1150:             * @return the version, for example 131 for JDK 1.3.1
1151:             */
1152:            private static int getJavaVersionAsInt() {
1153:                if (JAVA_VERSION_TRIMMED == null) {
1154:                    return 0;
1155:                }
1156:                String str = JAVA_VERSION_TRIMMED.substring(0, 1);
1157:                str = str + JAVA_VERSION_TRIMMED.substring(2, 3);
1158:                if (JAVA_VERSION_TRIMMED.length() >= 5) {
1159:                    str = str + JAVA_VERSION_TRIMMED.substring(4, 5);
1160:                } else {
1161:                    str = str + "0";
1162:                }
1163:                try {
1164:                    return Integer.parseInt(str);
1165:                } catch (Exception ex) {
1166:                    return 0;
1167:                }
1168:            }
1169:
1170:            /**
1171:             * Trims the text of the java version to start with numbers.
1172:             * 
1173:             * @return the trimmed java version
1174:             */
1175:            private static String getJavaVersionTrimmed() {
1176:                if (JAVA_VERSION != null) {
1177:                    for (int i = 0; i < JAVA_VERSION.length(); i++) {
1178:                        char ch = JAVA_VERSION.charAt(i);
1179:                        if (ch >= '0' && ch <= '9') {
1180:                            return JAVA_VERSION.substring(i);
1181:                        }
1182:                    }
1183:                }
1184:                return null;
1185:            }
1186:
1187:            /**
1188:             * <p>Decides if the java version matches.</p>
1189:             * 
1190:             * @param versionPrefix  the prefix for the java version
1191:             * @return true if matches, or false if not or can't determine
1192:             */
1193:            private static boolean getJavaVersionMatches(String versionPrefix) {
1194:                if (JAVA_VERSION_TRIMMED == null) {
1195:                    return false;
1196:                }
1197:                return JAVA_VERSION_TRIMMED.startsWith(versionPrefix);
1198:            }
1199:
1200:            /**
1201:             * <p>Decides if the operating system matches.</p>
1202:             * 
1203:             * @param osNamePrefix  the prefix for the os name
1204:             * @return true if matches, or false if not or can't determine
1205:             */
1206:            private static boolean getOSMatches(String osNamePrefix) {
1207:                if (OS_NAME == null) {
1208:                    return false;
1209:                }
1210:                return OS_NAME.startsWith(osNamePrefix);
1211:            }
1212:
1213:            /**
1214:             * <p>Decides if the operating system matches.</p>
1215:             * 
1216:             * @param osNamePrefix  the prefix for the os name
1217:             * @param osVersionPrefix  the prefix for the version
1218:             * @return true if matches, or false if not or can't determine
1219:             */
1220:            private static boolean getOSMatches(String osNamePrefix,
1221:                    String osVersionPrefix) {
1222:                if (OS_NAME == null || OS_VERSION == null) {
1223:                    return false;
1224:                }
1225:                return OS_NAME.startsWith(osNamePrefix)
1226:                        && OS_VERSION.startsWith(osVersionPrefix);
1227:            }
1228:
1229:            //-----------------------------------------------------------------------
1230:            /**
1231:             * <p>Gets a System property, defaulting to <code>null</code> if the property
1232:             * cannot be read.</p>
1233:             *
1234:             * <p>If a <code>SecurityException</code> is caught, the return
1235:             * value is <code>null</code> and a message is written to <code>System.err</code>.</p>
1236:             * 
1237:             * @param property the system property name
1238:             * @return the system property value or <code>null</code> if a security problem occurs
1239:             */
1240:            private static String getSystemProperty(String property) {
1241:                try {
1242:                    return System.getProperty(property);
1243:                } catch (SecurityException ex) {
1244:                    // we are not allowed to look at this property
1245:                    System.err
1246:                            .println("Caught a SecurityException reading the system property '"
1247:                                    + property
1248:                                    + "'; the SystemUtils property value will default to null.");
1249:                    return null;
1250:                }
1251:            }
1252:
1253:            /**
1254:             * <p>Is the Java version at least the requested version.</p>
1255:             *
1256:             * <p>Example input:</p>
1257:             * <ul>
1258:             *  <li><code>1.2f</code> to test for JDK 1.2</li>
1259:             *  <li><code>1.31f</code> to test for JDK 1.3.1</li>
1260:             * </ul>
1261:             * 
1262:             * @param requiredVersion  the required version, for example 1.31f
1263:             * @return <code>true</code> if the actual version is equal or greater
1264:             *  than the required version
1265:             */
1266:            public static boolean isJavaVersionAtLeast(float requiredVersion) {
1267:                return JAVA_VERSION_FLOAT >= requiredVersion;
1268:            }
1269:
1270:            /**
1271:             * <p>Is the Java version at least the requested version.</p>
1272:             *
1273:             * <p>Example input:</p>
1274:             * <ul>
1275:             *  <li><code>120</code> to test for JDK 1.2 or greater</li>
1276:             *  <li><code>131</code> to test for JDK 1.3.1 or greater</li>
1277:             * </ul>
1278:             * 
1279:             * @param requiredVersion  the required version, for example 131
1280:             * @return <code>true</code> if the actual version is equal or greater
1281:             *  than the required version
1282:             * @since 2.0
1283:             */
1284:            public static boolean isJavaVersionAtLeast(int requiredVersion) {
1285:                return JAVA_VERSION_INT >= requiredVersion;
1286:            }
1287:
1288:            /**
1289:             * Returns whether the {@link #JAVA_AWT_HEADLESS} value is <code>true</code>.
1290:             *  
1291:             * @return <code>true</code> if <code>JAVA_AWT_HEADLESS</code> is <code>"true"</code>,
1292:             * <code>false</code> otherwise.
1293:             * 
1294:             * @see #JAVA_AWT_HEADLESS
1295:             * @since 2.1
1296:             * @since Java 1.4
1297:             */
1298:            public static boolean isJavaAwtHeadless() {
1299:                return JAVA_AWT_HEADLESS != null ? JAVA_AWT_HEADLESS
1300:                        .equals(Boolean.TRUE.toString()) : false;
1301:            }
1302:
1303:            /**
1304:             * <p>Gets the Java home directory as a <code>File</code>.</p>
1305:             * 
1306:             * @return a directory
1307:             * @throws  SecurityException  if a security manager exists and its  
1308:             *             <code>checkPropertyAccess</code> method doesn't allow
1309:             *              access to the specified system property.
1310:             * @see System#getProperty(String)
1311:             * @since 2.1
1312:             */
1313:            public static File getJavaHome() {
1314:                return new File(System.getProperty(JAVA_HOME_KEY));
1315:            }
1316:
1317:            /**
1318:             * <p>Gets the Java IO temporary directory as a <code>File</code>.</p>
1319:             * 
1320:             * @return a directory
1321:             * @throws  SecurityException  if a security manager exists and its  
1322:             *             <code>checkPropertyAccess</code> method doesn't allow
1323:             *              access to the specified system property.
1324:             * @see System#getProperty(String)
1325:             * @since 2.1
1326:             */
1327:            public static File getJavaIoTmpDir() {
1328:                return new File(System.getProperty(JAVA_IO_TMPDIR_KEY));
1329:            }
1330:
1331:            /**
1332:             * <p>Gets the user directory as a <code>File</code>.</p>
1333:             * 
1334:             * @return a directory
1335:             * @throws  SecurityException  if a security manager exists and its  
1336:             *             <code>checkPropertyAccess</code> method doesn't allow
1337:             *              access to the specified system property.
1338:             * @see System#getProperty(String)
1339:             * @since 2.1
1340:             */
1341:            public static File getUserDir() {
1342:                return new File(System.getProperty(USER_DIR_KEY));
1343:            }
1344:
1345:            /**
1346:             * <p>Gets the user home directory as a <code>File</code>.</p>
1347:             * 
1348:             * @return a directory
1349:             * @throws  SecurityException  if a security manager exists and its  
1350:             *             <code>checkPropertyAccess</code> method doesn't allow
1351:             *              access to the specified system property.
1352:             * @see System#getProperty(String)
1353:             * @since 2.1
1354:             */
1355:            public static File getUserHome() {
1356:                return new File(System.getProperty(USER_HOME_KEY));
1357:            }
1358:
1359:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.