changeset in /hg/icedtea6: 2009-06-10 Omair Majid <omajid at redh...

Omair Majid omajid at redhat.com
Wed Jun 10 07:54:10 PDT 2009


changeset c68aaf028ad2 in /hg/icedtea6
details: http://icedtea.classpath.org/hg/icedtea6?cmd=changeset;node=c68aaf028ad2
description:
	2009-06-10  Omair Majid  <omajid at redhat.com>

	    * rt/net/sourceforge/jnlp/services/XBasicService.java
	    (isOffline): Check if the system is offline by retrieving data from a URL.
	    (findFirstURLFromJNLPFile): New function. Obtain a URL from the JNLP file.
	    As a last resort, return an arbitrary known URL.

diffstat:

2 files changed, 76 insertions(+), 9 deletions(-)
ChangeLog                                           |    7 +
rt/net/sourceforge/jnlp/services/XBasicService.java |   78 ++++++++++++++++---

diffs (109 lines):

diff -r ce70ed27635c -r c68aaf028ad2 ChangeLog
--- a/ChangeLog	Wed Jun 10 13:22:21 2009 +0100
+++ b/ChangeLog	Wed Jun 10 10:53:03 2009 -0400
@@ -1,3 +1,10 @@ 2009-06-10  Gary Benson  <gbenson at redhat
+2009-06-10  Omair Majid  <omajid at redhat.com>
+
+	* rt/net/sourceforge/jnlp/services/XBasicService.java
+	(isOffline): Check if the system is offline by retrieving data from a URL.
+	(findFirstURLFromJNLPFile): New function. Obtain a URL from the JNLP file.
+	As a last resort, return an arbitrary known URL. 
+
 2009-06-10  Gary Benson  <gbenson at redhat.com>
 
 	* ports/hotspot/src/share/vm/shark/sharkTopLevelBlock.hpp
diff -r ce70ed27635c -r c68aaf028ad2 rt/net/sourceforge/jnlp/services/XBasicService.java
--- a/rt/net/sourceforge/jnlp/services/XBasicService.java	Wed Jun 10 13:22:21 2009 +0100
+++ b/rt/net/sourceforge/jnlp/services/XBasicService.java	Wed Jun 10 10:53:03 2009 -0400
@@ -17,14 +17,21 @@
 
 package net.sourceforge.jnlp.services;
 
-import java.io.*;
-import java.net.*;
-import javax.jnlp.*;
-import javax.swing.*;
-
-import net.sourceforge.jnlp.*;
-import net.sourceforge.jnlp.runtime.*;
-import net.sourceforge.jnlp.util.*;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import javax.jnlp.BasicService;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+
+import net.sourceforge.jnlp.InformationDesc;
+import net.sourceforge.jnlp.JARDesc;
+import net.sourceforge.jnlp.JNLPFile;
+import net.sourceforge.jnlp.Launcher;
+import net.sourceforge.jnlp.runtime.ApplicationInstance;
+import net.sourceforge.jnlp.runtime.JNLPRuntime;
+import net.sourceforge.jnlp.util.PropertiesFile;
 
 /**
  * The BasicService JNLP service.
@@ -81,7 +88,60 @@ class XBasicService implements BasicServ
      * Return true if the Environment is Offline
      */
     public boolean isOffline() {
-        return false;
+        
+        URL url = findFirstURLFromJNLPFile();
+        
+        try {
+            url.openConnection().getInputStream().close();
+            return false;
+        } catch (IOException exception) {
+            return true;
+        }
+    }
+
+    /**
+     * Return the first URL from the jnlp file
+     * Or a default URL if no url found in JNLP file
+     */
+    private URL findFirstURLFromJNLPFile() {
+        
+        ApplicationInstance app = JNLPRuntime.getApplication();
+        
+        if (app != null) {
+            JNLPFile jnlpFile = app.getJNLPFile();
+            
+            URL sourceURL = jnlpFile.getSourceLocation();
+            if (sourceURL != null) {
+                return sourceURL;
+            }
+            
+            URL codeBaseURL = jnlpFile.getCodeBase();
+            if (codeBaseURL != null) {
+                return codeBaseURL;
+            }
+    
+            InformationDesc informationDesc = jnlpFile.getInformation();
+            URL homePage = informationDesc.getHomepage();
+            if (homePage != null) {
+                return homePage;
+            }
+            
+            JARDesc[] jarDescs = jnlpFile.getResources().getJARs();
+            for (JARDesc jarDesc: jarDescs) {
+                return jarDesc.getLocation();
+            }
+        }
+        
+        // this section is only reached if the jnlp file has no jars.
+        // that doesnt seem very likely.
+        URL arbitraryURL;
+        try {
+            arbitraryURL = new URL("http://icedtea.classpath.org");
+        } catch (MalformedURLException malformedURL) {
+            throw new RuntimeException(malformedURL);
+        }
+        
+        return arbitraryURL;
     }
 
     /**



More information about the distro-pkg-dev mailing list