/*
- * 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
import java.util.Map;
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;
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[]>();
return bytesUsed;
}
- public void setLastModified(Date lastModified) {
- this.lastModified = lastModified;
- }
-
public Set<Folder> getSubfolders() {
return subfolders;
}
return prefix;
}
- public void setPrefix(String prefix) {
- this.prefix = prefix;
- }
-
private void parsePermissions(String rawPermissions) {
String[] readwrite = rawPermissions.split(";");
for (String s : readwrite) {
this.owner = _owner;
String header = response.getHeader("Last-Modified");
if (header != null)
- lastModified = DateTimeFormat.getFormat(PredefinedFormat.RFC_2822).parse(header);
+ try {
+ lastModified = DateTimeFormat.getFormat(PredefinedFormat.RFC_2822).parse(header);
+ } catch (IllegalArgumentException e) {
+ GWT.log("Last-Modified will be set to null", e);
+ lastModified = null;
+ }
header = response.getHeader("X-Container-Bytes-Used");
- if (header != null)
+ 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) {
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);
}
}
}
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;
}
- if (path.endsWith("/"))
- path = path.substring(0, path.length() - 1);
- if (path.contains("/"))
- name = path.substring(path.lastIndexOf("/") + 1, path.length()); //strip the prefix
- else
- name = path;
if (aContainer != null) {
container = aContainer;
prefix = path;
public boolean equals(Object other) {
if (other instanceof Folder) {
Folder o = (Folder) other;
- return getUri().equals(o.getUri());
+ return owner.equals(o.getOwner()) && getUri().equals(o.getUri());
}
return false;
}
this.container = container;
}
- public Set<String> getTags() {
- return tags;
- }
-
public String getInheritedPermissionsFrom() {
return inheritedPermissionsFrom;
}
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();
}