changeset 1832:98c88b32cdb4

Assignment default values to certain non required attributes.
author Man Lung Wong <mwong@redhat.com>
date Tue, 19 Jan 2010 14:38:40 -0500
parents 10d4e6ddaac9
children daf81eeba901 94849480798f 91e3d06e1283
files ChangeLog rt/net/sourceforge/jnlp/JNLPFile.java rt/net/sourceforge/jnlp/Parser.java rt/net/sourceforge/jnlp/runtime/JNLPClassLoader.java
diffstat 4 files changed, 72 insertions(+), 50 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Mon Jan 18 20:12:25 2010 +0000
+++ b/ChangeLog	Tue Jan 19 14:38:40 2010 -0500
@@ -1,3 +1,19 @@
+2010-01-19 Man Lung Wong  <mwong@redhat.com>
+
+	* rt/net/sourceforge/jnlp/JNLPFile.java
+	(parse): Added a default value for sourceLocation to make sure it is
+	not null (location is never null).
+	* rt/net/sourceforge/jnlp/Parser.java:
+	Removed variable base, and replaced it with codebase. The fix ended
+	with base the same as codebase, hence no longer needed. Otherwise,
+	netx will launch a jnlp file with codebase null and href not 
+	null (not the way sun's webstart behaves).
+	* rt/net/sourceforge/jnlp/runtime/JNLPClassLoader.java
+	(setSecurity): Added a variable codebase, which gets the value of
+	codebae attribute in the jnlp file ifit exists. Otherwise, it gets
+	the value of the location of main jar resource (which needs to be
+	changed to the codebase portion instead of the entire location).
+
 2010-01-18 Andrew John Hughes  <ahughes@redhat.com>
 
 	* configure.ac:
--- a/rt/net/sourceforge/jnlp/JNLPFile.java	Mon Jan 18 20:12:25 2010 +0000
+++ b/rt/net/sourceforge/jnlp/JNLPFile.java	Tue Jan 19 14:38:40 2010 -0500
@@ -559,8 +559,7 @@
             specVersion = parser.getSpecVersion();
             fileVersion = parser.getFileVersion();
             codeBase = parser.getCodeBase();
-            sourceLocation = parser.getFileLocation();
-
+            sourceLocation = parser.getFileLocation() != null ? parser.getFileLocation() : location;
             info = parser.getInfo(root);
             resources = parser.getResources(root, false); // false == not a j2se/java resources section
             launchType = parser.getLauncher(root);
--- a/rt/net/sourceforge/jnlp/Parser.java	Mon Jan 18 20:12:25 2010 +0000
+++ b/rt/net/sourceforge/jnlp/Parser.java	Tue Jan 19 14:38:40 2010 -0500
@@ -87,9 +87,6 @@
     /** the specification version */
     private Version spec;
 
-    /** the base URL that all hrefs are relative to */
-    private URL base;
-
     /** the codebase URL */
     private URL codebase;
 
@@ -132,8 +129,8 @@
         // 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
-        fileLocation = getURL(root, "href", this.base);
+        
+        fileLocation = getURL(root, "href", codebase);
 
         // ensure version is supported
         if (!supportedVersions.matchesAny(spec))
@@ -279,7 +276,7 @@
      */
     public JREDesc getJRE(Node node) throws ParseException {
         Version version = getVersion(node, "version", null);
-        URL location = getURL(node, "href", base);
+        URL location = getURL(node, "href", codebase);
         String vmArgs = getAttribute(node, "java-vm-args",null);
         try {
             checkVMArgs(vmArgs);
@@ -306,7 +303,7 @@
      */
     public JARDesc getJAR(Node node) throws ParseException {
         boolean nativeJar = "nativelib".equals(node.getNodeName());
-        URL location = getRequiredURL(node, "href", base);
+        URL location = getRequiredURL(node, "href", codebase);
         Version version = getVersion(node, "version", null);
         String part = getAttribute(node, "part", null);
         boolean main = "true".equals(getAttribute(node, "main", "false"));
@@ -330,7 +327,7 @@
     public ExtensionDesc getExtension(Node node) throws ParseException {
         String name = getAttribute(node, "name", null);
         Version version = getVersion(node, "version", null);
-        URL location = getRequiredURL(node, "href", base);
+        URL location = getRequiredURL(node, "href", codebase);
 
         ExtensionDesc ext = new ExtensionDesc(name, version, location);
 
@@ -433,7 +430,7 @@
                 addInfo(info, child, kind, getSpanText(child));
             }
             if ("homepage".equals(name))
-                addInfo(info, child, null, getRequiredURL(child, "href", base));
+                addInfo(info, child, null, getRequiredURL(child, "href", codebase));
             if ("icon".equals(name))
                 addInfo(info, child, getAttribute(child, "kind", "default"), getIcon(child));
             if ("offline-allowed".equals(name))
@@ -487,7 +484,7 @@
         int height = Integer.parseInt(getAttribute(node, "height", "-1"));
         int size = Integer.parseInt(getAttribute(node, "size", "-1"));
         int depth = Integer.parseInt(getAttribute(node, "depth", "-1"));
-        URL location = getRequiredURL(node, "href", base);
+        URL location = getRequiredURL(node, "href", codebase);
         Object kind = getAttribute(node, "kind", "default"); 
 
         return new IconDesc(location, kind, width, height, depth, size);
@@ -524,8 +521,8 @@
         else if (strict)
             throw new ParseException(R("PEmptySecurity"));
 
-        if (base != null)
-            return new SecurityDesc(file, type, base.getHost());
+        if (codebase != null)
+            return new SecurityDesc(file, type, codebase.getHost());
         else
             return new SecurityDesc(file, type, null);
     }
@@ -592,7 +589,7 @@
     public AppletDesc getApplet(Node node) throws ParseException {
         String name = getRequiredAttribute(node, "name", R("PUnknownApplet"));
         String main = getRequiredAttribute(node, "main-class", null);
-        URL docbase = getURL(node, "documentbase", base);
+        URL docbase = getURL(node, "documentbase", codebase);
         Map paramMap = new HashMap();
         int width = 0;
         int height = 0;
@@ -724,7 +721,7 @@
     public RelatedContentDesc getRelatedContent(Node node) throws ParseException {
         
         getRequiredAttribute(node, "href", null);
-        URL location = getURL(node, "href", base);
+        URL location = getURL(node, "href", codebase);
         
         String title = null;
         String description = null;
@@ -1176,8 +1173,7 @@
             final XMLElement xml = new XMLElement();
             final PipedInputStream pin = new PipedInputStream();
             final PipedOutputStream pout = new PipedOutputStream(pin);
-            final InputStreamReader isr = new InputStreamReader(input);
-            
+            final InputStreamReader isr = new InputStreamReader(input);    
             // Clean the jnlp xml file of all comments before passing
             // it to the parser.
             new Thread(
--- a/rt/net/sourceforge/jnlp/runtime/JNLPClassLoader.java	Mon Jan 18 20:12:25 2010 +0000
+++ b/rt/net/sourceforge/jnlp/runtime/JNLPClassLoader.java	Tue Jan 19 14:38:40 2010 -0500
@@ -167,39 +167,50 @@
     }
 
     private void setSecurity() {
-		/**
-		 * When we're trying to load an applet, file.getSecurity() will return
-		 * null since there is no jnlp file to specify permissions. We
-		 * determine security settings here, after trying to verify jars.
-		 */
-		if (file instanceof PluginBridge) {
-			if (signing == true) {
-				this.security = new SecurityDesc(file, 
-					SecurityDesc.ALL_PERMISSIONS,
-					file.getCodeBase().getHost());
-			} else {
-				this.security = new SecurityDesc(file, 
-					SecurityDesc.SANDBOX_PERMISSIONS, 
-					file.getCodeBase().getHost());
-			}
-		} else { //regular jnlp file
+		
+        URL codebase = null;
+
+        if (file.getCodeBase() != null) {
+            codebase = file.getCodeBase();
+        } else {
+            //Fixme: codebase should be the codebase of the Main Jar not 
+            //the location. Although, it still works in the current state.
+            codebase = file.getResources().getMainJAR().getLocation();
+        }
+
+        /**
+         * When we're trying to load an applet, file.getSecurity() will return
+         * null since there is no jnlp file to specify permissions. We
+         * determine security settings here, after trying to verify jars.
+         */
+        if (file instanceof PluginBridge) {
+            if (signing == true) {
+                this.security = new SecurityDesc(file, 
+                    SecurityDesc.ALL_PERMISSIONS,
+                    codebase.getHost());
+            } else {
+                this.security = new SecurityDesc(file, 
+                    SecurityDesc.SANDBOX_PERMISSIONS, 
+                    codebase.getHost());
+            }
+        } else { //regular jnlp file
 			
-			/**
-			 * If the application is signed, then we set the SecurityDesc to the
-			 * <security> tag in the jnlp file. Note that if an application is
-			 * signed, but there is no <security> tag in the jnlp file, the
-			 * application will get sandbox permissions.
-			 * If the application is unsigned, we ignore the <security> tag and 
-			 * use a sandbox instead. 
-			 */
-			if (signing == true) {
-				this.security = file.getSecurity();
-			} else {
-				this.security = new SecurityDesc(file, 
-						SecurityDesc.SANDBOX_PERMISSIONS, 
-						file.getCodeBase().getHost());
-			}
-		}
+            /**
+             * If the application is signed, then we set the SecurityDesc to the
+             * <security> tag in the jnlp file. Note that if an application is
+             * signed, but there is no <security> tag in the jnlp file, the
+             * application will get sandbox permissions.
+             * If the application is unsigned, we ignore the <security> tag and 
+             * use a sandbox instead. 
+             */
+            if (signing == true) {
+                this.security = file.getSecurity();
+            } else {
+                this.security = new SecurityDesc(file, 
+                        SecurityDesc.SANDBOX_PERMISSIONS, 
+                        codebase.getHost());
+            }
+        }
     }
     
     /**