You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ti...@apache.org on 2012/06/07 22:40:44 UTC
[38/48] js commit: changed how things referenced each other
changed how things referenced each other
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/34b6e3fb
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/tree/34b6e3fb
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/diff/34b6e3fb
Branch: refs/heads/master
Commit: 34b6e3fbe9ac78a799c74f6698c1cb23a390122c
Parents: 84b2a49
Author: Tim Kim <ti...@adobe.com>
Authored: Tue May 8 11:56:35 2012 -0700
Committer: Tim Kim <ti...@nitobi.com>
Committed: Thu Jun 7 13:40:22 2012 -0700
----------------------------------------------------------------------
lib/playbook/platform.js | 6 +-
lib/playbook/plugin/playbook/DirectoryEntry.js | 455 ++++++++--------
lib/playbook/plugin/playbook/FileEntry.js | 6 +-
lib/playbook/plugin/playbook/requestFileSystem.js | 2 +-
4 files changed, 222 insertions(+), 247 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/34b6e3fb/lib/playbook/platform.js
----------------------------------------------------------------------
diff --git a/lib/playbook/platform.js b/lib/playbook/platform.js
index 6cbbef4..0ec37a6 100644
--- a/lib/playbook/platform.js
+++ b/lib/playbook/platform.js
@@ -5,9 +5,6 @@ module.exports = {
device: {
path: "cordova/plugin/playbook/device"
},
- DirectoryEntry: {
- path: 'cordova/plugin/playbook/DirectoryEntry'
- },
File:{
path: 'cordova/plugin/playbook/File'
},
@@ -32,6 +29,9 @@ module.exports = {
}
}
},
+ DirectoryEntry: {
+ path: 'cordova/plugin/playbook/DirectoryEntry'
+ },
Entry: {
path: 'cordova/plugin/playbook/Entry'
}
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/34b6e3fb/lib/playbook/plugin/playbook/DirectoryEntry.js
----------------------------------------------------------------------
diff --git a/lib/playbook/plugin/playbook/DirectoryEntry.js b/lib/playbook/plugin/playbook/DirectoryEntry.js
index 9b134de..7d4b542 100644
--- a/lib/playbook/plugin/playbook/DirectoryEntry.js
+++ b/lib/playbook/plugin/playbook/DirectoryEntry.js
@@ -1,273 +1,248 @@
-var utils = require('cordova/utils'),
- Entry = require('cordova/plugin/Entry'),
- DirectoryReader = require('cordova/plugin/DirectoryReader'),
+var DirectoryEntry = require('cordova/plugin/DirectoryEntry'),
FileEntry = require('cordova/plugin/FileEntry'),
FileError = require('cordova/plugin/FileError');
-
-/**
- * An interface representing a directory on the file system.
- *
- * {boolean} isFile always false (readonly)
- * {boolean} isDirectory always true (readonly)
- * {DOMString} name of the directory, excluding the path leading to it (readonly)
- * {DOMString} fullPath the absolute full path to the directory (readonly)
- * {FileSystem} filesystem on which the directory resides (readonly)
- */
-var DirectoryEntry = function(name, fullPath) {
- DirectoryEntry.__super__.constructor.apply(this, [false, true, name, fullPath]);
-};
-
-utils.extend(DirectoryEntry, Entry);
-
-/**
- * Creates a new DirectoryReader to read entries from this directory
- */
-DirectoryEntry.prototype.createReader = function() {
- return new DirectoryReader(this.fullPath);
-};
-
-/**
- * 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
- */
-DirectoryEntry.prototype.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,
- // if true, causes failure if create is true and path already exists
- exclusive = (options && options.exclusive === true) ? true : false,
- // directory exists
- exists,
- // create a new DirectoryEntry object and invoke success callback
- createEntry = function() {
- var path_parts = path.split('/'),
- name = path_parts[path_parts.length - 1],
- dirEntry = new DirectoryEntry(name, path);
-
- // invoke success callback
- if (typeof successCallback === 'function') {
- successCallback(dirEntry);
- }
- };
-
- 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 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;
- }
-
- // 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();
- }
- }
- // 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 += '/';
- }
- blackberry.io.dir.createNewDir(dirPath);
- createEntry();
- } catch (eone) {
- // unable to create directory
- 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.
- *
- * @param path {DOMString}
- * either a relative or absolute path from this directory in
- * which to look up or create a file
- * @param options {Flags}
- * options to create or exclusively create the file
- * @param successCallback {Function}
- * called with the new FileEntry object
- * @param errorCallback {Function}
- * called with a FileError object if error occurs
- */
-DirectoryEntry.prototype.getFile = function(path, options, successCallback, errorCallback) {
- // create file 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,
- // file exists
+ // directory exists
exists,
- // create a new FileEntry object and invoke success callback
+ // create a new DirectoryEntry object and invoke success callback
createEntry = function() {
var path_parts = path.split('/'),
name = path_parts[path_parts.length - 1],
- fileEntry = new FileEntry(name, path);
+ dirEntry = new DirectoryEntry(name, path);
// invoke success callback
if (typeof successCallback === 'function') {
- successCallback(fileEntry);
+ successCallback(dirEntry);
}
};
- 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
+ console.log('exists :' + exists);
+ exists = blackberry.io.dir.exists(path);
+ } catch (e) {
+ // invalid path
+ console.log('invalid path');
+ fail(FileError.ENCODING_ERR);
+ return;
+ }
- // determine if file exists
- try {
+ // 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();
+ }
+ }
// will return true if path exists AND is a file
- exists = blackberry.io.file.exists(path);
- }
- catch (e) {
- // invalid path
- fail(FileError.ENCODING_ERR);
- return;
- }
-
- // path is a file
- if (exists) {
- if (create && exclusive) {
- // can't guarantee exclusivity
- fail(FileError.PATH_EXISTS_ERR);
+ 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 += '/';
+ }
+ blackberry.io.dir.createNewDir(dirPath);
+ createEntry();
+ } catch (eone) {
+ // unable to create directory
+ fail(FileError.NOT_FOUND_ERR);
+ }
}
+ // path does not exist, don't create
else {
- // create entry for existing file
- createEntry();
+ // directory doesn't exist
+ fail(FileError.NOT_FOUND_ERR);
}
- }
- // will return true if path exists AND is a directory
- else if (blackberry.io.dir.exists(path)) {
- // the path is a directory
- fail(FileError.TYPE_MISMATCH_ERR);
- }
- // 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 {
- // file doesn't exist
- fail(FileError.NOT_FOUND_ERR);
- }
-};
+ },
+
+ /**
+ * Create or look up a file.
+ *
+ * @param path {DOMString}
+ * either a relative or absolute path from this directory in
+ * which to look up or create a file
+ * @param options {Flags}
+ * options to create or exclusively create the file
+ * @param successCallback {Function}
+ * called with the new FileEntry object
+ * @param errorCallback {Function}
+ * called with a FileError object if error occurs
+ */
+ getFile : function(path, options, successCallback, errorCallback) {
+ // 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,
+ // file exists
+ exists,
+ // create a new FileEntry object and invoke success callback
+ createEntry = function() {
+ var path_parts = path.split('/'),
+ name = path_parts[path_parts.length - 1],
+ fileEntry = new FileEntry(name, path);
+
+ // invoke success callback
+ if (typeof successCallback === 'function') {
+ successCallback(fileEntry);
+ }
+ };
-/**
- * Delete a directory and all of it's contents.
- *
- * @param successCallback {Function} called with no parameters
- * @param errorCallback {Function} called with a FileError
- */
-DirectoryEntry.prototype.removeRecursively = function(successCallback, errorCallback) {
- // we're removing THIS directory
- var path = this.fullPath;
+ 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;
+ }
- var fail = function(error) {
- if (typeof errorCallback === 'function') {
- errorCallback(new FileError(error));
+ // determine if file exists
+ try {
+ // will return true if path exists AND is a file
+ exists = blackberry.io.file.exists(path);
+ }
+ catch (e) {
+ // invalid path
+ fail(FileError.ENCODING_ERR);
+ return;
}
- };
- // attempt to delete directory
- if (blackberry.io.dir.exists(path)) {
- // it is an error to attempt to remove the file system root
- //exec(null, null, "File", "isFileSystemRoot", [ path ]) === true
- if (false) {
- fail(FileError.NO_MODIFICATION_ALLOWED_ERR);
+ // path is a file
+ if (exists) {
+ if (create && exclusive) {
+ // can't guarantee exclusivity
+ fail(FileError.PATH_EXISTS_ERR);
+ }
+ else {
+ // create entry for existing file
+ createEntry();
+ }
}
+ // will return true if path exists AND is a directory
+ else if (blackberry.io.dir.exists(path)) {
+ // the path is a directory
+ fail(FileError.TYPE_MISMATCH_ERR);
+ }
+ // 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 {
- try {
- // delete the directory, setting recursive flag to true
- blackberry.io.dir.deleteDirectory(path, true);
- if (typeof successCallback === "function") {
- successCallback();
- }
- } catch (e) {
- // permissions don't allow deletion
- console.log(e);
+ // file doesn't exist
+ fail(FileError.NOT_FOUND_ERR);
+ }
+ },
+
+ /**
+ * Delete a directory and all of it's contents.
+ *
+ * @param successCallback {Function} called with no parameters
+ * @param errorCallback {Function} called with a FileError
+ */
+ removeRecursively : function(successCallback, errorCallback) {
+ // we're removing THIS directory
+ var path = this.fullPath;
+
+ var fail = function(error) {
+ if (typeof errorCallback === 'function') {
+ errorCallback(new FileError(error));
+ }
+ };
+
+ // attempt to delete directory
+ if (blackberry.io.dir.exists(path)) {
+ // it is an error to attempt to remove the file system root
+ //exec(null, null, "File", "isFileSystemRoot", [ path ]) === true
+ if (false) {
fail(FileError.NO_MODIFICATION_ALLOWED_ERR);
}
+ else {
+ try {
+ // delete the directory, setting recursive flag to true
+ blackberry.io.dir.deleteDirectory(path, true);
+ if (typeof successCallback === "function") {
+ successCallback();
+ }
+ } catch (e) {
+ // permissions don't allow deletion
+ console.log(e);
+ fail(FileError.NO_MODIFICATION_ALLOWED_ERR);
+ }
+ }
+ }
+ // it's a file, not a directory
+ else if (blackberry.io.file.exists(path)) {
+ fail(FileError.TYPE_MISMATCH_ERR);
+ }
+ // not found
+ else {
+ fail(FileError.NOT_FOUND_ERR);
}
}
- // it's a file, not a directory
- else if (blackberry.io.file.exists(path)) {
- fail(FileError.TYPE_MISMATCH_ERR);
- }
- // not found
- else {
- fail(FileError.NOT_FOUND_ERR);
- }
-};
-
-module.exports = new DirectoryEntry();
+};
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/34b6e3fb/lib/playbook/plugin/playbook/FileEntry.js
----------------------------------------------------------------------
diff --git a/lib/playbook/plugin/playbook/FileEntry.js b/lib/playbook/plugin/playbook/FileEntry.js
index 0f04c4d..77a2588 100644
--- a/lib/playbook/plugin/playbook/FileEntry.js
+++ b/lib/playbook/plugin/playbook/FileEntry.js
@@ -1,7 +1,7 @@
var utils = require('cordova/utils'),
- Entry = require('cordova/plugin/Entry'),
- FileWriter = require('cordova/plugin/FileWriter'),
- File = require('cordova/plugin/File'),
+ Entry = require('cordova/plugin/playbook/Entry'),
+ FileWriter = require('cordova/plugin/playbook/FileWriter'),
+ File = require('cordova/plugin/playbook/File'),
FileError = require('cordova/plugin/FileError');
/**
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/34b6e3fb/lib/playbook/plugin/playbook/requestFileSystem.js
----------------------------------------------------------------------
diff --git a/lib/playbook/plugin/playbook/requestFileSystem.js b/lib/playbook/plugin/playbook/requestFileSystem.js
index 28c7ab0..aa7d3e9 100644
--- a/lib/playbook/plugin/playbook/requestFileSystem.js
+++ b/lib/playbook/plugin/playbook/requestFileSystem.js
@@ -1,4 +1,4 @@
-var DirectoryEntry = require('cordova/plugin/DirectoryEntry'),
+var DirectoryEntry = require('cordova/plugin/playbook/DirectoryEntry'),
FileError = require('cordova/plugin/FileError'),
FileSystem = require('cordova/plugin/FileSystem');
var exec = require('cordova/exec');