You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by gt...@apache.org on 2012/11/02 14:31:14 UTC
[2/5] Refactored BlackBerry into one javascript file
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/0919268c/lib/blackberry/plugin/air/network.js
----------------------------------------------------------------------
diff --git a/lib/blackberry/plugin/air/network.js b/lib/blackberry/plugin/air/network.js
new file mode 100644
index 0000000..85e671e
--- /dev/null
+++ b/lib/blackberry/plugin/air/network.js
@@ -0,0 +1,54 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+
+var cordova = require('cordova'),
+ connection = require('cordova/plugin/Connection');
+
+module.exports = {
+ getConnectionInfo: function (args, win, fail) {
+ var connectionType = connection.NONE,
+ eventType = "offline",
+ callbackID,
+ request;
+
+ /**
+ * For PlayBooks, we currently only have WiFi connections, so
+ * return WiFi if there is any access at all.
+ * TODO: update if/when PlayBook gets other connection types...
+ */
+ if (blackberry.system.hasDataCoverage()) {
+ connectionType = connection.WIFI;
+ eventType = "online";
+ }
+
+ //Register an event handler for the networkChange event
+ callbackID = blackberry.events.registerEventHandler("networkChange", function (status) {
+ win(status.type);
+ });
+
+ //pass our callback id down to our network extension
+ request = new blackberry.transport.RemoteFunctionCall("org/apache/cordova/getConnectionInfo");
+ request.addParam("networkStatusChangedID", callbackID);
+ request.makeSyncCall();
+
+ return { "status": cordova.callbackStatus.OK, "message": connectionType};
+ }
+};
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/0919268c/lib/blackberry/plugin/air/platform.js
----------------------------------------------------------------------
diff --git a/lib/blackberry/plugin/air/platform.js b/lib/blackberry/plugin/air/platform.js
new file mode 100644
index 0000000..bfa236d
--- /dev/null
+++ b/lib/blackberry/plugin/air/platform.js
@@ -0,0 +1,56 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+
+module.exports = {
+ id: "playbook",
+ initialize:function() {},
+ objects: {
+ DirectoryReader:{
+ path: 'cordova/plugin/air/DirectoryReader'
+ },
+ File:{
+ path: 'cordova/plugin/air/File'
+ },
+ FileReader:{
+ path: 'cordova/plugin/air/FileReader'
+ },
+ FileWriter:{
+ path: 'cordova/plugin/air/FileWriter'
+ },
+ requestFileSystem:{
+ path: 'cordova/plugin/air/requestFileSystem'
+ },
+ resolveLocalFileSystemURI:{
+ path: 'cordova/plugin/air/resolveLocalFileSystemURI'
+ }
+ },
+ merges: {
+ DirectoryEntry: {
+ path: 'cordova/plugin/air/DirectoryEntry'
+ },
+ Entry: {
+ path: 'cordova/plugin/air/Entry'
+ },
+ FileEntry:{
+ path: 'cordova/plugin/air/FileEntry'
+ }
+ }
+};
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/0919268c/lib/blackberry/plugin/air/requestFileSystem.js
----------------------------------------------------------------------
diff --git a/lib/blackberry/plugin/air/requestFileSystem.js b/lib/blackberry/plugin/air/requestFileSystem.js
new file mode 100644
index 0000000..b1079cc
--- /dev/null
+++ b/lib/blackberry/plugin/air/requestFileSystem.js
@@ -0,0 +1,80 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+
+var DirectoryEntry = require('cordova/plugin/DirectoryEntry'),
+FileError = require('cordova/plugin/FileError'),
+FileSystem = require('cordova/plugin/FileSystem'),
+LocalFileSystem = require('cordova/plugin/LocalFileSystem');
+
+/**
+ * Request a file system in which to store application data.
+ * @param type local file system type
+ * @param size indicates how much storage space, in bytes, the application expects to need
+ * @param successCallback invoked with a FileSystem object
+ * @param errorCallback invoked if error occurs retrieving file system
+ */
+var requestFileSystem = function(type, size, successCallback, errorCallback) {
+ var fail = function(code) {
+ if (typeof errorCallback === 'function') {
+ errorCallback(new FileError(code));
+ }
+ };
+
+ if (type < 0 || type > 3) {
+ fail(FileError.SYNTAX_ERR);
+ } else {
+ // if successful, return a FileSystem object
+ var success = function(file_system) {
+ if (file_system) {
+ if (typeof successCallback === 'function') {
+ successCallback(file_system);
+ }
+ }
+ else {
+ // no FileSystem object returned
+ fail(FileError.NOT_FOUND_ERR);
+ }
+ };
+
+ // guessing the max file size is 2GB - 1 bytes?
+ // https://bdsc.webapps.blackberry.com/native/documentation/com.qnx.doc.neutrino.user_guide/topic/limits_filesystems.html
+
+ if(size>=2147483648){
+ fail(FileError.QUOTA_EXCEEDED_ERR);
+ return;
+ }
+
+
+ var theFileSystem;
+ try{
+ // is there a way to get space for the app that doesn't point to the appDirs folder?
+ if(type==LocalFileSystem.TEMPORARY){
+ theFileSystem = new FileSystem('temporary', new DirectoryEntry('root', blackberry.io.dir.appDirs.app.storage.path));
+ }else if(type==LocalFileSystem.PERSISTENT){
+ theFileSystem = new FileSystem('persistent', new DirectoryEntry('root', blackberry.io.dir.appDirs.app.storage.path));
+ }
+ success(theFileSystem);
+ }catch(e){
+ fail(FileError.SYNTAX_ERR);
+ }
+ }
+};
+module.exports = requestFileSystem;
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/0919268c/lib/blackberry/plugin/air/resolveLocalFileSystemURI.js
----------------------------------------------------------------------
diff --git a/lib/blackberry/plugin/air/resolveLocalFileSystemURI.js b/lib/blackberry/plugin/air/resolveLocalFileSystemURI.js
new file mode 100644
index 0000000..f179fed
--- /dev/null
+++ b/lib/blackberry/plugin/air/resolveLocalFileSystemURI.js
@@ -0,0 +1,102 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+
+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);
+ return;
+ }
+ };
+
+ if(!uri || uri === ""){
+ fail(FileError.NOT_FOUND_ERR);
+ return;
+ }
+
+ // decode uri if % char found
+ if(uri.indexOf('%')>=0){
+ uri = decodeURI(uri);
+ }
+
+ // pop the parameters if any
+ if(uri.indexOf('?')>=0){
+ uri = uri.split('?')[0];
+ }
+
+ // check for leading /
+ if(uri.indexOf('/')===0){
+ fail(FileError.ENCODING_ERR);
+ return;
+ }
+
+ // Entry object is borked - unable to instantiate a new Entry object so just create one
+ 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);
+ return;
+ }else{
+ fail(FileError.NOT_FOUND_ERR);
+ return;
+ }
+
+};
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/0919268c/lib/blackberry/plugin/java/Contact.js
----------------------------------------------------------------------
diff --git a/lib/blackberry/plugin/java/Contact.js b/lib/blackberry/plugin/java/Contact.js
new file mode 100644
index 0000000..52d82cf
--- /dev/null
+++ b/lib/blackberry/plugin/java/Contact.js
@@ -0,0 +1,406 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+
+var ContactError = require('cordova/plugin/ContactError'),
+ ContactUtils = require('cordova/plugin/java/ContactUtils'),
+ utils = require('cordova/utils'),
+ ContactAddress = require('cordova/plugin/ContactAddress'),
+ exec = require('cordova/exec');
+
+// ------------------
+// Utility functions
+// ------------------
+
+/**
+ * Retrieves a BlackBerry contact from the device by unique id.
+ *
+ * @param uid
+ * Unique id of the contact on the device
+ * @return {blackberry.pim.Contact} BlackBerry contact or null if contact with
+ * specified id is not found
+ */
+var findByUniqueId = function(uid) {
+ if (!uid) {
+ return null;
+ }
+ var bbContacts = blackberry.pim.Contact.find(new blackberry.find.FilterExpression("uid", "==", uid));
+ return bbContacts[0] || null;
+};
+
+/**
+ * Creates a BlackBerry contact object from the W3C Contact object and persists
+ * it to device storage.
+ *
+ * @param {Contact}
+ * contact The contact to save
+ * @return a new contact object with all properties set
+ */
+var saveToDevice = function(contact) {
+
+ if (!contact) {
+ return;
+ }
+
+ var bbContact = null;
+ var update = false;
+
+ // if the underlying BlackBerry contact already exists, retrieve it for
+ // update
+ if (contact.id) {
+ // we must attempt to retrieve the BlackBerry contact from the device
+ // because this may be an update operation
+ bbContact = findByUniqueId(contact.id);
+ }
+
+ // contact not found on device, create a new one
+ if (!bbContact) {
+ bbContact = new blackberry.pim.Contact();
+ }
+ // update the existing contact
+ else {
+ update = true;
+ }
+
+ // NOTE: The user may be working with a partial Contact object, because only
+ // user-specified Contact fields are returned from a find operation (blame
+ // the W3C spec). If this is an update to an existing Contact, we don't
+ // want to clear an attribute from the contact database simply because the
+ // Contact object that the user passed in contains a null value for that
+ // attribute. So we only copy the non-null Contact attributes to the
+ // BlackBerry contact object before saving.
+ //
+ // This means that a user must explicitly set a Contact attribute to a
+ // non-null value in order to update it in the contact database.
+ //
+ // name
+ if (contact.name !== null) {
+ if (contact.name.givenName) {
+ bbContact.firstName = contact.name.givenName;
+ }
+ if (contact.name.familyName) {
+ bbContact.lastName = contact.name.familyName;
+ }
+ if (contact.name.honorificPrefix) {
+ bbContact.title = contact.name.honorificPrefix;
+ }
+ }
+
+ // display name
+ if (contact.displayName !== null) {
+ bbContact.user1 = contact.displayName;
+ }
+
+ // note
+ if (contact.note !== null) {
+ bbContact.note = contact.note;
+ }
+
+ // birthday
+ //
+ // user may pass in Date object or a string representation of a date
+ // if it is a string, we don't know the date format, so try to create a
+ // new Date with what we're given
+ //
+ // NOTE: BlackBerry's Date.parse() does not work well, so use new Date()
+ //
+ if (contact.birthday !== null) {
+ if (utils.isDate(contact.birthday)) {
+ bbContact.birthday = contact.birthday;
+ } else {
+ var bday = contact.birthday.toString();
+ bbContact.birthday = (bday.length > 0) ? new Date(bday) : "";
+ }
+ }
+
+ // BlackBerry supports three email addresses
+ if (contact.emails && utils.isArray(contact.emails)) {
+
+ // if this is an update, re-initialize email addresses
+ if (update) {
+ bbContact.email1 = "";
+ bbContact.email2 = "";
+ bbContact.email3 = "";
+ }
+
+ // copy the first three email addresses found
+ var email = null;
+ for ( var i = 0; i < contact.emails.length; i += 1) {
+ email = contact.emails[i];
+ if (!email || !email.value) {
+ continue;
+ }
+ if (bbContact.email1 === "") {
+ bbContact.email1 = email.value;
+ } else if (bbContact.email2 === "") {
+ bbContact.email2 = email.value;
+ } else if (bbContact.email3 === "") {
+ bbContact.email3 = email.value;
+ }
+ }
+ }
+
+ // BlackBerry supports a finite number of phone numbers
+ // copy into appropriate fields based on type
+ if (contact.phoneNumbers && utils.isArray(contact.phoneNumbers)) {
+
+ // if this is an update, re-initialize phone numbers
+ if (update) {
+ bbContact.homePhone = "";
+ bbContact.homePhone2 = "";
+ bbContact.workPhone = "";
+ bbContact.workPhone2 = "";
+ bbContact.mobilePhone = "";
+ bbContact.faxPhone = "";
+ bbContact.pagerPhone = "";
+ bbContact.otherPhone = "";
+ }
+
+ var type = null;
+ var number = null;
+ for ( var j = 0; j < contact.phoneNumbers.length; j += 1) {
+ if (!contact.phoneNumbers[j] || !contact.phoneNumbers[j].value) {
+ continue;
+ }
+ type = contact.phoneNumbers[j].type;
+ number = contact.phoneNumbers[j].value;
+ if (type === 'home') {
+ if (bbContact.homePhone === "") {
+ bbContact.homePhone = number;
+ } else if (bbContact.homePhone2 === "") {
+ bbContact.homePhone2 = number;
+ }
+ } else if (type === 'work') {
+ if (bbContact.workPhone === "") {
+ bbContact.workPhone = number;
+ } else if (bbContact.workPhone2 === "") {
+ bbContact.workPhone2 = number;
+ }
+ } else if (type === 'mobile' && bbContact.mobilePhone === "") {
+ bbContact.mobilePhone = number;
+ } else if (type === 'fax' && bbContact.faxPhone === "") {
+ bbContact.faxPhone = number;
+ } else if (type === 'pager' && bbContact.pagerPhone === "") {
+ bbContact.pagerPhone = number;
+ } else if (bbContact.otherPhone === "") {
+ bbContact.otherPhone = number;
+ }
+ }
+ }
+
+ // BlackBerry supports two addresses: home and work
+ // copy the first two addresses found from Contact
+ if (contact.addresses && utils.isArray(contact.addresses)) {
+
+ // if this is an update, re-initialize addresses
+ if (update) {
+ bbContact.homeAddress = null;
+ bbContact.workAddress = null;
+ }
+
+ var address = null;
+ var bbHomeAddress = null;
+ var bbWorkAddress = null;
+ for ( var k = 0; k < contact.addresses.length; k += 1) {
+ address = contact.addresses[k];
+ if (!address || address.id === undefined || address.pref === undefined || address.type === undefined || address.formatted === undefined) {
+ continue;
+ }
+
+ if (bbHomeAddress === null && (!address.type || address.type === "home")) {
+ bbHomeAddress = createBlackBerryAddress(address);
+ bbContact.homeAddress = bbHomeAddress;
+ } else if (bbWorkAddress === null && (!address.type || address.type === "work")) {
+ bbWorkAddress = createBlackBerryAddress(address);
+ bbContact.workAddress = bbWorkAddress;
+ }
+ }
+ }
+
+ // copy first url found to BlackBerry 'webpage' field
+ if (contact.urls && utils.isArray(contact.urls)) {
+
+ // if this is an update, re-initialize web page
+ if (update) {
+ bbContact.webpage = "";
+ }
+
+ var url = null;
+ for ( var m = 0; m < contact.urls.length; m += 1) {
+ url = contact.urls[m];
+ if (!url || !url.value) {
+ continue;
+ }
+ if (bbContact.webpage === "") {
+ bbContact.webpage = url.value;
+ break;
+ }
+ }
+ }
+
+ // copy fields from first organization to the
+ // BlackBerry 'company' and 'jobTitle' fields
+ if (contact.organizations && utils.isArray(contact.organizations)) {
+
+ // if this is an update, re-initialize org attributes
+ if (update) {
+ bbContact.company = "";
+ }
+
+ var org = null;
+ for ( var n = 0; n < contact.organizations.length; n += 1) {
+ org = contact.organizations[n];
+ if (!org) {
+ continue;
+ }
+ if (bbContact.company === "") {
+ bbContact.company = org.name || "";
+ bbContact.jobTitle = org.title || "";
+ break;
+ }
+ }
+ }
+
+ // categories
+ if (contact.categories && utils.isArray(contact.categories)) {
+ bbContact.categories = [];
+ var category = null;
+ for ( var o = 0; o < contact.categories.length; o += 1) {
+ category = contact.categories[o];
+ if (typeof category == "string") {
+ bbContact.categories.push(category);
+ }
+ }
+ }
+
+ // save to device
+ bbContact.save();
+
+ // invoke native side to save photo
+ // fail gracefully if photo URL is no good, but log the error
+ if (contact.photos && utils.isArray(contact.photos)) {
+ var photo = null;
+ for ( var p = 0; p < contact.photos.length; p += 1) {
+ photo = contact.photos[p];
+ if (!photo || !photo.value) {
+ continue;
+ }
+ exec(
+ // success
+ function() {
+ },
+ // fail
+ function(e) {
+ console.log('Contact.setPicture failed:' + e);
+ }, "Contacts", "setPicture", [ bbContact.uid, photo.type,
+ photo.value ]);
+ break;
+ }
+ }
+
+ // Use the fully populated BlackBerry contact object to create a
+ // corresponding W3C contact object.
+ return ContactUtils.createContact(bbContact, [ "*" ]);
+};
+
+/**
+ * Creates a BlackBerry Address object from a W3C ContactAddress.
+ *
+ * @return {blackberry.pim.Address} a BlackBerry address object
+ */
+var createBlackBerryAddress = function(address) {
+ var bbAddress = new blackberry.pim.Address();
+
+ if (!address) {
+ return bbAddress;
+ }
+
+ bbAddress.address1 = address.streetAddress || "";
+ bbAddress.city = address.locality || "";
+ bbAddress.stateProvince = address.region || "";
+ bbAddress.zipPostal = address.postalCode || "";
+ bbAddress.country = address.country || "";
+
+ return bbAddress;
+};
+
+module.exports = {
+ /**
+ * Persists contact to device storage.
+ */
+ save : function(success, fail) {
+ try {
+ // save the contact and store it's unique id
+ var fullContact = saveToDevice(this);
+ this.id = fullContact.id;
+
+ // This contact object may only have a subset of properties
+ // if the save was an update of an existing contact. This is
+ // because the existing contact was likely retrieved using a
+ // subset of properties, so only those properties were set in the
+ // object. For this reason, invoke success with the contact object
+ // returned by saveToDevice since it is fully populated.
+ if (typeof success === 'function') {
+ success(fullContact);
+ }
+ } catch (e) {
+ console.log('Error saving contact: ' + e);
+ if (typeof fail === 'function') {
+ fail(new ContactError(ContactError.UNKNOWN_ERROR));
+ }
+ }
+ },
+
+ /**
+ * Removes contact from device storage.
+ *
+ * @param success
+ * success callback
+ * @param fail
+ * error callback
+ */
+ remove : function(success, fail) {
+ try {
+ // retrieve contact from device by id
+ var bbContact = null;
+ if (this.id) {
+ bbContact = findByUniqueId(this.id);
+ }
+
+ // if contact was found, remove it
+ if (bbContact) {
+ console.log('removing contact: ' + bbContact.uid);
+ bbContact.remove();
+ if (typeof success === 'function') {
+ success(this);
+ }
+ }
+ // attempting to remove a contact that hasn't been saved
+ else if (typeof fail === 'function') {
+ fail(new ContactError(ContactError.UNKNOWN_ERROR));
+ }
+ } catch (e) {
+ console.log('Error removing contact ' + this.id + ": " + e);
+ if (typeof fail === 'function') {
+ fail(new ContactError(ContactError.UNKNOWN_ERROR));
+ }
+ }
+ }
+};
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/0919268c/lib/blackberry/plugin/java/ContactUtils.js
----------------------------------------------------------------------
diff --git a/lib/blackberry/plugin/java/ContactUtils.js b/lib/blackberry/plugin/java/ContactUtils.js
new file mode 100644
index 0000000..2b7f030
--- /dev/null
+++ b/lib/blackberry/plugin/java/ContactUtils.js
@@ -0,0 +1,382 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+
+var ContactAddress = require('cordova/plugin/ContactAddress'),
+ ContactName = require('cordova/plugin/ContactName'),
+ ContactField = require('cordova/plugin/ContactField'),
+ ContactOrganization = require('cordova/plugin/ContactOrganization'),
+ utils = require('cordova/utils'),
+ Contact = require('cordova/plugin/Contact');
+
+/**
+ * Mappings for each Contact field that may be used in a find operation. Maps
+ * W3C Contact fields to one or more fields in a BlackBerry contact object.
+ *
+ * Example: user searches with a filter on the Contact 'name' field:
+ *
+ * <code>Contacts.find(['name'], onSuccess, onFail, {filter:'Bob'});</code>
+ *
+ * The 'name' field does not exist in a BlackBerry contact. Instead, a filter
+ * expression will be built to search the BlackBerry contacts using the
+ * BlackBerry 'title', 'firstName' and 'lastName' fields.
+ */
+var fieldMappings = {
+ "id" : "uid",
+ "displayName" : "user1",
+ "name" : [ "title", "firstName", "lastName" ],
+ "name.formatted" : [ "title", "firstName", "lastName" ],
+ "name.givenName" : "firstName",
+ "name.familyName" : "lastName",
+ "name.honorificPrefix" : "title",
+ "phoneNumbers" : [ "faxPhone", "homePhone", "homePhone2", "mobilePhone",
+ "pagerPhone", "otherPhone", "workPhone", "workPhone2" ],
+ "phoneNumbers.value" : [ "faxPhone", "homePhone", "homePhone2",
+ "mobilePhone", "pagerPhone", "otherPhone", "workPhone",
+ "workPhone2" ],
+ "emails" : [ "email1", "email2", "email3" ],
+ "addresses" : [ "homeAddress.address1", "homeAddress.address2",
+ "homeAddress.city", "homeAddress.stateProvince",
+ "homeAddress.zipPostal", "homeAddress.country",
+ "workAddress.address1", "workAddress.address2", "workAddress.city",
+ "workAddress.stateProvince", "workAddress.zipPostal",
+ "workAddress.country" ],
+ "addresses.formatted" : [ "homeAddress.address1", "homeAddress.address2",
+ "homeAddress.city", "homeAddress.stateProvince",
+ "homeAddress.zipPostal", "homeAddress.country",
+ "workAddress.address1", "workAddress.address2", "workAddress.city",
+ "workAddress.stateProvince", "workAddress.zipPostal",
+ "workAddress.country" ],
+ "addresses.streetAddress" : [ "homeAddress.address1",
+ "homeAddress.address2", "workAddress.address1",
+ "workAddress.address2" ],
+ "addresses.locality" : [ "homeAddress.city", "workAddress.city" ],
+ "addresses.region" : [ "homeAddress.stateProvince",
+ "workAddress.stateProvince" ],
+ "addresses.country" : [ "homeAddress.country", "workAddress.country" ],
+ "organizations" : [ "company", "jobTitle" ],
+ "organizations.name" : "company",
+ "organizations.title" : "jobTitle",
+ "birthday" : "birthday",
+ "note" : "note",
+ "categories" : "categories",
+ "urls" : "webpage",
+ "urls.value" : "webpage"
+};
+
+/*
+ * Build an array of all of the valid W3C Contact fields. This is used to
+ * substitute all the fields when ["*"] is specified.
+ */
+var allFields = [];
+for ( var key in fieldMappings) {
+ if (fieldMappings.hasOwnProperty(key)) {
+ allFields.push(key);
+ }
+}
+
+/**
+ * Create a W3C ContactAddress object from a BlackBerry Address object.
+ *
+ * @param {String}
+ * type the type of address (e.g. work, home)
+ * @param {blackberry.pim.Address}
+ * bbAddress a BlackBerry Address object
+ * @return {ContactAddress} a contact address object or null if the specified
+ * address is null
+ */
+var createContactAddress = function(type, bbAddress) {
+
+ if (!bbAddress) {
+ return null;
+ }
+
+ var address1 = bbAddress.address1 || "";
+ var address2 = bbAddress.address2 || "";
+ var streetAddress = address1 + ", " + address2;
+ var locality = bbAddress.city || "";
+ var region = bbAddress.stateProvince || "";
+ var postalCode = bbAddress.zipPostal || "";
+ var country = bbAddress.country || "";
+ var formatted = streetAddress + ", " + locality + ", " + region + ", " + postalCode + ", " + country;
+
+ return new ContactAddress(null, type, formatted, streetAddress, locality,
+ region, postalCode, country);
+};
+
+module.exports = {
+ /**
+ * Builds a BlackBerry filter expression for contact search using the
+ * contact fields and search filter provided.
+ *
+ * @param {String[]}
+ * fields Array of Contact fields to search
+ * @param {String}
+ * filter Filter, or search string
+ * @return filter expression or null if fields is empty or filter is null or
+ * empty
+ */
+ buildFilterExpression : function(fields, filter) {
+
+ // ensure filter exists
+ if (!filter || filter === "") {
+ return null;
+ }
+
+ if (fields.length == 1 && fields[0] === "*") {
+ // Cordova enhancement to allow fields value of ["*"] to indicate
+ // all supported fields.
+ fields = allFields;
+ }
+
+ // BlackBerry API uses specific operators to build filter expressions
+ // for
+ // querying Contact lists. The operators are
+ // ["!=","==","<",">","<=",">="].
+ // Use of regex is also an option, and the only one we can use to
+ // simulate
+ // an SQL '%LIKE%' clause.
+ //
+ // Note: The BlackBerry regex implementation doesn't seem to support
+ // conventional regex switches that would enable a case insensitive
+ // search.
+ // It does not honor the (?i) switch (which causes Contact.find() to
+ // fail).
+ // We need case INsensitivity to match the W3C Contacts API spec.
+ // So the guys at RIM proposed this method:
+ //
+ // original filter = "norm"
+ // case insensitive filter = "[nN][oO][rR][mM]"
+ //
+ var ciFilter = "";
+ for ( var i = 0; i < filter.length; i++) {
+ ciFilter = ciFilter + "[" + filter[i].toLowerCase() + filter[i].toUpperCase() + "]";
+ }
+
+ // match anything that contains our filter string
+ filter = ".*" + ciFilter + ".*";
+
+ // build a filter expression using all Contact fields provided
+ var filterExpression = null;
+ if (fields && utils.isArray(fields)) {
+ var fe = null;
+ for (var f = 0; f < fields.length; f++) {
+ if (!fields[f]) {
+ continue;
+ }
+
+ // retrieve the BlackBerry contact fields that map to the one
+ // specified
+ var bbFields = fieldMappings[fields[f]];
+
+ // BlackBerry doesn't support the field specified
+ if (!bbFields) {
+ continue;
+ }
+
+ if (!utils.isArray(bbFields)) {
+ bbFields = [bbFields];
+ }
+
+ // construct the filter expression using the BlackBerry fields
+ for (var j = 0; j < bbFields.length; j++) {
+ fe = new blackberry.find.FilterExpression(bbFields[j],
+ "REGEX", filter);
+ if (filterExpression === null) {
+ filterExpression = fe;
+ } else {
+ // combine the filters
+ filterExpression = new blackberry.find.FilterExpression(
+ filterExpression, "OR", fe);
+ }
+ }
+ }
+ }
+
+ return filterExpression;
+ },
+
+ /**
+ * Creates a Contact object from a BlackBerry Contact object, copying only
+ * the fields specified.
+ *
+ * This is intended as a privately used function but it is made globally
+ * available so that a Contact.save can convert a BlackBerry contact object
+ * into its W3C equivalent.
+ *
+ * @param {blackberry.pim.Contact}
+ * bbContact BlackBerry Contact object
+ * @param {String[]}
+ * fields array of contact fields that should be copied
+ * @return {Contact} a contact object containing the specified fields or
+ * null if the specified contact is null
+ */
+ createContact : function(bbContact, fields) {
+
+ if (!bbContact) {
+ return null;
+ }
+
+ // construct a new contact object
+ // always copy the contact id and displayName fields
+ var contact = new Contact(bbContact.uid, bbContact.user1);
+
+ // nothing to do
+ if (!fields || !(utils.isArray(fields)) || fields.length === 0) {
+ return contact;
+ } else if (fields.length == 1 && fields[0] === "*") {
+ // Cordova enhancement to allow fields value of ["*"] to indicate
+ // all supported fields.
+ fields = allFields;
+ }
+
+ // add the fields specified
+ for (var i = 0; i < fields.length; i++) {
+ var field = fields[i];
+
+ if (!field) {
+ continue;
+ }
+
+ // name
+ if (field.indexOf('name') === 0) {
+ var formattedName = bbContact.title + ' ' + bbContact.firstName + ' ' + bbContact.lastName;
+ contact.name = new ContactName(formattedName,
+ bbContact.lastName, bbContact.firstName, null,
+ bbContact.title, null);
+ }
+ // phone numbers
+ else if (field.indexOf('phoneNumbers') === 0) {
+ var phoneNumbers = [];
+ if (bbContact.homePhone) {
+ phoneNumbers.push(new ContactField('home',
+ bbContact.homePhone));
+ }
+ if (bbContact.homePhone2) {
+ phoneNumbers.push(new ContactField('home',
+ bbContact.homePhone2));
+ }
+ if (bbContact.workPhone) {
+ phoneNumbers.push(new ContactField('work',
+ bbContact.workPhone));
+ }
+ if (bbContact.workPhone2) {
+ phoneNumbers.push(new ContactField('work',
+ bbContact.workPhone2));
+ }
+ if (bbContact.mobilePhone) {
+ phoneNumbers.push(new ContactField('mobile',
+ bbContact.mobilePhone));
+ }
+ if (bbContact.faxPhone) {
+ phoneNumbers.push(new ContactField('fax',
+ bbContact.faxPhone));
+ }
+ if (bbContact.pagerPhone) {
+ phoneNumbers.push(new ContactField('pager',
+ bbContact.pagerPhone));
+ }
+ if (bbContact.otherPhone) {
+ phoneNumbers.push(new ContactField('other',
+ bbContact.otherPhone));
+ }
+ contact.phoneNumbers = phoneNumbers.length > 0 ? phoneNumbers
+ : null;
+ }
+ // emails
+ else if (field.indexOf('emails') === 0) {
+ var emails = [];
+ if (bbContact.email1) {
+ emails.push(new ContactField(null, bbContact.email1, null));
+ }
+ if (bbContact.email2) {
+ emails.push(new ContactField(null, bbContact.email2, null));
+ }
+ if (bbContact.email3) {
+ emails.push(new ContactField(null, bbContact.email3, null));
+ }
+ contact.emails = emails.length > 0 ? emails : null;
+ }
+ // addresses
+ else if (field.indexOf('addresses') === 0) {
+ var addresses = [];
+ if (bbContact.homeAddress) {
+ addresses.push(createContactAddress("home",
+ bbContact.homeAddress));
+ }
+ if (bbContact.workAddress) {
+ addresses.push(createContactAddress("work",
+ bbContact.workAddress));
+ }
+ contact.addresses = addresses.length > 0 ? addresses : null;
+ }
+ // birthday
+ else if (field.indexOf('birthday') === 0) {
+ if (bbContact.birthday) {
+ contact.birthday = bbContact.birthday;
+ }
+ }
+ // note
+ else if (field.indexOf('note') === 0) {
+ if (bbContact.note) {
+ contact.note = bbContact.note;
+ }
+ }
+ // organizations
+ else if (field.indexOf('organizations') === 0) {
+ var organizations = [];
+ if (bbContact.company || bbContact.jobTitle) {
+ organizations.push(new ContactOrganization(null, null,
+ bbContact.company, null, bbContact.jobTitle));
+ }
+ contact.organizations = organizations.length > 0 ? organizations
+ : null;
+ }
+ // categories
+ else if (field.indexOf('categories') === 0) {
+ if (bbContact.categories && bbContact.categories.length > 0) {
+ contact.categories = bbContact.categories;
+ } else {
+ contact.categories = null;
+ }
+ }
+ // urls
+ else if (field.indexOf('urls') === 0) {
+ var urls = [];
+ if (bbContact.webpage) {
+ urls.push(new ContactField(null, bbContact.webpage));
+ }
+ contact.urls = urls.length > 0 ? urls : null;
+ }
+ // photos
+ else if (field.indexOf('photos') === 0) {
+ var photos = [];
+ // The BlackBerry Contact object will have a picture attribute
+ // with Base64 encoded image
+ if (bbContact.picture) {
+ photos.push(new ContactField('base64', bbContact.picture));
+ }
+ contact.photos = photos.length > 0 ? photos : null;
+ }
+ }
+
+ return contact;
+ }
+};
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/0919268c/lib/blackberry/plugin/java/DirectoryEntry.js
----------------------------------------------------------------------
diff --git a/lib/blackberry/plugin/java/DirectoryEntry.js b/lib/blackberry/plugin/java/DirectoryEntry.js
new file mode 100644
index 0000000..d8315d2
--- /dev/null
+++ b/lib/blackberry/plugin/java/DirectoryEntry.js
@@ -0,0 +1,260 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+
+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);
+ }
+ }
+};
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/0919268c/lib/blackberry/plugin/java/Entry.js
----------------------------------------------------------------------
diff --git a/lib/blackberry/plugin/java/Entry.js b/lib/blackberry/plugin/java/Entry.js
new file mode 100644
index 0000000..5e2f313
--- /dev/null
+++ b/lib/blackberry/plugin/java/Entry.js
@@ -0,0 +1,109 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+
+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/0919268c/lib/blackberry/plugin/java/MediaError.js
----------------------------------------------------------------------
diff --git a/lib/blackberry/plugin/java/MediaError.js b/lib/blackberry/plugin/java/MediaError.js
new file mode 100644
index 0000000..6702452
--- /dev/null
+++ b/lib/blackberry/plugin/java/MediaError.js
@@ -0,0 +1,29 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+
+
+// The MediaError object exists on BB OS 6+ which prevents the Cordova version
+// from 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
+};
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/0919268c/lib/blackberry/plugin/java/app.js
----------------------------------------------------------------------
diff --git a/lib/blackberry/plugin/java/app.js b/lib/blackberry/plugin/java/app.js
new file mode 100644
index 0000000..ff61ba5
--- /dev/null
+++ b/lib/blackberry/plugin/java/app.js
@@ -0,0 +1,72 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+
+var exec = require('cordova/exec');
+ platform = require('cordova/platform'),
+ manager = require('cordova/plugin/' + platform.runtime() + '/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 request 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/0919268c/lib/blackberry/plugin/java/contacts.js
----------------------------------------------------------------------
diff --git a/lib/blackberry/plugin/java/contacts.js b/lib/blackberry/plugin/java/contacts.js
new file mode 100644
index 0000000..522ad7a
--- /dev/null
+++ b/lib/blackberry/plugin/java/contacts.js
@@ -0,0 +1,84 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+
+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/0919268c/lib/blackberry/plugin/java/manager.js
----------------------------------------------------------------------
diff --git a/lib/blackberry/plugin/java/manager.js b/lib/blackberry/plugin/java/manager.js
new file mode 100644
index 0000000..aa93ef6
--- /dev/null
+++ b/lib/blackberry/plugin/java/manager.js
@@ -0,0 +1,91 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+
+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 evalResult value back to caller
+ if (evalResult.status === cordova.callbackStatus.OK) {
+
+ // If there is a success callback, then call it now with returned evalResult value
+ 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 evalResult value
+ 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
+};
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/0919268c/lib/blackberry/plugin/java/notification.js
----------------------------------------------------------------------
diff --git a/lib/blackberry/plugin/java/notification.js b/lib/blackberry/plugin/java/notification.js
new file mode 100644
index 0000000..8586393
--- /dev/null
+++ b/lib/blackberry/plugin/java/notification.js
@@ -0,0 +1,74 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+
+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 ]);
+ }
+};
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/0919268c/lib/blackberry/plugin/java/platform.js
----------------------------------------------------------------------
diff --git a/lib/blackberry/plugin/java/platform.js b/lib/blackberry/plugin/java/platform.js
new file mode 100644
index 0000000..7b9a028
--- /dev/null
+++ b/lib/blackberry/plugin/java/platform.js
@@ -0,0 +1,184 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+
+module.exports = {
+ id: "blackberry",
+ initialize:function() {
+ var cordova = require('cordova'),
+ exec = require('cordova/exec'),
+ channel = require('cordova/channel'),
+ platform = require('cordova/platform'),
+ manager = require('cordova/plugin/' + platform.runtime() + '/manager'),
+ app = require('cordova/plugin/java/app');
+
+ // BB OS 5 does not define window.console.
+ if (typeof window.console === 'undefined') {
+ window.console = {};
+ }
+
+ // Override console.log with native logging ability.
+ // BB OS 7 devices define console.log for use with web inspector
+ // debugging. If console.log is already defined, invoke it in addition
+ // to native logging.
+ var origLog = window.console.log;
+ window.console.log = function(msg) {
+ if (typeof origLog === 'function') {
+ origLog.call(window.console, msg);
+ }
+ org.apache.cordova.Logger.log(''+msg);
+ };
+
+ // Mapping of button events to BlackBerry key identifier.
+ var buttonMapping = {
+ 'backbutton' : blackberry.system.event.KEY_BACK,
+ 'conveniencebutton1' : blackberry.system.event.KEY_CONVENIENCE_1,
+ 'conveniencebutton2' : blackberry.system.event.KEY_CONVENIENCE_2,
+ 'endcallbutton' : blackberry.system.event.KEY_ENDCALL,
+ 'menubutton' : blackberry.system.event.KEY_MENU,
+ 'startcallbutton' : blackberry.system.event.KEY_STARTCALL,
+ 'volumedownbutton' : blackberry.system.event.KEY_VOLUMEDOWN,
+ 'volumeupbutton' : blackberry.system.event.KEY_VOLUMEUP
+ };
+
+ // Generates a function which fires the specified event.
+ var fireEvent = function(event) {
+ return function() {
+ cordova.fireDocumentEvent(event, null);
+ };
+ };
+
+ var eventHandler = function(event) {
+ return function() {
+ // If we just attached the first handler, let native know we
+ // need to override the hardware button.
+ if (this.numHandlers) {
+ blackberry.system.event.onHardwareKey(
+ buttonMapping[event], fireEvent(event));
+ }
+ // If we just detached the last handler, let native know we
+ // no longer override the hardware button.
+ else {
+ blackberry.system.event.onHardwareKey(
+ buttonMapping[event], null);
+ }
+ };
+ };
+
+ // Inject listeners for buttons on the document.
+ for (var button in buttonMapping) {
+ if (buttonMapping.hasOwnProperty(button)) {
+ var buttonChannel = cordova.addDocumentEventHandler(button);
+ buttonChannel.onHasSubscribersChange = eventHandler(button);
+ }
+ }
+
+ // Fires off necessary code to pause/resume app
+ var resume = function() {
+ cordova.fireDocumentEvent('resume');
+ manager.resume();
+ };
+ var pause = function() {
+ cordova.fireDocumentEvent('pause');
+ manager.pause();
+ };
+
+ /************************************************
+ * Patch up the generic pause/resume listeners. *
+ ************************************************/
+
+ // Unsubscribe handler - turns off native backlight change
+ // listener
+ var onHasSubscribersChange = function() {
+ // If we just attached the first handler and there are
+ // no pause handlers, start the backlight system
+ // listener on the native side.
+ if (this.numHandlers && (channel.onResume.numHandlers + channel.onPause.numHandlers === 1)) {
+ exec(backlightWin, backlightFail, "App", "detectBacklight", []);
+ } else if (channel.onResume.numHandlers === 0 && channel.onPause.numHandlers === 0) {
+ exec(null, null, 'App', 'ignoreBacklight', []);
+ }
+ };
+
+ // Native backlight detection win/fail callbacks
+ var backlightWin = function(isOn) {
+ if (isOn === true) {
+ resume();
+ } else {
+ pause();
+ }
+ };
+ var backlightFail = function(e) {
+ console.log("Error detecting backlight on/off.");
+ };
+
+ // Override stock resume and pause listeners so we can trigger
+ // some native methods during attach/remove
+ channel.onResume = cordova.addDocumentEventHandler('resume');
+ channel.onResume.onHasSubscribersChange = onHasSubscribersChange;
+ channel.onPause = cordova.addDocumentEventHandler('pause');
+ channel.onPause.onHasSubscribersChange = onHasSubscribersChange;
+
+ // Fire resume event when application brought to foreground.
+ blackberry.app.event.onForeground(resume);
+
+ // Fire pause event when application sent to background.
+ blackberry.app.event.onBackground(pause);
+
+ // Trap BlackBerry WebWorks exit. Allow plugins to clean up before exiting.
+ blackberry.app.event.onExit(app.exitApp);
+ },
+ objects: {
+ navigator: {
+ children: {
+ app: {
+ path: "cordova/plugin/java/app"
+ }
+ }
+ },
+ File: { // exists natively on BlackBerry OS 7, override
+ path: "cordova/plugin/File"
+ }
+ },
+ merges: {
+ navigator: {
+ children: {
+ contacts: {
+ path: 'cordova/plugin/java/contacts'
+ },
+ notification: {
+ path: 'cordova/plugin/java/notification'
+ }
+ }
+ },
+ Contact: {
+ path: 'cordova/plugin/java/Contact'
+ },
+ DirectoryEntry: {
+ path: 'cordova/plugin/java/DirectoryEntry'
+ },
+ Entry: {
+ path: 'cordova/plugin/java/Entry'
+ },
+ MediaError: { // Exists natively on BB OS 6+, merge in Cordova specifics
+ path: 'cordova/plugin/java/MediaError'
+ }
+ }
+};
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/0919268c/lib/blackberry/plugin/qnx/battery.js
----------------------------------------------------------------------
diff --git a/lib/blackberry/plugin/qnx/battery.js b/lib/blackberry/plugin/qnx/battery.js
new file mode 100644
index 0000000..1971a49
--- /dev/null
+++ b/lib/blackberry/plugin/qnx/battery.js
@@ -0,0 +1,36 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+
+var cordova = require('cordova'),
+ handler;
+
+module.exports = {
+ start: function (args, win, fail) {
+ handler = win;
+ blackberry.event.addEventListener("batterystatus", handler);
+ return { "status" : cordova.callbackStatus.NO_RESULT, "message" : "WebWorks Is On It" };
+ },
+
+ stop: function (args, win, fail) {
+ blackberry.event.removeEventListener("batterystatus", handler);
+ return { "status" : cordova.callbackStatus.NO_RESULT, "message" : "WebWorks Is On It" };
+ }
+};
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/0919268c/lib/blackberry/plugin/qnx/camera.js
----------------------------------------------------------------------
diff --git a/lib/blackberry/plugin/qnx/camera.js b/lib/blackberry/plugin/qnx/camera.js
new file mode 100644
index 0000000..c357437
--- /dev/null
+++ b/lib/blackberry/plugin/qnx/camera.js
@@ -0,0 +1,32 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+
+var cordova = require('cordova');
+
+module.exports = {
+ takePicture: function (args, win, fail) {
+ var noop = function () {};
+ blackberry.invoke.card.invokeCamera("photo", function (path) {
+ win("file://" + path);
+ }, noop, noop);
+ return { "status" : cordova.callbackStatus.NO_RESULT, "message" : "WebWorks Is On It" };
+ }
+};
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/0919268c/lib/blackberry/plugin/qnx/capture.js
----------------------------------------------------------------------
diff --git a/lib/blackberry/plugin/qnx/capture.js b/lib/blackberry/plugin/qnx/capture.js
new file mode 100644
index 0000000..41c5de0
--- /dev/null
+++ b/lib/blackberry/plugin/qnx/capture.js
@@ -0,0 +1,76 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+
+var cordova = require('cordova');
+
+function capture(action, win, fail) {
+ var noop = function () {};
+
+ blackberry.invoke.card.invokeCamera(action, function (path) {
+ var sb = blackberry.io.sandbox;
+ blackberry.io.sandbox = false;
+ webkitRequestFileSystem(PERSISTENT, 1024, function (fs) {
+ fs.root.getFile(path, {}, function (fe) {
+ fe.file(function (file) {
+ file.fullPath = fe.fullPath;
+ win([file]);
+ blackberry.io.sandbox = sb;
+ }, fail);
+ }, fail);
+ }, fail);
+ }, noop, noop);
+}
+
+module.exports = {
+ getSupportedAudioModes: function (args, win, fail) {
+ return {"status": cordova.callbackStatus.OK, "message": []};
+ },
+ getSupportedImageModes: function (args, win, fail) {
+ return {"status": cordova.callbackStatus.OK, "message": []};
+ },
+ getSupportedVideoModes: function (args, win, fail) {
+ return {"status": cordova.callbackStatus.OK, "message": []};
+ },
+ captureImage: function (args, win, fail) {
+ if (args[0].limit > 0) {
+ capture("photo", win, fail);
+ }
+ else {
+ win([]);
+ }
+
+ return { "status" : cordova.callbackStatus.NO_RESULT, "message" : "WebWorks Is On It" };
+ },
+ captureVideo: function (args, win, fail) {
+ if (args[0].limit > 0) {
+ capture("video", win, fail);
+ }
+ else {
+ win([]);
+ }
+
+ return { "status" : cordova.callbackStatus.NO_RESULT, "message" : "WebWorks Is On It" };
+ },
+ captureAudio: function (args, win, fail) {
+ fail("Capturing Audio not supported");
+ return {"status": cordova.callbackStatus.NO_RESULT, "message": "WebWorks Is On It"};
+ }
+};