changeset 1594:c68aaf028ad2

2009-06-10 Omair Majid <omajid@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.
author Omair Majid <omajid@redhat.com>
date Wed, 10 Jun 2009 10:53:03 -0400
parents ce70ed27635c
children 0b4d2e77cf97
files ChangeLog rt/net/sourceforge/jnlp/services/XBasicService.java
diffstat 2 files changed, 75 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- 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  Omair Majid  <omajid@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@redhat.com>
 
 	* ports/hotspot/src/share/vm/shark/sharkTopLevelBlock.hpp
--- 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 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.*;
-import net.sourceforge.jnlp.runtime.*;
-import net.sourceforge.jnlp.util.*;
+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 @@
      * 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;
     }
 
     /**