consolidation of Platform isJS calls
[jalview.git] / src / jalview / javascript / web / WebResource.java
index 6d12932..c55e9ba 100644 (file)
@@ -1,29 +1,28 @@
 package jalview.javascript.web;
 
+import jalview.util.Platform;
+
 import java.net.URI;
 import java.net.URISyntaxException;
 
-/* this class is a proxy for 
+/*
+ *  A JavaScript-only proxy for com.sun.jersey.api.client.WebResource
  * 
  */
 public class WebResource
 {
 
   private String endpoint, params = "";
-  
-  public WebResource(String endpoint) {
+
+  public WebResource(String endpoint)
+  {
     this.endpoint = endpoint;
   }
-  
 
   public WebResource queryParam(String key, String value)
   {
-    params += (params == "" ? "?" : "&") + key + "=";
-    /**
-     * @j2sNative
-     * value = encodeURIComponent(value);
-     */
-    params += value;
+    params += (params == "" ? "?" : "&") + key + "="
+            + Platform.encodeURI(value);
     return this;
   }
 
@@ -41,31 +40,33 @@ public class WebResource
 
   public Builder accept(String... encoding)
   {
-    return  new Builder(getURI(), encoding);
+    return new Builder(getURI(), encoding);
   }
-  
-  
-  public static class Builder {
-      private URI uri;
-      private String[] encoding;
 
-      public Builder(URI uri, String... encoding)
+  public static class Builder
+  {
+    private URI uri;
+
+    private String[] encoding;
+
+    public Builder(URI uri, String... encoding)
     {
-        this.uri = uri;
-        this.encoding = encoding; // application/json
-        
-      // TODO Auto-generated constructor stub
+      this.uri = uri;
+      this.encoding = encoding; // application/json
     }
 
-      public ClientResponse get(Class<?> c) {
-        String data = uri.toString();
-        // c will be ClientResponse 
-        data = /** @j2sNative swingjs.JSUtil.getFileAsString$S(data) || */ null;
-        return new ClientResponse(data, encoding);
-      }
+    /**
+     * Get the response
+     * 
+     * @param c
+     *          must be ClientResponse
+     * @return
+     */
+    public ClientResponse get(Class<?> c)
+    {
+      return new ClientResponse(Platform.getFileAsString(uri.toString()),
+              encoding);
+    }
   }
-  
-  
 
 }