1.1 --- a/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Console.java Sat Dec 22 21:35:14 2012 +0100
1.2 +++ b/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Console.java Tue Dec 25 14:07:02 2012 +0100
1.3 @@ -22,6 +22,8 @@
1.4 import java.lang.reflect.InvocationTargetException;
1.5 import java.lang.reflect.Method;
1.6 import java.net.URL;
1.7 +import java.net.URLDecoder;
1.8 +import java.net.URLEncoder;
1.9 import java.util.Enumeration;
1.10 import org.apidesign.bck2brwsr.core.JavaScriptBody;
1.11
1.12 @@ -45,7 +47,7 @@
1.13 "window.document.getElementById(id)[attr] = value;")
1.14 private static native void setAttr(String id, String attr, Object value);
1.15
1.16 - @JavaScriptBody(args = {}, body = "window.close();")
1.17 + @JavaScriptBody(args = {}, body = "return; window.close();")
1.18 private static native void closeWindow();
1.19
1.20 private static void log(String newText) {
1.21 @@ -81,6 +83,9 @@
1.22 Object result = invokeMethod(c.getClassName(), c.getMethodName());
1.23
1.24 log("Result: " + result);
1.25 +
1.26 + result = encodeURL("" + result);
1.27 +
1.28 log("Sending back: " + url + "?request=" + c.getRequestId() + "&result=" + result);
1.29 u = new URL(url + "?request=" + c.getRequestId() + "&result=" + result);
1.30 }
1.31 @@ -91,6 +96,23 @@
1.32 }
1.33 }
1.34
1.35 + private static String encodeURL(String r) {
1.36 + StringBuilder sb = new StringBuilder();
1.37 + for (int i = 0; i < r.length(); i++) {
1.38 + int ch = r.charAt(i);
1.39 + if (ch < 32 || ch == '%' || ch == '+') {
1.40 + sb.append("%").append(("0" + Integer.toHexString(ch)).substring(0, 2));
1.41 + } else {
1.42 + if (ch == 32) {
1.43 + sb.append("+");
1.44 + } else {
1.45 + sb.append((char)ch);
1.46 + }
1.47 + }
1.48 + }
1.49 + return sb.toString();
1.50 + }
1.51 +
1.52 static String invoke(String clazz, String method) throws ClassNotFoundException, InvocationTargetException, IllegalAccessException {
1.53 final Object r = invokeMethod(clazz, method);
1.54 return r == null ? "null" : r.toString().toString();