2 * Copyright 2009 Electronic Business Systems Ltd.
4 * This file is part of GSS.
6 * GSS is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * GSS is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with GSS. If not, see <http://www.gnu.org/licenses/>.
19 package gr.ebs.gss.client.rest.resource;
21 import java.util.ArrayList;
22 import java.util.Date;
23 import java.util.LinkedList;
24 import java.util.List;
26 import com.google.gwt.http.client.URL;
27 import com.google.gwt.json.client.JSONArray;
28 import com.google.gwt.json.client.JSONObject;
29 import com.google.gwt.json.client.JSONParser;
36 public class TrashResource extends RestResource{
38 public TrashResource(String aUri) {
42 List<String> filePaths = new LinkedList<String>();
43 List<String> subfolderPaths = new LinkedList<String>();
44 List<FolderResource> folders = new ArrayList<FolderResource>();
45 List<FileResource> files = new ArrayList<FileResource>();
48 * Retrieve the file paths.
50 * @return the file paths
52 public List<String> getFilePaths() {
57 * Modify the file paths.
59 * @param newFilePaths the file paths to set
61 public void setFilePaths(List<String> newFilePaths) {
62 filePaths = newFilePaths;
66 * Retrieve the subfolder paths.
68 * @return the subfolder paths
70 public List<String> getSubfolderPaths() {
71 return subfolderPaths;
75 * Modify the subfolder paths.
77 * @param newSubfolderPaths the subfolders to set
79 public void setSubfolderPaths(List<String> newSubfolderPaths) {
80 subfolderPaths = newSubfolderPaths;
84 * Retrieve the folders.
88 public List<FolderResource> getFolders() {
95 * @param newFolders the folders to set
97 public void setFolders(List<FolderResource> newFolders) {
102 * Retrieve the files.
106 public List<FileResource> getFiles() {
113 * @param newFiles the files to set
115 public void setFiles(List<FileResource> newFiles) {
120 public void createFromJSON(String text) {
121 JSONObject json = (JSONObject) JSONParser.parse(text);
122 if (json.get("folders") != null) {
123 JSONArray subs = json.get("folders").isArray();
125 for (int i = 0; i < subs.size(); i++) {
126 JSONObject so = subs.get(i).isObject();
128 String subUri = unmarshallString(so, "uri");
129 String subName = unmarshallString(so, "name");
130 subName = URL.decodeComponent(subName);
131 if (subUri != null && subName != null) {
132 if (!subUri.endsWith("/"))
133 subUri = subUri + "/";
134 FolderResource sub = new FolderResource(subUri);
135 sub.setName(subName);
136 sub.setNeedsExpanding(true);
138 subfolderPaths.add(subUri);
143 if (json.get("files") != null) {
144 JSONArray subs = json.get("files").isArray();
146 for (int i = 0; i < subs.size(); i++) {
147 JSONObject fo = subs.get(i).isObject();
149 String fname = unmarshallString(fo, "name");
150 String fowner = unmarshallString(fo, "owner");
151 String fcontent = unmarshallString(fo, "content");
152 String fpath = unmarshallString(fo, "path");
153 fpath = URL.decodeComponent(fpath);
154 Integer fversion = null;
155 if (fo.get("version") != null)
156 fversion = new Integer(fo.get("version").toString());
157 boolean fdeleted = unmarshallBoolean(fo, "deleted");
158 Date fcreationDate = null;
159 if (fo.get("creationDate") != null)
160 fcreationDate = new Date(new Long(fo.get("creationDate").toString()));
161 String furi = unmarshallString(fo,"uri");
163 if(fo.get("size") != null)
164 fsize = new Long(fo.get("size").toString());
166 FileResource fs = new FileResource(furi);
169 fs.setVersion(fversion);
170 fs.setContentLength(fsize);
171 fs.setDeleted(fdeleted);
173 fs.setCreationDate(fcreationDate);
174 fs.setContentType(fcontent);
181 public List<FolderResource> getTrashedFolders(){
182 List<FolderResource> res = new ArrayList<FolderResource>();
183 for(String s : subfolderPaths){
184 String[] pathElements = s.split("/");
185 FolderResource tr = new FolderResource(s);
186 tr.setName(URL.decodeComponent(pathElements[pathElements.length-1]));