/*
-----BEGIN PGP SIGNED MESSAGE-----
*/
/** Test whether the current or a given version is suffiently recent. A
* few WWW sites are testing for the browser version and assuming a certain
* Java version (incorrectly). This code allows your applet to test whether
* the host machine's browser or OS is supplying an adequate version of Java
* to run your code.
* @author Tony Dahlman
* @version 1.1 1998/01/01
*/
class VersionTest {
/** General solution to testing for the java version: you supply the string
* to be tested for compatibility. This allows various "proprietary" or
* deviant properties lists to be handled however you wnat to handle them.
* The 3-parameter morph of isVersionOK() is less general but it handles
* version strings like "11" or "1.2beta4".
* @param major - required minimum major version.
* @param minor - required minimum minor version, if major version is acceptable.
* @param bugfix - required minimum minor sub-version, if major & minor versions
* are acceptable.
* @param testVersion - Here's where you supply a string to be tested, usually but
* not always, the result of directly calling String testVersion =
* System.getProperty("java.version").
*/
boolean isVersionOK( int major, int minor, int bugfix, String testVersion) {
int dex = testVersion.indexOf('.');
if( dex < 1 ) return false;
try {
// check major version
int temp = Integer.parseInt( testVersion.substring(0,dex) );
if( temp < major ) return false;
if( temp > major ) return true;
testVersion = testVersion.substring( dex + 1 );
// lose any trailing letter as in 1.1.7A
char ch = testVersion.charAt(testVersion.length()-1);
if( ! Character.isDigit(ch) )
testVersion = testVersion.substring(0,testVersion.length()-1);
// check minor version
dex = testVersion.indexOf('.');
if( dex < 1 ) { // case of no bugfix number as in 1.2 or 1.0
testVersion += ".0";
dex = testVersion.indexOf('.');
}
temp = Integer.parseInt( testVersion.substring(0,dex) );
if( temp < minor ) return false;
if( temp > minor ) return true;
// check bugfix version
testVersion = testVersion.substring( dex + 1 );
temp = Integer.parseInt( testVersion );
return ( temp >= bugfix );
} catch ( NumberFormatException e ) {
System.err.println("Number format exception checking version. Is properties list corrupt?");
return false;
} catch ( StringIndexOutOfBoundsException se ) {
System.err.println("isVersionOK() failed due to input that couldn't be parsed: "+testVersion);
return false;
} /* end catch */
}
/** A simpler method for testing whether the current java version is
* sufficiently recent. Thanks to Roedy Green
* for pointing out some of the pitfalls and making this version test
* more robust.
*/
boolean isVersionOK( int major, int minor, int bugfix) {
String ver = System.getProperty("java.version");
if( ver == null ) return false;
ver = ver.trim();
if( ver.indexOf('.') < 0 )
// case of missing dot (Symantec applet viewer)
ver = ver.charAt(0) + '.' + ver.substring(1);
int fdex;
if( ( fdex = find( "beta", ver, true )) > 0 )
// case of 1.2beta4, and so on...
ver = ver.substring(0,fdex);
return isVersionOK( major, minor, bugfix, ver);
}
static int find(String searchString, String testString, boolean caseInsensitive) {
int len = searchString.length();
if (caseInsensitive) {
for (int i=0; i 0) ) {
ver = ver.substring(0, find("beta", ver, true));
System.out.println("Testing whether the beta version " + ver
+" equals or exceeds " + major +"."+ minor +"."+ bug +"...\n"
+"isVersionOkay() returns \""
+ vt.isVersionOK( major, minor, bug, ver ) + "\"\n");
} else {
System.out.println("Testing whether version " + ver
+" equals or exceeds " + major +"."+ minor +"."+ bug +"...\n"
+"isVersionOkay() returns \""
+ vt.isVersionOK( major, minor, bug, ver ) + "\"\n");
}
} else {
System.out.println("Testing whether the current version "
+" equals or exceeds " + major +"."+ minor +"."+ bug +"...\n"
+"isVersionOkay() returns \""
+ vt.isVersionOK( major, minor, bug ) + "\"\n");
}
}
}
/*
-----BEGIN PGP SIGNATURE-----
Version: 2.6.2
iQCVAwUBNo2WbmbsFmrW0oYFAQGy9AP/WrRuNE3QCouC7shRGXPgIIwafZsFxztz
EeZeX1FlBUPsPsAa2U/iPjJ6FOy0mGHuj4Y8D42GZFn+Tl8CcfQOI3OLcuhKCOgc
T0GIgf5PN2OopZdLL/iArThKFP4zdC8Zohp7n4XZpR97k+TZDcOvnq92fDMt0ywb
9MZHWS/PCb0=
=Gr5F
-----END PGP SIGNATURE-----
*/