001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 * 019 */ 020 package org.apache.directory.shared.ldap.util; 021 022 023 import java.io.File; 024 025 import org.apache.directory.shared.i18n.I18n; 026 027 028 /** 029 * <p> 030 * Helpers for <code>java.lang.System</code>. 031 * </p> 032 * <p> 033 * If a system property cannot be read due to security restrictions, the 034 * corresponding field in this class will be set to <code>null</code> and a 035 * message will be written to <code>System.err</code>. 036 * </p> 037 * 038 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 039 */ 040 public class SystemUtils 041 { 042 043 /** 044 * The prefix String for all Windows OS. 045 */ 046 private static final String OS_NAME_WINDOWS_PREFIX = "Windows"; 047 048 // System property constants 049 // ----------------------------------------------------------------------- 050 // These MUST be declared first. Other constants depend on this. 051 052 /** 053 * The System property key for the user home directory. 054 */ 055 private static final String USER_HOME_KEY = "user.home"; 056 057 /** 058 * The System property key for the user directory. 059 */ 060 private static final String USER_DIR_KEY = "user.dir"; 061 062 /** 063 * The System property key for the Java IO temporary directory. 064 */ 065 private static final String JAVA_IO_TMPDIR_KEY = "java.io.tmpdir"; 066 067 /** 068 * The System property key for the Java home directory. 069 */ 070 private static final String JAVA_HOME_KEY = "java.home"; 071 072 /** 073 * <p> 074 * The <code>awt.toolkit</code> System Property. 075 * </p> 076 * <p> 077 * Holds a class name, on Windows XP this is 078 * <code>sun.awt.windows.WToolkit</code>. 079 * </p> 080 * <p> 081 * <b>On platforms without a GUI, this value is <code>null</code>.</b> 082 * </p> 083 * <p> 084 * Defaults to <code>null</code> if the runtime does not have security 085 * access to read this property or the property does not exist. 086 * </p> 087 * <p> 088 * This value is initialized when the class is loaded. If 089 * {@link System#setProperty(String,String)} or 090 * {@link System#setProperties(java.util.Properties)} is called after this 091 * class is loaded, the value will be out of sync with that System property. 092 * </p> 093 * 094 * @since 2.1 095 */ 096 public static final String AWT_TOOLKIT = getSystemProperty( "awt.toolkit" ); 097 098 /** 099 * <p> 100 * The <code>file.encoding</code> System Property. 101 * </p> 102 * <p> 103 * File encoding, such as <code>Cp1252</code>. 104 * </p> 105 * <p> 106 * Defaults to <code>null</code> if the runtime does not have security 107 * access to read this property or the property does not exist. 108 * </p> 109 * <p> 110 * This value is initialized when the class is loaded. If 111 * {@link System#setProperty(String,String)} or 112 * {@link System#setProperties(java.util.Properties)} is called after this 113 * class is loaded, the value will be out of sync with that System property. 114 * </p> 115 * 116 * @since 2.0 117 * @since Java 1.2 118 */ 119 public static final String FILE_ENCODING = getSystemProperty( "file.encoding" ); 120 121 /** 122 * <p> 123 * The <code>file.separator</code> System Property. File separator (<code>"/"</code> 124 * on UNIX). 125 * </p> 126 * <p> 127 * Defaults to <code>null</code> if the runtime does not have security 128 * access to read this property or the property does not exist. 129 * </p> 130 * <p> 131 * This value is initialized when the class is loaded. If 132 * {@link System#setProperty(String,String)} or 133 * {@link System#setProperties(java.util.Properties)} is called after this 134 * class is loaded, the value will be out of sync with that System property. 135 * </p> 136 * 137 * @since Java 1.1 138 */ 139 public static final String FILE_SEPARATOR = getSystemProperty( "file.separator" ); 140 141 /** 142 * <p> 143 * The <code>java.awt.fonts</code> System Property. 144 * </p> 145 * <p> 146 * Defaults to <code>null</code> if the runtime does not have security 147 * access to read this property or the property does not exist. 148 * </p> 149 * <p> 150 * This value is initialized when the class is loaded. If 151 * {@link System#setProperty(String,String)} or 152 * {@link System#setProperties(java.util.Properties)} is called after this 153 * class is loaded, the value will be out of sync with that System property. 154 * </p> 155 * 156 * @since 2.1 157 */ 158 public static final String JAVA_AWT_FONTS = getSystemProperty( "java.awt.fonts" ); 159 160 /** 161 * <p> 162 * The <code>java.awt.graphicsenv</code> System Property. 163 * </p> 164 * <p> 165 * Defaults to <code>null</code> if the runtime does not have security 166 * access to read this property or the property does not exist. 167 * </p> 168 * <p> 169 * This value is initialized when the class is loaded. If 170 * {@link System#setProperty(String,String)} or 171 * {@link System#setProperties(java.util.Properties)} is called after this 172 * class is loaded, the value will be out of sync with that System property. 173 * </p> 174 * 175 * @since 2.1 176 */ 177 public static final String JAVA_AWT_GRAPHICSENV = getSystemProperty( "java.awt.graphicsenv" ); 178 179 /** 180 * <p> 181 * The <code>java.awt.headless</code> System Property. The value of this 182 * property is the String <code>"true"</code> or <code>"false"</code>. 183 * </p> 184 * <p> 185 * Defaults to <code>null</code> if the runtime does not have security 186 * access to read this property or the property does not exist. 187 * </p> 188 * <p> 189 * This value is initialized when the class is loaded. If 190 * {@link System#setProperty(String,String)} or 191 * {@link System#setProperties(java.util.Properties)} is called after this 192 * class is loaded, the value will be out of sync with that System property. 193 * </p> 194 * 195 * @see #isJavaAwtHeadless() 196 * @since 2.1 197 * @since Java 1.4 198 */ 199 public static final String JAVA_AWT_HEADLESS = getSystemProperty( "java.awt.headless" ); 200 201 /** 202 * <p> 203 * The <code>java.awt.printerjob</code> System Property. 204 * </p> 205 * <p> 206 * Defaults to <code>null</code> if the runtime does not have security 207 * access to read this property or the property does not exist. 208 * </p> 209 * <p> 210 * This value is initialized when the class is loaded. If 211 * {@link System#setProperty(String,String)} or 212 * {@link System#setProperties(java.util.Properties)} is called after this 213 * class is loaded, the value will be out of sync with that System property. 214 * </p> 215 * 216 * @since 2.1 217 */ 218 public static final String JAVA_AWT_PRINTERJOB = getSystemProperty( "java.awt.printerjob" ); 219 220 /** 221 * <p> 222 * The <code>java.class.path</code> System Property. Java class path. 223 * </p> 224 * <p> 225 * Defaults to <code>null</code> if the runtime does not have security 226 * access to read this property or the property does not exist. 227 * </p> 228 * <p> 229 * This value is initialized when the class is loaded. If 230 * {@link System#setProperty(String,String)} or 231 * {@link System#setProperties(java.util.Properties)} is called after this 232 * class is loaded, the value will be out of sync with that System property. 233 * </p> 234 * 235 * @since Java 1.1 236 */ 237 public static final String JAVA_CLASS_PATH = getSystemProperty( "java.class.path" ); 238 239 /** 240 * <p> 241 * The <code>java.class.version</code> System Property. Java class format 242 * version number. 243 * </p> 244 * <p> 245 * Defaults to <code>null</code> if the runtime does not have security 246 * access to read this property or the property does not exist. 247 * </p> 248 * <p> 249 * This value is initialized when the class is loaded. If 250 * {@link System#setProperty(String,String)} or 251 * {@link System#setProperties(java.util.Properties)} is called after this 252 * class is loaded, the value will be out of sync with that System property. 253 * </p> 254 * 255 * @since Java 1.1 256 */ 257 public static final String JAVA_CLASS_VERSION = getSystemProperty( "java.class.version" ); 258 259 /** 260 * <p> 261 * The <code>java.compiler</code> System Property. Name of JIT compiler to 262 * use. First in JDK version 1.2. Not used in Sun JDKs after 1.2. 263 * </p> 264 * <p> 265 * Defaults to <code>null</code> if the runtime does not have security 266 * access to read this property or the property does not exist. 267 * </p> 268 * <p> 269 * This value is initialized when the class is loaded. If 270 * {@link System#setProperty(String,String)} or 271 * {@link System#setProperties(java.util.Properties)} is called after this 272 * class is loaded, the value will be out of sync with that System property. 273 * </p> 274 * 275 * @since Java 1.2. Not used in Sun versions after 1.2. 276 */ 277 public static final String JAVA_COMPILER = getSystemProperty( "java.compiler" ); 278 279 /** 280 * <p> 281 * The <code>java.endorsed.dirs</code> System Property. Path of endorsed 282 * directory or directories. 283 * </p> 284 * <p> 285 * Defaults to <code>null</code> if the runtime does not have security 286 * access to read this property or the property does not exist. 287 * </p> 288 * <p> 289 * This value is initialized when the class is loaded. If 290 * {@link System#setProperty(String,String)} or 291 * {@link System#setProperties(java.util.Properties)} is called after this 292 * class is loaded, the value will be out of sync with that System property. 293 * </p> 294 * 295 * @since Java 1.4 296 */ 297 public static final String JAVA_ENDORSED_DIRS = getSystemProperty( "java.endorsed.dirs" ); 298 299 /** 300 * <p> 301 * The <code>java.ext.dirs</code> System Property. Path of extension 302 * directory or directories. 303 * </p> 304 * <p> 305 * Defaults to <code>null</code> if the runtime does not have security 306 * access to read this property or the property does not exist. 307 * </p> 308 * <p> 309 * This value is initialized when the class is loaded. If 310 * {@link System#setProperty(String,String)} or 311 * {@link System#setProperties(java.util.Properties)} is called after this 312 * class is loaded, the value will be out of sync with that System property. 313 * </p> 314 * 315 * @since Java 1.3 316 */ 317 public static final String JAVA_EXT_DIRS = getSystemProperty( "java.ext.dirs" ); 318 319 /** 320 * <p> 321 * The <code>java.home</code> System Property. Java installation 322 * directory. 323 * </p> 324 * <p> 325 * Defaults to <code>null</code> if the runtime does not have security 326 * access to read this property or the property does not exist. 327 * </p> 328 * <p> 329 * This value is initialized when the class is loaded. If 330 * {@link System#setProperty(String,String)} or 331 * {@link System#setProperties(java.util.Properties)} is called after this 332 * class is loaded, the value will be out of sync with that System property. 333 * </p> 334 * 335 * @since Java 1.1 336 */ 337 public static final String JAVA_HOME = getSystemProperty( JAVA_HOME_KEY ); 338 339 /** 340 * <p> 341 * The <code>java.io.tmpdir</code> System Property. Default temp file 342 * path. 343 * </p> 344 * <p> 345 * Defaults to <code>null</code> if the runtime does not have security 346 * access to read this property or the property does not exist. 347 * </p> 348 * <p> 349 * This value is initialized when the class is loaded. If 350 * {@link System#setProperty(String,String)} or 351 * {@link System#setProperties(java.util.Properties)} is called after this 352 * class is loaded, the value will be out of sync with that System property. 353 * </p> 354 * 355 * @since Java 1.2 356 */ 357 public static final String JAVA_IO_TMPDIR = getSystemProperty( JAVA_IO_TMPDIR_KEY ); 358 359 /** 360 * <p> 361 * The <code>java.library.path</code> System Property. List of paths to 362 * search when loading libraries. 363 * </p> 364 * <p> 365 * Defaults to <code>null</code> if the runtime does not have security 366 * access to read this property or the property does not exist. 367 * </p> 368 * <p> 369 * This value is initialized when the class is loaded. If 370 * {@link System#setProperty(String,String)} or 371 * {@link System#setProperties(java.util.Properties)} is called after this 372 * class is loaded, the value will be out of sync with that System property. 373 * </p> 374 * 375 * @since Java 1.2 376 */ 377 public static final String JAVA_LIBRARY_PATH = getSystemProperty( "java.library.path" ); 378 379 /** 380 * <p> 381 * The <code>java.runtime.name</code> System Property. Java Runtime 382 * Environment name. 383 * </p> 384 * <p> 385 * Defaults to <code>null</code> if the runtime does not have security 386 * access to read this property or the property does not exist. 387 * </p> 388 * <p> 389 * This value is initialized when the class is loaded. If 390 * {@link System#setProperty(String,String)} or 391 * {@link System#setProperties(java.util.Properties)} is called after this 392 * class is loaded, the value will be out of sync with that System property. 393 * </p> 394 * 395 * @since 2.0 396 * @since Java 1.3 397 */ 398 public static final String JAVA_RUNTIME_NAME = getSystemProperty( "java.runtime.name" ); 399 400 /** 401 * <p> 402 * The <code>java.runtime.version</code> System Property. Java Runtime 403 * Environment version. 404 * </p> 405 * <p> 406 * Defaults to <code>null</code> if the runtime does not have security 407 * access to read this property or the property does not exist. 408 * </p> 409 * <p> 410 * This value is initialized when the class is loaded. If 411 * {@link System#setProperty(String,String)} or 412 * {@link System#setProperties(java.util.Properties)} is called after this 413 * class is loaded, the value will be out of sync with that System property. 414 * </p> 415 * 416 * @since 2.0 417 * @since Java 1.3 418 */ 419 public static final String JAVA_RUNTIME_VERSION = getSystemProperty( "java.runtime.version" ); 420 421 /** 422 * <p> 423 * The <code>java.specification.name</code> System Property. Java Runtime 424 * Environment specification name. 425 * </p> 426 * <p> 427 * Defaults to <code>null</code> if the runtime does not have security 428 * access to read this property or the property does not exist. 429 * </p> 430 * <p> 431 * This value is initialized when the class is loaded. If 432 * {@link System#setProperty(String,String)} or 433 * {@link System#setProperties(java.util.Properties)} is called after this 434 * class is loaded, the value will be out of sync with that System property. 435 * </p> 436 * 437 * @since Java 1.2 438 */ 439 public static final String JAVA_SPECIFICATION_NAME = getSystemProperty( "java.specification.name" ); 440 441 /** 442 * <p> 443 * The <code>java.specification.vendor</code> System Property. Java 444 * Runtime Environment specification vendor. 445 * </p> 446 * <p> 447 * Defaults to <code>null</code> if the runtime does not have security 448 * access to read this property or the property does not exist. 449 * </p> 450 * <p> 451 * This value is initialized when the class is loaded. If 452 * {@link System#setProperty(String,String)} or 453 * {@link System#setProperties(java.util.Properties)} is called after this 454 * class is loaded, the value will be out of sync with that System property. 455 * </p> 456 * 457 * @since Java 1.2 458 */ 459 public static final String JAVA_SPECIFICATION_VENDOR = getSystemProperty( "java.specification.vendor" ); 460 461 /** 462 * <p> 463 * The <code>java.specification.version</code> System Property. Java 464 * Runtime Environment specification version. 465 * </p> 466 * <p> 467 * Defaults to <code>null</code> if the runtime does not have security 468 * access to read this property or the property does not exist. 469 * </p> 470 * <p> 471 * This value is initialized when the class is loaded. If 472 * {@link System#setProperty(String,String)} or 473 * {@link System#setProperties(java.util.Properties)} is called after this 474 * class is loaded, the value will be out of sync with that System property. 475 * </p> 476 * 477 * @since Java 1.3 478 */ 479 public static final String JAVA_SPECIFICATION_VERSION = getSystemProperty( "java.specification.version" ); 480 481 /** 482 * <p> 483 * The <code>java.util.prefs.PreferencesFactory</code> System Property. A 484 * class name. 485 * </p> 486 * <p> 487 * Defaults to <code>null</code> if the runtime does not have security 488 * access to read this property or the property does not exist. 489 * </p> 490 * <p> 491 * This value is initialized when the class is loaded. If 492 * {@link System#setProperty(String,String)} or 493 * {@link System#setProperties(java.util.Properties)} is called after this 494 * class is loaded, the value will be out of sync with that System property. 495 * </p> 496 * 497 * @since 2.1 498 * @since Java 1.4 499 */ 500 public static final String JAVA_UTIL_PREFS_PREFERENCES_FACTORY = getSystemProperty( "java.util.prefs.PreferencesFactory" ); 501 502 /** 503 * <p> 504 * The <code>java.vendor</code> System Property. Java vendor-specific 505 * string. 506 * </p> 507 * <p> 508 * Defaults to <code>null</code> if the runtime does not have security 509 * access to read this property or the property does not exist. 510 * </p> 511 * <p> 512 * This value is initialized when the class is loaded. If 513 * {@link System#setProperty(String,String)} or 514 * {@link System#setProperties(java.util.Properties)} is called after this 515 * class is loaded, the value will be out of sync with that System property. 516 * </p> 517 * 518 * @since Java 1.1 519 */ 520 public static final String JAVA_VENDOR = getSystemProperty( "java.vendor" ); 521 522 /** 523 * <p> 524 * The <code>java.vendor.url</code> System Property. Java vendor URL. 525 * </p> 526 * <p> 527 * Defaults to <code>null</code> if the runtime does not have security 528 * access to read this property or the property does not exist. 529 * </p> 530 * <p> 531 * This value is initialized when the class is loaded. If 532 * {@link System#setProperty(String,String)} or 533 * {@link System#setProperties(java.util.Properties)} is called after this 534 * class is loaded, the value will be out of sync with that System property. 535 * </p> 536 * 537 * @since Java 1.1 538 */ 539 public static final String JAVA_VENDOR_URL = getSystemProperty( "java.vendor.url" ); 540 541 /** 542 * <p> 543 * The <code>java.version</code> System Property. Java version number. 544 * </p> 545 * <p> 546 * Defaults to <code>null</code> if the runtime does not have security 547 * access to read this property or the property does not exist. 548 * </p> 549 * <p> 550 * This value is initialized when the class is loaded. If 551 * {@link System#setProperty(String,String)} or 552 * {@link System#setProperties(java.util.Properties)} is called after this 553 * class is loaded, the value will be out of sync with that System property. 554 * </p> 555 * 556 * @since Java 1.1 557 */ 558 public static final String JAVA_VERSION = getSystemProperty( "java.version" ); 559 560 /** 561 * <p> 562 * The <code>java.vm.info</code> System Property. Java Virtual Machine 563 * implementation info. 564 * </p> 565 * <p> 566 * Defaults to <code>null</code> if the runtime does not have security 567 * access to read this property or the property does not exist. 568 * </p> 569 * <p> 570 * This value is initialized when the class is loaded. If 571 * {@link System#setProperty(String,String)} or 572 * {@link System#setProperties(java.util.Properties)} is called after this 573 * class is loaded, the value will be out of sync with that System property. 574 * </p> 575 * 576 * @since 2.0 577 * @since Java 1.2 578 */ 579 public static final String JAVA_VM_INFO = getSystemProperty( "java.vm.info" ); 580 581 /** 582 * <p> 583 * The <code>java.vm.name</code> System Property. Java Virtual Machine 584 * implementation name. 585 * </p> 586 * <p> 587 * Defaults to <code>null</code> if the runtime does not have security 588 * access to read this property or the property does not exist. 589 * </p> 590 * <p> 591 * This value is initialized when the class is loaded. If 592 * {@link System#setProperty(String,String)} or 593 * {@link System#setProperties(java.util.Properties)} is called after this 594 * class is loaded, the value will be out of sync with that System property. 595 * </p> 596 * 597 * @since Java 1.2 598 */ 599 public static final String JAVA_VM_NAME = getSystemProperty( "java.vm.name" ); 600 601 /** 602 * <p> 603 * The <code>java.vm.specification.name</code> System Property. Java 604 * Virtual Machine specification name. 605 * </p> 606 * <p> 607 * Defaults to <code>null</code> if the runtime does not have security 608 * access to read this property or the property does not exist. 609 * </p> 610 * <p> 611 * This value is initialized when the class is loaded. If 612 * {@link System#setProperty(String,String)} or 613 * {@link System#setProperties(java.util.Properties)} is called after this 614 * class is loaded, the value will be out of sync with that System property. 615 * </p> 616 * 617 * @since Java 1.2 618 */ 619 public static final String JAVA_VM_SPECIFICATION_NAME = getSystemProperty( "java.vm.specification.name" ); 620 621 /** 622 * <p> 623 * The <code>java.vm.specification.vendor</code> System Property. Java 624 * Virtual Machine specification vendor. 625 * </p> 626 * <p> 627 * Defaults to <code>null</code> if the runtime does not have security 628 * access to read this property or the property does not exist. 629 * </p> 630 * <p> 631 * This value is initialized when the class is loaded. If 632 * {@link System#setProperty(String,String)} or 633 * {@link System#setProperties(java.util.Properties)} is called after this 634 * class is loaded, the value will be out of sync with that System property. 635 * </p> 636 * 637 * @since Java 1.2 638 */ 639 public static final String JAVA_VM_SPECIFICATION_VENDOR = getSystemProperty( "java.vm.specification.vendor" ); 640 641 /** 642 * <p> 643 * The <code>java.vm.specification.version</code> System Property. Java 644 * Virtual Machine specification version. 645 * </p> 646 * <p> 647 * Defaults to <code>null</code> if the runtime does not have security 648 * access to read this property or the property does not exist. 649 * </p> 650 * <p> 651 * This value is initialized when the class is loaded. If 652 * {@link System#setProperty(String,String)} or 653 * {@link System#setProperties(java.util.Properties)} is called after this 654 * class is loaded, the value will be out of sync with that System property. 655 * </p> 656 * 657 * @since Java 1.2 658 */ 659 public static final String JAVA_VM_SPECIFICATION_VERSION = getSystemProperty( "java.vm.specification.version" ); 660 661 /** 662 * <p> 663 * The <code>java.vm.vendor</code> System Property. Java Virtual Machine 664 * implementation vendor. 665 * </p> 666 * <p> 667 * Defaults to <code>null</code> if the runtime does not have security 668 * access to read this property or the property does not exist. 669 * </p> 670 * <p> 671 * This value is initialized when the class is loaded. If 672 * {@link System#setProperty(String,String)} or 673 * {@link System#setProperties(java.util.Properties)} is called after this 674 * class is loaded, the value will be out of sync with that System property. 675 * </p> 676 * 677 * @since Java 1.2 678 */ 679 public static final String JAVA_VM_VENDOR = getSystemProperty( "java.vm.vendor" ); 680 681 /** 682 * <p> 683 * The <code>java.vm.version</code> System Property. Java Virtual Machine 684 * implementation version. 685 * </p> 686 * <p> 687 * Defaults to <code>null</code> if the runtime does not have security 688 * access to read this property or the property does not exist. 689 * </p> 690 * <p> 691 * This value is initialized when the class is loaded. If 692 * {@link System#setProperty(String,String)} or 693 * {@link System#setProperties(java.util.Properties)} is called after this 694 * class is loaded, the value will be out of sync with that System property. 695 * </p> 696 * 697 * @since Java 1.2 698 */ 699 public static final String JAVA_VM_VERSION = getSystemProperty( "java.vm.version" ); 700 701 /** 702 * <p> 703 * The <code>line.separator</code> System Property. Line separator (<code>"\n<"</code> 704 * on UNIX). 705 * </p> 706 * <p> 707 * Defaults to <code>null</code> if the runtime does not have security 708 * access to read this property or the property does not exist. 709 * </p> 710 * <p> 711 * This value is initialized when the class is loaded. If 712 * {@link System#setProperty(String,String)} or 713 * {@link System#setProperties(java.util.Properties)} is called after this 714 * class is loaded, the value will be out of sync with that System property. 715 * </p> 716 * 717 * @since Java 1.1 718 */ 719 public static final String LINE_SEPARATOR = getSystemProperty( "line.separator" ); 720 721 /** 722 * <p> 723 * The <code>os.arch</code> System Property. Operating system 724 * architecture. 725 * </p> 726 * <p> 727 * Defaults to <code>null</code> if the runtime does not have security 728 * access to read this property or the property does not exist. 729 * </p> 730 * <p> 731 * This value is initialized when the class is loaded. If 732 * {@link System#setProperty(String,String)} or 733 * {@link System#setProperties(java.util.Properties)} is called after this 734 * class is loaded, the value will be out of sync with that System property. 735 * </p> 736 * 737 * @since Java 1.1 738 */ 739 public static final String OS_ARCH = getSystemProperty( "os.arch" ); 740 741 /** 742 * <p> 743 * The <code>os.name</code> System Property. Operating system name. 744 * </p> 745 * <p> 746 * Defaults to <code>null</code> if the runtime does not have security 747 * access to read this property or the property does not exist. 748 * </p> 749 * <p> 750 * This value is initialized when the class is loaded. If 751 * {@link System#setProperty(String,String)} or 752 * {@link System#setProperties(java.util.Properties)} is called after this 753 * class is loaded, the value will be out of sync with that System property. 754 * </p> 755 * 756 * @since Java 1.1 757 */ 758 public static final String OS_NAME = getSystemProperty( "os.name" ); 759 760 /** 761 * <p> 762 * The <code>os.version</code> System Property. Operating system version. 763 * </p> 764 * <p> 765 * Defaults to <code>null</code> if the runtime does not have security 766 * access to read this property or the property does not exist. 767 * </p> 768 * <p> 769 * This value is initialized when the class is loaded. If 770 * {@link System#setProperty(String,String)} or 771 * {@link System#setProperties(java.util.Properties)} is called after this 772 * class is loaded, the value will be out of sync with that System property. 773 * </p> 774 * 775 * @since Java 1.1 776 */ 777 public static final String OS_VERSION = getSystemProperty( "os.version" ); 778 779 /** 780 * <p> 781 * The <code>path.separator</code> System Property. Path separator (<code>":"</code> 782 * on UNIX). 783 * </p> 784 * <p> 785 * Defaults to <code>null</code> if the runtime does not have security 786 * access to read this property or the property does not exist. 787 * </p> 788 * <p> 789 * This value is initialized when the class is loaded. If 790 * {@link System#setProperty(String,String)} or 791 * {@link System#setProperties(java.util.Properties)} is called after this 792 * class is loaded, the value will be out of sync with that System property. 793 * </p> 794 * 795 * @since Java 1.1 796 */ 797 public static final String PATH_SEPARATOR = getSystemProperty( "path.separator" ); 798 799 /** 800 * <p> 801 * The <code>user.country</code> or <code>user.region</code> System 802 * Property. User's country code, such as <code>GB</code>. First in JDK 803 * version 1.2 as <code>user.region</code>. Renamed to 804 * <code>user.country</code> in 1.4 805 * </p> 806 * <p> 807 * Defaults to <code>null</code> if the runtime does not have security 808 * access to read this property or the property does not exist. 809 * </p> 810 * <p> 811 * This value is initialized when the class is loaded. If 812 * {@link System#setProperty(String,String)} or 813 * {@link System#setProperties(java.util.Properties)} is called after this 814 * class is loaded, the value will be out of sync with that System property. 815 * </p> 816 * 817 * @since 2.0 818 * @since Java 1.2 819 */ 820 public static final String USER_COUNTRY = ( getSystemProperty( "user.country" ) == null ? getSystemProperty( "user.region" ) 821 : getSystemProperty( "user.country" ) ); 822 823 /** 824 * <p> 825 * The <code>user.dir</code> System Property. User's current working 826 * directory. 827 * </p> 828 * <p> 829 * Defaults to <code>null</code> if the runtime does not have security 830 * access to read this property or the property does not exist. 831 * </p> 832 * <p> 833 * This value is initialized when the class is loaded. If 834 * {@link System#setProperty(String,String)} or 835 * {@link System#setProperties(java.util.Properties)} is called after this 836 * class is loaded, the value will be out of sync with that System property. 837 * </p> 838 * 839 * @since Java 1.1 840 */ 841 public static final String USER_DIR = getSystemProperty( USER_DIR_KEY ); 842 843 /** 844 * <p> 845 * The <code>user.home</code> System Property. User's home directory. 846 * </p> 847 * <p> 848 * Defaults to <code>null</code> if the runtime does not have security 849 * access to read this property or the property does not exist. 850 * </p> 851 * <p> 852 * This value is initialized when the class is loaded. If 853 * {@link System#setProperty(String,String)} or 854 * {@link System#setProperties(java.util.Properties)} is called after this 855 * class is loaded, the value will be out of sync with that System property. 856 * </p> 857 * 858 * @since Java 1.1 859 */ 860 public static final String USER_HOME = getSystemProperty( USER_HOME_KEY ); 861 862 /** 863 * <p> 864 * The <code>user.language</code> System Property. User's language code, 865 * such as <code>"en"</code>. 866 * </p> 867 * <p> 868 * Defaults to <code>null</code> if the runtime does not have security 869 * access to read this property or the property does not exist. 870 * </p> 871 * <p> 872 * This value is initialized when the class is loaded. If 873 * {@link System#setProperty(String,String)} or 874 * {@link System#setProperties(java.util.Properties)} is called after this 875 * class is loaded, the value will be out of sync with that System property. 876 * </p> 877 * 878 * @since 2.0 879 * @since Java 1.2 880 */ 881 public static final String USER_LANGUAGE = getSystemProperty( "user.language" ); 882 883 /** 884 * <p> 885 * The <code>user.name</code> System Property. User's account name. 886 * </p> 887 * <p> 888 * Defaults to <code>null</code> if the runtime does not have security 889 * access to read this property or the property does not exist. 890 * </p> 891 * <p> 892 * This value is initialized when the class is loaded. If 893 * {@link System#setProperty(String,String)} or 894 * {@link System#setProperties(java.util.Properties)} is called after this 895 * class is loaded, the value will be out of sync with that System property. 896 * </p> 897 * 898 * @since Java 1.1 899 */ 900 public static final String USER_NAME = getSystemProperty( "user.name" ); 901 902 /** 903 * <p> 904 * The <code>user.timezone</code> System Property. For example: 905 * <code>"America/Los_Angeles"</code>. 906 * </p> 907 * <p> 908 * Defaults to <code>null</code> if the runtime does not have security 909 * access to read this property or the property does not exist. 910 * </p> 911 * <p> 912 * This value is initialized when the class is loaded. If 913 * {@link System#setProperty(String,String)} or 914 * {@link System#setProperties(java.util.Properties)} is called after this 915 * class is loaded, the value will be out of sync with that System property. 916 * </p> 917 * 918 * @since 2.1 919 */ 920 public static final String USER_TIMEZONE = getSystemProperty( "user.timezone" ); 921 922 // Java version 923 // ----------------------------------------------------------------------- 924 // These MUST be declared after those above as they depend on the 925 // values being set up 926 927 /** 928 * <p> 929 * Gets the Java version as a <code>float</code>. 930 * </p> 931 * <p> 932 * Example return values: 933 * </p> 934 * <ul> 935 * <li><code>1.2f</code> for JDK 1.2 936 * <li><code>1.31f</code> for JDK 1.3.1 937 * </ul> 938 * <p> 939 * The field will return zero if {@link #JAVA_VERSION} is <code>null</code>. 940 * </p> 941 * 942 * @since 2.0 943 */ 944 public static final float JAVA_VERSION_FLOAT = getJavaVersionAsFloat(); 945 946 /** 947 * <p> 948 * Gets the Java version as an <code>int</code>. 949 * </p> 950 * <p> 951 * Example return values: 952 * </p> 953 * <ul> 954 * <li><code>120</code> for JDK 1.2 955 * <li><code>131</code> for JDK 1.3.1 956 * </ul> 957 * <p> 958 * The field will return zero if {@link #JAVA_VERSION} is <code>null</code>. 959 * </p> 960 * 961 * @since 2.0 962 */ 963 public static final int JAVA_VERSION_INT = getJavaVersionAsInt(); 964 965 // Java version checks 966 // ----------------------------------------------------------------------- 967 // These MUST be declared after those above as they depend on the 968 // values being set up 969 970 /** 971 * <p> 972 * Is <code>true</code> if this is Java version 1.1 (also 1.1.x versions). 973 * </p> 974 * <p> 975 * The field will return <code>false</code> if {@link #JAVA_VERSION} is 976 * <code>null</code>. 977 * </p> 978 */ 979 public static final boolean IS_JAVA_1_1 = getJavaVersionMatches( "1.1" ); 980 981 /** 982 * <p> 983 * Is <code>true</code> if this is Java version 1.2 (also 1.2.x versions). 984 * </p> 985 * <p> 986 * The field will return <code>false</code> if {@link #JAVA_VERSION} is 987 * <code>null</code>. 988 * </p> 989 */ 990 public static final boolean IS_JAVA_1_2 = getJavaVersionMatches( "1.2" ); 991 992 /** 993 * <p> 994 * Is <code>true</code> if this is Java version 1.3 (also 1.3.x versions). 995 * </p> 996 * <p> 997 * The field will return <code>false</code> if {@link #JAVA_VERSION} is 998 * <code>null</code>. 999 * </p> 1000 */ 1001 public static final boolean IS_JAVA_1_3 = getJavaVersionMatches( "1.3" ); 1002 1003 /** 1004 * <p> 1005 * Is <code>true</code> if this is Java version 1.4 (also 1.4.x versions). 1006 * </p> 1007 * <p> 1008 * The field will return <code>false</code> if {@link #JAVA_VERSION} is 1009 * <code>null</code>. 1010 * </p> 1011 */ 1012 public static final boolean IS_JAVA_1_4 = getJavaVersionMatches( "1.4" ); 1013 1014 /** 1015 * <p> 1016 * Is <code>true</code> if this is Java version 1.5 (also 1.5.x versions). 1017 * </p> 1018 * <p> 1019 * The field will return <code>false</code> if {@link #JAVA_VERSION} is 1020 * <code>null</code>. 1021 * </p> 1022 */ 1023 public static final boolean IS_JAVA_1_5 = getJavaVersionMatches( "1.5" ); 1024 1025 // Operating system checks 1026 // ----------------------------------------------------------------------- 1027 // These MUST be declared after those above as they depend on the 1028 // values being set up 1029 // OS names from http://www.vamphq.com/os.html 1030 // Selected ones included - please advise commons-dev@jakarta.apache.org 1031 // if you want another added or a mistake corrected 1032 1033 /** 1034 * <p> 1035 * Is <code>true</code> if this is AIX. 1036 * </p> 1037 * <p> 1038 * The field will return <code>false</code> if <code>OS_NAME</code> is 1039 * <code>null</code>. 1040 * </p> 1041 * 1042 * @since 2.0 1043 */ 1044 public static final boolean IS_OS_AIX = getOSMatches( "AIX" ); 1045 1046 /** 1047 * <p> 1048 * Is <code>true</code> if this is HP-UX. 1049 * </p> 1050 * <p> 1051 * The field will return <code>false</code> if <code>OS_NAME</code> is 1052 * <code>null</code>. 1053 * </p> 1054 * 1055 * @since 2.0 1056 */ 1057 public static final boolean IS_OS_HP_UX = getOSMatches( "HP-UX" ); 1058 1059 /** 1060 * <p> 1061 * Is <code>true</code> if this is Irix. 1062 * </p> 1063 * <p> 1064 * The field will return <code>false</code> if <code>OS_NAME</code> is 1065 * <code>null</code>. 1066 * </p> 1067 * 1068 * @since 2.0 1069 */ 1070 public static final boolean IS_OS_IRIX = getOSMatches( "Irix" ); 1071 1072 /** 1073 * <p> 1074 * Is <code>true</code> if this is Linux. 1075 * </p> 1076 * <p> 1077 * The field will return <code>false</code> if <code>OS_NAME</code> is 1078 * <code>null</code>. 1079 * </p> 1080 * 1081 * @since 2.0 1082 */ 1083 public static final boolean IS_OS_LINUX = getOSMatches( "Linux" ) || getOSMatches( "LINUX" ); 1084 1085 /** 1086 * <p> 1087 * Is <code>true</code> if this is Mac. 1088 * </p> 1089 * <p> 1090 * The field will return <code>false</code> if <code>OS_NAME</code> is 1091 * <code>null</code>. 1092 * </p> 1093 * 1094 * @since 2.0 1095 */ 1096 public static final boolean IS_OS_MAC = getOSMatches( "Mac" ); 1097 1098 /** 1099 * <p> 1100 * Is <code>true</code> if this is Mac. 1101 * </p> 1102 * <p> 1103 * The field will return <code>false</code> if <code>OS_NAME</code> is 1104 * <code>null</code>. 1105 * </p> 1106 * 1107 * @since 2.0 1108 */ 1109 public static final boolean IS_OS_MAC_OSX = getOSMatches( "Mac OS X" ); 1110 1111 /** 1112 * <p> 1113 * Is <code>true</code> if this is OS/2. 1114 * </p> 1115 * <p> 1116 * The field will return <code>false</code> if <code>OS_NAME</code> is 1117 * <code>null</code>. 1118 * </p> 1119 * 1120 * @since 2.0 1121 */ 1122 public static final boolean IS_OS_OS2 = getOSMatches( "OS/2" ); 1123 1124 /** 1125 * <p> 1126 * Is <code>true</code> if this is Solaris. 1127 * </p> 1128 * <p> 1129 * The field will return <code>false</code> if <code>OS_NAME</code> is 1130 * <code>null</code>. 1131 * </p> 1132 * 1133 * @since 2.0 1134 */ 1135 public static final boolean IS_OS_SOLARIS = getOSMatches( "Solaris" ); 1136 1137 /** 1138 * <p> 1139 * Is <code>true</code> if this is SunOS. 1140 * </p> 1141 * <p> 1142 * The field will return <code>false</code> if <code>OS_NAME</code> is 1143 * <code>null</code>. 1144 * </p> 1145 * 1146 * @since 2.0 1147 */ 1148 public static final boolean IS_OS_SUN_OS = getOSMatches( "SunOS" ); 1149 1150 /** 1151 * <p> 1152 * Is <code>true</code> if this is a POSIX compilant system, as in any of 1153 * AIX, HP-UX, Irix, Linux, MacOSX, Solaris or SUN OS. 1154 * </p> 1155 * <p> 1156 * The field will return <code>false</code> if <code>OS_NAME</code> is 1157 * <code>null</code>. 1158 * </p> 1159 * 1160 * @since 2.1 1161 */ 1162 public static final boolean IS_OS_UNIX = IS_OS_AIX || IS_OS_HP_UX || IS_OS_IRIX || IS_OS_LINUX || IS_OS_MAC_OSX 1163 || IS_OS_SOLARIS || IS_OS_SUN_OS; 1164 1165 /** 1166 * <p> 1167 * Is <code>true</code> if this is Windows. 1168 * </p> 1169 * <p> 1170 * The field will return <code>false</code> if <code>OS_NAME</code> is 1171 * <code>null</code>. 1172 * </p> 1173 * 1174 * @since 2.0 1175 */ 1176 public static final boolean IS_OS_WINDOWS = getOSMatches( OS_NAME_WINDOWS_PREFIX ); 1177 1178 /** 1179 * <p> 1180 * Is <code>true</code> if this is Windows 2000. 1181 * </p> 1182 * <p> 1183 * The field will return <code>false</code> if <code>OS_NAME</code> is 1184 * <code>null</code>. 1185 * </p> 1186 * 1187 * @since 2.0 1188 */ 1189 public static final boolean IS_OS_WINDOWS_2000 = getOSMatches( OS_NAME_WINDOWS_PREFIX, "5.0" ); 1190 1191 /** 1192 * <p> 1193 * Is <code>true</code> if this is Windows 95. 1194 * </p> 1195 * <p> 1196 * The field will return <code>false</code> if <code>OS_NAME</code> is 1197 * <code>null</code>. 1198 * </p> 1199 * 1200 * @since 2.0 1201 */ 1202 public static final boolean IS_OS_WINDOWS_95 = getOSMatches( OS_NAME_WINDOWS_PREFIX + " 9", "4.0" ); 1203 1204 // JDK 1.2 running on Windows98 returns 'Windows 95', hence the above 1205 1206 /** 1207 * <p> 1208 * Is <code>true</code> if this is Windows 98. 1209 * </p> 1210 * <p> 1211 * The field will return <code>false</code> if <code>OS_NAME</code> is 1212 * <code>null</code>. 1213 * </p> 1214 * 1215 * @since 2.0 1216 */ 1217 public static final boolean IS_OS_WINDOWS_98 = getOSMatches( OS_NAME_WINDOWS_PREFIX + " 9", "4.1" ); 1218 1219 // JDK 1.2 running on Windows98 returns 'Windows 95', hence the above 1220 1221 /** 1222 * <p> 1223 * Is <code>true</code> if this is Windows ME. 1224 * </p> 1225 * <p> 1226 * The field will return <code>false</code> if <code>OS_NAME</code> is 1227 * <code>null</code>. 1228 * </p> 1229 * 1230 * @since 2.0 1231 */ 1232 public static final boolean IS_OS_WINDOWS_ME = getOSMatches( OS_NAME_WINDOWS_PREFIX, "4.9" ); 1233 1234 // JDK 1.2 running on WindowsME may return 'Windows 95', hence the above 1235 1236 /** 1237 * <p> 1238 * Is <code>true</code> if this is Windows NT. 1239 * </p> 1240 * <p> 1241 * The field will return <code>false</code> if <code>OS_NAME</code> is 1242 * <code>null</code>. 1243 * </p> 1244 * 1245 * @since 2.0 1246 */ 1247 public static final boolean IS_OS_WINDOWS_NT = getOSMatches( OS_NAME_WINDOWS_PREFIX + " NT" ); 1248 1249 // Windows 2000 returns 'Windows 2000' but may suffer from same JDK1.2 1250 // problem 1251 1252 /** 1253 * <p> 1254 * Is <code>true</code> if this is Windows XP. 1255 * </p> 1256 * <p> 1257 * The field will return <code>false</code> if <code>OS_NAME</code> is 1258 * <code>null</code>. 1259 * </p> 1260 * 1261 * @since 2.0 1262 */ 1263 public static final boolean IS_OS_WINDOWS_XP = getOSMatches( OS_NAME_WINDOWS_PREFIX, "5.1" ); 1264 1265 1266 // ----------------------------------------------------------------------- 1267 /** 1268 * <p> 1269 * SystemUtils instances should NOT be constructed in standard programming. 1270 * Instead, the class should be used as 1271 * <code>SystemUtils.FILE_SEPARATOR</code>. 1272 * </p> 1273 * <p> 1274 * This constructor is public to permit tools that require a JavaBean 1275 * instance to operate. 1276 * </p> 1277 */ 1278 public SystemUtils() 1279 { 1280 // no init. 1281 } 1282 1283 1284 // ----------------------------------------------------------------------- 1285 /** 1286 * <p> 1287 * Gets the Java version number as a <code>float</code>. 1288 * </p> 1289 * <p> 1290 * Example return values: 1291 * </p> 1292 * <ul> 1293 * <li><code>1.2f</code> for JDK 1.2 1294 * <li><code>1.31f</code> for JDK 1.3.1 1295 * </ul> 1296 * 1297 * @return the version, for example 1.31f for JDK 1.3.1 1298 * @deprecated Use {@link #JAVA_VERSION_FLOAT} instead. Method will be 1299 * removed in Commons Lang 3.0. 1300 */ 1301 public static float getJavaVersion() 1302 { 1303 return JAVA_VERSION_FLOAT; 1304 } 1305 1306 1307 /** 1308 * <p> 1309 * Gets the Java version number as a <code>float</code>. 1310 * </p> 1311 * <p> 1312 * Example return values: 1313 * </p> 1314 * <ul> 1315 * <li><code>1.2f</code> for JDK 1.2 1316 * <li><code>1.31f</code> for JDK 1.3.1 1317 * </ul> 1318 * <p> 1319 * Patch releases are not reported. Zero is returned if 1320 * {@link #JAVA_VERSION} is <code>null</code>. 1321 * </p> 1322 * 1323 * @return the version, for example 1.31f for JDK 1.3.1 1324 */ 1325 private static float getJavaVersionAsFloat() 1326 { 1327 if ( JAVA_VERSION == null ) 1328 { 1329 return 0f; 1330 } 1331 String str = JAVA_VERSION.substring( 0, 3 ); 1332 if ( JAVA_VERSION.length() >= 5 ) 1333 { 1334 str = str + JAVA_VERSION.substring( 4, 5 ); 1335 } 1336 return Float.parseFloat( str ); 1337 } 1338 1339 1340 /** 1341 * <p> 1342 * Gets the Java version number as an <code>int</code>. 1343 * </p> 1344 * <p> 1345 * Example return values: 1346 * </p> 1347 * <ul> 1348 * <li><code>120</code> for JDK 1.2 1349 * <li><code>131</code> for JDK 1.3.1 1350 * </ul> 1351 * <p> 1352 * Patch releases are not reported. Zero is returned if 1353 * {@link #JAVA_VERSION} is <code>null</code>. 1354 * </p> 1355 * 1356 * @return the version, for example 131 for JDK 1.3.1 1357 */ 1358 private static int getJavaVersionAsInt() 1359 { 1360 if ( JAVA_VERSION == null ) 1361 { 1362 return 0; 1363 } 1364 String str = JAVA_VERSION.substring( 0, 1 ); 1365 str = str + JAVA_VERSION.substring( 2, 3 ); 1366 if ( JAVA_VERSION.length() >= 5 ) 1367 { 1368 str = str + JAVA_VERSION.substring( 4, 5 ); 1369 } 1370 else 1371 { 1372 str = str + "0"; 1373 } 1374 return Integer.parseInt( str ); 1375 } 1376 1377 1378 /** 1379 * <p> 1380 * Decides if the java version matches. 1381 * </p> 1382 * 1383 * @param versionPrefix 1384 * the prefix for the java version 1385 * @return true if matches, or false if not or can't determine 1386 */ 1387 private static boolean getJavaVersionMatches( String versionPrefix ) 1388 { 1389 if ( JAVA_VERSION == null ) 1390 { 1391 return false; 1392 } 1393 return JAVA_VERSION.startsWith( versionPrefix ); 1394 } 1395 1396 1397 /** 1398 * <p> 1399 * Decides if the operating system matches. 1400 * </p> 1401 * 1402 * @param osNamePrefix 1403 * the prefix for the os name 1404 * @return true if matches, or false if not or can't determine 1405 */ 1406 private static boolean getOSMatches( String osNamePrefix ) 1407 { 1408 if ( OS_NAME == null ) 1409 { 1410 return false; 1411 } 1412 return OS_NAME.startsWith( osNamePrefix ); 1413 } 1414 1415 1416 /** 1417 * <p> 1418 * Decides if the operating system matches. 1419 * </p> 1420 * 1421 * @param osNamePrefix 1422 * the prefix for the os name 1423 * @param osVersionPrefix 1424 * the prefix for the version 1425 * @return true if matches, or false if not or can't determine 1426 */ 1427 private static boolean getOSMatches( String osNamePrefix, String osVersionPrefix ) 1428 { 1429 if ( OS_NAME == null || OS_VERSION == null ) 1430 { 1431 return false; 1432 } 1433 return OS_NAME.startsWith( osNamePrefix ) && OS_VERSION.startsWith( osVersionPrefix ); 1434 } 1435 1436 1437 // ----------------------------------------------------------------------- 1438 /** 1439 * <p> 1440 * Gets a System property, defaulting to <code>null</code> if the property 1441 * cannot be read. 1442 * </p> 1443 * <p> 1444 * If a <code>SecurityException</code> is caught, the return value is 1445 * <code>null</code> and a message is written to <code>System.err</code>. 1446 * </p> 1447 * 1448 * @param property 1449 * the system property name 1450 * @return the system property value or <code>null</code> if a security 1451 * problem occurs 1452 */ 1453 private static String getSystemProperty( String property ) 1454 { 1455 try 1456 { 1457 return System.getProperty( property ); 1458 } 1459 catch ( SecurityException ex ) 1460 { 1461 // we are not allowed to look at this property 1462 System.err.println( I18n.err( I18n.ERR_04437, property ) ); 1463 return null; 1464 } 1465 } 1466 1467 1468 /** 1469 * <p> 1470 * Is the Java version at least the requested version. 1471 * </p> 1472 * <p> 1473 * Example input: 1474 * </p> 1475 * <ul> 1476 * <li><code>1.2f</code> to test for JDK 1.2</li> 1477 * <li><code>1.31f</code> to test for JDK 1.3.1</li> 1478 * </ul> 1479 * 1480 * @param requiredVersion 1481 * the required version, for example 1.31f 1482 * @return <code>true</code> if the actual version is equal or greater 1483 * than the required version 1484 */ 1485 public static boolean isJavaVersionAtLeast( float requiredVersion ) 1486 { 1487 return ( JAVA_VERSION_FLOAT >= requiredVersion ); 1488 } 1489 1490 1491 /** 1492 * <p> 1493 * Is the Java version at least the requested version. 1494 * </p> 1495 * <p> 1496 * Example input: 1497 * </p> 1498 * <ul> 1499 * <li><code>120</code> to test for JDK 1.2 or greater</li> 1500 * <li><code>131</code> to test for JDK 1.3.1 or greater</li> 1501 * </ul> 1502 * 1503 * @param requiredVersion 1504 * the required version, for example 131 1505 * @return <code>true</code> if the actual version is equal or greater 1506 * than the required version 1507 * @since 2.0 1508 */ 1509 public static boolean isJavaVersionAtLeast( int requiredVersion ) 1510 { 1511 return ( JAVA_VERSION_INT >= requiredVersion ); 1512 } 1513 1514 1515 /** 1516 * Returns whether the {@link #JAVA_AWT_HEADLESS} value is <code>true</code>. 1517 * 1518 * @return <code>true</code> if <code>JAVA_AWT_HEADLESS</code> is 1519 * <code>"true"</code>, <code>false</code> otherwise. 1520 * @see #JAVA_AWT_HEADLESS 1521 * @since 2.1 1522 * @since Java 1.4 1523 */ 1524 public static boolean isJavaAwtHeadless() 1525 { 1526 return JAVA_AWT_HEADLESS != null ? JAVA_AWT_HEADLESS.equals( Boolean.TRUE.toString() ) : false; 1527 } 1528 1529 1530 /** 1531 * <p> 1532 * Gets the Java home directory as a <code>File</code>. 1533 * </p> 1534 * 1535 * @return a directory 1536 * @throws SecurityException 1537 * if a security manager exists and its 1538 * <code>checkPropertyAccess</code> method doesn't allow 1539 * access to the specified system property. 1540 * @see System#getProperty(String) 1541 */ 1542 public static File getJavaHome() 1543 { 1544 return new File( System.getProperty( JAVA_HOME_KEY ) ); 1545 } 1546 1547 1548 /** 1549 * <p> 1550 * Gets the Java IO temporary directory as a <code>File</code>. 1551 * </p> 1552 * 1553 * @return a directory 1554 * @throws SecurityException 1555 * if a security manager exists and its 1556 * <code>checkPropertyAccess</code> method doesn't allow 1557 * access to the specified system property. 1558 * @see System#getProperty(String) 1559 */ 1560 public static File getJavaIoTmpDir() 1561 { 1562 return new File( System.getProperty( JAVA_IO_TMPDIR_KEY ) ); 1563 } 1564 1565 1566 /** 1567 * <p> 1568 * Gets the user directory as a <code>File</code>. 1569 * </p> 1570 * 1571 * @return a directory 1572 * @throws SecurityException 1573 * if a security manager exists and its 1574 * <code>checkPropertyAccess</code> method doesn't allow 1575 * access to the specified system property. 1576 * @see System#getProperty(String) 1577 */ 1578 public static File getUserDir() 1579 { 1580 return new File( System.getProperty( USER_DIR_KEY ) ); 1581 } 1582 1583 1584 /** 1585 * <p> 1586 * Gets the user home directory as a <code>File</code>. 1587 * </p> 1588 * 1589 * @return a directory 1590 * @throws SecurityException 1591 * if a security manager exists and its 1592 * <code>checkPropertyAccess</code> method doesn't allow 1593 * access to the specified system property. 1594 * @see System#getProperty(String) 1595 */ 1596 public static File getUserHome() 1597 { 1598 return new File( System.getProperty( USER_HOME_KEY ) ); 1599 } 1600 1601 }