JAL-3633 ensure check both http:// or https:// for urls
authorBen Soares <b.soares@dundee.ac.uk>
Wed, 8 Jul 2020 16:01:32 +0000 (17:01 +0100)
committerBen Soares <b.soares@dundee.ac.uk>
Thu, 12 Nov 2020 17:42:51 +0000 (17:42 +0000)
src/jalview/bin/Jalview.java
src/jalview/gui/AlignFrame.java
src/jalview/project/Jalview2XML.java
src/jalview/util/HttpUtils.java

index 06f3a47..6a67750 100755 (executable)
@@ -67,6 +67,7 @@ import jalview.io.NewickFile;
 import jalview.io.gff.SequenceOntologyFactory;
 import jalview.schemes.ColourSchemeI;
 import jalview.schemes.ColourSchemeProperty;
+import jalview.util.HttpUtils;
 import jalview.util.MessageManager;
 import jalview.util.Platform;
 import jalview.ws.jws2.Jws2Discoverer;
@@ -531,8 +532,7 @@ public class Jalview
        * @j2sIgnore
        */
       {
-        if (!file.startsWith("http://") && !file.startsWith("https://"))
-        // BH 2019 added https check for Java
+        if (!HttpUtils.startsWithHttpOrHttps(file))
         {
           if (!(new File(file)).exists())
           {
index 4354ac6..e886ad0 100644 (file)
@@ -144,6 +144,7 @@ import jalview.schemes.ColourSchemeI;
 import jalview.schemes.ColourSchemes;
 import jalview.schemes.ResidueColourScheme;
 import jalview.schemes.TCoffeeColourScheme;
+import jalview.util.HttpUtils;
 import jalview.util.ImageMaker.TYPE;
 import jalview.util.MessageManager;
 import jalview.util.Platform;
@@ -1062,7 +1063,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
         Desktop.instance.closeAssociatedWindows();
 
         FileLoader loader = new FileLoader();
-        DataSourceType protocol = fileName.startsWith("http:")
+        DataSourceType protocol = HttpUtils.startsWithHttpOrHttps(fileName)
                 ? DataSourceType.URL
                 : DataSourceType.FILE;
         loader.LoadFile(viewport, fileName, protocol, currentFileFormat);
@@ -1078,9 +1079,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
         if (fileObject == null)
         {
 
-          DataSourceType protocol = (fileName.startsWith("http:")
+          DataSourceType protocol = HttpUtils.startsWithHttpOrHttps(fileName)
                   ? DataSourceType.URL
-                  : DataSourceType.FILE);
+                  : DataSourceType.FILE;
           newframe = loader.LoadFileWaitTillLoaded(fileName, protocol,
                   currentFileFormat);
         }
@@ -1131,7 +1132,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   public void save_actionPerformed(ActionEvent e)
   {
     if (fileName == null || (currentFileFormat == null)
-            || fileName.startsWith("http"))
+            || HttpUtils.startsWithHttpOrHttps(fileName))
     {
       saveAs_actionPerformed();
     }
index ccd9ab0..aa4cd6c 100644 (file)
@@ -29,6 +29,8 @@ import java.awt.Font;
 import java.awt.Rectangle;
 import java.io.BufferedReader;
 import java.io.ByteArrayInputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
@@ -107,6 +109,7 @@ import jalview.gui.AlignFrame;
 import jalview.gui.AlignViewport;
 import jalview.gui.AlignmentPanel;
 import jalview.gui.AppVarna;
+import jalview.gui.ChimeraViewFrame;
 import jalview.gui.Desktop;
 import jalview.gui.JvOptionPane;
 import jalview.gui.OOMWarning;
@@ -133,6 +136,7 @@ import jalview.schemes.UserColourScheme;
 import jalview.structure.StructureSelectionManager;
 import jalview.structures.models.AAStructureBindingModel;
 import jalview.util.Format;
+import jalview.util.HttpUtils;
 import jalview.util.MessageManager;
 import jalview.util.Platform;
 import jalview.util.StringUtils;
@@ -957,7 +961,7 @@ public class Jalview2XML
         else
         {
           vamsasSeq = createVamsasSequence(id, jds);
-//          vamsasSet.addSequence(vamsasSeq);
+          // vamsasSet.addSequence(vamsasSeq);
           vamsasSet.getSequence().add(vamsasSeq);
           vamsasSetIds.put(id, vamsasSeq);
           seqRefIds.put(id, jds);
@@ -1401,7 +1405,7 @@ public class Jalview2XML
         }
       }
 
-      //jms.setJGroup(groups);
+      // jms.setJGroup(groups);
       Object group;
       for (JGroup grp : groups)
       {
@@ -2788,11 +2792,13 @@ public class Jalview2XML
                        viewportsAdded.clear();
                        frefedSequence = null;
 
-                       if (file.startsWith("http://")) {
-                               url = new URL(file);
-                       }
-                       final URL _url = url;
-                       return new jarInputStreamProvider() {
+    if (HttpUtils.startsWithHttpOrHttps(file))
+    {
+      url = new URL(file);
+    }
+    final URL _url = url;
+    return new jarInputStreamProvider()
+    {
 
                                @Override
                                public JarInputStream getJarInputStream() throws IOException {
index a5a9460..74f77a2 100644 (file)
@@ -64,4 +64,9 @@ public class HttpUtils
     return false;
   }
 
+  public static boolean startsWithHttpOrHttps(String file)
+  {
+    return file.startsWith("http://") || file.startsWith("https://");
+  }
+
 }