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 OtherUserResource extends RestResource{
37 public OtherUserResource(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 username.
50 * @return the username
52 public String getUsername() {
57 * Modify the username.
59 * @param aUsername the username to set
61 public void setUsername(String aUsername) {
70 public List<String> getFilePaths() {
77 * @param newFiles the files to set
79 public void setFilePaths(List<String> newFiles) {
84 * Retrieve the subfolders.
86 * @return the subfolders
88 public List<String> getSubfolderPaths() {
89 return subfolderPaths;
93 * Modify the subfolders.
95 * @param subfolders the subfolders to set
97 public void setSubfolderPaths(List<String> subfolders) {
98 subfolderPaths = subfolders;
102 * Retrieve the folders.
104 * @return the folders
106 public List<FolderResource> getFolders() {
111 * Modify the folders.
113 * @param newFolders the folders to set
115 public void setFolders(List<FolderResource> newFolders) {
116 folders = newFolders;
120 * Retrieve the files.
124 public List<FileResource> getFiles() {
131 * @param newFiles the files to set
133 public void setFiles(List<FileResource> newFiles) {
138 public void createFromJSON(String text) {
139 JSONObject json = (JSONObject) JSONParser.parse(text);
140 if (json.get("folders") != null) {
141 JSONArray subs = json.get("folders").isArray();
143 for (int i = 0; i < subs.size(); i++) {
144 JSONObject so = subs.get(i).isObject();
146 String subUri = unmarshallString(so, "uri");
147 String subName = unmarshallString(so, "name");
148 if (subUri != null && subName != null) {
149 if (!subUri.endsWith("/"))
150 subUri = subUri + "/";
151 FolderResource sub = new FolderResource(subUri);
152 sub.setName(subName);
153 sub.setNeedsExpanding(true);
155 subfolderPaths.add(subUri);
160 if (json.get("files") != null) {
161 JSONArray subs = json.get("files").isArray();
163 for (int i = 0; i < subs.size(); i++) {
164 JSONObject fo = subs.get(i).isObject();
166 String fname = unmarshallString(fo, "name");
167 String fowner = unmarshallString(fo, "owner");
168 String fcontent = unmarshallString(fo, "content");
169 Integer fversion = null;
170 if (fo.get("version") != null)
171 fversion = new Integer(fo.get("version").toString());
172 boolean fdeleted = unmarshallBoolean(fo, "deleted");
173 Date fcreationDate = null;
174 if (fo.get("creationDate") != null)
175 fcreationDate = new Date(new Long(fo.get("creationDate").toString()));
176 String furi = unmarshallString(fo,"uri");
178 if(fo.get("size") != null)
179 fsize = new Long(fo.get("size").toString());
181 String fpath = unmarshallString(fo, "path");
182 fpath = URL.decodeComponent(fpath);
183 FileResource fs = new FileResource(furi);
187 fs.setVersion(fversion);
188 fs.setContentLength(fsize);
189 fs.setDeleted(fdeleted);
190 fs.setCreationDate(fcreationDate);
191 fs.setContentType(fcontent);
198 public String getName(){
199 String[] names = uri.split("/");
200 return names[names.length -1];