removed comments and cleaning stuff up
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/bb6d27df Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/tree/bb6d27df Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/diff/bb6d27df Branch: refs/heads/playbookFile Commit: bb6d27df86e2fb2a2a5c00f59a659c6bfdef524c Parents: 1af4b05 Author: Tim Kim <t...@adobe.com> Authored: Thu May 10 16:23:43 2012 -0700 Committer: Tim Kim <t...@adobe.com> Committed: Thu May 10 16:23:43 2012 -0700 ---------------------------------------------------------------------- lib/common/plugin/FileEntry.js | 2 - lib/playbook/plugin/playbook/DirectoryEntry.js | 11 --- lib/playbook/plugin/playbook/Entry.js | 63 ++++++++++++++- lib/playbook/plugin/playbook/FileEntry.js | 26 +++--- lib/playbook/plugin/playbook/FileReader.js | 6 +- .../plugin/playbook/resolveLocalFileSystemURI.js | 4 +- 6 files changed, 79 insertions(+), 33 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/bb6d27df/lib/common/plugin/FileEntry.js ---------------------------------------------------------------------- diff --git a/lib/common/plugin/FileEntry.js b/lib/common/plugin/FileEntry.js index 2e41888..fb6cfaa 100644 --- a/lib/common/plugin/FileEntry.js +++ b/lib/common/plugin/FileEntry.js @@ -56,9 +56,7 @@ FileEntry.prototype.file = function(successCallback, errorCallback) { var fail = typeof errorCallback !== 'function' ? null : function(code) { errorCallback(new FileError(code)); }; - console.log('this is messing it up'); exec(win, fail, "File", "getFileMetadata", [this.fullPath]); - console.log('ya'); }; http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/bb6d27df/lib/playbook/plugin/playbook/DirectoryEntry.js ---------------------------------------------------------------------- diff --git a/lib/playbook/plugin/playbook/DirectoryEntry.js b/lib/playbook/plugin/playbook/DirectoryEntry.js index 7d4b542..e261e53 100644 --- a/lib/playbook/plugin/playbook/DirectoryEntry.js +++ b/lib/playbook/plugin/playbook/DirectoryEntry.js @@ -54,11 +54,9 @@ module.exports = { // determine if directory exists try { // will return true if path exists AND is a directory - console.log('exists :' + exists); exists = blackberry.io.dir.exists(path); } catch (e) { // invalid path - console.log('invalid path'); fail(FileError.ENCODING_ERR); return; } @@ -179,18 +177,9 @@ module.exports = { // path does not exist, create it else if (create) { // create empty file - console.log('making file'); var emptyBlob = blackberry.utils.stringToBlob(''); blackberry.io.file.saveFile(path,emptyBlob); createEntry(); - /* - exec( - function(result) { - // file created - createEntry(); - }, - fail, "File", "write", [ path, "", 0 ]); - */ } // path does not exist, don't create else { http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/bb6d27df/lib/playbook/plugin/playbook/Entry.js ---------------------------------------------------------------------- diff --git a/lib/playbook/plugin/playbook/Entry.js b/lib/playbook/plugin/playbook/Entry.js index 52b1fd5..21a0408 100644 --- a/lib/playbook/plugin/playbook/Entry.js +++ b/lib/playbook/plugin/playbook/Entry.js @@ -1,9 +1,68 @@ var FileError = require('cordova/plugin/FileError'), LocalFileSystem = require('cordova/plugin/LocalFileSystem'), - resolveLocalFileSystemURI = require('cordova/plugin/resolveLocalFileSystemURI'), - exec = require('cordova/exec'); + resolveLocalFileSystemURI = require('cordova/plugin/resolveLocalFileSystemURI'); module.exports = { + getMetadata : function(successCallback, errorCallback){ + var success = typeof successCallback !== 'function' ? null : function(lastModified) { + var metadata = new Metadata(lastModified); + successCallback(metadata); + }; + var fail = typeof errorCallback !== 'function' ? null : function(code) { + errorCallback(new FileError(code)); + }; + + if(this.isFile){ + if(blackberry.io.file.exists(this.fullPath)){ + var theFileProperties = blackberry.io.file.getFileProperties(this.fullPath); + success(theFileProperties.dateModified) + } + }else{ + console.log('Unsupported for directories') + fail(FileError.INVALID_MODIFICATION_ERR); + } + }, + + moveTo : function(parent, newName, successCallback, errorCallback){ + var fail = function(code) { + if (typeof errorCallback === 'function') { + errorCallback(new FileError(code)); + } + }; + // user must specify parent Entry + if (!parent) { + fail(FileError.NOT_FOUND_ERR); + return; + } + // source path + var srcPath = this.fullPath, + // entry name + name = newName || this.name, + success = function(entry) { + if (entry) { + if (typeof successCallback === 'function') { + // create appropriate Entry object + var result = (entry.isDirectory) ? new (require('cordova/plugin/playbook/DirectoryEntry'))(entry.name, entry.fullPath) : new (require('cordova/plugin/playbook/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); + } + }; + + }, + + copyTo : function(parent, newName, successCallback, errorCallback) { + + }, + remove : function(successCallback, errorCallback) { var path = this.fullPath, // directory contents http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/bb6d27df/lib/playbook/plugin/playbook/FileEntry.js ---------------------------------------------------------------------- diff --git a/lib/playbook/plugin/playbook/FileEntry.js b/lib/playbook/plugin/playbook/FileEntry.js index 5edfa37..42bedb8 100644 --- a/lib/playbook/plugin/playbook/FileEntry.js +++ b/lib/playbook/plugin/playbook/FileEntry.js @@ -41,19 +41,19 @@ module.exports = { var fail = typeof errorCallback !== 'function' ? null : function(code) { errorCallback(new FileError(code)); }; - console.log('getting file properties'); - // TODO Need to set up win/fail callbacks - var theFileProperties = blackberry.io.file.getFileProperties(this.fullPath); - var theFile = {}; - console.log(this.fullPath); - console.log(this.name); - //theFile.name = - theFile.fullPath = this.fullPath; - theFile.type = theFileProperties.fileExtension; - theFile.lastModifiedDate = theFileProperties.dateModified; - theFile.size = theFileProperties.size; - win(theFile); - //exec(win, fail, "File", "getFileMetadata", [this.fullPath]); + + if(blackberry.io.file.exists(this.fullPath)){ + var theFileProperties = blackberry.io.file.getFileProperties(this.fullPath); + var theFile = {}; + + theFile.fullPath = this.fullPath; + theFile.type = theFileProperties.fileExtension; + theFile.lastModifiedDate = theFileProperties.dateModified; + theFile.size = theFileProperties.size; + win(theFile); + }else{ + fail(FileError.NOT_FOUND_ERR); + } } }; http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/bb6d27df/lib/playbook/plugin/playbook/FileReader.js ---------------------------------------------------------------------- diff --git a/lib/playbook/plugin/playbook/FileReader.js b/lib/playbook/plugin/playbook/FileReader.js index 0fa4918..7d6d20d 100644 --- a/lib/playbook/plugin/playbook/FileReader.js +++ b/lib/playbook/plugin/playbook/FileReader.js @@ -93,14 +93,14 @@ FileReader.prototype.readAsText = function(file, encoding) { var theText = ''; var getFileContents = function(path,blob){ if(blob){ - + theText = blackberry.utils.blobToString(blob); me.result = theText; - + if (typeof me.onload === "function") { me.onload(new ProgressEvent("load", {target:me})); } - + me.readyState = FileReader.DONE; if (typeof me.onloadend === "function") { http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/bb6d27df/lib/playbook/plugin/playbook/resolveLocalFileSystemURI.js ---------------------------------------------------------------------- diff --git a/lib/playbook/plugin/playbook/resolveLocalFileSystemURI.js b/lib/playbook/plugin/playbook/resolveLocalFileSystemURI.js index e02cfc3..5e30537 100644 --- a/lib/playbook/plugin/playbook/resolveLocalFileSystemURI.js +++ b/lib/playbook/plugin/playbook/resolveLocalFileSystemURI.js @@ -49,7 +49,7 @@ module.exports = function(uri, successCallback, errorCallback) { theEntry.fullPath = uri; success(theEntry); }else{ - // TODO: Throw error + fail(FileError.NOT_FOUND_ERR); } - //exec(success, fail, "File", "resolveLocalFileSystemURI", [uri]); + };