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 SharedResource extends RestResource{
38 public SharedResource(String aUri) {
42 List<String> filePaths = new LinkedList<String>();
43 List<String> subfolderPaths = new LinkedList<String>();
44 List<FolderResource> folders = new ArrayList<FolderResource>();
46 List<FileResource> files = new ArrayList<FileResource>();
53 public List<String> getFilePaths() {
60 * @param newFilePaths the files to set
62 public void setFilePaths(List<String> newFilePaths) {
63 filePaths = newFilePaths;
67 * Retrieve the subfolders.
69 * @return the subfolders
71 public List<String> getSubfolderPaths() {
72 return subfolderPaths;
76 * Modify the subfolder paths.
78 * @param newSubfolderPaths the subfolder paths 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 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 Integer fversion = null;
153 if (fo.get("version") != null)
154 fversion = new Integer(fo.get("version").toString());
155 boolean fdeleted = unmarshallBoolean(fo, "deleted");
156 Date fcreationDate = null;
157 if (fo.get("creationDate") != null)
158 fcreationDate = new Date(new Long(fo.get("creationDate").toString()));
159 String furi = unmarshallString(fo,"uri");
161 if(fo.get("size") != null)
162 fsize = new Long(fo.get("size").toString());
164 String fpath = unmarshallString(fo, "path");
165 fpath = URL.decodeComponent(fpath);
166 FileResource fs = new FileResource(furi);
170 fs.setVersion(fversion);
171 fs.setContentLength(fsize);
172 fs.setDeleted(fdeleted);
173 fs.setCreationDate(fcreationDate);
174 fs.setContentType(fcontent);
181 public List<String> getRootSharedFiles(){
182 List<String> res = new ArrayList<String>();
183 for(String f : getFilePaths()){
184 boolean contained = false;
185 for(String fo : getSubfolderPaths())