JAL-4409 Allow more URI schemes (e.g. file) to filter through to Jalview
[jalview.git] / getdown / src / getdown / core / src / main / java / jalview / util / HttpUtils.java
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
    *