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;
21 import java.util.List;
23 import gr.ebs.gss.client.rest.RestCommand;
25 import com.google.gwt.gears.client.desktop.File;
26 import com.google.gwt.gears.client.httprequest.HttpRequest;
27 import com.google.gwt.gears.client.httprequest.ProgressEvent;
28 import com.google.gwt.gears.client.httprequest.ProgressHandler;
29 import com.google.gwt.gears.client.httprequest.RequestCallback;
32 * The 'File upload' dialog box implementation with Google Gears support
35 public class FileUploadGearsIEDialog extends FileUploadGearsDialog implements Updateable {
38 * Perform the HTTP request to upload the specified file.
41 protected void doSend(final List<File> filesRemaining) {
42 final GSS app = GSS.get();
43 HttpRequest request = factory.createHttpRequest();
44 requests.add(request);
45 String method = "POST";
48 final String filename = getFilename(filesRemaining.get(0).getName());
49 path = folder.getUri();
50 if (!path.endsWith("/"))
52 path = path + encode(filename);
54 String token = app.getToken();
55 String resource = path.substring(app.getApiPath().length()-1, path.length());
56 String date = RestCommand.getDate();
57 String sig = RestCommand.calculateSig(method, date, resource, RestCommand.base64decode(token));
58 request.open(method, path);
59 request.setRequestHeader("X-GSS-Date", date);
60 request.setRequestHeader("Authorization", app.getCurrentUserResource().getUsername() + " " + sig);
61 request.setRequestHeader("Accept", "application/json; charset=utf-8");
62 request.setCallback(new RequestCallback() {
64 public void onResponseReceived(HttpRequest req) {
65 // XXX: No error checking, since IE throws an Internal Error
66 // when accessing req.getStatus().
67 filesRemaining.remove(0);
68 if(filesRemaining.isEmpty()){
71 doSend(filesRemaining);
74 request.getUpload().setProgressHandler(new ProgressHandler() {
76 public void onProgress(ProgressEvent event) {
77 double pcnt = (double) event.getLoaded() / event.getTotal();
78 progressBars.get(0).setProgress((int) Math.floor(pcnt * 100));
80 progressBars.remove(0);
83 request.send(filesRemaining.get(0).getBlob());