2 * Copyright 2009, 2010 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 org.gss_project.gss.web.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;
30 import com.google.gwt.user.client.ui.TreeItem;
37 public class TrashResource extends RestResource{
39 public TrashResource(String aUri) {
43 List<String> filePaths = new LinkedList<String>();
44 List<String> subfolderPaths = new LinkedList<String>();
45 List<FolderResource> folders = new ArrayList<FolderResource>();
46 List<FileResource> files = new ArrayList<FileResource>();
49 * Retrieve the file paths.
51 * @return the file paths
53 public List<String> getFilePaths() {
58 * Modify the file paths.
60 * @param newFilePaths the file paths to set
62 public void setFilePaths(List<String> newFilePaths) {
63 filePaths = newFilePaths;
67 * Retrieve the subfolder paths.
69 * @return the subfolder paths
71 public List<String> getSubfolderPaths() {
72 return subfolderPaths;
76 * Modify the subfolder paths.
78 * @param newSubfolderPaths the subfolders to set
80 public void setSubfolderPaths(List<String> newSubfolderPaths) {
81 subfolderPaths = newSubfolderPaths;
85 * Retrieve the folders.
89 public List<FolderResource> getFolders() {
96 * @param newFolders the folders to set
98 public void setFolders(List<FolderResource> newFolders) {
103 * Retrieve the files.
107 public List<FileResource> getFiles() {
114 * @param newFiles the files to set
116 public void setFiles(List<FileResource> newFiles) {
121 public void createFromJSON(String text) {
122 JSONObject json = (JSONObject) JSONParser.parse(text);
123 if (json.get("folders") != null) {
124 JSONArray subs = json.get("folders").isArray();
126 for (int i = 0; i < subs.size(); i++) {
127 JSONObject so = subs.get(i).isObject();
129 String subUri = unmarshallString(so, "uri");
130 String subName = unmarshallString(so, "name");
131 subName = URL.decodeComponent(subName);
132 if (subUri != null && subName != null) {
133 if (!subUri.endsWith("/"))
134 subUri = subUri + "/";
135 FolderResource sub = new FolderResource(subUri);
136 sub.setName(subName);
137 sub.setNeedsExpanding(true);
139 subfolderPaths.add(subUri);
144 if (json.get("files") != null) {
145 JSONArray subs = json.get("files").isArray();
147 for (int i = 0; i < subs.size(); i++) {
148 JSONObject fo = subs.get(i).isObject();
150 String fname = unmarshallString(fo, "name");
151 String fowner = unmarshallString(fo, "owner");
152 String fcontent = unmarshallString(fo, "content");
153 Boolean fshared = unmarshallBoolean(fo, "shared");
154 Boolean fversioned = unmarshallBoolean(fo, "versioned");
155 String fpath = unmarshallString(fo, "path");
156 fpath = URL.decodeComponent(fpath);
157 Integer fversion = null;
158 if (fo.get("version") != null)
159 fversion = new Integer(fo.get("version").toString());
160 boolean fdeleted = unmarshallBoolean(fo, "deleted");
161 Date fcreationDate = null;
162 if (fo.get("creationDate") != null)
163 fcreationDate = new Date(new Long(fo.get("creationDate").toString()));
164 Date fmodificationDate = null;
165 if (fo.get("modificationDate") != null)
166 fmodificationDate = new Date(new Long(fo.get("modificationDate").toString()));
167 String furi = unmarshallString(fo,"uri");
169 if(fo.get("size") != null)
170 fsize = new Long(fo.get("size").toString());
172 FileResource fs = new FileResource(furi);
175 fs.setVersion(fversion);
176 fs.setContentLength(fsize);
177 fs.setDeleted(fdeleted);
179 fs.setCreationDate(fcreationDate);
180 fs.setModificationDate(fmodificationDate);
181 fs.setContentType(fcontent);
182 fs.setShared(fshared);
183 fs.setVersioned(fversioned);
190 public List<FolderResource> getTrashedFolders(){
191 List<FolderResource> res = new ArrayList<FolderResource>();
192 for(String s : subfolderPaths){
193 String[] pathElements = s.split("/");
194 FolderResource tr = new FolderResource(s);
195 tr.setName(URL.decodeComponent(pathElements[pathElements.length-1]));
202 public String getLastModifiedSince() {
206 public String constructUri(TreeItem treeItem, String path){
207 String constructedUri = "Files/"+ getUri().substring(path.lastIndexOf("/")+1);
208 if (!constructedUri.endsWith("/"))
209 constructedUri += "/";
210 return constructedUri;