1 6 7 package org.jfox.ioc.util; 8 9 import java.io.File ; 10 11 14 15 public class Systems { 16 17 20 private static final String USER_HOME_KEY = "user.home"; 21 22 25 private static final String USER_DIR_KEY = "user.dir"; 26 27 30 private static final String JAVA_IO_TMPDIR_KEY = "java.io.tmpdir"; 31 32 35 private static final String JAVA_HOME_KEY = "java.home"; 36 37 52 public static final String FILE_ENCODING = getSystemProperty("file.encoding"); 53 54 69 public static final String FILE_SEPARATOR = getSystemProperty("file.separator"); 70 71 85 public static final String JAVA_AWT_FONTS = getSystemProperty("java.awt.fonts"); 86 87 101 public static final String JAVA_CLASS_PATH = getSystemProperty("java.class.path"); 102 103 118 public static final String JAVA_CLASS_VERSION = getSystemProperty("java.class.version"); 119 120 135 public static final String JAVA_COMPILER = getSystemProperty("java.compiler"); 136 137 152 public static final String JAVA_ENDORSED_DIRS = getSystemProperty("java.endorsed.dirs"); 153 154 169 public static final String JAVA_EXT_DIRS = getSystemProperty("java.ext.dirs"); 170 171 185 public static final String JAVA_HOME = getSystemProperty(JAVA_HOME_KEY); 186 187 201 public static final String JAVA_IO_TMPDIR = getSystemProperty(JAVA_IO_TMPDIR_KEY); 202 203 218 public static final String JAVA_LIBRARY_PATH = getSystemProperty("java.library.path"); 219 220 235 public static final String JAVA_RUNTIME_NAME = getSystemProperty("java.runtime.name"); 236 237 252 public static final String JAVA_RUNTIME_VERSION = getSystemProperty("java.runtime.version"); 253 254 269 public static final String JAVA_SPECIFICATION_NAME = getSystemProperty("java.specification.name"); 270 271 286 public static final String JAVA_SPECIFICATION_VENDOR = getSystemProperty("java.specification.vendor"); 287 288 303 public static final String JAVA_SPECIFICATION_VERSION = getSystemProperty("java.specification.version"); 304 305 319 public static final String JAVA_UTIL_PREFS_PREFERENCES_FACTORY = getSystemProperty("java.util.prefs.PreferencesFactory"); 320 321 335 public static final String JAVA_VENDOR = getSystemProperty("java.vendor"); 336 337 351 public static final String JAVA_VENDOR_URL = getSystemProperty("java.vendor.url"); 352 353 367 public static final String JAVA_VERSION = getSystemProperty("java.version"); 368 369 384 public static final String JAVA_VM_INFO = getSystemProperty("java.vm.info"); 385 386 401 public static final String JAVA_VM_NAME = getSystemProperty("java.vm.name"); 402 403 418 public static final String JAVA_VM_SPECIFICATION_NAME = getSystemProperty("java.vm.specification.name"); 419 420 435 public static final String JAVA_VM_SPECIFICATION_VENDOR = getSystemProperty("java.vm.specification.vendor"); 436 437 452 public static final String JAVA_VM_SPECIFICATION_VERSION = getSystemProperty("java.vm.specification.version"); 453 454 469 public static final String JAVA_VM_VENDOR = getSystemProperty("java.vm.vendor"); 470 471 486 public static final String JAVA_VM_VERSION = getSystemProperty("java.vm.version"); 487 488 503 public static final String LINE_SEPARATOR = getSystemProperty("line.separator"); 504 505 519 public static final String OS_ARCH = getSystemProperty("os.arch"); 520 521 535 public static final String OS_NAME = getSystemProperty("os.name"); 536 537 551 public static final String OS_VERSION = getSystemProperty("os.version"); 552 553 568 public static final String PATH_SEPARATOR = getSystemProperty("path.separator"); 569 570 586 public static final String USER_COUNTRY = 587 (getSystemProperty("user.country") == null ? 588 getSystemProperty("user.region") : getSystemProperty("user.country")); 589 590 605 public static final String USER_DIR = getSystemProperty(USER_DIR_KEY); 606 607 621 public static final String USER_HOME = getSystemProperty(USER_HOME_KEY); 622 623 638 public static final String USER_LANGUAGE = getSystemProperty("user.language"); 639 640 654 public static final String USER_NAME = getSystemProperty("user.name"); 655 656 671 public static final String USER_TIMEZONE = getSystemProperty("user.timezone"); 672 673 678 691 public static final float JAVA_VERSION_FLOAT = getJavaVersionAsFloat(); 692 693 706 public static final int JAVA_VERSION_INT = getJavaVersionAsInt(); 707 708 713 719 public static final boolean IS_JAVA_1_1 = getJavaVersionMatches("1.1"); 720 721 727 public static final boolean IS_JAVA_1_2 = getJavaVersionMatches("1.2"); 728 729 735 public static final boolean IS_JAVA_1_3 = getJavaVersionMatches("1.3"); 736 737 743 public static final boolean IS_JAVA_1_4 = getJavaVersionMatches("1.4"); 744 745 751 public static final boolean IS_JAVA_1_5 = getJavaVersionMatches("1.5"); 752 753 761 769 public static final boolean IS_OS_AIX = getOSMatches("AIX"); 770 771 779 public static final boolean IS_OS_HP_UX = getOSMatches("HP-UX"); 780 781 789 public static final boolean IS_OS_IRIX = getOSMatches("Irix"); 790 791 799 public static final boolean IS_OS_LINUX = getOSMatches("Linux") || getOSMatches("LINUX"); 800 801 809 public static final boolean IS_OS_MAC = getOSMatches("Mac"); 810 811 819 public static final boolean IS_OS_MAC_OSX = getOSMatches("Mac OS X"); 820 821 829 public static final boolean IS_OS_OS2 = getOSMatches("OS/2"); 830 831 839 public static final boolean IS_OS_SOLARIS = getOSMatches("Solaris"); 840 841 849 public static final boolean IS_OS_SUN_OS = getOSMatches("SunOS"); 850 851 860 public static final boolean IS_OS_UNIX = 861 IS_OS_AIX || IS_OS_HP_UX || IS_OS_IRIX || IS_OS_LINUX || 862 IS_OS_MAC_OSX || IS_OS_SOLARIS || IS_OS_SUN_OS; 863 864 872 public static final boolean IS_OS_WINDOWS = getOSMatches("Windows"); 873 874 882 public static final boolean IS_OS_WINDOWS_2000 = getOSMatches("Windows", "5.0"); 883 884 892 public static final boolean IS_OS_WINDOWS_95 = getOSMatches("Windows 9", "4.0"); 893 895 903 public static final boolean IS_OS_WINDOWS_98 = getOSMatches("Windows 9", "4.1"); 904 906 914 public static final boolean IS_OS_WINDOWS_ME = getOSMatches("Windows", "4.9"); 915 917 925 public static final boolean IS_OS_WINDOWS_NT = getOSMatches("Windows NT"); 926 928 936 public static final boolean IS_OS_WINDOWS_XP = getOSMatches("Windows", "5.1"); 937 939 948 public Systems() { 949 } 951 952 966 public static float getJavaVersion() { 967 return JAVA_VERSION_FLOAT; 968 } 969 970 984 private static float getJavaVersionAsFloat() { 985 if(JAVA_VERSION == null) { 986 return 0f; 987 } 988 String str = JAVA_VERSION.substring(0, 3); 989 if(JAVA_VERSION.length() >= 5) { 990 str = str + JAVA_VERSION.substring(4, 5); 991 } 992 return Float.parseFloat(str); 993 } 994 995 1009 private static int getJavaVersionAsInt() { 1010 if(JAVA_VERSION == null) { 1011 return 0; 1012 } 1013 String str = JAVA_VERSION.substring(0, 1); 1014 str = str + JAVA_VERSION.substring(2, 3); 1015 if(JAVA_VERSION.length() >= 5) { 1016 str = str + JAVA_VERSION.substring(4, 5); 1017 } 1018 else { 1019 str = str + "0"; 1020 } 1021 return Integer.parseInt(str); 1022 } 1023 1024 1030 private static boolean getJavaVersionMatches(String versionPrefix) { 1031 if(JAVA_VERSION == null) { 1032 return false; 1033 } 1034 return JAVA_VERSION.startsWith(versionPrefix); 1035 } 1036 1037 1043 private static boolean getOSMatches(String osNamePrefix) { 1044 if(OS_NAME == null) { 1045 return false; 1046 } 1047 return OS_NAME.startsWith(osNamePrefix); 1048 } 1049 1050 1057 private static boolean getOSMatches(String osNamePrefix, String osVersionPrefix) { 1058 if(OS_NAME == null || OS_VERSION == null) { 1059 return false; 1060 } 1061 return OS_NAME.startsWith(osNamePrefix) && OS_VERSION.startsWith(osVersionPrefix); 1062 } 1063 1064 1075 private static String getSystemProperty(String property) { 1076 try { 1077 return System.getProperty(property); 1078 } 1079 catch(SecurityException ex) { 1080 System.err.println("Caught a SecurityException reading the system property '" + property 1082 + "'; the SystemUtils property value will default to null."); 1083 return null; 1084 } 1085 } 1086 1087 1100 public static boolean isJavaVersionAtLeast(float requiredVersion) { 1101 return (JAVA_VERSION_FLOAT >= requiredVersion); 1102 } 1103 1104 1118 public static boolean isJavaVersionAtLeast(int requiredVersion) { 1119 return (JAVA_VERSION_INT >= requiredVersion); 1120 } 1121 1122 1131 public static File getJavaHome() { 1132 return new File (System.getProperty(JAVA_HOME_KEY)); 1133 } 1134 1135 1144 public static File getJavaIoTmpDir() { 1145 return new File (System.getProperty(JAVA_IO_TMPDIR_KEY)); 1146 } 1147 1148 1157 public static File getUserDir() { 1158 return new File (System.getProperty(USER_DIR_KEY)); 1159 } 1160 1161 1170 public static File getUserHome() { 1171 return new File (System.getProperty(USER_HOME_KEY)); 1172 } 1173 1174 public static void main(String [] args) { 1175 1176 } 1177} 1178 1179 | Popular Tags |