changeset 253:011a29a0d8a2

Enable passing applet parameters through JNLP files.
author Andrew Su <asu@redhat.com>
date Wed, 08 Jun 2011 13:32:54 -0400
parents a25cdbe75706
children 179a8db14d70
files ChangeLog NEWS netx/net/sourceforge/jnlp/JNLPFile.java netx/net/sourceforge/jnlp/Parser.java netx/net/sourceforge/jnlp/PluginBridge.java
diffstat 5 files changed, 67 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Wed Jun 08 16:12:38 2011 -0400
+++ b/ChangeLog	Wed Jun 08 13:32:54 2011 -0400
@@ -1,3 +1,17 @@
+2011-07-08  Andrew Su  <asu@redhat.com>
+
+	* NEWS: Updated.
+	* netx/net/sourceforge/jnlp/JNLPFile.java:
+	(JNLPFile): Calls new constructor.
+	(JNLPFile): New constructor to take an option for forcing a codebase.
+	(JNLPFile): Call parse with extra parameter.
+	(parse): Use the given codebase passed in if we did not find one.
+	* netx/net/sourceforge/jnlp/Parser.java:
+	(Parser): Calls new constructor.
+	(Parser): New constructor which takes in a codebase as a last option.
+	* netx/net/sourceforge/jnlp/PluginBridge.java:
+	(PluginBridge): Calls new JNLPFile's constructor with current codebase
+
 2011-07-08  Andrew Su  <asu@redhat.com>
 
 	* netx/net/sourceforge/jnlp/PluginBridge.java:
--- a/NEWS	Wed Jun 08 16:12:38 2011 -0400
+++ b/NEWS	Wed Jun 08 13:32:54 2011 -0400
@@ -26,6 +26,7 @@
   - Use Firefox's proxy settings if possible
   - The user's default browser (determined from xdg-open or $BROWSER) is used
   - RH669942: javaws fails to download version/packed files (missing support for jnlp.packEnabled and jnlp.versionEnabled)
+  - PR464: plugin can now load parameters from jnlp files.
   - PR658: now jnlp.packEnabled works with applets.
   - PR726: closing javaws -about no longer throws exceptions.
   - PR727: cache now properly removes files.
