root / gss / src / gr / ebs / gss / client / rest / resource / FileResource.java @ 2ec3aa1c
History | View | Annotate | Download (9 kB)
1 | a52ea5e4 | pastith | /*
|
---|---|---|---|
2 | a52ea5e4 | pastith | * Copyright 2009 Electronic Business Systems Ltd.
|
3 | a52ea5e4 | pastith | *
|
4 | a52ea5e4 | pastith | * This file is part of GSS.
|
5 | a52ea5e4 | pastith | *
|
6 | a52ea5e4 | pastith | * GSS is free software: you can redistribute it and/or modify
|
7 | a52ea5e4 | pastith | * it under the terms of the GNU General Public License as published by
|
8 | a52ea5e4 | pastith | * the Free Software Foundation, either version 3 of the License, or
|
9 | a52ea5e4 | pastith | * (at your option) any later version.
|
10 | a52ea5e4 | pastith | *
|
11 | a52ea5e4 | pastith | * GSS is distributed in the hope that it will be useful,
|
12 | a52ea5e4 | pastith | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | a52ea5e4 | pastith | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 | a52ea5e4 | pastith | * GNU General Public License for more details.
|
15 | a52ea5e4 | pastith | *
|
16 | a52ea5e4 | pastith | * You should have received a copy of the GNU General Public License
|
17 | a52ea5e4 | pastith | * along with GSS. If not, see <http://www.gnu.org/licenses/>.
|
18 | a52ea5e4 | pastith | */
|
19 | a52ea5e4 | pastith | package gr.ebs.gss.client.rest.resource; |
20 | a52ea5e4 | pastith | |
21 | a52ea5e4 | pastith | import java.util.ArrayList; |
22 | a52ea5e4 | pastith | import java.util.Date; |
23 | a52ea5e4 | pastith | import java.util.HashSet; |
24 | a52ea5e4 | pastith | import java.util.List; |
25 | a52ea5e4 | pastith | import java.util.Set; |
26 | a52ea5e4 | pastith | |
27 | a52ea5e4 | pastith | import com.google.gwt.core.client.GWT; |
28 | a52ea5e4 | pastith | import com.google.gwt.http.client.URL; |
29 | a52ea5e4 | pastith | import com.google.gwt.i18n.client.NumberFormat; |
30 | a52ea5e4 | pastith | import com.google.gwt.json.client.JSONArray; |
31 | a52ea5e4 | pastith | import com.google.gwt.json.client.JSONObject; |
32 | a52ea5e4 | pastith | import com.google.gwt.json.client.JSONParser; |
33 | a52ea5e4 | pastith | import com.google.gwt.json.client.JSONString; |
34 | a52ea5e4 | pastith | |
35 | a52ea5e4 | pastith | /**
|
36 | a52ea5e4 | pastith | * @author kman
|
37 | a52ea5e4 | pastith | */
|
38 | a52ea5e4 | pastith | public class FileResource extends RestResource { |
39 | a52ea5e4 | pastith | |
40 | a52ea5e4 | pastith | /**
|
41 | a52ea5e4 | pastith | * @param path
|
42 | a52ea5e4 | pastith | */
|
43 | a52ea5e4 | pastith | public FileResource(String path) { |
44 | a52ea5e4 | pastith | super(path);
|
45 | a52ea5e4 | pastith | // TODO Auto-generated constructor stub
|
46 | a52ea5e4 | pastith | } |
47 | a52ea5e4 | pastith | |
48 | a52ea5e4 | pastith | String name;
|
49 | a52ea5e4 | pastith | |
50 | a52ea5e4 | pastith | String owner;
|
51 | a52ea5e4 | pastith | |
52 | a52ea5e4 | pastith | String createdBy;
|
53 | a52ea5e4 | pastith | |
54 | a52ea5e4 | pastith | String modifiedBy;
|
55 | a52ea5e4 | pastith | |
56 | a52ea5e4 | pastith | Date creationDate;
|
57 | a52ea5e4 | pastith | |
58 | a52ea5e4 | pastith | Date modificationDate;
|
59 | a52ea5e4 | pastith | |
60 | a52ea5e4 | pastith | String contentType;
|
61 | a52ea5e4 | pastith | |
62 | a52ea5e4 | pastith | Long contentLength;
|
63 | a52ea5e4 | pastith | |
64 | a52ea5e4 | pastith | boolean readForAll;
|
65 | a52ea5e4 | pastith | |
66 | a52ea5e4 | pastith | boolean versioned;
|
67 | a52ea5e4 | pastith | |
68 | a52ea5e4 | pastith | Integer version;
|
69 | a52ea5e4 | pastith | |
70 | a52ea5e4 | pastith | String etag;
|
71 | a52ea5e4 | pastith | |
72 | a52ea5e4 | pastith | boolean deleted = false; |
73 | a52ea5e4 | pastith | |
74 | a52ea5e4 | pastith | List<String> tags = new ArrayList<String>(); |
75 | a52ea5e4 | pastith | |
76 | a52ea5e4 | pastith | Set<PermissionHolder> permissions = new HashSet<PermissionHolder>(); |
77 | a52ea5e4 | pastith | |
78 | a52ea5e4 | pastith | String folderURI;
|
79 | a52ea5e4 | pastith | |
80 | a52ea5e4 | pastith | /**
|
81 | a52ea5e4 | pastith | * Retrieve the name.
|
82 | a52ea5e4 | pastith | *
|
83 | a52ea5e4 | pastith | * @return the name
|
84 | a52ea5e4 | pastith | */
|
85 | a52ea5e4 | pastith | public String getName() { |
86 | a52ea5e4 | pastith | return name;
|
87 | a52ea5e4 | pastith | } |
88 | a52ea5e4 | pastith | |
89 | a52ea5e4 | pastith | /**
|
90 | a52ea5e4 | pastith | * Modify the name.
|
91 | a52ea5e4 | pastith | *
|
92 | a52ea5e4 | pastith | * @param name the name to set
|
93 | a52ea5e4 | pastith | */
|
94 | a52ea5e4 | pastith | public void setName(String name) { |
95 | a52ea5e4 | pastith | this.name = name;
|
96 | a52ea5e4 | pastith | } |
97 | a52ea5e4 | pastith | |
98 | a52ea5e4 | pastith | /**
|
99 | a52ea5e4 | pastith | * Retrieve the owner.
|
100 | a52ea5e4 | pastith | *
|
101 | a52ea5e4 | pastith | * @return the owner
|
102 | a52ea5e4 | pastith | */
|
103 | a52ea5e4 | pastith | public String getOwner() { |
104 | a52ea5e4 | pastith | return owner;
|
105 | a52ea5e4 | pastith | } |
106 | a52ea5e4 | pastith | |
107 | a52ea5e4 | pastith | /**
|
108 | a52ea5e4 | pastith | * Modify the owner.
|
109 | a52ea5e4 | pastith | *
|
110 | a52ea5e4 | pastith | * @param owner the owner to set
|
111 | a52ea5e4 | pastith | */
|
112 | a52ea5e4 | pastith | public void setOwner(String owner) { |
113 | a52ea5e4 | pastith | this.owner = owner;
|
114 | a52ea5e4 | pastith | } |
115 | a52ea5e4 | pastith | |
116 | a52ea5e4 | pastith | /**
|
117 | a52ea5e4 | pastith | * Retrieve the createdBy.
|
118 | a52ea5e4 | pastith | *
|
119 | a52ea5e4 | pastith | * @return the createdBy
|
120 | a52ea5e4 | pastith | */
|
121 | a52ea5e4 | pastith | public String getCreatedBy() { |
122 | a52ea5e4 | pastith | return createdBy;
|
123 | a52ea5e4 | pastith | } |
124 | a52ea5e4 | pastith | |
125 | a52ea5e4 | pastith | /**
|
126 | a52ea5e4 | pastith | * Modify the createdBy.
|
127 | a52ea5e4 | pastith | *
|
128 | a52ea5e4 | pastith | * @param createdBy the createdBy to set
|
129 | a52ea5e4 | pastith | */
|
130 | a52ea5e4 | pastith | public void setCreatedBy(String createdBy) { |
131 | a52ea5e4 | pastith | this.createdBy = createdBy;
|
132 | a52ea5e4 | pastith | } |
133 | a52ea5e4 | pastith | |
134 | a52ea5e4 | pastith | /**
|
135 | a52ea5e4 | pastith | * Retrieve the modifiedBy.
|
136 | a52ea5e4 | pastith | *
|
137 | a52ea5e4 | pastith | * @return the modifiedBy
|
138 | a52ea5e4 | pastith | */
|
139 | a52ea5e4 | pastith | public String getModifiedBy() { |
140 | a52ea5e4 | pastith | return modifiedBy;
|
141 | a52ea5e4 | pastith | } |
142 | a52ea5e4 | pastith | |
143 | a52ea5e4 | pastith | /**
|
144 | a52ea5e4 | pastith | * Modify the modifiedBy.
|
145 | a52ea5e4 | pastith | *
|
146 | a52ea5e4 | pastith | * @param modifiedBy the modifiedBy to set
|
147 | a52ea5e4 | pastith | */
|
148 | a52ea5e4 | pastith | public void setModifiedBy(String modifiedBy) { |
149 | a52ea5e4 | pastith | this.modifiedBy = modifiedBy;
|
150 | a52ea5e4 | pastith | } |
151 | a52ea5e4 | pastith | |
152 | a52ea5e4 | pastith | /**
|
153 | a52ea5e4 | pastith | * Retrieve the creationDate.
|
154 | a52ea5e4 | pastith | *
|
155 | a52ea5e4 | pastith | * @return the creationDate
|
156 | a52ea5e4 | pastith | */
|
157 | a52ea5e4 | pastith | public Date getCreationDate() { |
158 | a52ea5e4 | pastith | return creationDate;
|
159 | a52ea5e4 | pastith | } |
160 | a52ea5e4 | pastith | |
161 | a52ea5e4 | pastith | /**
|
162 | a52ea5e4 | pastith | * Modify the creationDate.
|
163 | a52ea5e4 | pastith | *
|
164 | a52ea5e4 | pastith | * @param creationDate the creationDate to set
|
165 | a52ea5e4 | pastith | */
|
166 | a52ea5e4 | pastith | public void setCreationDate(Date creationDate) { |
167 | a52ea5e4 | pastith | this.creationDate = creationDate;
|
168 | a52ea5e4 | pastith | } |
169 | a52ea5e4 | pastith | |
170 | a52ea5e4 | pastith | /**
|
171 | a52ea5e4 | pastith | * Retrieve the modificationDate.
|
172 | a52ea5e4 | pastith | *
|
173 | a52ea5e4 | pastith | * @return the modificationDate
|
174 | a52ea5e4 | pastith | */
|
175 | a52ea5e4 | pastith | public Date getModificationDate() { |
176 | a52ea5e4 | pastith | return modificationDate;
|
177 | a52ea5e4 | pastith | } |
178 | a52ea5e4 | pastith | |
179 | a52ea5e4 | pastith | /**
|
180 | a52ea5e4 | pastith | * Modify the modificationDate.
|
181 | a52ea5e4 | pastith | *
|
182 | a52ea5e4 | pastith | * @param modificationDate the modificationDate to set
|
183 | a52ea5e4 | pastith | */
|
184 | a52ea5e4 | pastith | public void setModificationDate(Date modificationDate) { |
185 | a52ea5e4 | pastith | this.modificationDate = modificationDate;
|
186 | a52ea5e4 | pastith | } |
187 | a52ea5e4 | pastith | |
188 | a52ea5e4 | pastith | /**
|
189 | a52ea5e4 | pastith | * Retrieve the contentType.
|
190 | a52ea5e4 | pastith | *
|
191 | a52ea5e4 | pastith | * @return the contentType
|
192 | a52ea5e4 | pastith | */
|
193 | a52ea5e4 | pastith | public String getContentType() { |
194 | a52ea5e4 | pastith | return contentType;
|
195 | a52ea5e4 | pastith | } |
196 | a52ea5e4 | pastith | |
197 | a52ea5e4 | pastith | /**
|
198 | a52ea5e4 | pastith | * Modify the contentType.
|
199 | a52ea5e4 | pastith | *
|
200 | a52ea5e4 | pastith | * @param contentType the contentType to set
|
201 | a52ea5e4 | pastith | */
|
202 | a52ea5e4 | pastith | public void setContentType(String contentType) { |
203 | a52ea5e4 | pastith | this.contentType = contentType;
|
204 | a52ea5e4 | pastith | } |
205 | a52ea5e4 | pastith | |
206 | a52ea5e4 | pastith | /**
|
207 | a52ea5e4 | pastith | * Retrieve the contentLength.
|
208 | a52ea5e4 | pastith | *
|
209 | a52ea5e4 | pastith | * @return the contentLength
|
210 | a52ea5e4 | pastith | */
|
211 | a52ea5e4 | pastith | public Long getContentLength() { |
212 | a52ea5e4 | pastith | return contentLength;
|
213 | a52ea5e4 | pastith | } |
214 | a52ea5e4 | pastith | |
215 | a52ea5e4 | pastith | /**
|
216 | a52ea5e4 | pastith | * Modify the contentLength.
|
217 | a52ea5e4 | pastith | *
|
218 | a52ea5e4 | pastith | * @param contentLength the contentLength to set
|
219 | a52ea5e4 | pastith | */
|
220 | a52ea5e4 | pastith | public void setContentLength(Long contentLength) { |
221 | a52ea5e4 | pastith | this.contentLength = contentLength;
|
222 | a52ea5e4 | pastith | } |
223 | a52ea5e4 | pastith | |
224 | a52ea5e4 | pastith | /**
|
225 | a52ea5e4 | pastith | * Retrieve the readForAll.
|
226 | a52ea5e4 | pastith | *
|
227 | a52ea5e4 | pastith | * @return the readForAll
|
228 | a52ea5e4 | pastith | */
|
229 | a52ea5e4 | pastith | public boolean isReadForAll() { |
230 | a52ea5e4 | pastith | return readForAll;
|
231 | a52ea5e4 | pastith | } |
232 | a52ea5e4 | pastith | |
233 | a52ea5e4 | pastith | /**
|
234 | a52ea5e4 | pastith | * Modify the readForAll.
|
235 | a52ea5e4 | pastith | *
|
236 | a52ea5e4 | pastith | * @param readForAll the readForAll to set
|
237 | a52ea5e4 | pastith | */
|
238 | a52ea5e4 | pastith | public void setReadForAll(boolean readForAll) { |
239 | a52ea5e4 | pastith | this.readForAll = readForAll;
|
240 | a52ea5e4 | pastith | } |
241 | a52ea5e4 | pastith | |
242 | a52ea5e4 | pastith | /**
|
243 | a52ea5e4 | pastith | * Retrieve the versioned.
|
244 | a52ea5e4 | pastith | *
|
245 | a52ea5e4 | pastith | * @return the versioned
|
246 | a52ea5e4 | pastith | */
|
247 | a52ea5e4 | pastith | public boolean isVersioned() { |
248 | a52ea5e4 | pastith | return versioned;
|
249 | a52ea5e4 | pastith | } |
250 | a52ea5e4 | pastith | |
251 | a52ea5e4 | pastith | /**
|
252 | a52ea5e4 | pastith | * Modify the versioned.
|
253 | a52ea5e4 | pastith | *
|
254 | a52ea5e4 | pastith | * @param versioned the versioned to set
|
255 | a52ea5e4 | pastith | */
|
256 | a52ea5e4 | pastith | public void setVersioned(boolean versioned) { |
257 | a52ea5e4 | pastith | this.versioned = versioned;
|
258 | a52ea5e4 | pastith | } |
259 | a52ea5e4 | pastith | |
260 | a52ea5e4 | pastith | /**
|
261 | a52ea5e4 | pastith | * Retrieve the version.
|
262 | a52ea5e4 | pastith | *
|
263 | a52ea5e4 | pastith | * @return the version
|
264 | a52ea5e4 | pastith | */
|
265 | a52ea5e4 | pastith | public Integer getVersion() { |
266 | a52ea5e4 | pastith | return version;
|
267 | a52ea5e4 | pastith | } |
268 | a52ea5e4 | pastith | |
269 | a52ea5e4 | pastith | /**
|
270 | a52ea5e4 | pastith | * Modify the version.
|
271 | a52ea5e4 | pastith | *
|
272 | a52ea5e4 | pastith | * @param version the version to set
|
273 | a52ea5e4 | pastith | */
|
274 | a52ea5e4 | pastith | public void setVersion(Integer version) { |
275 | a52ea5e4 | pastith | this.version = version;
|
276 | a52ea5e4 | pastith | } |
277 | a52ea5e4 | pastith | |
278 | a52ea5e4 | pastith | /**
|
279 | a52ea5e4 | pastith | * Retrieve the etag.
|
280 | a52ea5e4 | pastith | *
|
281 | a52ea5e4 | pastith | * @return the etag
|
282 | a52ea5e4 | pastith | */
|
283 | a52ea5e4 | pastith | public String getEtag() { |
284 | a52ea5e4 | pastith | return etag;
|
285 | a52ea5e4 | pastith | } |
286 | a52ea5e4 | pastith | |
287 | a52ea5e4 | pastith | /**
|
288 | a52ea5e4 | pastith | * Modify the etag.
|
289 | a52ea5e4 | pastith | *
|
290 | a52ea5e4 | pastith | * @param etag the etag to set
|
291 | a52ea5e4 | pastith | */
|
292 | a52ea5e4 | pastith | public void setEtag(String etag) { |
293 | a52ea5e4 | pastith | this.etag = etag;
|
294 | a52ea5e4 | pastith | } |
295 | a52ea5e4 | pastith | |
296 | a52ea5e4 | pastith | /**
|
297 | a52ea5e4 | pastith | * Retrieve the tags.
|
298 | a52ea5e4 | pastith | *
|
299 | a52ea5e4 | pastith | * @return the tags
|
300 | a52ea5e4 | pastith | */
|
301 | a52ea5e4 | pastith | public List<String> getTags() { |
302 | a52ea5e4 | pastith | return tags;
|
303 | a52ea5e4 | pastith | } |
304 | a52ea5e4 | pastith | |
305 | a52ea5e4 | pastith | /**
|
306 | a52ea5e4 | pastith | * Modify the tags.
|
307 | a52ea5e4 | pastith | *
|
308 | a52ea5e4 | pastith | * @param tags the tags to set
|
309 | a52ea5e4 | pastith | */
|
310 | a52ea5e4 | pastith | public void setTags(List<String> tags) { |
311 | a52ea5e4 | pastith | this.tags = tags;
|
312 | a52ea5e4 | pastith | } |
313 | a52ea5e4 | pastith | |
314 | a52ea5e4 | pastith | /**
|
315 | a52ea5e4 | pastith | * Retrieve the permissions.
|
316 | a52ea5e4 | pastith | *
|
317 | a52ea5e4 | pastith | * @return the permissions
|
318 | a52ea5e4 | pastith | */
|
319 | a52ea5e4 | pastith | public Set<PermissionHolder> getPermissions() { |
320 | a52ea5e4 | pastith | return permissions;
|
321 | a52ea5e4 | pastith | } |
322 | a52ea5e4 | pastith | |
323 | a52ea5e4 | pastith | /**
|
324 | a52ea5e4 | pastith | * Modify the permissions.
|
325 | a52ea5e4 | pastith | *
|
326 | a52ea5e4 | pastith | * @param permissions the permissions to set
|
327 | a52ea5e4 | pastith | */
|
328 | a52ea5e4 | pastith | public void setPermissions(Set<PermissionHolder> permissions) { |
329 | a52ea5e4 | pastith | this.permissions = permissions;
|
330 | a52ea5e4 | pastith | } |
331 | a52ea5e4 | pastith | |
332 | a52ea5e4 | pastith | /**
|
333 | a52ea5e4 | pastith | * Retrieve the deleted.
|
334 | a52ea5e4 | pastith | *
|
335 | a52ea5e4 | pastith | * @return the deleted
|
336 | a52ea5e4 | pastith | */
|
337 | a52ea5e4 | pastith | public boolean isDeleted() { |
338 | a52ea5e4 | pastith | return deleted;
|
339 | a52ea5e4 | pastith | } |
340 | a52ea5e4 | pastith | |
341 | a52ea5e4 | pastith | /**
|
342 | a52ea5e4 | pastith | * Modify the deleted.
|
343 | a52ea5e4 | pastith | *
|
344 | a52ea5e4 | pastith | * @param deleted the deleted to set
|
345 | a52ea5e4 | pastith | */
|
346 | a52ea5e4 | pastith | public void setDeleted(boolean deleted) { |
347 | a52ea5e4 | pastith | this.deleted = deleted;
|
348 | a52ea5e4 | pastith | } |
349 | a52ea5e4 | pastith | |
350 | a52ea5e4 | pastith | /**
|
351 | a52ea5e4 | pastith | * Retrieve the folderURI.
|
352 | a52ea5e4 | pastith | *
|
353 | a52ea5e4 | pastith | * @return the folderURI
|
354 | a52ea5e4 | pastith | */
|
355 | a52ea5e4 | pastith | public String getFolderURI() { |
356 | a52ea5e4 | pastith | return folderURI;
|
357 | a52ea5e4 | pastith | } |
358 | a52ea5e4 | pastith | |
359 | a52ea5e4 | pastith | /**
|
360 | a52ea5e4 | pastith | * Modify the folderURI.
|
361 | a52ea5e4 | pastith | *
|
362 | a52ea5e4 | pastith | * @param folderURI the folderURI to set
|
363 | a52ea5e4 | pastith | */
|
364 | a52ea5e4 | pastith | public void setFolderURI(String folderURI) { |
365 | a52ea5e4 | pastith | this.folderURI = folderURI;
|
366 | a52ea5e4 | pastith | } |
367 | a52ea5e4 | pastith | |
368 | a52ea5e4 | pastith | public void createFromJSON(String text) { |
369 | a52ea5e4 | pastith | JSONObject metadata = (JSONObject) JSONParser.parse(text); |
370 | a52ea5e4 | pastith | name = unmarshallString(metadata, "name");
|
371 | a52ea5e4 | pastith | name = URL.decodeComponent(name);
|
372 | a52ea5e4 | pastith | owner = unmarshallString(metadata, "owner");
|
373 | a52ea5e4 | pastith | readForAll = unmarshallBoolean(metadata, "readForAll");
|
374 | a52ea5e4 | pastith | versioned = unmarshallBoolean(metadata, "versioned");
|
375 | a52ea5e4 | pastith | |
376 | a52ea5e4 | pastith | if (metadata.get("version") != null) |
377 | a52ea5e4 | pastith | version = new Integer(metadata.get("version").toString()); |
378 | a52ea5e4 | pastith | |
379 | a52ea5e4 | pastith | folderURI = unmarshallString(metadata, "folder");
|
380 | a52ea5e4 | pastith | deleted = unmarshallBoolean(metadata, "deleted");
|
381 | a52ea5e4 | pastith | if (deleted)
|
382 | a52ea5e4 | pastith | GWT.log("FOUND A DELETED FILE:" + name, null); |
383 | a52ea5e4 | pastith | |
384 | a52ea5e4 | pastith | if (metadata.get("permissions") != null) { |
385 | a52ea5e4 | pastith | JSONArray perm = metadata.get("permissions").isArray();
|
386 | a52ea5e4 | pastith | if (perm != null) |
387 | a52ea5e4 | pastith | for (int i = 0; i < perm.size(); i++) { |
388 | a52ea5e4 | pastith | JSONObject obj = perm.get(i).isObject(); |
389 | a52ea5e4 | pastith | if (obj != null) { |
390 | a52ea5e4 | pastith | PermissionHolder permission = new PermissionHolder();
|
391 | a52ea5e4 | pastith | if (obj.get("user") != null) |
392 | a52ea5e4 | pastith | permission.setUser(unmarshallString(obj, "user"));
|
393 | a52ea5e4 | pastith | if (obj.get("group") != null) |
394 | a52ea5e4 | pastith | permission.setGroup(unmarshallString(obj, "group"));
|
395 | a52ea5e4 | pastith | permission.setRead(unmarshallBoolean(obj, "read"));
|
396 | a52ea5e4 | pastith | permission.setWrite(unmarshallBoolean(obj, "write"));
|
397 | a52ea5e4 | pastith | permission.setModifyACL(unmarshallBoolean(obj, "modifyACL"));
|
398 | a52ea5e4 | pastith | permissions.add(permission); |
399 | a52ea5e4 | pastith | } |
400 | a52ea5e4 | pastith | } |
401 | a52ea5e4 | pastith | |
402 | a52ea5e4 | pastith | } |
403 | a52ea5e4 | pastith | if (metadata.get("tags") != null) { |
404 | a52ea5e4 | pastith | JSONArray perm = metadata.get("tags").isArray();
|
405 | a52ea5e4 | pastith | if (perm != null) |
406 | a52ea5e4 | pastith | for (int i = 0; i < perm.size(); i++) { |
407 | a52ea5e4 | pastith | JSONString obj = perm.get(i).isString(); |
408 | a52ea5e4 | pastith | if(obj != null) |
409 | a52ea5e4 | pastith | tags.add(obj.stringValue()); |
410 | a52ea5e4 | pastith | } |
411 | a52ea5e4 | pastith | } |
412 | a52ea5e4 | pastith | if (metadata.get("creationDate") != null) |
413 | a52ea5e4 | pastith | creationDate = new Date(new Long(metadata.get("creationDate").toString())); |
414 | a52ea5e4 | pastith | if (metadata.get("modificationDate") != null) |
415 | a52ea5e4 | pastith | modificationDate = new Date(new Long(metadata.get("modificationDate").toString())); |
416 | a52ea5e4 | pastith | } |
417 | a52ea5e4 | pastith | |
418 | a52ea5e4 | pastith | /**
|
419 | a52ea5e4 | pastith | * Return the file size in a humanly readable form, using SI units to denote
|
420 | a52ea5e4 | pastith | * size information, e.g. 1 KB = 1000 B (bytes).
|
421 | a52ea5e4 | pastith | *
|
422 | a52ea5e4 | pastith | * @return the fileSize
|
423 | a52ea5e4 | pastith | */
|
424 | a52ea5e4 | pastith | public String getFileSizeAsString() { |
425 | 2ec3aa1c | fstamatelopoulos | return getFileSizeAsString(contentLength);
|
426 | a52ea5e4 | pastith | } |
427 | a52ea5e4 | pastith | |
428 | 2ec3aa1c | fstamatelopoulos | |
429 | 2ec3aa1c | fstamatelopoulos | /**
|
430 | 2ec3aa1c | fstamatelopoulos | * Return the given size in a humanly readable form, using SI units to denote
|
431 | 2ec3aa1c | fstamatelopoulos | * size information, e.g. 1 KB = 1000 B (bytes).
|
432 | 2ec3aa1c | fstamatelopoulos | *
|
433 | 2ec3aa1c | fstamatelopoulos | * @param size in bytes
|
434 | 2ec3aa1c | fstamatelopoulos | * @return the size in human readable string
|
435 | 2ec3aa1c | fstamatelopoulos | */
|
436 | 2ec3aa1c | fstamatelopoulos | public static String getFileSizeAsString(long size) { |
437 | 2ec3aa1c | fstamatelopoulos | if (size < 1024) |
438 | 2ec3aa1c | fstamatelopoulos | return String.valueOf(size) + " B"; |
439 | 2ec3aa1c | fstamatelopoulos | else if (size <= 1024 * 1024) |
440 | 2ec3aa1c | fstamatelopoulos | return getSize(size, 1024D) + " KB"; |
441 | 2ec3aa1c | fstamatelopoulos | else if (size <= 1024 * 1024 * 1024) |
442 | 2ec3aa1c | fstamatelopoulos | return getSize(size, (1024D * 1024D)) + " MB"; |
443 | 2ec3aa1c | fstamatelopoulos | return getSize(size, (1024D * 1024D * 1024D)) + " GB"; |
444 | 2ec3aa1c | fstamatelopoulos | } |
445 | 2ec3aa1c | fstamatelopoulos | |
446 | 2ec3aa1c | fstamatelopoulos | private static String getSize(Long size, Double division) { |
447 | a52ea5e4 | pastith | Double res = Double.valueOf(size.toString()) / division; |
448 | a52ea5e4 | pastith | NumberFormat nf = NumberFormat.getFormat("######.###"); |
449 | a52ea5e4 | pastith | return nf.format(res);
|
450 | a52ea5e4 | pastith | } |
451 | a52ea5e4 | pastith | } |