Updated Branches: refs/heads/master 7e623fa95 -> 5659d9398
Switch File prototype overrides over to merges object. - Cleanup some formatting also. 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/5659d939 Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/tree/5659d939 Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/diff/5659d939 Branch: refs/heads/master Commit: 5659d9398d9be4677312b7a766a60efebf2f792c Parents: 7e623fa Author: Drew Walters <deedu...@gmail.com> Authored: Fri Mar 16 14:03:39 2012 -0500 Committer: Drew Walters <deedu...@gmail.com> Committed: Fri Mar 16 14:03:39 2012 -0500 ---------------------------------------------------------------------- lib/platform/blackberry.js | 21 +--- lib/plugin/blackberry/DirectoryEntry.js | 149 ++++++++++++-------------- lib/plugin/blackberry/Entry.js | 143 ++++++++++++------------- 3 files changed, 145 insertions(+), 168 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/5659d939/lib/platform/blackberry.js ---------------------------------------------------------------------- diff --git a/lib/platform/blackberry.js b/lib/platform/blackberry.js index be154c6..e7fa2e3 100644 --- a/lib/platform/blackberry.js +++ b/lib/platform/blackberry.js @@ -24,21 +24,6 @@ module.exports = { org.apache.cordova.Logger.log(''+msg); }; - // TODO: is there a better way to do this? build-time - // convention? how can we save the few bytes from - // cordova/plugin/Entry + DirectoryEntry that will get - // overridden? - // Override File API's Entry + children's prototype methods - var BB_Entry = require('cordova/plugin/blackberry/Entry'), - BB_DirectoryEntry = require('cordova/plugin/blackberry/DirectoryEntry'); - - Entry.prototype.remove = BB_Entry.remove; - Entry.prototype.getParent = BB_Entry.getParent; - - DirectoryEntry.prototype.getDirectory = BB_DirectoryEntry.getDirectory; - DirectoryEntry.prototype.getFile = BB_DirectoryEntry.getFile; - DirectoryEntry.prototype.removeRecursively = BB_DirectoryEntry.removeRecursively; - // Mapping of button events to BlackBerry key identifier. var buttonMapping = { 'backbutton' : blackberry.system.event.KEY_BACK, @@ -177,6 +162,12 @@ module.exports = { path: 'cordova/plugin/blackberry/notification' } } + }, + DirectoryEntry: { + path: 'cordova/plugin/blackberry/DirectoryEntry' + }, + Entry: { + path: 'cordova/plugin/blackberry/Entry' } } }; http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/5659d939/lib/plugin/blackberry/DirectoryEntry.js ---------------------------------------------------------------------- diff --git a/lib/plugin/blackberry/DirectoryEntry.js b/lib/plugin/blackberry/DirectoryEntry.js index 0dbbb8e..76acaf7 100644 --- a/lib/plugin/blackberry/DirectoryEntry.js +++ b/lib/plugin/blackberry/DirectoryEntry.js @@ -3,24 +3,23 @@ var DirectoryEntry = require('cordova/plugin/DirectoryEntry'), FileError = require('cordova/plugin/FileError'), exec = require('cordova/exec'); -var BB_DirectoryEntry = { -/** - * Creates or looks up a directory; override for BlackBerry. - * - * @param path - * {DOMString} either a relative or absolute path from this - * directory in which to look up or create a directory - * @param options - * {Flags} options to create or exclusively create the - * directory - * @param successCallback - * {Function} called with the new DirectoryEntry - * @param errorCallback - * {Function} called with a FileError - */ - getDirectory:function(path, options, successCallback, errorCallback) { +module.exports = { + /** + * Creates or looks up a directory; override for BlackBerry. + * + * @param path + * {DOMString} either a relative or absolute path from this + * directory in which to look up or create a directory + * @param options + * {Flags} options to create or exclusively create the directory + * @param successCallback + * {Function} called with the new DirectoryEntry + * @param errorCallback + * {Function} called with a FileError + */ + getDirectory : function(path, options, successCallback, errorCallback) { // create directory if it doesn't exist - var create = (options && options.create === true) ? true : false, + var create = (options && options.create === true) ? true : false, // if true, causes failure if create is true and path already exists exclusive = (options && options.exclusive === true) ? true : false, // directory exists @@ -37,72 +36,68 @@ var BB_DirectoryEntry = { } }; - var fail = function(error) { - if (typeof errorCallback === 'function') { - errorCallback(new FileError(error)); - } - }; + var fail = function(error) { + if (typeof errorCallback === 'function') { + errorCallback(new FileError(error)); + } + }; - // determine if path is relative or absolute - if (!path) { - fail(FileError.ENCODING_ERR); - return; - } - else if (path.indexOf(this.fullPath) !== 0) { - // path does not begin with the fullPath of this directory - // therefore, it is relative - path = this.fullPath + '/' + path; - } + // determine if path is relative or absolute + if (!path) { + fail(FileError.ENCODING_ERR); + return; + } else if (path.indexOf(this.fullPath) !== 0) { + // path does not begin with the fullPath of this directory + // therefore, it is relative + path = this.fullPath + '/' + path; + } - // determine if directory exists - try { - // will return true if path exists AND is a directory - exists = blackberry.io.dir.exists(path); - } - catch (e) { - // invalid path - fail(FileError.ENCODING_ERR); - return; - } + // determine if directory exists + try { + // will return true if path exists AND is a directory + exists = blackberry.io.dir.exists(path); + } catch (e) { + // invalid path + fail(FileError.ENCODING_ERR); + return; + } - // path is a directory - if (exists) { - if (create && exclusive) { - // can't guarantee exclusivity - fail(FileError.PATH_EXISTS_ERR); + // path is a directory + if (exists) { + if (create && exclusive) { + // can't guarantee exclusivity + fail(FileError.PATH_EXISTS_ERR); + } else { + // create entry for existing directory + createEntry(); + } } - else { - // create entry for existing directory - createEntry(); + // will return true if path exists AND is a file + else if (blackberry.io.file.exists(path)) { + // the path is a file + fail(FileError.TYPE_MISMATCH_ERR); } - } - // will return true if path exists AND is a file - else if (blackberry.io.file.exists(path)) { - // the path is a file - fail(FileError.TYPE_MISMATCH_ERR); - } - // path does not exist, create it - else if (create) { - try { - // directory path must have trailing slash - var dirPath = path; - if (dirPath.substr(-1) !== '/') { - dirPath += '/'; + // path does not exist, create it + else if (create) { + try { + // directory path must have trailing slash + var dirPath = path; + if (dirPath.substr(-1) !== '/') { + dirPath += '/'; + } + blackberry.io.dir.createNewDir(dirPath); + createEntry(); + } catch (eone) { + // unable to create directory + fail(FileError.NOT_FOUND_ERR); } - blackberry.io.dir.createNewDir(dirPath); - createEntry(); } - catch (eone) { - // unable to create directory + // path does not exist, don't create + else { + // directory doesn't exist fail(FileError.NOT_FOUND_ERR); } - } - // path does not exist, don't create - else { - // directory doesn't exist - fail(FileError.NOT_FOUND_ERR); - } - }, + }, /** * Create or look up a file. * @@ -117,7 +112,7 @@ var BB_DirectoryEntry = { * called with a FileError object if error occurs */ getFile:function(path, options, successCallback, errorCallback) { - // create file if it doesn't exist + // create file if it doesn't exist var create = (options && options.create === true) ? true : false, // if true, causes failure if create is true and path already exists exclusive = (options && options.exclusive === true) ? true : false, @@ -202,7 +197,7 @@ var BB_DirectoryEntry = { * @param successCallback {Function} called with no parameters * @param errorCallback {Function} called with a FileError */ - removeRecursively:function(successCallback, errorCallback) { + removeRecursively : function(successCallback, errorCallback) { // we're removing THIS directory var path = this.fullPath; @@ -242,5 +237,3 @@ var BB_DirectoryEntry = { } } }; - -module.exports = BB_DirectoryEntry; http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/5659d939/lib/plugin/blackberry/Entry.js ---------------------------------------------------------------------- diff --git a/lib/plugin/blackberry/Entry.js b/lib/plugin/blackberry/Entry.js index 9d7e0eb..cc9626d 100644 --- a/lib/plugin/blackberry/Entry.js +++ b/lib/plugin/blackberry/Entry.js @@ -4,91 +4,84 @@ var FileError = require('cordova/plugin/FileError'), exec = require('cordova/exec'); module.exports = { - remove:function(successCallback, errorCallback) { - var path = this.fullPath, - // directory contents - contents = []; + remove : function(successCallback, errorCallback) { + var path = this.fullPath, + // directory contents + contents = []; - var fail = function(error) { - if (typeof errorCallback === 'function') { - errorCallback(new FileError(error)); - } - }; - - // file - if (blackberry.io.file.exists(path)) { - try { - blackberry.io.file.deleteFile(path); - if (typeof successCallback === "function") { - successCallback(); + var fail = function(error) { + if (typeof errorCallback === 'function') { + errorCallback(new FileError(error)); } - } - catch (e) { - // permissions don't allow - fail(FileError.INVALID_MODIFICATION_ERR); - } - } - // directory - else if (blackberry.io.dir.exists(path)) { - // it is an error to attempt to remove the file system root - if (exec(null, null, "File", "isFileSystemRoot", [ path ]) === true) { - fail(FileError.NO_MODIFICATION_ALLOWED_ERR); - } - else { - // check to see if directory is empty - contents = blackberry.io.dir.listFiles(path); - if (contents.length !== 0) { + }; + + // file + if (blackberry.io.file.exists(path)) { + try { + blackberry.io.file.deleteFile(path); + if (typeof successCallback === "function") { + successCallback(); + } + } catch (e) { + // permissions don't allow fail(FileError.INVALID_MODIFICATION_ERR); } - else { - try { - // delete - blackberry.io.dir.deleteDirectory(path, false); - if (typeof successCallback === "function") { - successCallback(); + } + // directory + else if (blackberry.io.dir.exists(path)) { + // it is an error to attempt to remove the file system root + if (exec(null, null, "File", "isFileSystemRoot", [ path ]) === true) { + fail(FileError.NO_MODIFICATION_ALLOWED_ERR); + } else { + // check to see if directory is empty + contents = blackberry.io.dir.listFiles(path); + if (contents.length !== 0) { + fail(FileError.INVALID_MODIFICATION_ERR); + } else { + try { + // delete + blackberry.io.dir.deleteDirectory(path, false); + if (typeof successCallback === "function") { + successCallback(); + } + } catch (eone) { + // permissions don't allow + fail(FileError.NO_MODIFICATION_ALLOWED_ERR); } } - catch (eone) { - // permissions don't allow - fail(FileError.NO_MODIFICATION_ALLOWED_ERR); - } } } - } - // not found - else { - fail(FileError.NOT_FOUND_ERR); - } - }, - getParent:function(successCallback, errorCallback) { - var that = this; + // not found + else { + fail(FileError.NOT_FOUND_ERR); + } + }, + getParent : function(successCallback, errorCallback) { + var that = this; - try { - // On BlackBerry, the TEMPORARY file system is actually a temporary - // directory that is created on a per-application basis. This is - // to help ensure that applications do not share the same temporary - // space. So we check to see if this is the TEMPORARY file system - // (directory). If it is, we must return this Entry, rather than - // the Entry for its parent. - requestFileSystem(LocalFileSystem.TEMPORARY, 0, - function(fileSystem) { - if (fileSystem.root.fullPath === that.fullPath) { - if (typeof successCallback === 'function') { - successCallback(fileSystem.root); + try { + // On BlackBerry, the TEMPORARY file system is actually a temporary + // directory that is created on a per-application basis. This is + // to help ensure that applications do not share the same temporary + // space. So we check to see if this is the TEMPORARY file system + // (directory). If it is, we must return this Entry, rather than + // the Entry for its parent. + requestFileSystem(LocalFileSystem.TEMPORARY, 0, + function(fileSystem) { + if (fileSystem.root.fullPath === that.fullPath) { + if (typeof successCallback === 'function') { + successCallback(fileSystem.root); + } + } else { + resolveLocalFileSystemURI(blackberry.io.dir + .getParentDirectory(that.fullPath), + successCallback, errorCallback); } - } - else { - resolveLocalFileSystemURI( - blackberry.io.dir.getParentDirectory(that.fullPath), - successCallback, - errorCallback); - } - }, errorCallback); - } - catch (e) { - if (typeof errorCallback === 'function') { - errorCallback(new FileError(FileError.NOT_FOUND_ERR)); + }, errorCallback); + } catch (e) { + if (typeof errorCallback === 'function') { + errorCallback(new FileError(FileError.NOT_FOUND_ERR)); + } } } - } };