JAL-4409 JAL-4160 Don't let getdown turn jalviewX:// URIs into absolute local file...
authorBen Soares <b.soares@dundee.ac.uk>
Tue, 28 May 2024 21:14:17 +0000 (22:14 +0100)
committerBen Soares <b.soares@dundee.ac.uk>
Tue, 28 May 2024 21:14:17 +0000 (22:14 +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 9a6626f..61ee4e5 100644 (file)
Binary files a/getdown/lib/getdown-core.jar and b/getdown/lib/getdown-core.jar differ
index 3ba56f5..8f7d6c8 100644 (file)
Binary files a/getdown/lib/getdown-launcher-local.jar and b/getdown/lib/getdown-launcher-local.jar differ
index e6b43ab..d86a00f 100644 (file)
Binary files a/getdown/lib/getdown-launcher.jar and b/getdown/lib/getdown-launcher.jar differ
index fca6b4d..dade5de 100644 (file)
@@ -1142,6 +1142,14 @@ public class Application
             jvmmemmax = argString.substring(11);
             continue;
           }
+          if (argString.startsWith("--jvmmempc=")) {
+            jvmmempc = argString.substring(11);
+            continue;
+          }
+          if (argString.startsWith("--jvmmemmax=")) {
+            jvmmemmax = argString.substring(12);
+            continue;
+          }
         }
 
         // use saved preferences if no cmdline args
@@ -1198,7 +1206,7 @@ public class Application
 
         // almost finally check the startup file arguments
         for (String f : _startupFiles) {
-          _appargs.add(HttpUtils.startsWithHttpOrHttps(f)?f:new File(f).getAbsolutePath());
+          _appargs.add(HttpUtils.startsWithHttpOrHttpsOrJalviewScheme(f)?f:new File(f).getAbsolutePath());
         }
         
         // check if one arg with recognised extension
index 04a820d..c607840 100644 (file)
@@ -28,9 +28,11 @@ import java.net.ProtocolException;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
+import java.net.URLConnection;
 
 public class HttpUtils
 {
+  public final static String JALVIEWSCHEMEPREFIX = "jalview";
 
   /**
    * Returns true if it is possible to open an input stream at the given URL,
@@ -74,6 +76,15 @@ 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
    * 
@@ -149,13 +160,13 @@ public class HttpUtils
    *          url
    * @return HttpUrlConnection conn
    */
-  public static HttpURLConnection openConnection(URL url) throws IOException
+  public static URLConnection openConnection(URL url) throws IOException
   {
     if (url == null)
     {
       return null;
     }
-    HttpURLConnection conn = null;
+    URLConnection conn = null;
     String protocol = url.getProtocol();
     if ("http".equals(protocol) || "https".equals(protocol))
     {
@@ -169,6 +180,10 @@ public class HttpUtils
         conn = conn0;
       }
     }
+    else
+    {
+      conn = url.openConnection();
+    }
     return conn;
   }
 
@@ -222,14 +237,15 @@ public class HttpUtils
       return false;
     }
     String scheme = jalviewUri.getScheme();
-    if (scheme == null || !scheme.startsWith("jalview"))
+    if (scheme == null || !scheme.startsWith(JALVIEWSCHEMEPREFIX))
     {
       return false;
     }
-    return scheme.length() == 7 // jalview
-            || scheme.length() == 8 // jalviewX
-            || scheme.substring(7).equals("http") // jalviewhttp
-            || scheme.substring(7).equals("https"); // jalviewhttps
+    int jspl = JALVIEWSCHEMEPREFIX.length();
+    return scheme.length() == jspl // jalview
+            || scheme.length() == jspl + 1 // jalviewX
+            || scheme.substring(jspl).equals("http") // jalviewhttp
+            || scheme.substring(jspl).equals("https"); // jalviewhttps
   }
 
   /**
@@ -256,13 +272,15 @@ public class HttpUtils
     }
     String scheme = jalviewUri.getScheme();
     String host = jalviewUri.getHost();
-    if (host != null && host.length() > 0
-            || scheme.substring(7).startsWith("http"))
+    if (host != null && host.length() > 0 || scheme
+            .substring(JALVIEWSCHEMEPREFIX.length()).startsWith("http"))
     {
       URI newUri;
       try
       {
-        newUri = new URI(scheme.equals("jalviewhttp") ? "http" : "https",
+        newUri = new URI(
+                scheme.equals(JALVIEWSCHEMEPREFIX + "http") ? "http"
+                        : "https",
                 jalviewUri.getUserInfo(), host, jalviewUri.getPort(),
                 jalviewUri.getPath(), jalviewUri.getQuery(),
                 jalviewUri.getFragment());
index 9a6626f..61ee4e5 100644 (file)
Binary files a/j11lib/getdown-core.jar and b/j11lib/getdown-core.jar differ
index 9a6626f..61ee4e5 100644 (file)
Binary files a/j8lib/getdown-core.jar and b/j8lib/getdown-core.jar differ
index d6e4c14..c607840 100644 (file)
@@ -32,6 +32,7 @@ import java.net.URLConnection;
 
 public class HttpUtils
 {
+  public final static String JALVIEWSCHEMEPREFIX = "jalview";
 
   /**
    * Returns true if it is possible to open an input stream at the given URL,
@@ -75,6 +76,15 @@ 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
    * 
@@ -227,14 +237,15 @@ public class HttpUtils
       return false;
     }
     String scheme = jalviewUri.getScheme();
-    if (scheme == null || !scheme.startsWith("jalview"))
+    if (scheme == null || !scheme.startsWith(JALVIEWSCHEMEPREFIX))
     {
       return false;
     }
-    return scheme.length() == 7 // jalview
-            || scheme.length() == 8 // jalviewX
-            || scheme.substring(7).equals("http") // jalviewhttp
-            || scheme.substring(7).equals("https"); // jalviewhttps
+    int jspl = JALVIEWSCHEMEPREFIX.length();
+    return scheme.length() == jspl // jalview
+            || scheme.length() == jspl + 1 // jalviewX
+            || scheme.substring(jspl).equals("http") // jalviewhttp
+            || scheme.substring(jspl).equals("https"); // jalviewhttps
   }
 
   /**
@@ -261,13 +272,15 @@ public class HttpUtils
     }
     String scheme = jalviewUri.getScheme();
     String host = jalviewUri.getHost();
-    if (host != null && host.length() > 0
-            || scheme.substring(7).startsWith("http"))
+    if (host != null && host.length() > 0 || scheme
+            .substring(JALVIEWSCHEMEPREFIX.length()).startsWith("http"))
     {
       URI newUri;
       try
       {
-        newUri = new URI(scheme.equals("jalviewhttp") ? "http" : "https",
+        newUri = new URI(
+                scheme.equals(JALVIEWSCHEMEPREFIX + "http") ? "http"
+                        : "https",
                 jalviewUri.getUserInfo(), host, jalviewUri.getPort(),
                 jalviewUri.getPath(), jalviewUri.getQuery(),
                 jalviewUri.getFragment());