From 9041085cce94f093479be520a8f3553de6e2381f Mon Sep 17 00:00:00 2001 From: Ben Soares Date: Wed, 8 Jul 2020 17:01:32 +0100 Subject: [PATCH] JAL-3633 ensure check both http:// or https:// for urls --- src/jalview/bin/Jalview.java | 4 ++-- src/jalview/gui/AlignFrame.java | 9 +++++---- src/jalview/project/Jalview2XML.java | 20 +++++++++++++------- src/jalview/util/HttpUtils.java | 5 +++++ 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/jalview/bin/Jalview.java b/src/jalview/bin/Jalview.java index 06f3a47..6a67750 100755 --- a/src/jalview/bin/Jalview.java +++ b/src/jalview/bin/Jalview.java @@ -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()) { diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 4354ac6..e886ad0 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -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(); } diff --git a/src/jalview/project/Jalview2XML.java b/src/jalview/project/Jalview2XML.java index ccd9ab0..aa4cd6c 100644 --- a/src/jalview/project/Jalview2XML.java +++ b/src/jalview/project/Jalview2XML.java @@ -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 { diff --git a/src/jalview/util/HttpUtils.java b/src/jalview/util/HttpUtils.java index a5a9460..74f77a2 100644 --- a/src/jalview/util/HttpUtils.java +++ b/src/jalview/util/HttpUtils.java @@ -64,4 +64,9 @@ public class HttpUtils return false; } + public static boolean startsWithHttpOrHttps(String file) + { + return file.startsWith("http://") || file.startsWith("https://"); + } + } -- 1.7.10.2