Merge branch 'master' of https://code.grnet.gr/git/pithos
[pithos] / web_client / src / gr / grnet / pithos / web / client / SharingUsers.java
1 package gr.grnet.pithos.web.client;
2
3 import gr.grnet.pithos.web.client.foldertree.Resource;
4
5 import java.util.ArrayList;
6 import java.util.Date;
7 import java.util.List;
8
9 import com.google.gwt.http.client.Response;
10 import com.google.gwt.json.client.JSONArray;
11 import com.google.gwt.json.client.JSONObject;
12 import com.google.gwt.json.client.JSONParser;
13 import com.google.gwt.json.client.JSONValue;
14
15 public class SharingUsers extends Resource {
16         private List<String> users;
17
18         public static SharingUsers createFromResponse(Response response, SharingUsers result) {
19                 SharingUsers u;
20                 if (result == null)
21                         u = new SharingUsers();
22                 else
23                         u = result;
24                 u.populate(response);
25                 return u;
26         }
27
28         private void populate(Response response) {
29                 users = new ArrayList<String>();
30         JSONValue json = JSONParser.parseStrict(response.getText());
31         JSONArray array = json.isArray();
32         if (array != null) {
33             for (int i=0; i<array.size(); i++) {
34                 JSONObject o = array.get(i).isObject();
35                 if (o != null) {
36                         users.add(unmarshallString(o, "name"));
37                 }
38             }
39         }
40         }
41
42         public List<String> getUsers() {
43                 return users;
44         }
45
46         @Override
47         public Date getLastModified() {
48                 return null;
49         }
50 }