From: gmungoc Date: Tue, 15 Sep 2015 15:00:52 +0000 (+0100) Subject: JAL-1859 strip file name from applet documentbase X-Git-Tag: Release_2_10_0~413 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=2cc63036b8b79c018cffdf7d7e0303107d79dec7;hp=6f2610ec4d7a79dde17f9b3d02225c62aa52cfd8;p=jalview.git JAL-1859 strip file name from applet documentbase --- diff --git a/src/jalview/bin/JalviewLite.java b/src/jalview/bin/JalviewLite.java index e736009..7cad007 100644 --- a/src/jalview/bin/JalviewLite.java +++ b/src/jalview/bin/JalviewLite.java @@ -45,6 +45,7 @@ import jalview.io.NewickFile; import jalview.javascript.JSFunctionExec; import jalview.javascript.JalviewLiteJsApi; import jalview.javascript.JsCallBack; +import jalview.javascript.MouseOverStructureListener; import jalview.structure.SelectionListener; import jalview.structure.StructureSelectionManager; import jalview.util.MessageManager; @@ -979,8 +980,8 @@ public class JalviewLite extends Applet implements return; } } - jalview.javascript.MouseOverStructureListener mol = new jalview.javascript.MouseOverStructureListener( - this, listener, separatorListToArray(modelSet)); + MouseOverStructureListener mol = new MouseOverStructureListener(this, + listener, separatorListToArray(modelSet)); javascriptListeners.addElement(mol); StructureSelectionManager.getStructureSelectionManager(this) .addStructureViewerListener(mol); @@ -2906,35 +2907,51 @@ public class JalviewLite extends Applet implements * form a complete URL given a path to a resource and a reference location on * the same server * - * @param url + * @param targetPath * - an absolute path on the same server as localref or a document * located relative to localref * @param localref * - a URL on the same server as url * @return a complete URL for the resource located by url */ - private String resolveUrlForLocalOrAbsolute(String url, URL localref) + private String resolveUrlForLocalOrAbsolute(String targetPath, + URL localref) { - String codebase = localref.toString(); - if (url.indexOf("/") == 0) + String resolvedPath = ""; + + /* + * get URL path and strip off any trailing file e.g. + * www.jalview.org/examples/index.html#applets?a=b is trimmed to + * www.jalview.org/examples/ + */ + String urlPath = localref.toString(); + String directoryPath = urlPath; + int lastSeparator = directoryPath.lastIndexOf("/"); + if (lastSeparator > 0) { + directoryPath = directoryPath.substring(0, lastSeparator + 1); + } + + if (targetPath.startsWith("/")) + { + /* + * construct absolute URL to a file on the server + */ String localfile = localref.getFile(); - url = codebase.substring(0, codebase.length() - localfile.length()) - + url; + resolvedPath = urlPath.substring(0, + urlPath.length() - localfile.length()) + + targetPath; } else { - url = localref + url; + resolvedPath = directoryPath + targetPath; } - if (true/* debug */) + 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("resolveUrlForLocalOrAbsolute returning " + url); + System.err.println("resolveUrlForLocalOrAbsolute returning " + + resolvedPath); } - return url; + return resolvedPath; } /** @@ -2956,8 +2973,8 @@ public class JalviewLite extends Applet implements URL prepend; url = resolveUrlForLocalOrAbsolute( url, - prepend = getDefaultParameter("resolvetocodebase", false) ? getDocumentBase() - : getCodeBase()); + prepend = getDefaultParameter("resolvetocodebase", false) ? getCodeBase() + : getDocumentBase()); if (debug) { System.err