JAL-4409 Allow more URI schemes (e.g. file) to filter through to Jalview
authorBen Soares <b.soares@dundee.ac.uk>
Wed, 29 May 2024 15:11:38 +0000 (16:11 +0100)
committerBen Soares <b.soares@dundee.ac.uk>
Wed, 29 May 2024 15:11:38 +0000 (16:11 +0100)
getdown/lib/getdown-core.jar
getdown/lib/getdown-launcher-local.jar
getdown/lib/getdown-launcher.jar
getdown/src/getdown/core/src/main/java/com/threerings/getdown/data/Application.java
getdown/src/getdown/core/src/main/java/jalview/util/HttpUtils.java
j11lib/getdown-core.jar
j8lib/getdown-core.jar
src/jalview/util/HttpUtils.java

index 61ee4e5..b2b4fae 100644 (file)
Binary files a/getdown/lib/getdown-core.jar and b/getdown/lib/getdown-core.jar differ
index 8f7d6c8..149c9e6 100644 (file)
Binary files a/getdown/lib/getdown-launcher-local.jar and b/getdown/lib/getdown-launcher-local.jar differ
index d86a00f..6a0f1a1 100644 (file)
Binary files a/getdown/lib/getdown-launcher.jar and b/getdown/lib/getdown-launcher.jar differ
index dade5de..f83add3 100644 (file)
@@ -1206,7 +1206,7 @@ public class Application
 
         // almost finally check the startup file arguments
         for (String f : _startupFiles) {
-          _appargs.add(HttpUtils.startsWithHttpOrHttpsOrJalviewScheme(f)?f:new File(f).getAbsolutePath());
+          _appargs.add(HttpUtils.isPlausibleUri(f)?f:new File(f).getAbsolutePath());
         }
         
         // check if one arg with recognised extension
index c607840..44880a0 100644 (file)
@@ -34,6 +34,31 @@ public class HttpUtils
 {
   public final static String JALVIEWSCHEMEPREFIX = "jalview";
 
+  public static boolean isPlausibleUri(String s)
+  {
+    if (s == null)
+    {
+      return false;
+    }
+    if (startsWithHttpOrHttps(s) || isJalviewSchemeUri(s))
+    {
+      return true;
+    }
+    try
+    {
+      URI u = new URI(s);
+      // allow file:/home/... as well as file:///home... as java copes
+      if (s.startsWith("file:/"))
+      {
+        return true;
+      }
+    } catch (URISyntaxException e)
+    {
+      return false;
+    }
+    return false;
+  }
+
   /**
    * Returns true if it is possible to open an input stream at the given URL,
    * else false. The input stream is closed.
@@ -76,15 +101,6 @@ public class HttpUtils
     return file.startsWith("http://") || file.startsWith("https://");
   }
 
-  public static boolean startsWithHttpOrHttpsOrJalviewScheme(String file)
-  {
-    if (startsWithHttpOrHttps(file))
-    {
-      return true;
-    }
-    return isJalviewSchemeUri(file);
-  }
-
   /**
    * wrapper to get/post to a URL or check headers
    * 
index 61ee4e5..b2b4fae 100644 (file)
Binary files a/j11lib/getdown-core.jar and b/j11lib/getdown-core.jar differ
index 61ee4e5..b2b4fae 100644 (file)
Binary files a/j8lib/getdown-core.jar and b/j8lib/getdown-core.jar differ
index c607840..44880a0 100644 (file)
@@ -34,6 +34,31 @@ public class HttpUtils
 {
   public final static String JALVIEWSCHEMEPREFIX = "jalview";
 
+  public static boolean isPlausibleUri(String s)
+  {
+    if (s == null)
+    {
+      return false;
+    }
+    if (startsWithHttpOrHttps(s) || isJalviewSchemeUri(s))
+    {
+      return true;
+    }
+    try
+    {
+      URI u = new URI(s);
+      // allow file:/home/... as well as file:///home... as java copes
+      if (s.startsWith("file:/"))
+      {
+        return true;
+      }
+    } catch (URISyntaxException e)
+    {
+      return false;
+    }
+    return false;
+  }
+
   /**
    * Returns true if it is possible to open an input stream at the given URL,
    * else false. The input stream is closed.
@@ -76,15 +101,6 @@ public class HttpUtils
     return file.startsWith("http://") || file.startsWith("https://");
   }
 
-  public static boolean startsWithHttpOrHttpsOrJalviewScheme(String file)
-  {
-    if (startsWithHttpOrHttps(file))
-    {
-      return true;
-    }
-    return isJalviewSchemeUri(file);
-  }
-
   /**
    * wrapper to get/post to a URL or check headers
    *