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