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;
21 import gr.ebs.gss.client.GSS;
22 import gr.ebs.gss.client.exceptions.ObjectNotFoundException;
23 import gr.ebs.gss.client.rest.resource.FileResource;
24 import gr.ebs.gss.client.rest.resource.FolderResource;
25 import gr.ebs.gss.client.rest.resource.GroupResource;
26 import gr.ebs.gss.client.rest.resource.GroupUserResource;
27 import gr.ebs.gss.client.rest.resource.GroupsResource;
28 import gr.ebs.gss.client.rest.resource.RestResource;
29 import gr.ebs.gss.client.rest.resource.SharedResource;
30 import gr.ebs.gss.client.rest.resource.TrashResource;
31 import gr.ebs.gss.client.rest.resource.UserResource;
33 import com.google.gwt.http.client.Request;
34 import com.google.gwt.http.client.Response;
41 public abstract class HeadCommand <T extends RestResource> extends RestCommand{
43 boolean complete = false;
47 public HeadCommand(Class<T> aclass, String pathToGet){
48 this(aclass, pathToGet, true);
50 public HeadCommand(Class<T> aclass, String pathToGet, boolean showLoading){
51 setShowLoadingIndicator(showLoading);
53 if(isShowLoadingIndicator())
54 GSS.get().showLoadingIndicator();
56 if(aclass.equals(FileResource.class))
59 path = fixPath(pathToGet);
60 RestRequestBuilder builder = new RestRequestBuilder("HEAD", path);
63 handleHeaders(builder, path);
64 builder.sendRequest("", new RestCallback(path) {
66 public Object deserialize(Response response) {
67 return deserializeResponse(path, response);
70 public void handleError(Request request, Throwable exception) {
72 HeadCommand.this.onError(exception);
75 public void handleSuccess(Object object) {
81 } catch (Exception ex) {
88 public boolean isComplete() {
96 public boolean execute() {
97 boolean com = isComplete();
99 if(isShowLoadingIndicator())
100 GSS.get().hideLoadingIndicator();
101 if(getResult() != null)
104 onError(new ObjectNotFoundException("Resource Not Found"));
110 public Object deserializeResponse(String path, Response response){
111 RestResource result1 = null;
112 if(aclass.equals(FolderResource.class)){
113 result1 = new FolderResource(path);
114 result1.createFromJSON(response.getText());
117 else if(aclass.equals(FileResource.class)){
118 result1 = new FileResource(path);
119 result1.createFromJSON(response.getHeader("X-GSS-Metadata"));
121 else if(aclass.equals(GroupsResource.class)){
122 result1 = new GroupsResource(path);
123 result1.createFromJSON(response.getText());
125 else if(aclass.equals(TrashResource.class)){
126 result1 = new TrashResource(path);
127 result1.createFromJSON(response.getText());
130 else if(aclass.equals(SharedResource.class)){
131 result1 = new SharedResource(path);
132 result1.createFromJSON(response.getText());
135 else if(aclass.equals(GroupResource.class)){
136 result1 = new GroupResource(path);
137 result1.createFromJSON(response.getText());
140 else if(aclass.equals(GroupUserResource.class)){
141 result1 = new GroupUserResource(path);
142 result1.createFromJSON(response.getText());
145 else if(aclass.equals(UserResource.class)){
146 result1 = new UserResource(path);
147 result1.createFromJSON(response.getText());