X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fbin%2FJalviewLite.java;h=36a7cffee927eccaaf6fe0b2212ca92b2b561c23;hb=07eba26e68b83d767aac0af12c18db5eafe90db4;hp=1be926e91dd62240aee4139800a57e62506258cb;hpb=202bfccc5800bb71878437dc749e9c8c15b4375e;p=jalview.git diff --git a/src/jalview/bin/JalviewLite.java b/src/jalview/bin/JalviewLite.java index 1be926e..36a7cff 100644 --- a/src/jalview/bin/JalviewLite.java +++ b/src/jalview/bin/JalviewLite.java @@ -48,6 +48,7 @@ import jalview.javascript.JsCallBack; import jalview.javascript.MouseOverStructureListener; import jalview.structure.SelectionListener; import jalview.structure.StructureSelectionManager; +import jalview.util.HttpUtils; import jalview.util.MessageManager; import java.applet.Applet; @@ -62,8 +63,6 @@ import java.awt.event.ActionEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; import java.io.InputStreamReader; import java.net.URL; import java.util.ArrayList; @@ -1798,7 +1797,7 @@ public class JalviewLite extends Applet implements public String resolveFileProtocol(String path) { /* - * paste data + * is it paste data? */ if (path.startsWith("PASTE")) { @@ -1807,7 +1806,7 @@ public class JalviewLite extends Applet implements } /* - * a URL + * is it a URL? */ if (path.indexOf("://") != -1) { @@ -1816,40 +1815,42 @@ 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 (HttpUtils.isValidUrl(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) + && HttpUtils.isValidUrl(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)) { @@ -2403,97 +2404,10 @@ public class JalviewLite extends Applet implements return rtn; } catch (Exception ex) { - System.out.println("Exception checking resources: " + f + " " - + ex); + System.out.println("Exception checking resources: " + f + " " + ex); return false; } } - - /** - * If the file is not already in URL format, tries to locate it by resolving - * as a URL. - * - * @param f - * @return - */ - String addProtocol(final String f) - { - if (f.indexOf("://") != -1) - { - // already has URL format - return f; - } - - /* - * Try relative to document base - */ - URL documentBase = getDocumentBase(); - System.err.println("Trying documentbase: " + documentBase); - String url = applet.resolveUrlForLocalOrAbsolute(f, documentBase); - if (urlExists(url)) - { - if (true/* debug */) - { - System.err.println("Prepended document base '" + documentBase - + "' to make: '" + url + "'"); - } - return url; - } - - /* - * Try relative to codebase - */ - URL codeBase = getCodeBase(); - System.err.println("Trying codebase: " + codeBase); - url = applet.resolveUrlForLocalOrAbsolute(f, codeBase); - if (urlExists(url)) - { - if (true/* debug */) - { - System.err.println("Prepended codebase '" + codeBase - + "' to make: '" + url + "'"); - } - return url; - } - - return f; - } - - /** - * Returns true if an input stream can be opened on the specified URL, else - * false. - * - * @param url - * @return - */ - private boolean urlExists(String url) - { - InputStream is = null; - try - { - is = new URL(url).openStream(); - if (is != null) - { - return true; - } - } catch (Exception x) - { - // ignore - } finally - { - if (is != null) - { - try - { - is.close(); - } catch (IOException e) - { - // ignore - } - } - } - return false; - } } /** @@ -2945,6 +2859,15 @@ public class JalviewLite extends Applet implements URL localref) { String resolvedPath = ""; + if (targetPath.startsWith("/")) + { + String codebase = localref.toString(); + String localfile = localref.getFile(); + resolvedPath = codebase.substring(0, + codebase.length() - localfile.length()) + + targetPath; + return resolvedPath; + } /* * get URL path and strip off any trailing file e.g. @@ -2962,12 +2885,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 {