incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tim...@apache.org
Subject [35/48] js commit: Added in resolveLocalFileSystemURI
Date Thu, 07 Jun 2012 20:40:44 GMT
Added in resolveLocalFileSystemURI


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/73edeb83
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/tree/73edeb83
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/diff/73edeb83

Branch: refs/heads/master
Commit: 73edeb83a40fec24fb79acf6c8edcc1389a5295c
Parents: 881194c
Author: Tim Kim <timk@adobe.com>
Authored: Wed May 9 18:35:28 2012 -0700
Committer: Tim Kim <tim.kim@nitobi.com>
Committed: Thu Jun 7 13:40:22 2012 -0700

----------------------------------------------------------------------
 lib/playbook/platform.js                           |    3 +
 .../plugin/playbook/resolveLocalFileSystemURI.js   |   55 +++++++++++++++
 2 files changed, 58 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/73edeb83/lib/playbook/platform.js
----------------------------------------------------------------------
diff --git a/lib/playbook/platform.js b/lib/playbook/platform.js
index adabc6c..0b24e04 100644
--- a/lib/playbook/platform.js
+++ b/lib/playbook/platform.js
@@ -17,6 +17,9 @@ module.exports = {
         requestFileSystem:{
             path: 'cordova/plugin/playbook/requestFileSystem'
         },
+        resolveLocalFileSystemURI:{
+            path: 'cordova/plugin/playbook/resolveLocalFileSystemURI'
+        },
     },
     merges: {
         navigator: {

http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/73edeb83/lib/playbook/plugin/playbook/resolveLocalFileSystemURI.js
----------------------------------------------------------------------
diff --git a/lib/playbook/plugin/playbook/resolveLocalFileSystemURI.js b/lib/playbook/plugin/playbook/resolveLocalFileSystemURI.js
new file mode 100644
index 0000000..e02cfc3
--- /dev/null
+++ b/lib/playbook/plugin/playbook/resolveLocalFileSystemURI.js
@@ -0,0 +1,55 @@
+var DirectoryEntry = require('cordova/plugin/DirectoryEntry'),
+    FileEntry = require('cordova/plugin/FileEntry'),
+    FileError = require('cordova/plugin/FileError');
+
+/**
+ * Look up file system Entry referred to by local URI.
+ * @param {DOMString} uri  URI referring to a local file or directory
+ * @param successCallback  invoked with Entry object corresponding to URI
+ * @param errorCallback    invoked if error occurs retrieving file system entry
+ */
+module.exports = function(uri, successCallback, errorCallback) {
+    // error callback
+    var fail = function(error) {
+        if (typeof errorCallback === 'function') {
+            errorCallback(new FileError(error));
+        }
+    };
+    // if successful, return either a file or directory entry
+    var success = function(entry) {
+        var result;
+
+        if (entry) {
+            if (typeof successCallback === 'function') {
+                // create appropriate Entry object
+                result = (entry.isDirectory) ? new DirectoryEntry(entry.name, entry.fullPath)
: new FileEntry(entry.name, entry.fullPath);
+                try {
+                    successCallback(result);
+                }
+                catch (e) {
+                    console.log('Error invoking callback: ' + e);
+                }
+            }
+        }
+        else {
+            // no Entry object returned
+            fail(FileError.NOT_FOUND_ERR);
+        }
+    };
+    var theEntry = {};
+
+    if(blackberry.io.dir.exists(uri)){
+        theEntry.isDirectory = true;
+        theEntry.name = uri.split('/').pop();
+        theEntry.fullPath = uri;
+        success(theEntry);
+    }else if(blackberry.io.file.exists(uri)){
+        theEntry.isDirectory = false;
+        theEntry.name = uri.split('/').pop();
+        theEntry.fullPath = uri;
+        success(theEntry);
+    }else{
+        // TODO: Throw error
+    }
+    //exec(success, fail, "File", "resolveLocalFileSystemURI", [uri]);
+};


Mime
View raw message