Revision fbff60ff web_client/src/gr/grnet/pithos/web/client/foldertree/File.java

b/web_client/src/gr/grnet/pithos/web/client/foldertree/File.java
4 4

  
5 5
package gr.grnet.pithos.web.client.foldertree;
6 6

  
7
public class File {
7
import com.google.gwt.i18n.client.NumberFormat;
8
import com.google.gwt.json.client.JSONObject;
9
import java.util.Date;
10

  
11
public class File extends Resource {
12
    private String name;
13

  
14
    private String hash;
15

  
16
    private int version;
17

  
18
    private long bytes;
19

  
20
    private String contentType;
21

  
22
    private Date lastModified;
23

  
24
    private String modifiedBy;
25

  
26
    private Date versionTimestamp;
27

  
28
    private String path;
29

  
30
    private String owner;
31

  
32
    private boolean inTrash;
33

  
34
    public String getContentType() {
35
        return contentType;
36
    }
37

  
38
    public String getHash() {
39
        return hash;
40
    }
41

  
42
    public Date getLastModified() {
43
        return lastModified;
44
    }
45

  
46
    public String getModifiedBy() {
47
        return modifiedBy;
48
    }
49

  
50
    public String getName() {
51
        return name;
52
    }
53

  
54
    public int getVersion() {
55
        return version;
56
    }
57

  
58
    public Date getVersionTimestamp() {
59
        return versionTimestamp;
60
    }
61

  
62
    @Override
63
    public String getLastModifiedSince() {
64
        return null;  //To change body of implemented methods use File | Settings | File Templates.
65
    }
66

  
67
    public String getUri() {
68
        return path + "/" + name;
69
    }
70

  
71
    public String getOwner() {
72
        return owner;
73
    }
74

  
75
    public String getPath() {
76
        return path;
77
    }
78

  
79
    public long getBytes() {
80
        return bytes;
81
    }
82

  
83
    public String getSizeAsString() {
84
        NumberFormat nf = NumberFormat.getFormat("######.#");
85
        if (bytes < 1024)
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";
92
    }
93

  
94
    public boolean isShared() {
95
        return false;
96
    }
97

  
98
    public boolean isInTrash() {
99
        return inTrash;
100
    }
101

  
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
106
        else
107
            name = path;
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");
115
    }
116

  
117
    public boolean equals(Object other) {
118
        if (other instanceof File) {
119
            File o = (File) other;
120
            return name.equals(o.getName());
121
        }
122
        return false;
123
    }
124

  
125
    public int hashCode() {
126
        return name.hashCode();
127
    }
8 128
}

Also available in: Unified diff