emul/src/main/java/java/net/URL.java
changeset 374 e5b4bd29f268
parent 340 785b53689e29
parent 342 60f9aad12731
     1.1 --- a/emul/src/main/java/java/net/URL.java	Mon Dec 17 10:05:55 2012 +0100
     1.2 +++ b/emul/src/main/java/java/net/URL.java	Mon Dec 24 07:57:33 2012 +0100
     1.3 @@ -27,6 +27,7 @@
     1.4  
     1.5  import java.io.IOException;
     1.6  import java.io.InputStream;
     1.7 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
     1.8  
     1.9  /**
    1.10   * Class <code>URL</code> represents a Uniform Resource
    1.11 @@ -964,9 +965,16 @@
    1.12       * @see        java.net.URLConnection#getContent()
    1.13       */
    1.14      public final Object getContent() throws java.io.IOException {
    1.15 -        throw new IOException();
    1.16 -//        return openConnection().getContent();
    1.17 +        return loadText(toExternalForm());
    1.18      }
    1.19 +    
    1.20 +    @JavaScriptBody(args = "url", body = ""
    1.21 +        + "var request = new XMLHttpRequest();\n"
    1.22 +        + "request.open('GET', url, false);\n"
    1.23 +        + "request.send();\n"
    1.24 +        + "return request.responseText;\n"
    1.25 +    )
    1.26 +    private static native String loadText(String url) throws IOException;
    1.27  
    1.28      /**
    1.29       * Gets the contents of this URL. This method is a shorthand for:
    1.30 @@ -984,8 +992,12 @@
    1.31       */
    1.32      public final Object getContent(Class[] classes)
    1.33      throws java.io.IOException {
    1.34 -        throw new IOException();
    1.35 -//        return openConnection().getContent(classes);
    1.36 +        for (Class<?> c : classes) {
    1.37 +            if (c == String.class) {
    1.38 +                return getContent();
    1.39 +            }
    1.40 +        }
    1.41 +        return null;
    1.42      }
    1.43  
    1.44      static URLStreamHandler getURLStreamHandler(String protocol) {