--- a/netx/net/sourceforge/jnlp/JNLPFile.java	Wed Jun 08 16:12:38 2011 -0400
+++ b/netx/net/sourceforge/jnlp/JNLPFile.java	Wed Jun 08 13:32:54 2011 -0400
@@ -174,8 +174,24 @@
      * @throws ParseException if the JNLP file was invalid
      */
     public JNLPFile(URL location, Version version, boolean strict, UpdatePolicy policy) throws IOException, ParseException {
+	this(location, version, strict, policy, null);
+    }
+    
+    /**
+     * Create a JNLPFile from a URL and a version, checking for updates
+     * using the specified policy.
+     *
+     * @param location the location of the JNLP file
+     * @param version the version of the JNLP file
+     * @param strict whether to enforce the spec when
+     * @param policy the update policy
+     * @param forceCodebase codebase to use if not specified in JNLP file.
+     * @throws IOException if an IO exception occurred
+     * @throws ParseException if the JNLP file was invalid
+     */
+    protected JNLPFile(URL location, Version version, boolean strict, UpdatePolicy policy, URL forceCodebase) throws IOException, ParseException {
         Node root = Parser.getRootNode(openURL(location, version, policy));
-        parse(root, strict, location);
+        parse(root, strict, location, forceCodebase);
 
         //Downloads the original jnlp file into the cache if possible
         //(i.e. If the jnlp file being launched exist locally, but it
@@ -222,7 +238,7 @@
      * @throws ParseException if the JNLP file was invalid
      */
     public JNLPFile(InputStream input, boolean strict) throws ParseException {
-        parse(Parser.getRootNode(input), strict, null);
+        parse(Parser.getRootNode(input), strict, null, null);
     }
 
     /**
@@ -574,12 +590,12 @@
      * @param strict whether to enforce the spec when
      * @param location the file location or null
      */
-    private void parse(Node root, boolean strict, URL location) throws ParseException {
+    private void parse(Node root, boolean strict, URL location, URL forceCodebase) throws ParseException {
         try {
             //if (location != null)
             //  location = new URL(location, "."); // remove filename
 
-            Parser parser = new Parser(this, location, root, strict, true); // true == allow extensions
+            Parser parser = new Parser(this, location, root, strict, true, forceCodebase); // true == allow extensions
 
             // JNLP tag information
             specVersion = parser.getSpecVersion();
--- a/netx/net/sourceforge/jnlp/Parser.java	Wed Jun 08 16:12:38 2011 -0400
+++ b/netx/net/sourceforge/jnlp/Parser.java	Wed Jun 08 13:32:54 2011 -0400
@@ -110,6 +110,27 @@
      * @throws ParseException if the JNLP file is invalid
      */
     public Parser(JNLPFile file, URL base, Node root, boolean strict, boolean allowExtensions) throws ParseException {
+	this(file, base, root, strict, allowExtensions, null);
+    }
+
+    /**
+     * Create a parser for the JNLP file.  If the location
+     * parameters is not null it is used as the default codebase
+     * (does not override value of jnlp element's href
+     * attribute).<p>
+     *
+     * The root node may be normalized as a side effect of this
+     * constructor.
+     *
+     * @param file the (uninitialized) file reference
+     * @param base if codebase is not specified, a default base for relative URLs
+     * @param root the root node
+     * @param strict whether to enforce strict compliance with the JNLP spec
+     * @param allowExtensions whether to allow extensions to the JNLP spec
+     * @param codebase codebase to use if we did not parse one from JNLP file.
+     * @throws ParseException if the JNLP file is invalid
+     */
+    public Parser(JNLPFile file, URL base, Node root, boolean strict, boolean allowExtensions, URL codebase) throws ParseException {
         this.file = file;
         this.root = root;
         this.strict = strict;
@@ -122,7 +143,9 @@
         // JNLP tag information
         this.spec = getVersion(root, "spec", "1.0+");
         this.codebase = addSlash(getURL(root, "codebase", base));
-        this.base = (codebase != null) ? codebase : base; // if codebase not specified use default codebase
+        if (this.codebase == null) // We only override it if it is not specified.
+            this.codebase = codebase;
+        this.base = (this.codebase != null) ? this.codebase : base; // if codebase not specified use default codebase
         fileLocation = getURL(root, "href", this.base);
 
         // normalize the text nodes
--- a/netx/net/sourceforge/jnlp/PluginBridge.java	Wed Jun 08 16:12:38 2011 -0400
+++ b/netx/net/sourceforge/jnlp/PluginBridge.java	Wed Jun 08 13:32:54 2011 -0400
@@ -53,17 +53,23 @@
         fileVersion = new Version("1.1");
         this.codeBase = codebase;
         this.sourceLocation = documentBase;
+        this.atts = atts;
 
         if (atts.containsKey("jnlp_href")) {
             try {
                 URL jnlp = new URL(codeBase.toExternalForm() + atts.get("jnlp_href"));
-                JNLPFile jnlpFile = new JNLPFile(jnlp);
+                JNLPFile jnlpFile = new JNLPFile(jnlp, null, false, JNLPRuntime.getDefaultUpdatePolicy(), this.codeBase);
                 Map<String, String> jnlpParams = jnlpFile.getApplet().getParameters();
 
                 // Change the parameter name to lowercase to follow conventions.
                 for (Map.Entry<String, String> entry : jnlpParams.entrySet()) {
-                    atts.put(entry.getKey().toLowerCase(), entry.getValue());
+                    this.atts.put(entry.getKey().toLowerCase(), entry.getValue());
                 }
+                JARDesc[] jarDescs = jnlpFile.getResources().getJARs();
+                for (JARDesc jarDesc : jarDescs) {
+                     String fileName = jarDesc.getLocation().toExternalForm();
+                     this.jars.add(fileName);
+                 }
             } catch (MalformedURLException e) {
                 // Don't fail because we cannot get the jnlp file. Parameters are optional not required.
                 // it is the site developer who should ensure that file exist.
@@ -117,7 +123,6 @@
                 System.err.println("jars length: " + jars.length);
             }
         }
-        this.atts = atts;
 
         name = atts.get("name");
         if (name == null)