diff options
author | andrew <devnull@localhost> | 2010-10-19 17:55:59 +0100 |
---|---|---|
committer | andrew <devnull@localhost> | 2010-10-19 17:55:59 +0100 |
commit | 7603e948d7a0a7eb2e72358cb4a40ae6779f95da (patch) | |
tree | c6441f7d14eafe8119d890cddd09b05b8f88c52a /netx/net/sourceforge/jnlp/Version.java |
Initial import from IcedTea6.
2010-10-19 Andrew John Hughes <[email protected]>
* .hgignore,
* Makefile.am,
* acinclude.m4,
* autogen.sh,
* configure.ac,
* extra/net/sourceforge/jnlp/about/HTMLPanel.java,
* extra/net/sourceforge/jnlp/about/Main.java,
* extra/net/sourceforge/jnlp/about/resources/about.html,
* extra/net/sourceforge/jnlp/about/resources/applications.html,
* extra/net/sourceforge/jnlp/about/resources/notes.html,
* javac.in,
* javaws.desktop: Imported from IcedTea6.
* launcher/java.c,
* launcher/java.h,
* launcher/java_md.c,
* launcher/java_md.h,
* launcher/jli_util.h,
* launcher/jni.h,
* launcher/jvm.h,
* launcher/jvm_md.h,
* launcher/manifest_info.h,
* launcher/splashscreen.h,
* launcher/splashscreen_stubs.c,
* launcher/version_comp.h,
* launcher/wildcard.h: Imported from OpenJDK.
* netx/javaws.1,
* netx/javax/jnlp/BasicService.java,
* netx/javax/jnlp/ClipboardService.java,
* netx/javax/jnlp/DownloadService.java,
* netx/javax/jnlp/DownloadServiceListener.java,
* netx/javax/jnlp/ExtendedService.java,
* netx/javax/jnlp/ExtensionInstallerService.java,
* netx/javax/jnlp/FileContents.java,
* netx/javax/jnlp/FileOpenService.java,
* netx/javax/jnlp/FileSaveService.java,
* netx/javax/jnlp/JNLPRandomAccessFile.java,
* netx/javax/jnlp/PersistenceService.java,
* netx/javax/jnlp/PrintService.java,
* netx/javax/jnlp/ServiceManager.java,
* netx/javax/jnlp/ServiceManagerStub.java,
* netx/javax/jnlp/SingleInstanceListener.java,
* netx/javax/jnlp/SingleInstanceService.java,
* netx/javax/jnlp/UnavailableServiceException.java,
* netx/net/sourceforge/jnlp/AppletDesc.java,
* netx/net/sourceforge/jnlp/ApplicationDesc.java,
* netx/net/sourceforge/jnlp/AssociationDesc.java,
* netx/net/sourceforge/jnlp/ComponentDesc.java,
* netx/net/sourceforge/jnlp/DefaultLaunchHandler.java,
* netx/net/sourceforge/jnlp/ExtensionDesc.java,
* netx/net/sourceforge/jnlp/IconDesc.java,
* netx/net/sourceforge/jnlp/InformationDesc.java,
* netx/net/sourceforge/jnlp/InstallerDesc.java,
* netx/net/sourceforge/jnlp/JARDesc.java,
* netx/net/sourceforge/jnlp/JNLPFile.java,
* netx/net/sourceforge/jnlp/JNLPSplashScreen.java,
* netx/net/sourceforge/jnlp/JREDesc.java,
* netx/net/sourceforge/jnlp/LaunchException.java,
* netx/net/sourceforge/jnlp/LaunchHandler.java,
* netx/net/sourceforge/jnlp/Launcher.java,
* netx/net/sourceforge/jnlp/MenuDesc.java,
* netx/net/sourceforge/jnlp/NetxPanel.java,
* netx/net/sourceforge/jnlp/Node.java,
* netx/net/sourceforge/jnlp/PackageDesc.java,
* netx/net/sourceforge/jnlp/ParseException.java,
* netx/net/sourceforge/jnlp/Parser.java,
* netx/net/sourceforge/jnlp/PluginBridge.java,
* netx/net/sourceforge/jnlp/PropertyDesc.java,
* netx/net/sourceforge/jnlp/RelatedContentDesc.java,
* netx/net/sourceforge/jnlp/ResourcesDesc.java,
* netx/net/sourceforge/jnlp/SecurityDesc.java,
* netx/net/sourceforge/jnlp/ShortcutDesc.java,
* netx/net/sourceforge/jnlp/StreamEater.java,
* netx/net/sourceforge/jnlp/UpdateDesc.java,
* netx/net/sourceforge/jnlp/Version.java,
* netx/net/sourceforge/jnlp/cache/CacheEntry.java,
* netx/net/sourceforge/jnlp/cache/CacheUtil.java,
* netx/net/sourceforge/jnlp/cache/DefaultDownloadIndicator.java,
* netx/net/sourceforge/jnlp/cache/DownloadIndicator.java,
* netx/net/sourceforge/jnlp/cache/Resource.java,
* netx/net/sourceforge/jnlp/cache/ResourceTracker.java,
* netx/net/sourceforge/jnlp/cache/UpdatePolicy.java,
* netx/net/sourceforge/jnlp/cache/package.html,
* netx/net/sourceforge/jnlp/event/ApplicationEvent.java,
* netx/net/sourceforge/jnlp/event/ApplicationListener.java,
* netx/net/sourceforge/jnlp/event/DownloadEvent.java,
* netx/net/sourceforge/jnlp/event/DownloadListener.java,
* netx/net/sourceforge/jnlp/event/package.html,
* netx/net/sourceforge/jnlp/package.html,
* netx/net/sourceforge/jnlp/resources/Manifest.mf,
* netx/net/sourceforge/jnlp/resources/Messages.properties,
* netx/net/sourceforge/jnlp/resources/about.jnlp,
* netx/net/sourceforge/jnlp/resources/default.jnlp,
* netx/net/sourceforge/jnlp/runtime/AppThreadGroup.java,
* netx/net/sourceforge/jnlp/runtime/AppletAudioClip.java,
* netx/net/sourceforge/jnlp/runtime/AppletEnvironment.java,
* netx/net/sourceforge/jnlp/runtime/AppletInstance.java,
* netx/net/sourceforge/jnlp/runtime/ApplicationInstance.java,
* netx/net/sourceforge/jnlp/runtime/Boot.java,
* netx/net/sourceforge/jnlp/runtime/Boot13.java,
* netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java,
* netx/net/sourceforge/jnlp/runtime/JNLPPolicy.java,
* netx/net/sourceforge/jnlp/runtime/JNLPRuntime.java,
* netx/net/sourceforge/jnlp/runtime/JNLPSecurityManager.java,
* netx/net/sourceforge/jnlp/runtime/package.html,
* netx/net/sourceforge/jnlp/security/AccessWarningPane.java,
* netx/net/sourceforge/jnlp/security/AppletWarningPane.java,
* netx/net/sourceforge/jnlp/security/CertVerifier.java,
* netx/net/sourceforge/jnlp/security/CertWarningPane.java,
* netx/net/sourceforge/jnlp/security/CertsInfoPane.java,
* netx/net/sourceforge/jnlp/security/HttpsCertVerifier.java,
* netx/net/sourceforge/jnlp/security/MoreInfoPane.java,
* netx/net/sourceforge/jnlp/security/NotAllSignedWarningPane.java,
* netx/net/sourceforge/jnlp/security/SecurityDialogPanel.java,
* netx/net/sourceforge/jnlp/security/SecurityUtil.java,
* netx/net/sourceforge/jnlp/security/SecurityWarningDialog.java,
* netx/net/sourceforge/jnlp/security/SingleCertInfoPane.java,
* netx/net/sourceforge/jnlp/security/VariableX509TrustManager.java,
* netx/net/sourceforge/jnlp/security/viewer/CertificatePane.java,
* netx/net/sourceforge/jnlp/security/viewer/CertificateViewer.java,
* netx/net/sourceforge/jnlp/services/ExtendedSingleInstanceService.java,
* netx/net/sourceforge/jnlp/services/InstanceExistsException.java,
* netx/net/sourceforge/jnlp/services/ServiceUtil.java,
* netx/net/sourceforge/jnlp/services/SingleInstanceLock.java,
* netx/net/sourceforge/jnlp/services/XBasicService.java,
* netx/net/sourceforge/jnlp/services/XClipboardService.java,
* netx/net/sourceforge/jnlp/services/XDownloadService.java,
* netx/net/sourceforge/jnlp/services/XExtendedService.java,
* netx/net/sourceforge/jnlp/services/XExtensionInstallerService.java,
* netx/net/sourceforge/jnlp/services/XFileContents.java,
* netx/net/sourceforge/jnlp/services/XFileOpenService.java,
* netx/net/sourceforge/jnlp/services/XFileSaveService.java,
* netx/net/sourceforge/jnlp/services/XJNLPRandomAccessFile.java,
* netx/net/sourceforge/jnlp/services/XPersistenceService.java,
* netx/net/sourceforge/jnlp/services/XPrintService.java,
* netx/net/sourceforge/jnlp/services/XServiceManagerStub.java,
* netx/net/sourceforge/jnlp/services/XSingleInstanceService.java,
* netx/net/sourceforge/jnlp/services/package.html,
* netx/net/sourceforge/jnlp/tools/CharacterEncoder.java,
* netx/net/sourceforge/jnlp/tools/HexDumpEncoder.java,
* netx/net/sourceforge/jnlp/tools/JarRunner.java,
* netx/net/sourceforge/jnlp/tools/JarSigner.java,
* netx/net/sourceforge/jnlp/tools/JarSignerResources.java,
* netx/net/sourceforge/jnlp/tools/KeyStoreUtil.java,
* netx/net/sourceforge/jnlp/tools/KeyTool.java,
* netx/net/sourceforge/jnlp/util/FileUtils.java,
* netx/net/sourceforge/jnlp/util/PropertiesFile.java,
* netx/net/sourceforge/jnlp/util/Reflect.java,
* netx/net/sourceforge/jnlp/util/WeakList.java,
* netx/net/sourceforge/jnlp/util/XDesktopEntry.java,
* netx/net/sourceforge/nanoxml/XMLElement.java,
* netx/net/sourceforge/nanoxml/XMLParseException.java,
* plugin/icedteanp/IcedTeaJavaRequestProcessor.cc,
* plugin/icedteanp/IcedTeaJavaRequestProcessor.h,
* plugin/icedteanp/IcedTeaNPPlugin.cc,
* plugin/icedteanp/IcedTeaNPPlugin.h,
* plugin/icedteanp/IcedTeaPluginRequestProcessor.cc,
* plugin/icedteanp/IcedTeaPluginRequestProcessor.h,
* plugin/icedteanp/IcedTeaPluginUtils.cc,
* plugin/icedteanp/IcedTeaPluginUtils.h,
* plugin/icedteanp/IcedTeaRunnable.cc,
* plugin/icedteanp/IcedTeaRunnable.h,
* plugin/icedteanp/IcedTeaScriptablePluginObject.cc,
* plugin/icedteanp/IcedTeaScriptablePluginObject.h,
* plugin/icedteanp/java/netscape/javascript/JSException.java,
* plugin/icedteanp/java/netscape/javascript/JSObject.java,
* plugin/icedteanp/java/netscape/javascript/JSObjectCreatePermission.java,
* plugin/icedteanp/java/netscape/javascript/JSProxy.java,
* plugin/icedteanp/java/netscape/javascript/JSRunnable.java,
* plugin/icedteanp/java/netscape/javascript/JSUtil.java,
* plugin/icedteanp/java/netscape/security/ForbiddenTargetException.java,
* plugin/icedteanp/java/sun/applet/AppletSecurityContextManager.java,
* plugin/icedteanp/java/sun/applet/GetMemberPluginCallRequest.java,
* plugin/icedteanp/java/sun/applet/GetWindowPluginCallRequest.java,
* plugin/icedteanp/java/sun/applet/JavaConsole.java,
* plugin/icedteanp/java/sun/applet/MethodOverloadResolver.java,
* plugin/icedteanp/java/sun/applet/PasswordAuthenticationDialog.java,
* plugin/icedteanp/java/sun/applet/PluginAppletSecurityContext.java,
* plugin/icedteanp/java/sun/applet/PluginAppletViewer.java,
* plugin/icedteanp/java/sun/applet/PluginCallRequest.java,
* plugin/icedteanp/java/sun/applet/PluginCallRequestFactory.java,
* plugin/icedteanp/java/sun/applet/PluginClassLoader.java,
* plugin/icedteanp/java/sun/applet/PluginCookieInfoRequest.java,
* plugin/icedteanp/java/sun/applet/PluginCookieManager.java,
* plugin/icedteanp/java/sun/applet/PluginDebug.java,
* plugin/icedteanp/java/sun/applet/PluginException.java,
* plugin/icedteanp/java/sun/applet/PluginMain.java,
* plugin/icedteanp/java/sun/applet/PluginMessageConsumer.java,
* plugin/icedteanp/java/sun/applet/PluginMessageHandlerWorker.java,
* plugin/icedteanp/java/sun/applet/PluginObjectStore.java,
* plugin/icedteanp/java/sun/applet/PluginProxyInfoRequest.java,
* plugin/icedteanp/java/sun/applet/PluginProxySelector.java,
* plugin/icedteanp/java/sun/applet/PluginStreamHandler.java,
* plugin/icedteanp/java/sun/applet/RequestQueue.java,
* plugin/icedteanp/java/sun/applet/TestEnv.java,
* plugin/icedteanp/java/sun/applet/VoidPluginCallRequest.java,
* plugin/tests/LiveConnect/DummyObject.java,
* plugin/tests/LiveConnect/OverloadTestHelper1.java,
* plugin/tests/LiveConnect/OverloadTestHelper2.java,
* plugin/tests/LiveConnect/OverloadTestHelper3.java,
* plugin/tests/LiveConnect/PluginTest.java,
* plugin/tests/LiveConnect/build,
* plugin/tests/LiveConnect/common.js,
* plugin/tests/LiveConnect/index.html,
* plugin/tests/LiveConnect/jjs_eval_test.js,
* plugin/tests/LiveConnect/jjs_func_parameters_tests.js,
* plugin/tests/LiveConnect/jjs_func_rettype_tests.js,
* plugin/tests/LiveConnect/jjs_get_tests.js,
* plugin/tests/LiveConnect/jjs_set_tests.js,
* plugin/tests/LiveConnect/jsj_func_overload_tests.js,
* plugin/tests/LiveConnect/jsj_func_parameters_tests.js,
* plugin/tests/LiveConnect/jsj_func_rettype_tests.js,
* plugin/tests/LiveConnect/jsj_get_tests.js,
* plugin/tests/LiveConnect/jsj_set_tests.js,
* plugin/tests/LiveConnect/jsj_type_casting_tests.js,
* plugin/tests/LiveConnect/jsj_type_conversion_tests.js:
Initial import from IcedTea6.
* AUTHORS,
* COPYING
* INSTALL,
* NEWS,
* README: New documentation.
Diffstat (limited to 'netx/net/sourceforge/jnlp/Version.java')
-rw-r--r-- | netx/net/sourceforge/jnlp/Version.java | 352 |
1 files changed, 352 insertions, 0 deletions
diff --git a/netx/net/sourceforge/jnlp/Version.java b/netx/net/sourceforge/jnlp/Version.java new file mode 100644 index 0000000..40178e8 --- /dev/null +++ b/netx/net/sourceforge/jnlp/Version.java @@ -0,0 +1,352 @@ +// Copyright (C) 2001-2003 Jon A. Maxwell (JAM) +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + +package net.sourceforge.jnlp; + +import java.io.*; +import java.net.*; +import java.util.*; + +/** + * A JNLP Version string in the form "1.2-3_abc" followed by an + * optional + (includes all later versions) or * (matches any + * suffixes on versions). More than one version can be included + * in a string by separating them with spaces.<p> + * + * Version strings are divided by "._-" charecters into parts. + * These parts are compared numerically if they can be parsed as + * integers or lexographically as strings otherwise. If the + * number of parts is different between two version strings then + * the smaller one is padded with zero or the empty string. Note + * that the padding in this version means that 1.2+ matches + * 1.4.0-beta1, but may not in future versions.<p> + * + * @author <a href="mailto:[email protected]">Jon A. Maxwell (JAM)</a> - initial author + * @version $Revision: 1.5 $ + */ +public class Version { + + // to do: web start does not match versions with a "-" like + // "1.4-beta1" using the + modifier, change to mimic that + // behavior. + + // also refactor into Version and VersionID classes so that + // individual version ids can be easily modified to add/remove + // "*" and "+" modifiers. + + /** separates parts of a version string */ + private static String seperators = ".-_"; + + /** magic key for whether a version part was created due to normalization */ + private static String emptyString = new String("<EMPTY>"); // not intern'ed + + /** contains all the versions matched */ + private String versionString; + + + /** + * Create a Version object based on a version string (ie, + * "1.2.3+ 4.56*"). + */ + public Version(String versions) { + versionString = versions; + } + + /** + * Returns true if the version represents a <i>version-id</i> (a + * single version number such as 1.2) and false otherwise. + */ + public boolean isVersionId() { + if (-1 != versionString.indexOf(" ")) + return false; + + return true; + } + + /** + * Returns true if all of this version's version-ids match one + * or more of the specifed version's version-id. + * + * @param version a version string + */ + public boolean matches(String version) { + return matches(new Version(version)); + } + + /** + * Returns true if all of this version's version-ids match one + * or more of the specifed version's version-id. + * + * @param version a Version object + */ + public boolean matches(Version version) { + List versionStrings = version.getVersionStrings(); + + for (int i=0; i < versionStrings.size(); i++) { + if (!this.matchesSingle( (String)versionStrings.get(i) )) + return false; + } + + return true; + } + + /** + * Returns true if any of this version's version-ids match one + * or more of the specifed version's version-id. + * + * @param version a version string + */ + public boolean matchesAny(String version) { + return matches(new Version(version)); + } + + + /** + * Returns true if any of this version's version-ids match one + * or more of the specifed version's version-id. + * + * @param version a Version object + */ + public boolean matchesAny(Version version) { + List versionStrings = version.getVersionStrings(); + + for (int i=0; i < versionStrings.size(); i++) { + if (this.matchesSingle( (String)versionStrings.get(i) )) + return true; + } + + return false; + } + + /** + * Returns whether a single version string is supported by this + * Version. + * + * @param version a non-compound version of the form "1.2.3[+*]" + */ + private boolean matchesSingle(String version) { + List versionStrings = this.getVersionStrings(); + for (int i=0; i < versionStrings.size(); i++) { + if ( matches(version, (String)versionStrings.get(i)) ) + return true; + } + return false; + } + + + /** + * Returns whether a single version string is supported by + * another single version string. + * + * @param subversion a non-compound version without "+" or "*" + * @param version a non-compound version optionally with "+" or "*" + */ + private boolean matches(String subversion, String version) { + List subparts = getParts(subversion); + List parts = getParts(version); + + int maxLength = Math.max(subversion.length(), version.length()); + if (version.endsWith("*")) // star means rest of parts irrelevant: truncate them + maxLength = parts.size(); + + normalize(new List[] {subparts, parts}, maxLength); + + if (equal(subparts, parts)) + return true; + + if (version.endsWith("+") && greater(subparts, parts)) + return true; + + return false; + } + + /** + * Returns whether the parts of one version are equal to the + * parts of another version. + * + * @param parts1 normalized version parts + * @param parts2 normalized version parts + */ + protected boolean equal(List parts1, List parts2) { + for (int i=0; i < parts1.size(); i++) { + if ( 0 != compare((String)parts1.get(i), (String)parts2.get(i)) ) + return false; + } + + return true; + } + + /** + * Returns whether the parts of one version are greater than + * the parts of another version. + * + * @param parts1 normalized version parts + * @param parts2 normalized version parts + */ + protected boolean greater(List parts1, List parts2) { + //if (true) return false; + + for (int i=0; i < parts1.size(); i++) { + // if part1 > part2 then it's a later version, so return true + if (compare((String)parts1.get(i), (String)parts2.get(i)) > 0) + return true; + + // if part1 < part2 then it's a ealier version, so return false + if (compare((String)parts1.get(i), (String)parts2.get(i)) < 0) + return false; + + // if equal go to next part + } + + // all parts were equal + return false; // not greater than + } + + /** + * Compares two parts of a version string, by value if both can + * be interpreted as integers or lexically otherwise. If a part + * is the result of normalization then it can be the Integer + * zero or an empty string. + * + * Returns a value equivalent to part1.compareTo(part2); + * + * @param part1 a part of a version string + * @param part2 a part of a version string + * @return comparison of the two parts + */ + protected int compare(String part1, String part2) { + Integer number1 = new Integer(0); + Integer number2 = new Integer(0); + + // compare as integers + try { + if (!(part1 == emptyString)) // compare to magic normalization key + number1 = Integer.valueOf(part1); + + if (!(part2 == emptyString)) // compare to magic normalization key + number2 = Integer.valueOf(part2); + + return number1.compareTo(number2); + } + catch (NumberFormatException ex) { + // means to compare as strings + } + + if (part1 == emptyString) + part1 = ""; + if (part2 == emptyString) + part2 = ""; + + return part1.compareTo(part2); + } + + /** + * Normalize version strings so that they contain the same + * number of constituent parts. + * + * @param versions list array of parts of a version string + * @param maxLength truncate lists to this maximum length + */ + protected void normalize(List versions[], int maxLength) { + int length = 0; + for (int i=0; i < versions.length; i++) + length = Math.max(length, versions[i].size()); + + if (length > maxLength) + length = maxLength; + + for (int i=0; i < versions.length; i++) { + // remove excess elements + while (versions[i].size() > length) + versions[i].remove( versions[i].size()-1 ); + + // add in empty pad elements + while (versions[i].size() < length) + versions[i].add( emptyString ); + } + } + + /** + * Return the individual version strings that make up a Version. + */ + protected List getVersionStrings() { + ArrayList strings = new ArrayList(); + + StringTokenizer st = new StringTokenizer(versionString, " "); + while (st.hasMoreTokens()) + strings.add( st.nextToken() ); + + return strings; + } + + /** + * Return the constituent parts of a version string. + * + * @param oneVersion a single version id string (not compound) + */ + protected List getParts(String oneVersion) { + ArrayList strings = new ArrayList(); + + StringTokenizer st = new StringTokenizer(oneVersion, seperators+"+*"); + while (st.hasMoreTokens()) { + strings.add( st.nextToken() ); + } + + return strings; + } + + public String toString() { + return versionString; + } + + /** + * Test. + */ + /* + public static void main(String args[]) { + Version jvms[] = { + new Version("1.1* 1.3*"), + new Version("1.2+"), + }; + + Version versions[] = { + new Version("1.1"), + new Version("1.1.8"), + new Version("1.2"), + new Version("1.3"), + new Version("2.0"), + new Version("1.3.1"), + new Version("1.2.1"), + new Version("1.3.1-beta"), + new Version("1.1 1.2"), + new Version("1.2 1.3"), + }; + + for (int j = 0; j < jvms.length; j++) { + for (int v = 0; v < versions.length; v++) { + System.out.print( jvms[j].toString() + " " ); + if (!jvms[j].matches(versions[v])) + System.out.print( "!" ); + System.out.println( "matches " + versions[v].toString() ); + } + } + + System.out.println("Test completed"); + } + */ + +} |