incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [29/50] [abbrv] js commit: Re-adding filetransfer back to the playbook
Date Fri, 24 Aug 2012 21:57:39 GMT
Re-adding filetransfer back to the playbook


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/commit/81823d62
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/tree/81823d62
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/diff/81823d62

Branch: refs/heads/master
Commit: 81823d627c59a43acfc66b1557af92edc1ab75fa
Parents: fce652c
Author: Tim Kim <tim.kim@nitobi.com>
Authored: Thu Aug 23 17:47:17 2012 -0700
Committer: Anis Kadri <anis.kadri@gmail.com>
Committed: Fri Aug 24 13:50:00 2012 -0700

----------------------------------------------------------------------
 lib/playbook/plugin/playbook/FileTransfer.js |  140 ---------------------
 lib/webworks/air/plugin/air/FileTransfer.js  |  140 +++++++++++++++++++++
 lib/webworks/air/plugin/manager.js           |    3 +-
 3 files changed, 142 insertions(+), 141 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/81823d62/lib/playbook/plugin/playbook/FileTransfer.js
----------------------------------------------------------------------
diff --git a/lib/playbook/plugin/playbook/FileTransfer.js b/lib/playbook/plugin/playbook/FileTransfer.js
deleted file mode 100644
index 4465621..0000000
--- a/lib/playbook/plugin/playbook/FileTransfer.js
+++ /dev/null
@@ -1,140 +0,0 @@
-var cordova = require('cordova'),
-resolveLocalFileSystemURI = require('cordova/plugin/playbook/resolveLocalFileSystemURI'),
-FileTransferError = require('cordova/plugin/FileTransferError'),
-FileUploadResult = require('cordova/plugin/FileUploadResult'),
-FileEntry = require('cordova/plugin/FileEntry');
-
-var validURLProtocol = new RegExp('^(https?|ftp):\/\/');
-
-function getParentPath(filePath) {
-    var pos = filePath.lastIndexOf('/');
-    return filePath.substring(0, pos + 1);
-}
-
-function getFileName(filePath) {
-    var pos = filePath.lastIndexOf('/');
-    return filePath.substring(pos + 1);
-}
-
-module.exports = {
-    upload: function (args, win, fail) {
-        var filePath = args[0],
-            server = args[1],
-            fileKey = args[2],
-            fileName = args[3],
-            mimeType = args[4],
-            params = args[5],
-            trustAllHosts = args[6],
-            chunkedMode = args[7],
-            headers = args[8];
-
-        if(!validURLProtocol.exec(server)){
-            return { "status" : cordova.callbackStatus.ERROR, "message" : new FileTransferError(FileTransferError.INVALID_URL_ERR)
};
-        }
-
-        resolveLocalFileSystemURI(filePath, fileWin, fail);
-
-        function fileWin(entryObject){
-            blackberry.io.file.readFile(filePath, readWin, false);
-        }
-
-        function readWin(filePath, blobFile){
-            var fd = new FormData();
-
-            fd.append(fileKey, blobFile, fileName);
-            for (var prop in params) {
-                if(params.hasOwnProperty(prop)) {
-                    fd.append(prop, params[prop]);
-                }
-            }
-
-            var xhr = new XMLHttpRequest();
-            xhr.open("POST", server);
-            xhr.onload = function(evt) {
-                if (xhr.status == 200) {
-                    var result = new FileUploadResult();
-                    result.bytesSent = xhr.response.length;
-                    result.responseCode = xhr.status;
-                    result.response = xhr.response;
-                    win(result);
-                } else if (xhr.status == 404) {
-                    fail(new FileTransferError(FileTransferError.INVALID_URL_ERR, null, null,
xhr.status));
-                } else if (xhr.status == 403) {
-                    fail(new FileTransferError(FileTransferError.INVALID_URL_ERR, null, null,
xhr.status));
-                } else {
-                    fail(new FileTransferError(FileTransferError.CONNECTION_ERR, null, null,
xhr.status));
-                }
-            };
-            xhr.ontimeout = function(evt) {
-                fail(new FileTransferError(FileTransferError.CONNECTION_ERR, null, null,
xhr.status));
-            };
-
-            if(headers){
-                for(var i in headers){
-                    xhr.setRequestHeader(i, headers[i]);
-                }
-            }
-            xhr.send(fd);
-        }
-
-        return { "status" : cordova.callbackStatus.NO_RESULT, "message" : "WebWorks Is On
It" };
-    },
-
-    download: function(args, win, fail){
-        var url = args[0],
-            filePath = args[1];
-
-        if(!validURLProtocol.exec(url)){
-            return { "status" : cordova.callbackStatus.ERROR, "message" : new FileTransferError(FileTransferError.INVALID_URL_ERR)
};
-        }
-
-        var xhr = new XMLHttpRequest();
-
-        function writeFile(fileEntry) {
-            fileEntry.createWriter(function(writer) {
-                writer.onwriteend = function(evt) {
-                    if (!evt.target.error) {
-                        win(new FileEntry(fileEntry.name, fileEntry.toURL()));
-                    } else {
-                        fail(new FileTransferError(FileTransferError.FILE_NOT_FOUND_ERR));
-                    }
-                };
-
-                writer.onerror = function(evt) {
-                    fail(new FileTransferError(FileTransferError.FILE_NOT_FOUND_ERR));
-                };
-
-                var blob = blackberry.utils.stringToBlob(xhr.response);
-                writer.write(blob);
-
-            },
-            function(error) {
-                fail(new FileTransferError(FileTransferError.FILE_NOT_FOUND_ERR));
-            });
-        }
-
-        xhr.onreadystatechange = function () {
-            if (xhr.readyState == xhr.DONE) {
-                if (xhr.status == 200 && xhr.response) {
-                    resolveLocalFileSystemURI(getParentPath(filePath), function(dir) {
-                        dir.getFile(getFileName(filePath), {create: true}, writeFile, function(error)
{
-                            fail(new FileTransferError(FileTransferError.FILE_NOT_FOUND_ERR));
-                        });
-                    }, function(error) {
-                        fail(new FileTransferError(FileTransferError.FILE_NOT_FOUND_ERR));
-                    });
-                } else if (xhr.status == 404) {
-                    fail(new FileTransferError(FileTransferError.INVALID_URL_ERR, null, null,
xhr.status));
-                } else {
-                    fail(new FileTransferError(FileTransferError.CONNECTION_ERR, null, null,
xhr.status));
-                }
-            }
-        };
-
-        xhr.open("GET", url, true);
-        xhr.responseType = "arraybuffer";
-        xhr.send();
-
-        return { "status" : cordova.callbackStatus.NO_RESULT, "message" : "WebWorks Is On
It" };
-    }
-};

http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/81823d62/lib/webworks/air/plugin/air/FileTransfer.js
----------------------------------------------------------------------
diff --git a/lib/webworks/air/plugin/air/FileTransfer.js b/lib/webworks/air/plugin/air/FileTransfer.js
new file mode 100644
index 0000000..4465621
--- /dev/null
+++ b/lib/webworks/air/plugin/air/FileTransfer.js
@@ -0,0 +1,140 @@
+var cordova = require('cordova'),
+resolveLocalFileSystemURI = require('cordova/plugin/playbook/resolveLocalFileSystemURI'),
+FileTransferError = require('cordova/plugin/FileTransferError'),
+FileUploadResult = require('cordova/plugin/FileUploadResult'),
+FileEntry = require('cordova/plugin/FileEntry');
+
+var validURLProtocol = new RegExp('^(https?|ftp):\/\/');
+
+function getParentPath(filePath) {
+    var pos = filePath.lastIndexOf('/');
+    return filePath.substring(0, pos + 1);
+}
+
+function getFileName(filePath) {
+    var pos = filePath.lastIndexOf('/');
+    return filePath.substring(pos + 1);
+}
+
+module.exports = {
+    upload: function (args, win, fail) {
+        var filePath = args[0],
+            server = args[1],
+            fileKey = args[2],
+            fileName = args[3],
+            mimeType = args[4],
+            params = args[5],
+            trustAllHosts = args[6],
+            chunkedMode = args[7],
+            headers = args[8];
+
+        if(!validURLProtocol.exec(server)){
+            return { "status" : cordova.callbackStatus.ERROR, "message" : new FileTransferError(FileTransferError.INVALID_URL_ERR)
};
+        }
+
+        resolveLocalFileSystemURI(filePath, fileWin, fail);
+
+        function fileWin(entryObject){
+            blackberry.io.file.readFile(filePath, readWin, false);
+        }
+
+        function readWin(filePath, blobFile){
+            var fd = new FormData();
+
+            fd.append(fileKey, blobFile, fileName);
+            for (var prop in params) {
+                if(params.hasOwnProperty(prop)) {
+                    fd.append(prop, params[prop]);
+                }
+            }
+
+            var xhr = new XMLHttpRequest();
+            xhr.open("POST", server);
+            xhr.onload = function(evt) {
+                if (xhr.status == 200) {
+                    var result = new FileUploadResult();
+                    result.bytesSent = xhr.response.length;
+                    result.responseCode = xhr.status;
+                    result.response = xhr.response;
+                    win(result);
+                } else if (xhr.status == 404) {
+                    fail(new FileTransferError(FileTransferError.INVALID_URL_ERR, null, null,
xhr.status));
+                } else if (xhr.status == 403) {
+                    fail(new FileTransferError(FileTransferError.INVALID_URL_ERR, null, null,
xhr.status));
+                } else {
+                    fail(new FileTransferError(FileTransferError.CONNECTION_ERR, null, null,
xhr.status));
+                }
+            };
+            xhr.ontimeout = function(evt) {
+                fail(new FileTransferError(FileTransferError.CONNECTION_ERR, null, null,
xhr.status));
+            };
+
+            if(headers){
+                for(var i in headers){
+                    xhr.setRequestHeader(i, headers[i]);
+                }
+            }
+            xhr.send(fd);
+        }
+
+        return { "status" : cordova.callbackStatus.NO_RESULT, "message" : "WebWorks Is On
It" };
+    },
+
+    download: function(args, win, fail){
+        var url = args[0],
+            filePath = args[1];
+
+        if(!validURLProtocol.exec(url)){
+            return { "status" : cordova.callbackStatus.ERROR, "message" : new FileTransferError(FileTransferError.INVALID_URL_ERR)
};
+        }
+
+        var xhr = new XMLHttpRequest();
+
+        function writeFile(fileEntry) {
+            fileEntry.createWriter(function(writer) {
+                writer.onwriteend = function(evt) {
+                    if (!evt.target.error) {
+                        win(new FileEntry(fileEntry.name, fileEntry.toURL()));
+                    } else {
+                        fail(new FileTransferError(FileTransferError.FILE_NOT_FOUND_ERR));
+                    }
+                };
+
+                writer.onerror = function(evt) {
+                    fail(new FileTransferError(FileTransferError.FILE_NOT_FOUND_ERR));
+                };
+
+                var blob = blackberry.utils.stringToBlob(xhr.response);
+                writer.write(blob);
+
+            },
+            function(error) {
+                fail(new FileTransferError(FileTransferError.FILE_NOT_FOUND_ERR));
+            });
+        }
+
+        xhr.onreadystatechange = function () {
+            if (xhr.readyState == xhr.DONE) {
+                if (xhr.status == 200 && xhr.response) {
+                    resolveLocalFileSystemURI(getParentPath(filePath), function(dir) {
+                        dir.getFile(getFileName(filePath), {create: true}, writeFile, function(error)
{
+                            fail(new FileTransferError(FileTransferError.FILE_NOT_FOUND_ERR));
+                        });
+                    }, function(error) {
+                        fail(new FileTransferError(FileTransferError.FILE_NOT_FOUND_ERR));
+                    });
+                } else if (xhr.status == 404) {
+                    fail(new FileTransferError(FileTransferError.INVALID_URL_ERR, null, null,
xhr.status));
+                } else {
+                    fail(new FileTransferError(FileTransferError.CONNECTION_ERR, null, null,
xhr.status));
+                }
+            }
+        };
+
+        xhr.open("GET", url, true);
+        xhr.responseType = "arraybuffer";
+        xhr.send();
+
+        return { "status" : cordova.callbackStatus.NO_RESULT, "message" : "WebWorks Is On
It" };
+    }
+};

http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/81823d62/lib/webworks/air/plugin/manager.js
----------------------------------------------------------------------
diff --git a/lib/webworks/air/plugin/manager.js b/lib/webworks/air/plugin/manager.js
index e6c98f7..fe54298 100644
--- a/lib/webworks/air/plugin/manager.js
+++ b/lib/webworks/air/plugin/manager.js
@@ -8,7 +8,8 @@ var cordova = require('cordova'),
         'Capture' : require('cordova/plugin/air/capture'),
         'Accelerometer' : require('cordova/plugin/webworks/accelerometer'),
         'NetworkStatus' : require('cordova/plugin/air/network'),
-        'Notification' : require('cordova/plugin/webworks/notification')
+        'Notification' : require('cordova/plugin/webworks/notification'),
+        'FileTransfer' : require('cordova/plugin/air/FileTransfer')
     };
 
 module.exports = {


Mime
View raw message