When last_modified is not in valid format the date will be set to null
[pithos-web-client] / src / gr / grnet / pithos / web / client / foldertree / Resource.java
index 745833a..09a29d9 100644 (file)
 
 package gr.grnet.pithos.web.client.foldertree;
 
+import com.google.gwt.core.client.GWT;
 import com.google.gwt.http.client.Response;
 import com.google.gwt.i18n.client.DateTimeFormat;
+import com.google.gwt.i18n.client.DateTimeFormat.PredefinedFormat;
 import com.google.gwt.json.client.JSONNumber;
 import com.google.gwt.json.client.JSONObject;
 import com.google.gwt.json.client.JSONString;
@@ -45,7 +47,7 @@ import gr.grnet.pithos.web.client.SharingUsers;
 
 import java.util.Date;
 
-public class Resource {
+public abstract class Resource {
 
     protected static String unmarshallString(JSONObject obj, String key){
         if(obj.get(key) != null) {
@@ -83,7 +85,11 @@ public class Resource {
         if(obj.get(key) != null) {
             JSONString s = obj.get(key).isString();
             if (s != null)
-                return DateTimeFormat.getFormat("yyyy-MM-dd'T'HH:mm:ss").parse(s.stringValue());
+                               try {
+                                       return DateTimeFormat.getFormat(PredefinedFormat.ISO_8601).parse(s.stringValue());
+                               } catch (IllegalArgumentException e) {
+                                       GWT.log("", e);
+                               }
         }
         return null;
     }
@@ -96,7 +102,7 @@ public class Resource {
        public static <T> T createFromResponse(Class<T> aClass, String owner, Response response, T result) {
        T result1 = null;
         if (aClass.equals(AccountResource.class)) {
-            result1 = (T) AccountResource.createFromResponse(owner, response);
+            result1 = (T) AccountResource.createFromResponse(owner, response, (AccountResource) result);
         }
         else if (aClass.equals(Folder.class)) {
             result1 = (T) Folder.createFromResponse(owner, response, (Folder) result);
@@ -107,6 +113,11 @@ public class Resource {
         else if (aClass.equals(SharingUsers.class)) {
                result1 = (T) SharingUsers.createFromResponse(response, (SharingUsers) result);
         }
+        else if (aClass.equals(FileVersions.class)) {
+               result1 = (T) FileVersions.createFromResponse(response);
+        }
         return result1;
     }
+    
+    public abstract Date getLastModified();
 }