2 * Copyright (c) 2011 Greek Research and Technology Network
5 package gr.grnet.pithos.web.client.foldertree;
7 import com.google.gwt.http.client.Response;
8 import com.google.gwt.i18n.client.DateTimeFormat;
9 import com.google.gwt.json.client.JSONArray;
10 import com.google.gwt.json.client.JSONNumber;
11 import com.google.gwt.json.client.JSONObject;
12 import com.google.gwt.json.client.JSONParser;
13 import com.google.gwt.json.client.JSONString;
14 import com.google.gwt.json.client.JSONValue;
15 import gr.grnet.pithos.web.client.rest.resource.FolderResource;
16 import java.util.Date;
18 public abstract class Resource {
20 protected static String unmarshallString(JSONObject obj, String key){
21 if(obj.get(key) != null) {
22 JSONString s = obj.get(key).isString();
24 return s.stringValue();
29 protected static int unmarshallInt(JSONObject obj, String key){
30 if(obj.get(key) != null)
31 if(obj.get(key).isNumber() != null)
32 return (int) obj.get(key).isNumber().getValue();
36 protected static long unmarshallLong(JSONObject obj, String key){
37 if(obj.get(key) != null) {
38 JSONNumber value = obj.get(key).isNumber();
40 return (long) value.doubleValue();
45 protected static boolean unmarshallBoolean(JSONObject obj, String key){
46 if(obj.get(key) != null)
47 if(obj.get(key).isBoolean() != null)
48 return obj.get(key).isBoolean().booleanValue();
52 protected static Date unmarshallDate(JSONObject obj, String key){
53 if(obj.get(key) != null) {
54 JSONString s = obj.get(key).isString();
56 return DateTimeFormat.getFormat("yyyy-MM-dd'T'HH:mm:ss").parse(s.stringValue());
61 public static native String getDate(Long ms)/*-{
62 return (new Date(ms)).toUTCString();
65 public abstract String getLastModifiedSince();
67 public static <T> T createFromResponse(Class<T> aClass, Response response, T result) {
68 if (aClass.equals(AccountResource.class)) {
69 result = (T) AccountResource.createFromResponse(response);
71 else if (aClass.equals(Folder.class)) {
72 result = (T) Folder.createFromResponse(response, (Folder) result);