JAL-2137 resolve baseURI for prepending to alignments/PDBs for STRUCTMODEL statement...
authorJim Procter <jprocter@issues.jalview.org>
Mon, 4 Jul 2016 10:56:39 +0000 (11:56 +0100)
committerJim Procter <jprocter@issues.jalview.org>
Mon, 4 Jul 2016 10:56:39 +0000 (11:56 +0100)
src/jalview/io/AnnotationFile.java

index d8f9f15..35651bb 100755 (executable)
@@ -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";