2 * Copyright (c) 2011 Greek Research and Technology Network
5 package gr.grnet.pithos.web.client.foldertree;
7 import com.google.gwt.i18n.client.NumberFormat;
8 import com.google.gwt.json.client.JSONObject;
11 public class File extends Resource {
20 private String contentType;
22 private Date lastModified;
24 private String modifiedBy;
26 private Date versionTimestamp;
32 private boolean inTrash;
34 public String getContentType() {
38 public String getHash() {
42 public Date getLastModified() {
46 public String getModifiedBy() {
50 public String getName() {
54 public int getVersion() {
58 public Date getVersionTimestamp() {
59 return versionTimestamp;
63 public String getLastModifiedSince() {
64 return null; //To change body of implemented methods use File | Settings | File Templates.
67 public String getUri() {
68 return path + "/" + name;
71 public String getOwner() {
75 public String getPath() {
79 public long getBytes() {
83 public String getSizeAsString() {
84 NumberFormat nf = NumberFormat.getFormat("######.#");
86 return String.valueOf(bytes) + " B";
87 else if (bytes < 1024 * 1024)
88 return nf.format(Double.valueOf(bytes)/(1024)) + " KB";
89 else if (bytes < 1024 * 1024 * 1024)
90 return nf.format(Double.valueOf(bytes)/(1024 * 1024)) + " MB";
91 return nf.format(Double.valueOf(bytes)/(1024 * 1024 * 1024)) + " GB";
94 public boolean isShared() {
98 public boolean isInTrash() {
102 public void populate(JSONObject o) {
103 String path = unmarshallString(o, "name");
104 if (path.contains("/"))
105 name = path.substring(path.lastIndexOf("/") + 1, path.length()); //strip the prefix
108 hash = unmarshallString(o, "hash");
109 bytes = unmarshallLong(o, "bytes");
110 version = unmarshallInt(o, "version");
111 contentType = unmarshallString(o, "content_type");
112 lastModified = unmarshallDate(o, "last_modified");
113 modifiedBy = unmarshallString(o, "modified_by");
114 versionTimestamp = unmarshallDate(o, "version_timestamp");
117 public boolean equals(Object other) {
118 if (other instanceof File) {
119 File o = (File) other;
120 return name.equals(o.getName());
125 public int hashCode() {
126 return name.hashCode();