Mercurial > hg > icedtea6-hg
changeset 2244:fa8c9bfd3da5
netx: parse update elements in jnlp files
2010-08-20 Omair Majid <omajid@redhat.com>
* netx/net/sourceforge/jnlp/JNLPFile.java
(getUpdate): New method. Returns the parsed UpdateDesc.
(parse): Call parser.getUpdate.
* netx/net/sourceforge/jnlp/Parser.java
(getUpdate): New method. Parses a node to find <update> elements.
* netx/net/sourceforge/jnlp/UpdateDesc.java: New class.
(UpdateDesc): New method. Creates a new UpdateDesc.
(getPolicy): New method. Returns the policy attribute of this update.
(getCheck): New method. Returns the check attribute for this update.
* netx/net/sourceforge/jnlp/resources/Messages.properties:
Add PTwoUpdates error.
author | omajid |
---|---|
date | Fri, 20 Aug 2010 17:22:24 -0400 |
parents | fe7d70ac2b1a |
children | 518927fb2498 |
files | ChangeLog netx/net/sourceforge/jnlp/JNLPFile.java netx/net/sourceforge/jnlp/Parser.java netx/net/sourceforge/jnlp/UpdateDesc.java netx/net/sourceforge/jnlp/resources/Messages.properties |
diffstat | 5 files changed, 145 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Fri Aug 20 17:06:32 2010 -0400 +++ b/ChangeLog Fri Aug 20 17:22:24 2010 -0400 @@ -1,3 +1,17 @@ +2010-08-20 Omair Majid <omajid@redhat.com> + + * netx/net/sourceforge/jnlp/JNLPFile.java + (getUpdate): New method. Returns the parsed UpdateDesc. + (parse): Call parser.getUpdate. + * netx/net/sourceforge/jnlp/Parser.java + (getUpdate): New method. Parses a node to find <update> elements. + * netx/net/sourceforge/jnlp/UpdateDesc.java: New class. + (UpdateDesc): New method. Creates a new UpdateDesc. + (getPolicy): New method. Returns the policy attribute of this update. + (getCheck): New method. Returns the check attribute for this update. + * netx/net/sourceforge/jnlp/resources/Messages.properties: + Add PTwoUpdates error. + 2010-08-19 Omair Majid <omajid@redhat.com> Fixes rhbz601281
--- a/netx/net/sourceforge/jnlp/JNLPFile.java Fri Aug 20 17:06:32 2010 -0400 +++ b/netx/net/sourceforge/jnlp/JNLPFile.java Fri Aug 20 17:22:24 2010 -0400 @@ -83,6 +83,8 @@ /** information */ protected List info; + protected UpdateDesc update; + /** resources */ protected List resources; @@ -345,6 +347,13 @@ } /** + * Returns the update section of the JNLP file. + */ + public UpdateDesc getUpdate() { + return update; + } + + /** * Returns the security section of the JNLP file. */ public SecurityDesc getSecurity() { @@ -561,6 +570,7 @@ codeBase = parser.getCodeBase(); sourceLocation = parser.getFileLocation() != null ? parser.getFileLocation() : location; info = parser.getInfo(root); + update = parser.getUpdate(root); resources = parser.getResources(root, false); // false == not a j2se/java resources section launchType = parser.getLauncher(root); security = parser.getSecurity(root);
--- a/netx/net/sourceforge/jnlp/Parser.java Fri Aug 20 17:06:32 2010 -0400 +++ b/netx/net/sourceforge/jnlp/Parser.java Fri Aug 20 17:22:24 2010 -0400 @@ -25,6 +25,8 @@ //import org.w3c.dom.*; // class for using Tiny XML | NanoXML //import org.xml.sax.*; //import gd.xml.tiny.*; +import net.sourceforge.jnlp.UpdateDesc.Check; +import net.sourceforge.jnlp.UpdateDesc.Policy; import net.sourceforge.jnlp.runtime.JNLPRuntime; import net.sourceforge.nanoxml.*; @@ -178,6 +180,53 @@ return spec; } + public UpdateDesc getUpdate(Node parent) throws ParseException { + UpdateDesc updateDesc = null; + Node child = parent.getFirstChild(); + while (child != null) { + if (child.getNodeName().equals("update")) { + if (strict && updateDesc != null) { + throw new ParseException(R("PTwoUpdates")); + } + + Node node = child; + + Check check; + String checkValue = getAttribute(node, "check", "timeout"); + if (checkValue.equals("always")) { + check = Check.ALWAYS; + } else if (checkValue.equals("timeout")) { + check = Check.TIMEOUT; + } else if (checkValue.equals("background")) { + check = Check.BACKGROUND; + } else { + check = Check.TIMEOUT; + } + + String policyString = getAttribute(node, "policy", "always"); + Policy policy; + if (policyString.equals("always")) { + policy = Policy.ALWAYS; + } else if (policyString.equals("prompt-update")) { + policy = Policy.PROMPT_UPDATE; + } else if (policyString.equals("prompt-run")) { + policy = Policy.PROMPT_RUN; + } else { + policy = Policy.ALWAYS; + } + + updateDesc = new UpdateDesc(check, policy); + } + + child = child.getNextSibling(); + } + + if (updateDesc == null) { + updateDesc = new UpdateDesc(Check.TIMEOUT, Policy.ALWAYS); + } + return updateDesc; + } + // // This section loads the resources elements // @@ -1267,4 +1316,5 @@ return encoding; } + }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/netx/net/sourceforge/jnlp/UpdateDesc.java Fri Aug 20 17:22:24 2010 -0400 @@ -0,0 +1,70 @@ +package net.sourceforge.jnlp; + +/** + * Represents an 'update' element in a JNLP file. This element describes when to + * check for updates and what actions to take if updates are available + * + * @see Check + * @see Policy + */ +public class UpdateDesc { + + /** + * Describes when/how long to check for updates. + */ + public enum Check { + /** Always check for updates before launching the application */ + ALWAYS, + + /** + * Default. Check for updates until a certain timeout. If the update + * check is not completed by timeout, launch the cached application and + * continue updating in the background + */ + TIMEOUT, + + /** Check for application updates in the background */ + BACKGROUND + } + + /** + * Describes what to do when the Runtime knows there is an applicatFion + * update before the application is launched. + */ + public enum Policy { + /** + * Default. Always download updates without any user prompt and then launch the + * application + */ + ALWAYS, + + /** + * Prompt the user asking whether the user wants to download and run the + * updated application or run the version in the cache + */ + PROMPT_UPDATE, + + /** + * Prompts the user asking to download and run the latest version of the + * application or abort running + */ + PROMPT_RUN, + } + + private Check check; + private Policy policy; + + public UpdateDesc(Check check, Policy policy) { + this.check = check; + this.policy = policy; + } + + public Check getCheck() { + return this.check; + } + + public Policy getPolicy() { + return this.policy; + } + +}
--- a/netx/net/sourceforge/jnlp/resources/Messages.properties Fri Aug 20 17:06:32 2010 -0400 +++ b/netx/net/sourceforge/jnlp/resources/Messages.properties Fri Aug 20 17:22:24 2010 -0400 @@ -88,6 +88,7 @@ PTwoMenus=Only one menu element allowed PTwoTitles=Only one title element allowed PTwoIcons=Only one icon element allowed +PTwoUpdates=Only one update element is allowed PUnknownApplet=Unknown Applet PBadWidth=Invalid applet width. PBadHeight=Invalid applet height.