j2sNative references moved to Platform
[jalview.git] / src / jalview / javascript / web / WebResource.java
1 package jalview.javascript.web;
2
3 import jalview.util.Platform;
4
5 import java.net.URI;
6 import java.net.URISyntaxException;
7
8 /* this class is a proxy for 
9  * 
10  */
11 public class WebResource
12 {
13
14   private String endpoint, params = "";
15   
16   public WebResource(String endpoint) {
17     this.endpoint = endpoint;
18   }
19   
20
21   public WebResource queryParam(String key, String value)
22   {
23     params += (params == "" ? "?" : "&") + key + "=";
24     params += Platform.encodeURI(value);
25     return this;
26   }
27
28   public URI getURI()
29   {
30     try
31     {
32       return new URI(endpoint + params);
33     } catch (URISyntaxException e)
34     {
35       e.printStackTrace();
36       return null;
37     }
38   }
39
40   public Builder accept(String... encoding)
41   {
42     return  new Builder(getURI(), encoding);
43   }
44   
45   
46   public static class Builder {
47       private URI uri;
48       private String[] encoding;
49
50       public Builder(URI uri, String... encoding)
51     {
52         this.uri = uri;
53         this.encoding = encoding; // application/json
54         
55       // TODO Auto-generated constructor stub
56     }
57
58       public ClientResponse get(Class<?> c) {
59         String data = uri.toString();
60         // c will be ClientResponse 
61         data = Platform.getFileAsString(data);
62         return new ClientResponse(data, encoding);
63       }
64   }
65  
66   
67   
68
69 }