From de6ff2396211d2ef6ccb3db5e852ef492175f27d Mon Sep 17 00:00:00 2001 From: gmungoc Date: Wed, 9 Sep 2015 15:06:51 +0100 Subject: [PATCH] JAL-857 added debug output to track down document base glitch --- src/jalview/bin/JalviewLite.java | 74 +++++++++++++++++++++----------------- 1 file changed, 42 insertions(+), 32 deletions(-) diff --git a/src/jalview/bin/JalviewLite.java b/src/jalview/bin/JalviewLite.java index 93b2a3f..d0c3829 100644 --- a/src/jalview/bin/JalviewLite.java +++ b/src/jalview/bin/JalviewLite.java @@ -2380,47 +2380,49 @@ public class JalviewLite extends Applet implements * If the file is not already in URL format, tries to locate it by resolving * as a URL. * - * @param file + * @param f * @return */ - String addProtocol(final String file) + String addProtocol(final String f) { - if (file.indexOf("://") == -1) + if (f.indexOf("://") != -1) { - /* - * Try relative to document base - */ - String url = applet.resolveUrlForLocalOrAbsolute(file, - getDocumentBase()); - if (urlExists(url)) - { - if (debug) - { - System.err.println("Prepended document base for resource: '" - + file + "'"); - } - return url; - } + // already has URL format + return f; + } - /* - * Try relative to codebase - */ - url = applet.resolveUrlForLocalOrAbsolute(file, getCodeBase()); - if (urlExists(url)) + /* + * Try relative to document base + */ + URL documentBase = getDocumentBase(); + String url = applet.resolveUrlForLocalOrAbsolute(f, documentBase); + if (urlExists(url)) + { + if (debug) { - if (debug) - { - System.err.println("Prepended codebase for resource: '" + file - + "'"); - } - return url; + System.err.println("Prepended document base '" + documentBase + + "' to make: '" + url + + "'"); } + return url; } /* - * Not resolved, leave unchanged + * Try relative to codebase */ - return file; + URL codeBase = getCodeBase(); + url = applet.resolveUrlForLocalOrAbsolute(f, codeBase); + if (urlExists(url)) + { + if (debug) + { + System.err.println("Prepended codebase '" + codeBase + + "' to make: '" + url + "'"); + } + return url; + } + + return f; } /** @@ -2512,7 +2514,6 @@ public class JalviewLite extends Applet implements */ public String[] separatorListToArray(String list, String separator) { - // note separator local variable intentionally masks object field int seplen = separator.length(); if (list == null || list.equals("") || list.equals(separator)) { @@ -2909,14 +2910,23 @@ public class JalviewLite extends Applet implements String codebase = localref.toString(); if (url.indexOf("/") == 0) { + String localfile = localref.getFile(); url = codebase.substring(0, codebase.length() - - localref.getFile().length()) + - localfile.length()) + url; } else { url = localref + url; } + if (debug) + { + System.err.println("URL: " + localref.toString()); + System.err.println("URL.getFile: " + localref.getFile()); + System.err.println("URL.getPath: " + localref.getPath()); + System.err.println("URL.getQuery: " + localref.getQuery()); + System.err.println("returning " + url); + } return url; } -- 1.7.10.2