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