Revision 623:66f69a7348ed src/gr/ebs/gss/client/FileUploadGearsIEDialog.java

b/src/gr/ebs/gss/client/FileUploadGearsIEDialog.java
1
/*
2
 * Copyright 2009 Electronic Business Systems Ltd.
3
 *
4
 * This file is part of GSS.
5
 *
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.
10
 *
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.
15
 *
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/>.
18
 */
19
package gr.ebs.gss.client;
20

  
21
import gr.ebs.gss.client.rest.RestCommand;
22

  
23
import com.google.gwt.gears.client.desktop.File;
24
import com.google.gwt.gears.client.httprequest.HttpRequest;
25
import com.google.gwt.gears.client.httprequest.ProgressEvent;
26
import com.google.gwt.gears.client.httprequest.ProgressHandler;
27
import com.google.gwt.gears.client.httprequest.RequestCallback;
28

  
29
/**
30
 * The 'File upload' dialog box implementation with Google Gears support
31
 * for IE.
32
 */
33
public class FileUploadGearsIEDialog extends FileUploadGearsDialog implements Updateable {
34

  
35
	/**
36
	 * Perform the HTTP request to upload the specified file.
37
	 */
38
	@Override
39
	protected void doSend(final File file, final int index) {
40
		final GSS app = GSS.get();
41
		HttpRequest request = factory.createHttpRequest();
42
		requests.add(request);
43
		String method = "POST";
44

  
45
		String path;
46
		final String filename = getFilename(file.getName());
47
		path = folder.getUri();
48
		if (!path.endsWith("/"))
49
			path = path + "/";
50
		path = path + encode(filename);
51

  
52
		String token = app.getToken();
53
		String resource = path.substring(app.getApiPath().length()-1, path.length());
54
		String date = RestCommand.getDate();
55
		String sig = RestCommand.calculateSig(method, date, resource, RestCommand.base64decode(token));
56
		request.open(method, path);
57
		request.setRequestHeader("X-GSS-Date", date);
58
		request.setRequestHeader("Authorization", app.getCurrentUserResource().getUsername() + " " + sig);
59
		request.setRequestHeader("Accept", "application/json; charset=utf-8");
60
		request.setCallback(new RequestCallback() {
61
			public void onResponseReceived(HttpRequest req) {
62
				// XXX: No error checking, since IE throws an Internal Error
63
				// when accessing req.getStatus().
64
				selectedFiles.remove(file);
65
				finish();
66
			}
67
		});
68
		request.getUpload().setProgressHandler(new ProgressHandler() {
69
			public void onProgress(ProgressEvent event) {
70
				double pcnt = (double) event.getLoaded() / event.getTotal();
71
				progressBars.get(index).setProgress((int) Math.floor(pcnt * 100));
72
			}
73
		});
74
		request.send(file.getBlob());
75
	}
76

  
77
}
1
/*
2
 * Copyright 2009 Electronic Business Systems Ltd.
3
 *
4
 * This file is part of GSS.
5
 *
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.
10
 *
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.
15
 *
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/>.
18
 */
19
package gr.ebs.gss.client;
20

  
21
import gr.ebs.gss.client.rest.RestCommand;
22

  
23
import com.google.gwt.gears.client.desktop.File;
24
import com.google.gwt.gears.client.httprequest.HttpRequest;
25
import com.google.gwt.gears.client.httprequest.ProgressEvent;
26
import com.google.gwt.gears.client.httprequest.ProgressHandler;
27
import com.google.gwt.gears.client.httprequest.RequestCallback;
28

  
29
/**
30
 * The 'File upload' dialog box implementation with Google Gears support
31
 * for IE.
32
 */
33
public class FileUploadGearsIEDialog extends FileUploadGearsDialog implements Updateable {
34

  
35
	/**
36
	 * Perform the HTTP request to upload the specified file.
37
	 */
38
	@Override
39
	protected void doSend(final File file, final int index) {
40
		final GSS app = GSS.get();
41
		HttpRequest request = factory.createHttpRequest();
42
		requests.add(request);
43
		String method = "POST";
44

  
45
		String path;
46
		final String filename = getFilename(file.getName());
47
		path = folder.getUri();
48
		if (!path.endsWith("/"))
49
			path = path + "/";
50
		path = path + encode(filename);
51

  
52
		String token = app.getToken();
53
		String resource = path.substring(app.getApiPath().length()-1, path.length());
54
		String date = RestCommand.getDate();
55
		String sig = RestCommand.calculateSig(method, date, resource, RestCommand.base64decode(token));
56
		request.open(method, path);
57
		request.setRequestHeader("X-GSS-Date", date);
58
		request.setRequestHeader("Authorization", app.getCurrentUserResource().getUsername() + " " + sig);
59
		request.setRequestHeader("Accept", "application/json; charset=utf-8");
60
		request.setCallback(new RequestCallback() {
61
			@Override
62
			public void onResponseReceived(HttpRequest req) {
63
				// XXX: No error checking, since IE throws an Internal Error
64
				// when accessing req.getStatus().
65
				selectedFiles.remove(file);
66
				finish();
67
			}
68
		});
69
		request.getUpload().setProgressHandler(new ProgressHandler() {
70
			@Override
71
			public void onProgress(ProgressEvent event) {
72
				double pcnt = (double) event.getLoaded() / event.getTotal();
73
				progressBars.get(index).setProgress((int) Math.floor(pcnt * 100));
74
			}
75
		});
76
		request.send(file.getBlob());
77
	}
78

  
79
}

Also available in: Unified diff