JAL-1859 code tidy, remove 'absolute URL' option
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Wed, 16 Sep 2015 11:57:22 +0000 (12:57 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Wed, 16 Sep 2015 11:57:22 +0000 (12:57 +0100)
src/jalview/bin/JalviewLite.java

index 1be926e..30b8d54 100644 (file)
@@ -1798,7 +1798,7 @@ public class JalviewLite extends Applet implements
     public String resolveFileProtocol(String path)
     {
       /*
-       * paste data
+       * is it paste data?
        */
       if (path.startsWith("PASTE"))
       {
@@ -1807,7 +1807,7 @@ public class JalviewLite extends Applet implements
       }
 
       /*
-       * a URL
+       * is it a URL?
        */
       if (path.indexOf("://") != -1)
       {
@@ -1816,40 +1816,41 @@ public class JalviewLite extends Applet implements
       }
 
       /*
-       * relative to document root
+       * try relative to document root
        */
       URL documentBase = getDocumentBase();
-      String url = resolveUrlForLocalOrAbsolute(path, documentBase);
-      if (urlExists(url))
+      String withDocBase = resolveUrlForLocalOrAbsolute(path, documentBase);
+      if (urlExists(withDocBase))
       {
         if (debug)
         {
           System.err.println("Prepended document base '" + documentBase
-                  + "' to make: '" + url + "'");
+                  + "' to make: '" + withDocBase + "'");
         }
         protocol = AppletFormatAdapter.URL;
-        return url;
+        return withDocBase;
       }
 
       /*
-       * relative to codebase
+       * try relative to codebase (if different to document base)
        */
       URL codeBase = getCodeBase();
-      url = applet.resolveUrlForLocalOrAbsolute(path, codeBase);
-      if (urlExists(url))
+      String withCodeBase = applet.resolveUrlForLocalOrAbsolute(path,
+              codeBase);
+      if (!withCodeBase.equals(withDocBase) && urlExists(withCodeBase))
       {
         protocol = AppletFormatAdapter.URL;
         if (debug)
         {
           System.err.println("Prepended codebase '" + codeBase
-                  + "' to make: '" + url + "'");
+                  + "' to make: '" + withCodeBase + "'");
         }
-        return url;
+        return withCodeBase;
       }
 
       /*
-       * locatable by classloader; test for this last as files in the document
-       * root may also be found by the classloader
+       * try locating by classloader; try this last so files in the directory
+       * are resolved using document base
        */
       if (inArchive(path))
       {
@@ -2962,12 +2963,13 @@ public class JalviewLite extends Applet implements
     if (targetPath.startsWith("/"))
     {
       /*
-       * construct absolute URL to a file on the server
+       * construct absolute URL to a file on the server - this is not allowed?
        */
-      String localfile = localref.getFile();
-      resolvedPath = urlPath.substring(0,
-              urlPath.length() - localfile.length())
-              + targetPath;
+      // String localfile = localref.getFile();
+      // resolvedPath = urlPath.substring(0,
+      // urlPath.length() - localfile.length())
+      // + targetPath;
+      resolvedPath = directoryPath + targetPath.substring(1);
     }
     else
     {