Subversion Repository Public Repository

litesoft

Diff Revisions 905 vs 906 for /trunk/mobileGWT/gwt-phonegap/src/main/java/com/googlecode/gwtphonegap/client/file/js/FileTransferJsImpl.java

Diff revisions: vs.
  @@ -1,58 +1,73 @@
1 1 /*
2 2 * Copyright 2011 Daniel Kurka
3 3 *
4 - * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 - * use this file except in compliance with the License. You may obtain a copy of
6 - * the License at
4 + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 + * in compliance with the License. You may obtain a copy of the License at
7 6 *
8 7 * http://www.apache.org/licenses/LICENSE-2.0
9 8 *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 - * License for the specific language governing permissions and limitations under
9 + * Unless required by applicable law or agreed to in writing, software distributed under the License
10 + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 + * or implied. See the License for the specific language governing permissions and limitations under
14 12 * the License.
15 13 */
16 14 package com.googlecode.gwtphonegap.client.file.js;
17 15
18 - import java.util.Map;
19 - import java.util.Map.Entry;
20 - import java.util.Set;
21 -
22 16 import com.google.gwt.core.client.JavaScriptObject;
17 +
23 18 import com.googlecode.gwtphonegap.client.file.FileDownloadCallback;
24 19 import com.googlecode.gwtphonegap.client.file.FileTransfer;
25 20 import com.googlecode.gwtphonegap.client.file.FileUploadCallback;
26 21 import com.googlecode.gwtphonegap.client.file.FileUploadOptions;
27 22 import com.googlecode.gwtphonegap.collection.client.JsLightMap;
28 23
24 + import java.util.Map;
25 + import java.util.Map.Entry;
26 + import java.util.Set;
27 +
29 28 public final class FileTransferJsImpl extends JavaScriptObject implements FileTransfer {
30 29
31 - protected FileTransferJsImpl() {
30 + protected FileTransferJsImpl() {
32 31
33 - }
32 + }
34 33
35 - @Override
36 - public void download(String sourceUrl, String filePath, FileDownloadCallback callback) {
37 - download0(sourceUrl, filePath, callback);
38 - }
39 -
40 - @Override
41 - public void upload(String fileUri, String serverUrl, FileUploadOptions options, FileUploadCallback callback) {
42 - Map<String, String> params = options.getParams();
43 - JsLightMap<String> map = new JsLightMap<String>();
44 - if (params != null && params.size() > 0) {
45 - Set<Entry<String, String>> entrySet = params.entrySet();
46 - for (Entry<String, String> entry : entrySet) {
47 - map.put(entry.getKey(), entry.getValue());
48 - }
49 - }
34 + @Override
35 + public native void abort()/*-{
36 + this.abort();
37 + }-*/;
38 +
39 + @Override
40 + public void download(String sourceUrl, String filePath, FileDownloadCallback callback) {
41 + download0(sourceUrl, filePath, callback);
42 + }
43 +
44 + @Override
45 + public void upload(String fileUri, String serverUrl, FileUploadOptions options,
46 + FileUploadCallback callback) {
47 + Map<String, String> params = options.getParams();
48 + JsLightMap<String> map = new JsLightMap<String>();
49 + if (params != null && params.size() > 0) {
50 + Set<Entry<String, String>> entrySet = params.entrySet();
51 + for (Entry<String, String> entry : entrySet) {
52 + map.put(entry.getKey(), entry.getValue());
53 + }
54 + }
55 +
56 + Map<String, String> head = options.getHeaders();
57 + JsLightMap<String> headers = new JsLightMap<String>();
58 + if (head != null && head.size() > 0) {
59 + Set<Entry<String, String>> entrySet = head.entrySet();
60 + for (Entry<String, String> entry : entrySet) {
61 + headers.put(entry.getKey(), entry.getValue());
62 + }
63 + }
50 64
51 - upload0(fileUri, serverUrl, options, map.getMap(), callback);
65 + upload0(fileUri, serverUrl, options, map.getMap(), headers.getMap(), callback);
52 66
53 - }
67 + }
54 68
55 - private native void upload0(String fileUri, String serverUrl, FileUploadOptions options, JavaScriptObject map, FileUploadCallback callback)/*-{
69 + private native void upload0(String fileUri, String serverUrl, FileUploadOptions options,
70 + JavaScriptObject map, JavaScriptObject headers, FileUploadCallback callback)/*-{
56 71 var that = this;
57 72
58 73 var suc = function(result) {
  @@ -73,11 +88,12 @@
73 88 fop.fileName = options.@com.googlecode.gwtphonegap.client.file.FileUploadOptions::getFileName()();
74 89 fop.mimeType = options.@com.googlecode.gwtphonegap.client.file.FileUploadOptions::getMimeType()();
75 90 fop.params = map;
91 + fop.heaaders = headers;
76 92
77 93 this.upload(fileUri, serverUrl, $entry(suc), $entry(fail), fop);
78 - }-*/;
94 + }-*/;
79 95
80 - private native void download0(String sourceUrl, String filePath, FileDownloadCallback callback)/*-{
96 + private native void download0(String sourceUrl, String filePath, FileDownloadCallback callback)/*-{
81 97
82 98 var suc = function(result) {
83 99 var en = @com.googlecode.gwtphonegap.client.file.js.FileEntryJsImpl::new(Lcom/google/gwt/core/client/JavaScriptObject;)(result);
  @@ -91,6 +107,6 @@
91 107 callback.@com.googlecode.gwtphonegap.client.file.FileDownloadCallback::onProgress(Lcom/googlecode/gwtphonegap/client/file/FileTransferProgressEvent;)(progressEvent);
92 108 });
93 109 this.download(sourceUrl, filePath, $entry(suc), $entry(fail));
94 - }-*/;
110 + }-*/;
95 111
96 112 }