diff -r e9b07d41de7f -r 9cc253aa9405 javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/ConvertTypes.java --- a/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/ConvertTypes.java Tue Apr 16 08:39:54 2013 +0200 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/ConvertTypes.java Thu Apr 18 16:58:55 2013 +0200 @@ -22,6 +22,7 @@ import java.io.InputStreamReader; import java.io.PushbackInputStream; import java.io.Reader; +import java.net.MalformedURLException; import java.net.URL; import java.util.Iterator; import java.util.concurrent.Executor; @@ -29,6 +30,7 @@ import java.util.logging.Level; import java.util.logging.Logger; import javafx.application.Platform; +import javafx.scene.web.WebEngine; import netscape.javascript.JSObject; import org.apidesign.bck2brwsr.core.JavaScriptBody; import org.json.JSONArray; @@ -106,6 +108,18 @@ } } + private static String findBaseURL() { + WebEngine eng = (WebEngine) System.getProperties().get("webEngine"); + return (String)eng.executeScript( + "var h;" + + "if (!!window && !!window.location && !!window.location.href)\n" + + " h = window.location.href;\n" + + "else " + + " h = null;" + + "h\n" + ); + } + public static String createJSONP(Object[] jsonResult, Runnable whenDone) { return "json" + Integer.toHexString(whenDone.hashCode()); } @@ -123,12 +137,21 @@ private final Object[] jsonResult; private final Runnable whenDone; private final String jsonp; + private final URL base; LoadJSON(String url, Object[] jsonResult, Runnable whenDone, String jsonp) { this.url = url; this.jsonResult = jsonResult; this.whenDone = whenDone; this.jsonp = jsonp; + URL b; + try { + b = new URL(findBaseURL()); + } catch (MalformedURLException ex) { + LOG.log(Level.SEVERE, "Can't find base url for " + url, ex); + b = null; + } + this.base = b; } @Override @@ -138,7 +161,7 @@ return; } try { - URL u = new URL(url.replace(" ", "%20")); + URL u = new URL(base, url.replace(" ", "%20")); InputStream is = u.openStream(); if (jsonp != null) { PushbackInputStream pis = new PushbackInputStream(is, 1);