Permissions are requested just before showing the contect and tools menu (issue ...
[pithos-web-client] / src / gr / grnet / pithos / web / client / foldertree / Folder.java
index 386109f..3c20908 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2011 GRNET S.A. All rights reserved.
+ * Copyright 2011-2012 GRNET S.A. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or
  * without modification, are permitted provided that the following
@@ -45,6 +45,7 @@ import java.util.Set;
 
 import com.google.gwt.core.client.GWT;
 import com.google.gwt.http.client.Response;
+import com.google.gwt.http.client.URL;
 import com.google.gwt.i18n.client.DateTimeFormat;
 import com.google.gwt.i18n.client.DateTimeFormat.PredefinedFormat;
 import com.google.gwt.json.client.JSONArray;
@@ -79,8 +80,6 @@ public class Folder extends Resource {
 
     private Set<File> files = new LinkedHashSet<File>();
 
-    private Set<String> tags = new LinkedHashSet<String>();
-
     private String owner;
 
     private Map<String, Boolean[]> permissions = new HashMap<String, Boolean[]>();
@@ -160,18 +159,18 @@ public class Folder extends Resource {
         if (header != null && header.length() > 0)
             bytesUsed = Long.valueOf(header);
 
-        header = response.getHeader("X-Container-Object-Meta");
-        if (header != null && header.length() > 0) {
-            for (String t : header.split(",")) {
-                tags.add(t.toLowerCase().trim());
-            }
+        String rawPermissions = response.getHeader("X-Object-Sharing");
+        if (rawPermissions != null && rawPermissions.length() > 0) {
+            parsePermissions(URL.decodePathSegment(rawPermissions));
         }
-
-        subfolders.clear(); //This is necessary in case we update a pre-existing Folder so that stale subfolders won't show up
-        files.clear();
+        
+        if (response.getText() == null || response.getText().isEmpty())
+               return;
         JSONValue json = JSONParser.parseStrict(response.getText());
         JSONArray array = json.isArray();
         if (array != null) {
+            subfolders.clear(); //This is necessary in case we update a pre-existing Folder so that stale subfolders won't show up
+            files.clear();
             for (int i=0; i<array.size(); i++) {
                 JSONObject o = array.get(i).isObject();
                 if (o != null) {
@@ -179,12 +178,14 @@ public class Folder extends Resource {
                     if (o.containsKey("subdir") || (contentType != null && (contentType.startsWith("application/directory") || contentType.startsWith("application/folder")))) {
                         Folder f = new Folder();
                         f.populate(this, o, _owner, container);
-                        subfolders.add(f);
+                        if (f.getName().length() > 0)
+                               subfolders.add(f);
                     }
                     else {
                         File file = new File();
                         file.populate(this, o, _owner, container);
-                        files.add(file);
+                        if (file.getName().length() > 0)
+                               files.add(file);
                     }
                 }
             }
@@ -196,22 +197,24 @@ public class Folder extends Resource {
         String path = null;
         if (o.containsKey("subdir")) {
             path = unmarshallString(o, "subdir");
+            if (path.endsWith("/")) { //Always true for "subdir"
+                path = path.substring(0, path.length() - 1);
+            }
+            if (parent != null && parent.getPrefix().length() > 0)
+               name = path.substring(parent.getPrefix().length() + 1);
+            else
+               name = path;
+            if (name.equals("/"))
+               name = "";
         }
         else {
             path = unmarshallString(o, "name");
             lastModified = unmarshallDate(o, "last_modified");
+            if (parent != null && parent.getPrefix().length() > 0)
+               name = path.substring(parent.getPrefix().length() + 1);
+            else
+               name = path;
         }
-        boolean endsWithSlash = false;
-        if (path.endsWith("/")) {
-            path = path.substring(0, path.length() - 1);
-            endsWithSlash = true;
-        }
-        if (path.contains("/"))
-            name = path.substring(path.lastIndexOf("/") + 1, path.length()); //strip the prefix
-        else
-            name = path;
-        if (endsWithSlash)
-               name += "/";
         if (aContainer != null) {
             container = aContainer;
             prefix = path;
@@ -273,10 +276,6 @@ public class Folder extends Resource {
         this.container = container;
     }
 
-    public Set<String> getTags() {
-        return tags;
-    }
-
     public String getInheritedPermissionsFrom() {
         return inheritedPermissionsFrom;
     }
@@ -289,17 +288,6 @@ public class Folder extends Resource {
         return owner;
     }
 
-    public boolean existChildrenPermissions() {
-        for (File f : files)
-            if (!f.getPermissions().isEmpty() && f.getInheritedPermissionsFrom() == null)
-                return true;
-
-        for (Folder fo : subfolders)
-            if ((!fo.getPermissions().isEmpty() && fo.getInheritedPermissionsFrom() == null) || fo.existChildrenPermissions())
-                return true;
-        return false;
-    }
-
        public boolean isShared() {
                return !permissions.isEmpty();
        }