From 19bc7d43bdc7c215c1d53b179aaf45aa9e7c859e Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Mon, 4 Jul 2016 11:56:39 +0100 Subject: [PATCH] JAL-2137 resolve baseURI for prepending to alignments/PDBs for STRUCTMODEL statement (needs test!) --- src/jalview/io/AnnotationFile.java | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/jalview/io/AnnotationFile.java b/src/jalview/io/AnnotationFile.java index d8f9f15..35651bb 100755 --- a/src/jalview/io/AnnotationFile.java +++ b/src/jalview/io/AnnotationFile.java @@ -38,6 +38,7 @@ import jalview.schemes.ResidueProperties; import jalview.schemes.UserColourScheme; import java.io.BufferedReader; +import java.io.File; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; @@ -690,21 +691,38 @@ public class AnnotationFile public boolean readAnnotationFile(AlignmentI al, ColumnSelection colSel, String file, String protocol) { + baseUri = ""; BufferedReader in = null; try { if (protocol.equals(AppletFormatAdapter.FILE)) { in = new BufferedReader(new FileReader(file)); + baseUri = new File(file).getParent(); + if (baseUri == null) + { + baseUri = ""; + } + else + { + baseUri += "/"; + } } else if (protocol.equals(AppletFormatAdapter.URL)) { URL url = new URL(file); in = new BufferedReader(new InputStreamReader(url.openStream())); + baseUri = url.toURI().getPath(); + if (baseUri.lastIndexOf("/") > -1) + { + baseUri = baseUri.substring(0, baseUri.lastIndexOf("/")) + "/"; + } } else if (protocol.equals(AppletFormatAdapter.PASTE)) { in = new BufferedReader(new StringReader(file)); + // TODO - support mimencoded PDBs for a paste.. ? + baseUri = ""; } else if (protocol.equals(AppletFormatAdapter.CLASSLOADER)) { @@ -712,6 +730,8 @@ public class AnnotationFile if (is != null) { in = new BufferedReader(new java.io.InputStreamReader(is)); + // TODO: this probably doesn't work for classloader - needs a test + baseUri = new File("/" + file).getParent() + "/"; } } if (in != null) @@ -737,6 +757,12 @@ public class AnnotationFile String lastread = ""; + /** + * used for resolving absolute references to resources relative to + * annotationFile location + */ + String baseUri = ""; + private static String GRAPHLINE = "GRAPHLINE", COMBINE = "COMBINE", STRUCTMODEL = "STRUCTMODEL"; -- 1.7.10.2