You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by an...@apache.org on 2012/08/24 23:57:39 UTC
[43/50] [abbrv] moved webworks platforms into air and java folders
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/366572ae/lib/webworks/java/plugin/java/DirectoryEntry.js
----------------------------------------------------------------------
diff --git a/lib/webworks/java/plugin/java/DirectoryEntry.js b/lib/webworks/java/plugin/java/DirectoryEntry.js
new file mode 100644
index 0000000..3941c05
--- /dev/null
+++ b/lib/webworks/java/plugin/java/DirectoryEntry.js
@@ -0,0 +1,239 @@
+var DirectoryEntry = require('cordova/plugin/DirectoryEntry'),
+ FileEntry = require('cordova/plugin/FileEntry'),
+ FileError = require('cordova/plugin/FileError'),
+ exec = require('cordova/exec');
+
+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
+ 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);
+ } 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
+ */
+ 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);
+ }
+ };
+
+ 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 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;
+ }
+
+ // 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
+ 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);
+ }
+ },
+
+ /**
+ * 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
+ if (exec(null, null, "File", "isFileSystemRoot", [ path ]) === true) {
+ 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);
+ }
+ }
+};
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/366572ae/lib/webworks/java/plugin/java/Entry.js
----------------------------------------------------------------------
diff --git a/lib/webworks/java/plugin/java/Entry.js b/lib/webworks/java/plugin/java/Entry.js
new file mode 100644
index 0000000..d66587f
--- /dev/null
+++ b/lib/webworks/java/plugin/java/Entry.js
@@ -0,0 +1,88 @@
+var FileError = require('cordova/plugin/FileError'),
+ LocalFileSystem = require('cordova/plugin/LocalFileSystem'),
+ resolveLocalFileSystemURI = require('cordova/plugin/resolveLocalFileSystemURI'),
+ requestFileSystem = require('cordova/plugin/requestFileSystem'),
+ exec = require('cordova/exec');
+
+module.exports = {
+ 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();
+ }
+ } 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) {
+ 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);
+ }
+ }
+ }
+ }
+ // 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);
+ }
+ } else {
+ resolveLocalFileSystemURI(blackberry.io.dir
+ .getParentDirectory(that.fullPath),
+ successCallback, errorCallback);
+ }
+ }, errorCallback);
+ } catch (e) {
+ if (typeof errorCallback === 'function') {
+ errorCallback(new FileError(FileError.NOT_FOUND_ERR));
+ }
+ }
+ }
+};
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/366572ae/lib/webworks/java/plugin/java/MediaError.js
----------------------------------------------------------------------
diff --git a/lib/webworks/java/plugin/java/MediaError.js b/lib/webworks/java/plugin/java/MediaError.js
new file mode 100644
index 0000000..88d544e
--- /dev/null
+++ b/lib/webworks/java/plugin/java/MediaError.js
@@ -0,0 +1,8 @@
+
+// The MediaError object exists on BB OS 6+ which prevents the Cordova version
+// being defined. This object is used to merge in differences between the BB
+// MediaError object and the Cordova version.
+module.exports = {
+ MEDIA_ERR_NONE_ACTIVE : 0,
+ MEDIA_ERR_NONE_SUPPORTED : 4
+};
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/366572ae/lib/webworks/java/plugin/java/app.js
----------------------------------------------------------------------
diff --git a/lib/webworks/java/plugin/java/app.js b/lib/webworks/java/plugin/java/app.js
new file mode 100644
index 0000000..a046013
--- /dev/null
+++ b/lib/webworks/java/plugin/java/app.js
@@ -0,0 +1,50 @@
+var exec = require('cordova/exec');
+var manager = require('cordova/plugin/manager');
+
+module.exports = {
+ /**
+ * Clear the resource cache.
+ */
+ clearCache:function() {
+ if (typeof blackberry.widgetcache === "undefined" || blackberry.widgetcache === null) {
+ console.log("blackberry.widgetcache permission not found. Cache clear denied.");
+ return;
+ }
+ blackberry.widgetcache.clearAll();
+ },
+
+ /**
+ * Clear web history in this web view.
+ * Instead of BACK button loading the previous web page, it will exit the app.
+ */
+ clearHistory:function() {
+ exec(null, null, "App", "clearHistory", []);
+ },
+
+ /**
+ * Go to previous page displayed.
+ * This is the same as pressing the backbutton on Android device.
+ */
+ backHistory:function() {
+ // window.history.back() behaves oddly on BlackBerry, so use
+ // native implementation.
+ exec(null, null, "App", "backHistory", []);
+ },
+
+ /**
+ * Exit and terminate the application.
+ */
+ exitApp:function() {
+ // Call onunload if it is defined since BlackBerry does not invoke
+ // on application exit.
+ if (typeof window.onunload === "function") {
+ window.onunload();
+ }
+
+ // allow Cordova JavaScript Extension opportunity to cleanup
+ manager.destroy();
+
+ // exit the app
+ blackberry.app.exit();
+ }
+};
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/366572ae/lib/webworks/java/plugin/java/contacts.js
----------------------------------------------------------------------
diff --git a/lib/webworks/java/plugin/java/contacts.js b/lib/webworks/java/plugin/java/contacts.js
new file mode 100644
index 0000000..8c51d4a
--- /dev/null
+++ b/lib/webworks/java/plugin/java/contacts.js
@@ -0,0 +1,63 @@
+var ContactError = require('cordova/plugin/ContactError'),
+ utils = require('cordova/utils'),
+ ContactUtils = require('cordova/plugin/java/ContactUtils');
+
+module.exports = {
+ /**
+ * Returns an array of Contacts matching the search criteria.
+ *
+ * @return array of Contacts matching search criteria
+ */
+ find : function(fields, success, fail, options) {
+ // Success callback is required. Throw exception if not specified.
+ if (typeof success !== 'function') {
+ throw new TypeError(
+ "You must specify a success callback for the find command.");
+ }
+
+ // Search qualifier is required and cannot be empty.
+ if (!fields || !(utils.isArray(fields)) || fields.length === 0) {
+ if (typeof fail == 'function') {
+ fail(new ContactError(ContactError.INVALID_ARGUMENT_ERROR));
+ }
+ return;
+ }
+
+ // default is to return a single contact match
+ var numContacts = 1;
+
+ // search options
+ var filter = null;
+ if (options) {
+ // return multiple objects?
+ if (options.multiple === true) {
+ // -1 on BlackBerry will return all contact matches.
+ numContacts = -1;
+ }
+ filter = options.filter;
+ }
+
+ // build the filter expression to use in find operation
+ var filterExpression = ContactUtils.buildFilterExpression(fields, filter);
+
+ // find matching contacts
+ // Note: the filter expression can be null here, in which case, the find
+ // won't filter
+ var bbContacts = blackberry.pim.Contact.find(filterExpression, null, numContacts);
+
+ // convert to Contact from blackberry.pim.Contact
+ var contacts = [];
+ for (var i = 0; i < bbContacts.length; i++) {
+ if (bbContacts[i]) {
+ // W3C Contacts API specification states that only the fields
+ // in the search filter should be returned, so we create
+ // a new Contact object, copying only the fields specified
+ contacts.push(ContactUtils.createContact(bbContacts[i], fields));
+ }
+ }
+
+ // return results
+ success(contacts);
+ }
+
+};
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/366572ae/lib/webworks/java/plugin/java/notification.js
----------------------------------------------------------------------
diff --git a/lib/webworks/java/plugin/java/notification.js b/lib/webworks/java/plugin/java/notification.js
new file mode 100644
index 0000000..d48efbd
--- /dev/null
+++ b/lib/webworks/java/plugin/java/notification.js
@@ -0,0 +1,53 @@
+var exec = require('cordova/exec');
+
+/**
+ * Provides BlackBerry enhanced notification API.
+ */
+module.exports = {
+ activityStart : function(title, message) {
+ // If title and message not specified then mimic Android behavior of
+ // using default strings.
+ if (typeof title === "undefined" && typeof message == "undefined") {
+ title = "Busy";
+ message = 'Please wait...';
+ }
+
+ exec(null, null, 'Notification', 'activityStart', [ title, message ]);
+ },
+
+ /**
+ * Close an activity dialog
+ */
+ activityStop : function() {
+ exec(null, null, 'Notification', 'activityStop', []);
+ },
+
+ /**
+ * Display a progress dialog with progress bar that goes from 0 to 100.
+ *
+ * @param {String}
+ * title Title of the progress dialog.
+ * @param {String}
+ * message Message to display in the dialog.
+ */
+ progressStart : function(title, message) {
+ exec(null, null, 'Notification', 'progressStart', [ title, message ]);
+ },
+
+ /**
+ * Close the progress dialog.
+ */
+ progressStop : function() {
+ exec(null, null, 'Notification', 'progressStop', []);
+ },
+
+ /**
+ * Set the progress dialog value.
+ *
+ * @param {Number}
+ * value 0-100
+ */
+ progressValue : function(value) {
+ exec(null, null, 'Notification', 'progressValue', [ value ]);
+ }
+};
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/366572ae/lib/webworks/java/plugin/manager.js
----------------------------------------------------------------------
diff --git a/lib/webworks/java/plugin/manager.js b/lib/webworks/java/plugin/manager.js
new file mode 100644
index 0000000..0aa56c8
--- /dev/null
+++ b/lib/webworks/java/plugin/manager.js
@@ -0,0 +1,70 @@
+var cordova = require('cordova');
+
+function _exec(win, fail, clazz, action, args) {
+ var callbackId = clazz + cordova.callbackId++,
+ origResult,
+ evalResult,
+ execResult;
+
+ try {
+ if (win || fail) {
+ cordova.callbacks[callbackId] = {success: win, fail: fail};
+ }
+
+ // Note: Device returns string, but for some reason emulator returns object - so convert to string.
+ origResult = "" + org.apache.cordova.JavaPluginManager.exec(clazz, action, callbackId, JSON.stringify(args), true);
+
+ // If a result was returned
+ if (origResult.length > 0) {
+ evalResult = JSON.parse(origResult);
+
+ // If status is OK, then return evalResultalue back to caller
+ if (evalResult.status === cordova.callbackStatus.OK) {
+
+ // If there is a success callback, then call it now with returned evalResultalue
+ if (win) {
+ // Clear callback if not expecting any more results
+ if (!evalResult.keepCallback) {
+ delete cordova.callbacks[callbackId];
+ }
+ }
+ } else if (evalResult.status === cordova.callbackStatus.NO_RESULT) {
+
+ // Clear callback if not expecting any more results
+ if (!evalResult.keepCallback) {
+ delete cordova.callbacks[callbackId];
+ }
+ } else {
+ // If there is a fail callback, then call it now with returned evalResultalue
+ if (fail) {
+
+ // Clear callback if not expecting any more results
+ if (!evalResult.keepCallback) {
+ delete cordova.callbacks[callbackId];
+ }
+ }
+ }
+ execResult = evalResult;
+ } else {
+ // Asynchronous calls return an empty string. Return a NO_RESULT
+ // status for those executions.
+ execResult = {"status" : cordova.callbackStatus.NO_RESULT,
+ "message" : ""};
+ }
+ } catch (e) {
+ console.log("BlackBerryPluginManager Error: " + e);
+ execResult = {"status" : cordova.callbackStatus.ERROR,
+ "message" : e.message};
+ }
+
+ return execResult;
+}
+
+module.exports = {
+ exec: function (win, fail, clazz, action, args) {
+ return _exec(win, fail, clazz, action, args);
+ },
+ resume: org.apache.cordova.JavaPluginManager.resume,
+ pause: org.apache.cordova.JavaPluginManager.pause,
+ destroy: org.apache.cordova.JavaPluginManager.destroy
+};