Statistics
| Branch: | Tag: | Revision:

root / src / gr / grnet / pithos / web / client / SharingUsers.java @ 0f797b1b

History | View | Annotate | Download (1.2 kB)

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