You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by fi...@apache.org on 2013/05/24 01:41:44 UTC
[23/38] updated android, ios,
bb libraries to 2.8.x branch. fixed a few assertions with project
changes. removed blackberry support until create script can be finalized.
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/88ad654c/lib/cordova-blackberry/bin/test/plugins/SplashScreen/index.js
----------------------------------------------------------------------
diff --git a/lib/cordova-blackberry/bin/test/plugins/SplashScreen/index.js b/lib/cordova-blackberry/bin/test/plugins/SplashScreen/index.js
new file mode 100644
index 0000000..658ce3d
--- /dev/null
+++ b/lib/cordova-blackberry/bin/test/plugins/SplashScreen/index.js
@@ -0,0 +1,82 @@
+/*
+* Copyright 2013 Research In Motion Limited.
+*
+* Licensed 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.
+*/
+describe("SplashScreen", function () {
+ var _apiDir = __dirname + "./../../../../plugins/SplashScreen/src/blackberry10/",
+ index,
+ mockedEnv = {
+ response: {
+ send: jasmine.createSpy()
+ }
+ },
+ mockedApplication = {
+ windowVisible: undefined
+ };
+
+ beforeEach(function () {
+ index = require(_apiDir + "index");
+ mockedEnv.response.send.reset();
+ });
+
+ afterEach(function () {
+ index = null;
+ delete require.cache[require.resolve(_apiDir + "index")];
+ });
+ describe("show", function () {
+ beforeEach(function () {
+ GLOBAL.PluginResult = function (args, env) {};
+ GLOBAL.PluginResult.prototype.error = jasmine.createSpy();
+ });
+
+ afterEach(function () {
+ delete GLOBAL.PluginResult;
+ });
+
+ it("calls PluginResult.error if show is called", function () {
+ index.show();
+
+ expect(PluginResult.prototype.error).toHaveBeenCalledWith("Not supported on platform", false);
+ });
+ });
+
+ describe("hide", function () {
+ beforeEach(function () {
+ GLOBAL.window = {
+ qnx: {
+ webplatform: {
+ getApplication: function () {
+ return mockedApplication;
+ }
+ }
+ }
+ };
+
+ GLOBAL.PluginResult = function (args, env) {};
+ GLOBAL.PluginResult.prototype.ok = jasmine.createSpy();
+ });
+
+ afterEach(function () {
+ delete GLOBAL.window;
+ delete GLOBAL.PluginResult;
+ });
+
+ it("calls PluginResult.ok if hide is called", function () {
+ index.hide();
+
+ expect(mockedApplication.windowVisible).toBeTruthy();
+ expect(PluginResult.prototype.ok).toHaveBeenCalledWith(undefined, false);
+ });
+ });
+});
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/88ad654c/lib/cordova-blackberry/build.xml
----------------------------------------------------------------------
diff --git a/lib/cordova-blackberry/build.xml b/lib/cordova-blackberry/build.xml
deleted file mode 100644
index dcddbb6..0000000
--- a/lib/cordova-blackberry/build.xml
+++ /dev/null
@@ -1,342 +0,0 @@
-<project name="Create & Update a Cordova BlackBerry WebWorks Project" default="help">
-<!--
- 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.
--->
- <!-- LOAD VERSION -->
-
- <loadfile property="version" srcFile="VERSION">
- <filterchain>
- <striplinebreaks/>
- </filterchain>
- </loadfile>
-
- <!-- LOAD PROPERTIES -->
-
- <property name="template.project.dir" location="bin/templates/project" />
- <property name="template.dist.dir" location="bin/templates/dist" />
-
- <property name="build.dir" location="build" />
- <property name="update.dir" value="lib/cordova.${version}" />
-
- <property name="dist.path" location="dist" />
- <property name="dist.www.path" location="${dist.path}/www" />
- <property name="dist.project.path" location="${dist.path}/sample" />
-
- <property name="jar.src" location="framework/ext/src" />
- <property name="jar.path" value="ext" />
- <property name="jar.basename" value="cordova.${version}.jar" />
- <property name="jar.file" value="${jar.path}/${jar.basename}" />
-
- <property name="playbook.js.path" value="javascript/playbook" />
- <property name="playbook.ext.src" location="framework/ext-air" />
- <property name="playbook.ext.path" value="ext-air" />
-
- <property name="qnx.js.path" value="javascript/qnx" />
- <property name="qnx.ext.src" location="framework/ext-qnx" />
- <property name="qnx.ext.path" value="ext-qnx" />
-
- <property name="js.src" location="javascript" />
- <property name="js.path" value="javascript" />
- <property name="js.basename" value="cordova-${version}.js" />
- <property name="js.file" value="${js.path}/${js.basename}" />
-
- <!-- BUILD JAVASCRIPT -->
-
- <target name="build-javascript">
- <!-- BB Javascript -->
- <mkdir dir="${build.dir}/${js.path}" />
- <copy file="${js.src}/cordova.blackberry.js" tofile="${build.dir}/${js.file}" />
- </target>
-
- <!-- BUILD BLACKBERRY EXTENSION -->
-
- <target name="build-bb-extension">
- <mkdir dir="${build.dir}/${jar.path}" />
-
- <zip destfile="${build.dir}/${jar.file}">
- <fileset dir="${jar.src}" includes="library.xml" />
- <fileset dir="${jar.src}" includes="**/*.java" />
- </zip>
- </target>
-
- <!-- BUILD PLAYBOOK EXTENSION -->
-
- <target name="build-pb-extension">
-
- <!-- Copy Ext -->
- <mkdir dir="${build.dir}/${playbook.ext.path}" />
- <copy todir="${build.dir}/${playbook.ext.path}">
- <fileset dir="${playbook.ext.src}" />
- </copy>
- </target>
-
- <!-- BUILD QNX EXTENSION -->
-
- <target name="build-qnx-extension">
-
- <!-- Copy Ext -->
- <mkdir dir="${build.dir}/${qnx.ext.path}" />
- <copy todir="${build.dir}/${qnx.ext.path}">
- <fileset dir="${qnx.ext.src}" />
- </copy>
- </target>
-
- <!-- CREATE A PROJECT -->
- <target name="create" depends="clean, build-javascript, build-bb-extension, build-pb-extension, build-qnx-extension">
- <fail unless="project.path" message="You must give a project PATH. Use the argument -Dproject.path="C:\dev\my_project"" />
-
- <available file="${project.path}" property="project.exists" />
- <fail if="project.exists" message="The project path must be an empty directory." />
-
- <!-- create project using template directory -->
- <mkdir dir="${project.path}" />
- <copy todir="${project.path}">
- <fileset dir="${template.project.dir}" />
- </copy>
-
- <!-- change file permission for cordova scripts because ant copy doesn't preserve file permissions -->
- <chmod dir="${project.path}/cordova" perm="700" includes="*"/>
-
- <!-- update project files to reference cordova.x.x.x.js -->
- <replaceregexp match="cordova\.js" replace="${js.basename}" byline="true">
- <fileset file="${project.path}/www/index.html" />
- <fileset file="${project.path}/build.xml" />
- </replaceregexp>
-
- <!-- copy cordova.js -->
- <copy todir="${project.path}/www">
- <fileset dir="${build.dir}/${js.path}" />
- </copy>
-
- <!-- copy ext/ -->
- <copy todir="${project.path}/www/ext">
- <fileset dir="${build.dir}/${jar.path}" />
- </copy>
-
- <!-- copy ext-air/ -->
- <copy todir="${project.path}/www/ext-air">
- <fileset dir="${build.dir}/${playbook.ext.path}" />
- </copy>
-
- <!-- copy ext-qnx/ -->
- <copy todir="${project.path}/www/ext-qnx">
- <fileset dir="${build.dir}/${qnx.ext.path}" />
- </copy>
-
- <!-- save release -->
- <mkdir dir="${project.path}/${update.dir}" />
- <copy todir="${project.path}/${update.dir}">
- <fileset dir="${build.dir}" />
- </copy>
-
- <echo>
-Project Creation Complete!
-==========================
-
-Getting Started:
-----------------
-
- cd ${project.path}
-
- ant help
- </echo>
- </target>
-
- <!-- DISTRIBUTION -->
- <target name="dist" depends="">
- <!-- create a sample project -->
- <antcall target="create">
- <param name="project.path" value="${dist.project.path}" />
- </antcall>
-
- <!-- copy dist template (README.md) -->
- <copy todir="${dist.path}">
- <fileset dir="${template.dist.dir}" />
- </copy>
-
- <!-- change file permission for cordova scripts because ant copy doesn't preserve file permissions -->
- <chmod dir="${dist.path}/sample/cordova" perm="700" includes="*" />
-
- <!-- copy cordova.jar -->
- <copy todir="${dist.www.path}/ext">
- <fileset dir="${build.dir}/${jar.path}" />
- </copy>
-
- <!-- copy ext-air/ -->
- <copy todir="${dist.www.path}/ext-air">
- <fileset dir="${build.dir}/${playbook.ext.path}" />
- </copy>
-
- <!-- copy ext-qnx/ -->
- <copy todir="${dist.www.path}/ext-qnx">
- <fileset dir="${build.dir}/${qnx.ext.path}" />
- </copy>
-
- <!-- copy cordova.js -->
- <copy todir="${dist.www.path}">
- <fileset dir="${build.dir}/${js.path}" />
- </copy>
-
- <!-- copy config.xml -->
- <copy todir="${dist.www.path}">
- <fileset file="${template.project.dir}/www/config.xml" />
- </copy>
-
- <!-- copy plugins.xml -->
- <copy todir="${dist.www.path}">
- <fileset file="${template.project.dir}/www/plugins.xml" />
- </copy>
-
- <!-- update config.xml to have a default name-->
- <replace file="${dist.project.path}/www/config.xml" token="__NAME__" value="cordovaExample"/>
- <replace file="${dist.project.path}/www/config.xml" token="__PACKAGE__" value="org.apache.cordova.example"/>
- <echo>
-Distribution Complete!
-======================
-
-Version:
---------
-
- ${version}
-
-Path:
------
-
- ${dist.path}
- </echo>
- </target>
-
- <target name="version">
- <replace dir="." token="${version}" value="${value}" />
-
- <echo>
-Version Update Complete!
-========================
-
-Version:
---------
-
- Previous: ${version}
- Current: ${value}
-
-Remember to:
-------------
-
- Review and commit the version update.
-
- $ git diff
- $ git commit -am "Update to version ${value}"
- $ git tag ${value}
- </echo>
- </target>
-
- <!-- UPDATE A PROJECT -->
-
- <target name="update" depends="clean, build-javascript, build-bb-extension, build-pb-extension, build-qnx-extension">
- <fail unless="project.path" message="You must give a project PATH. Use the argument -Dproject.path="C:\dev\my_project"" />
-
- <available file="${project.path}" property="project.exists" />
- <fail unless="project.exists" message="The project path cannot be empty." />
-
- <!-- save release -->
- <mkdir dir="${project.path}/${update.dir}" />
- <copy todir="${project.path}/${update.dir}">
- <fileset dir="${build.dir}" />
- </copy>
-
- <echo>
-Update complete!
-================
-
- Cordova ${version} has been created.
-
- Update does not alter your project files.
-
- See below for instructions to install Cordova ${version}.
-
-Where:
-------
-
- ${project.path}/${update.dir}
-
-Install:
---------
-
- 1. Install the Java Extension:
-
- - delete /www/${jar.path}/cordova.jar
-
- - copy /${update.dir}/${jar.file}
- to /www/${jar.file}
-
- 2. Install the JavaScript library:
-
- - delete /www/cordova.js
-
- - copy /${update.dir}/${js.file}
- to /www/${js.basename}
-
- 3. Update JavaScript references:
-
- - <script type="text/javascript" src="${js.basename}"></script>
- </echo>
- </target>
-
- <!-- CLEAN -->
-
- <target name="clean">
- <delete dir="${build.dir}" />
- <delete dir="${dist.path}" />
- </target>
-
- <!-- HELP -->
-
- <target name="help">
- <echo>
-NAME
- ${ant.project.name}
-
-SYNOPSIS
- ant COMMAND [-D<argument>=<value>]...
-
-DESCRIPTION
- This tool allows you to create and update Cordova-BlackBerry-WebWorks projects.
- You will want to run update after you have updated the framework source.
- In other words, when you <git pull origin master>.
-
-COMMANDS
- help ............ Show this help menu.
- ant, ant help
-
- create .......... Create a new project
- ant create PATH
- ant create -Dproject.path="C:\dev\my_project"
-
- update .......... Update an existing project
- ant update PATH
- ant update -Dproject.path="C:\dev\my_project"
-
- dist ............ Create a Cordova distribution build
- ant dist
-
- version ......... Update Cordova version
- ant version VERSION
- ant version -Dvalue="1.0.0"
- </echo>
- </target>
-</project>
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/88ad654c/lib/cordova-blackberry/framework/bootstrap/index.html
----------------------------------------------------------------------
diff --git a/lib/cordova-blackberry/framework/bootstrap/index.html b/lib/cordova-blackberry/framework/bootstrap/index.html
new file mode 100644
index 0000000..6e3b028
--- /dev/null
+++ b/lib/cordova-blackberry/framework/bootstrap/index.html
@@ -0,0 +1,23 @@
+<!DOCTYPE HTML>
+<html lang="en">
+ <head>
+ <meta charset="utf-8">
+ <meta name="viewport" content="user-scalable=no, target-densitydpi=device-dpi, width=device-width">
+ <title>WebWorks For BB10 Bootstrap</title>
+ <script src="./require.js"></script>
+ <script src="platform:///webplatform.js"></script>
+ <script src="./frameworkModules.js"></script>
+ <script>
+ function start() {
+ //Must load jnext first, as there seemed to be a race condition for if it was defined before it was used
+ require("lib/jnext.js");
+ require(frameworkModules, function () {
+ require('lib/framework').start();
+ });
+ }
+ </script>
+ </head>
+ <body onload="start();">
+ I am the man behind the curtain.
+ </body>
+</html>
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/88ad654c/lib/cordova-blackberry/framework/bootstrap/require.js
----------------------------------------------------------------------
diff --git a/lib/cordova-blackberry/framework/bootstrap/require.js b/lib/cordova-blackberry/framework/bootstrap/require.js
new file mode 100644
index 0000000..a68bfcc
--- /dev/null
+++ b/lib/cordova-blackberry/framework/bootstrap/require.js
@@ -0,0 +1,251 @@
+/*
+ * Copyright 2012 Research In Motion Limited.
+ *
+ * Licensed 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 define,
+ require;
+
+(function () {
+ var unpreparedModules = {},
+ readyModules = {},
+ ACCEPTABLE_EXTENSIONS = [".js", ".json"],
+ DEFAULT_EXTENSION = ".js";
+
+ function hasValidExtension(moduleName) {
+ return ACCEPTABLE_EXTENSIONS.some(function (element, index, array) {
+ return moduleName.match("\\" + element + "$");
+ });
+ }
+
+
+ function normalizeName(originalName, baseName) {
+ var nameParts,
+ name = originalName.slice(0);
+ //remove ^local:// (if it exists) and .js$
+ //This will not work for local:// without a trailing js
+ name = name.replace(/(?:^local:\/\/)/, "");
+ if (name.charAt(0) === '.' && baseName) {
+ //Split the baseName and remove the final part (the module name)
+ nameParts = baseName.split('/');
+ nameParts.pop();
+ nameParts = nameParts.concat(name.split('/'));
+
+ name = nameParts.reduce(function (previous, current, index, array) {
+ var returnValue,
+ slashIndex;
+
+ //If previous is a dot, ignore it
+ //If previous is ever just .. we're screwed anyway
+ if (previous !== '.') {
+ returnValue = previous;
+ }
+
+ //If we have a .. then remove a chunk of previous
+ if (current === "..") {
+ slashIndex = previous.lastIndexOf('/');
+ //If there's no slash we're either screwed or we remove the final token
+ if (slashIndex !== -1) {
+ returnValue = previous.slice(0, previous.lastIndexOf('/'));
+ } else {
+ returnValue = "";
+ }
+ } else if (current !== '.') {
+ //Otherwise simply append anything not a .
+ //Only append a slash if we're not empty
+ if (returnValue.length) {
+ returnValue += "/";
+ }
+ returnValue += current;
+ }
+
+ return returnValue;
+ });
+
+ }
+
+ //If there is no acceptable extension tack on a .js
+ if (!hasValidExtension(name)) {
+ name = name + DEFAULT_EXTENSION;
+ }
+
+ return name;
+ }
+
+ function buildModule(name, dependencies, factory) {
+ var module = {exports: {}},
+ localRequire = function (moduleName) {
+ return require(moduleName, name);
+ },
+ args = [];
+ localRequire.toUrl = function (moduleName, baseName) {
+ return require.toUrl(moduleName, baseName || name);
+ };
+ dependencies.forEach(function (dependency) {
+ if (dependency === 'require') {
+ args.push(localRequire);
+ } else if (dependency === 'exports') {
+ args.push(module.exports);
+ } else if (dependency === 'module') {
+ args.push(module);
+ } else {
+ //This is because jshint cannot handle out of order functions
+ /*global loadModule:false */
+ args.push(loadModule(dependency));
+ /*global loadModule:true */
+ }
+ });
+
+ //No need to process dependencies, webworks only has require, exports, module
+ factory.apply(this, args);
+
+ //For full AMD we would need logic to also check the return value
+ return module.exports;
+
+ }
+
+ function getDefineString(moduleName, body) {
+ var evalString = 'define("' + moduleName + '", function (require, exports, module) {',
+ isJson = /\.json$/.test(moduleName);
+
+ evalString += isJson ? ' module.exports = ' : '';
+ evalString += body.replace(/^\s+|\s+$/g, '');
+ evalString += isJson ? ' ;' : '';
+ evalString += '});';
+
+ return evalString;
+ }
+
+ function loadModule(name, baseName) {
+ var normalizedName = normalizeName(name, baseName),
+ url,
+ xhr,
+ loadResult;
+ //Always check undefined first, this allows the user to redefine modules
+ //(Not used in WebWorks, although it is used in our unit tests)
+ if (unpreparedModules[normalizedName]) {
+ readyModules[normalizedName] = buildModule(normalizedName, unpreparedModules[normalizedName].dependencies, unpreparedModules[normalizedName].factory);
+ delete unpreparedModules[normalizedName];
+ }
+
+ //If the module does not exist, load the module from external source
+ //Webworks currently only loads APIs from across bridge
+ if (!readyModules[normalizedName]) {
+ //If the module to be loaded ends in .js then we will define it
+ //Also if baseName exists than we have a local require situation
+ if (hasValidExtension(name) || baseName) {
+ xhr = new XMLHttpRequest();
+ url = name;
+ //If the module to be loaded starts with local:// go over the bridge
+ //Else If the module to be loaded is a relative load it may not have .js extension which is needed
+ if (/^local:\/\//.test(name)) {
+ url = "http://localhost:8472/extensions/load/" + normalizedName.replace(/(?:^ext\/)(.+)(?:\/client.js$)/, "$1");
+
+ xhr.open("GET", url, false);
+ xhr.send(null);
+ try {
+ loadResult = JSON.parse(xhr.responseText);
+
+ loadResult.dependencies.forEach(function (dep) {
+ /*jshint evil:true */
+ eval(getDefineString(dep.moduleName, dep.body));
+ /*jshint evil:false */
+ });
+
+ //Trimming responseText to remove EOF chars
+ /*jshint evil:true */
+ eval(getDefineString(normalizedName, loadResult.client));
+ /*jshint evil:false */
+ } catch (err1) {
+ err1.message += ' in ' + url;
+ throw err1;
+ }
+ } else {
+ if (baseName) {
+ url = normalizedName;
+ }
+
+ xhr.open("GET", url, false);
+ xhr.send(null);
+ try {
+ //Trimming responseText to remove EOF chars
+ /*jshint evil:true */
+ eval(getDefineString(normalizedName, xhr.responseText));
+ /*jshint evil:false */
+ } catch (err) {
+ err.message += ' in ' + url;
+ throw err;
+ }
+ }
+
+ if (unpreparedModules[normalizedName]) {
+ readyModules[normalizedName] = buildModule(normalizedName, unpreparedModules[normalizedName].dependencies, unpreparedModules[normalizedName].factory);
+ delete unpreparedModules[normalizedName];
+ }
+ } else {
+ throw "module " + name + " cannot be found";
+ }
+
+ }
+
+ return readyModules[normalizedName];
+
+ }
+
+ //Use the AMD signature incase we ever want to change.
+ //For now we will only be using (name, baseName)
+ require = function (dependencies, callback) {
+ if (typeof dependencies === "string") {
+ //dependencies is the module name and callback is the relName
+ //relName is not part of the AMDJS spec, but we use it from localRequire
+ return loadModule(dependencies, callback);
+ } else if (Array.isArray(dependencies) && typeof callback === 'function') {
+ //Call it Asynchronously
+ setTimeout(function () {
+ buildModule(undefined, dependencies, callback);
+ }, 0);
+ }
+ };
+
+ require.toUrl = function (originalName, baseName) {
+ return normalizeName(originalName, baseName);
+ };
+
+ //Use the AMD signature incase we ever want to change.
+ //For now webworks will only be using (name, factory) signature.
+ define = function (name, dependencies, factory) {
+ if (typeof name === "string" && typeof dependencies === 'function') {
+ factory = dependencies;
+ dependencies = ['require', 'exports', 'module'];
+ }
+
+ //According to the AMDJS spec we should parse out the require statments
+ //from factory.toString and add those to the list of dependencies
+
+ //Normalize the name. Remove local:// and .js
+ name = normalizeName(name);
+ unpreparedModules[name] = {
+ dependencies: dependencies,
+ factory: factory
+ };
+ };
+}());
+
+//Export for use in node for unit tests
+if (typeof module === "object" && typeof require === "function") {
+ module.exports = {
+ require: require,
+ define: define
+ };
+}
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/88ad654c/lib/cordova-blackberry/framework/bootstrap/ui.html
----------------------------------------------------------------------
diff --git a/lib/cordova-blackberry/framework/bootstrap/ui.html b/lib/cordova-blackberry/framework/bootstrap/ui.html
new file mode 100644
index 0000000..98c94a0
--- /dev/null
+++ b/lib/cordova-blackberry/framework/bootstrap/ui.html
@@ -0,0 +1,73 @@
+<!-- Copyright 2012 Research In Motion Limited.
+
+ Licensed 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.
+
+ -->
+<!DOCTYPE HTML>
+<html lang="en">
+ <head>
+ <meta charset="utf-8">
+ <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1, maximum-scale=1">
+ <title>Overlay WebView</title>
+ <link rel="stylesheet" href="platform:///ui-resources/styles/styles.css" type="text/css" media="screen" charset="utf-8">
+
+ <script src="../chrome/require.js" type="text/javascript"></script>
+ <script src="platform:///webplatform.js" type="text/javascript"></script>
+ <script src="platform:///i18n.js" type="text/javascript"></script>
+ <script src="platform:///ui-resources/index.js" type="text/javascript"></script>
+ </head>
+ <body>
+
+ <div id="contextMenuModal" style="display:none;"></div>
+<div id="contextMenu" class="hideMenu">
+ <div id="contextMenuHeader">
+ <div id="contextMenuHeadText"></div>
+ <div id="contextMenuSubheadText"></div>
+ </div>
+ <div id="contextMenuContent"></div>
+ <div id="contextMenuHandle"></div>
+ <div id="contextMenuDelete"></div>
+</div>
+
+ <div id="dialog" class="hidden">
+ <div class="dialog-top-third">
+ <div id="dialog-panel">
+ </div>
+ </div>
+ <div class="dialog-bottom-two-thirds">
+ </div>
+</div>
+
+ <div id="invocationlist" class="screenInner screenSlide removed">
+ <div id="cancelTitlebar"></div>
+ <div id="invocationListContent" class="targetList"></div>
+ <div id="targetLoader">
+ <div id="targetLoaderActivity" class="activityIndicator"></div>
+ </div>
+</div>
+
+ <div id="toaster" class="toaster"></div>
+
+
+ <div id="childwebviewcontrols"></div>
+
+ <div id="formcontrolPanel">
+ <div id="formcontrol">
+ <button id="formcontrol_previous"/>
+ <button id="formcontrol_next"/>
+ <button id="formcontrol_submit"/>
+ </div>
+ </div>
+
+ </body>
+</html>
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/88ad654c/lib/cordova-blackberry/framework/ext-air/Cordova_Network/library.xml
----------------------------------------------------------------------
diff --git a/lib/cordova-blackberry/framework/ext-air/Cordova_Network/library.xml b/lib/cordova-blackberry/framework/ext-air/Cordova_Network/library.xml
deleted file mode 100644
index c1835b4..0000000
--- a/lib/cordova-blackberry/framework/ext-air/Cordova_Network/library.xml
+++ /dev/null
@@ -1,40 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- 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.
--->
-<library isWhitelist="true">
- <extension>
- <entryClass>org.apache.cordova.network.Network</entryClass>
- </extension>
-
- <platforms>
- <platform value="AIR">
- <target version="default" config="AIR_XHR" />
- </platform>
- </platforms>
-
- <configurations>
- <configuration name="AIR_XHR" version="1.0" comment="For XHR architecture for Java implementation">
- <src type="text/actionscript" path="src" comment="ActionScript implementation" />
- </configuration>
- </configurations>
-
- <features>
- <feature id="org.apache.cordova" version="1.0.0" />
- </features>
-</library>
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/88ad654c/lib/cordova-blackberry/framework/ext-air/Cordova_Network/src/org/apache/cordova/network/Network.as
----------------------------------------------------------------------
diff --git a/lib/cordova-blackberry/framework/ext-air/Cordova_Network/src/org/apache/cordova/network/Network.as b/lib/cordova-blackberry/framework/ext-air/Cordova_Network/src/org/apache/cordova/network/Network.as
deleted file mode 100644
index d2ad030..0000000
--- a/lib/cordova-blackberry/framework/ext-air/Cordova_Network/src/org/apache/cordova/network/Network.as
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * 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.
- *
- * Copyright (c) 2011, Research In Motion Limited.
- */
-
-
-package org.apache.cordova.network {
- import flash.net.NetworkInfo;
- import flash.net.NetworkInterface;
- import flash.events.Event;
- import qnx.system.Device;
-
- import webworks.extension.DefaultExtension;
-
- public class Network extends DefaultExtension{
-
- private var _jsFunctionCallbackIDs:Array = [];
- private const FEATURE_ID:Array = [ "org.apache.cordova" ];
-
- public function Network() {
- //Attach event listener once only
- NetworkInfo.networkInfo.addEventListener(flash.events.Event.NETWORK_CHANGE, networkChange);
- }
-
- override public function getFeatureList():Array {
- return FEATURE_ID;
- }
-
- public function getConnectionInfo(param:String):void{
- if(_jsFunctionCallbackIDs.indexOf(param) < 0){
- _jsFunctionCallbackIDs.push(param);
- }
- }
-
- public function getDeviceInfo(id:String):void{
- evalJavaScriptEvent(id, [{
- "uuid" : Device.device.pin,
- "version": Device.device.scmBundle
- }]);
- }
-
- private function networkChange( event: Event ) : void {
-
- /**
- * Right now, we only care if there is a connection or not, since PlayBook only has WiFi
- * At the JS layer, we will map this from offline/online.
- * At some point in the future where there are more connection types on PlayBook,
- * we will want to attempt to map this to the real Cordova connection types...
- */
-
- var haveCoverage : Boolean = false;
- var networkStatus : String = "offline";
- var connectionType = "none";
-
- NetworkInfo.networkInfo.findInterfaces().some(
- function callback(item:NetworkInterface, index:int, vector:Vector.<NetworkInterface>):Boolean {
- this.webView.executeJavaScript("alert('Network Interface ' + item.name)");
- haveCoverage = item.active || haveCoverage;
- return haveCoverage;
- }, this);
-
- if (haveCoverage) {
- networkStatus = "online";
- connectionType = "wifi";
- }
-
- for (var i:Number=0; i<_jsFunctionCallbackIDs.length ; i++){
- evalJavaScriptEvent(_jsFunctionCallbackIDs[i], [{"type" : connectionType, "event" : networkStatus }] );
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/88ad654c/lib/cordova-blackberry/framework/ext-qnx/org.apache.cordova/client.js
----------------------------------------------------------------------
diff --git a/lib/cordova-blackberry/framework/ext-qnx/org.apache.cordova/client.js b/lib/cordova-blackberry/framework/ext-qnx/org.apache.cordova/client.js
deleted file mode 100644
index f8308b8..0000000
--- a/lib/cordova-blackberry/framework/ext-qnx/org.apache.cordova/client.js
+++ /dev/null
@@ -1,16 +0,0 @@
-/*
- * Copyright 2010-2011 Research In Motion Limited.
- *
- * Licensed 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.
- */
-
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/88ad654c/lib/cordova-blackberry/framework/ext-qnx/org.apache.cordova/index.js
----------------------------------------------------------------------
diff --git a/lib/cordova-blackberry/framework/ext-qnx/org.apache.cordova/index.js b/lib/cordova-blackberry/framework/ext-qnx/org.apache.cordova/index.js
deleted file mode 100644
index 4a60b93..0000000
--- a/lib/cordova-blackberry/framework/ext-qnx/org.apache.cordova/index.js
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright 2010-2011 Research In Motion Limited.
- *
- * Licensed 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 Whitelist = require("../../lib/policy/whitelist").Whitelist,
- whitelist = new Whitelist(),
- noop = function () {};
-
-module.exports = {
- isWhitelisted: function (success, fail, args) {
- var url = JSON.parse(decodeURIComponent(args[0])),
- success = success || noop,
- fail = fail || noop;
-
- if (url) {
- success(whitelist.isAccessAllowed(url));
- }
- else {
- error("please provide an url");
- }
- }
-};
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/88ad654c/lib/cordova-blackberry/framework/ext-qnx/org.apache.cordova/manifest.json
----------------------------------------------------------------------
diff --git a/lib/cordova-blackberry/framework/ext-qnx/org.apache.cordova/manifest.json b/lib/cordova-blackberry/framework/ext-qnx/org.apache.cordova/manifest.json
deleted file mode 100644
index 9efdda2..0000000
--- a/lib/cordova-blackberry/framework/ext-qnx/org.apache.cordova/manifest.json
+++ /dev/null
@@ -1,5 +0,0 @@
-{
- "global": false,
- "namespace": "org.apache.cordova",
- "dependencies": []
-}
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/88ad654c/lib/cordova-blackberry/framework/ext-qnx/readme.md
----------------------------------------------------------------------
diff --git a/lib/cordova-blackberry/framework/ext-qnx/readme.md b/lib/cordova-blackberry/framework/ext-qnx/readme.md
deleted file mode 100644
index 6527192..0000000
--- a/lib/cordova-blackberry/framework/ext-qnx/readme.md
+++ /dev/null
@@ -1 +0,0 @@
-Placeholder for native extensions needed on qnx
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/88ad654c/lib/cordova-blackberry/framework/ext/.classpath
----------------------------------------------------------------------
diff --git a/lib/cordova-blackberry/framework/ext/.classpath b/lib/cordova-blackberry/framework/ext/.classpath
deleted file mode 100644
index 8d3a567..0000000
--- a/lib/cordova-blackberry/framework/ext/.classpath
+++ /dev/null
@@ -1,7 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry kind="src" path="src"/>
- <classpathentry kind="src" path="res"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/net.rim.ejde.BlackBerryVMInstallType/BlackBerry JRE 5.0.0"/>
- <classpathentry kind="output" path="bin"/>
-</classpath>
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/88ad654c/lib/cordova-blackberry/framework/ext/.project
----------------------------------------------------------------------
diff --git a/lib/cordova-blackberry/framework/ext/.project b/lib/cordova-blackberry/framework/ext/.project
deleted file mode 100644
index ecbf8d5..0000000
--- a/lib/cordova-blackberry/framework/ext/.project
+++ /dev/null
@@ -1,29 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>CordovaExtension</name>
- <comment></comment>
- <projects>
- </projects>
- <buildSpec>
- <buildCommand>
- <name>net.rim.ejde.internal.builder.BlackBerryPreprocessBuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>net.rim.ejde.internal.builder.BlackBerryResourcesBuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.jdt.core.javabuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>net.rim.ejde.BlackBerryPreProcessNature</nature>
- <nature>net.rim.ejde.BlackBerryProjectCoreNature</nature>
- <nature>org.eclipse.jdt.core.javanature</nature>
- </natures>
-</projectDescription>
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/88ad654c/lib/cordova-blackberry/framework/ext/.settings/net.rim.browser.tools.debug.widget.prefs
----------------------------------------------------------------------
diff --git a/lib/cordova-blackberry/framework/ext/.settings/net.rim.browser.tools.debug.widget.prefs b/lib/cordova-blackberry/framework/ext/.settings/net.rim.browser.tools.debug.widget.prefs
deleted file mode 100644
index 524fddd..0000000
--- a/lib/cordova-blackberry/framework/ext/.settings/net.rim.browser.tools.debug.widget.prefs
+++ /dev/null
@@ -1,3 +0,0 @@
-#Sun May 23 23:01:24 PDT 2010
-eclipse.preferences.version=1
-outputfolder=build
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/88ad654c/lib/cordova-blackberry/framework/ext/.settings/org.eclipse.jdt.core.prefs
----------------------------------------------------------------------
diff --git a/lib/cordova-blackberry/framework/ext/.settings/org.eclipse.jdt.core.prefs b/lib/cordova-blackberry/framework/ext/.settings/org.eclipse.jdt.core.prefs
deleted file mode 100644
index be7e57d..0000000
--- a/lib/cordova-blackberry/framework/ext/.settings/org.eclipse.jdt.core.prefs
+++ /dev/null
@@ -1,12 +0,0 @@
-#Sun May 23 23:00:44 PDT 2010
-eclipse.preferences.version=1
-org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=disabled
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2
-org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
-org.eclipse.jdt.core.compiler.compliance=1.4
-org.eclipse.jdt.core.compiler.debug.lineNumber=generate
-org.eclipse.jdt.core.compiler.debug.localVariable=generate
-org.eclipse.jdt.core.compiler.debug.sourceFile=generate
-org.eclipse.jdt.core.compiler.problem.assertIdentifier=ignore
-org.eclipse.jdt.core.compiler.problem.enumIdentifier=ignore
-org.eclipse.jdt.core.compiler.source=1.3
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/88ad654c/lib/cordova-blackberry/framework/ext/BlackBerry_App_Descriptor.xml
----------------------------------------------------------------------
diff --git a/lib/cordova-blackberry/framework/ext/BlackBerry_App_Descriptor.xml b/lib/cordova-blackberry/framework/ext/BlackBerry_App_Descriptor.xml
deleted file mode 100644
index bb973e8..0000000
--- a/lib/cordova-blackberry/framework/ext/BlackBerry_App_Descriptor.xml
+++ /dev/null
@@ -1,36 +0,0 @@
-<Properties ModelVersion="1.1.2">
-<!--
- 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.
--->
- <General Title="" Version="1.0.0" Vendor="BlackBerry Developer" Description=""/>
- <Application Type="BlackBerry Application" MainMIDletName="" MainArgs="" HomeScreenPosition="0" StartupTier="7" IsSystemModule="false" IsAutostartup="false"/>
- <Resources hasTitleResource="false" TitleResourceBundleName="" TitleResourceBundleRelativePath="" TitleResourceBundleClassName="" TitleResourceBundleKey="" DescriptionId="">
- <Icons/>
- </Resources>
- <Compile OutputCompilerMessages="false" ConvertImages="false" CreateWarningForNoExportedRoutine="true" CompressResources="false" AliasList="">
- <PreprocessorDefines/>
- </Compile>
- <Packaging OutputFileName="Cordova" OutputFolder="deliverables" PreBuildStep="" PostBuildStep="" CleanStep="" GenerateALXFile="false">
- <AlxFiles/>
- </Packaging>
- <HiddenProperties>
- <ClassProtection/>
- <PackageProtection/>
- </HiddenProperties>
- <AlternateEntryPoints/>
-</Properties>
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/88ad654c/lib/cordova-blackberry/framework/ext/src/library.xml
----------------------------------------------------------------------
diff --git a/lib/cordova-blackberry/framework/ext/src/library.xml b/lib/cordova-blackberry/framework/ext/src/library.xml
deleted file mode 100644
index d408e9f..0000000
--- a/lib/cordova-blackberry/framework/ext/src/library.xml
+++ /dev/null
@@ -1,35 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- 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.
--->
-<library>
- <extension>
- <entryClass>org.apache.cordova.CordovaExtension</entryClass>
- </extension>
- <features>
- <feature id="org.apache.cordova" version="1.0.0">Cordova JavaScript Extension</feature>
- <feature id="blackberry.connection" version="1.0.0">Stub in for backwards bb10 support</feature>
- <feature id="blackberry.io" version="1.0.0">Stub in for backwards bb10 support</feature>
- <feature id="blackberry.invoked" version="1.0.0">Stub in for backwards bb10 support</feature>
- <feature id="blackberry.invoke.card" version="1.0.0">Stub in for backwards bb10 support</feature>
- <feature id="blackberry.ui.contextmenu" version="1.0.0">Stub in for backwards bb10 support</feature>
- <feature id="blackberry.io.filetransfer" version="1.0.0">Stub in for backwards bb10 support</feature>
- <feature id="blackberry.pim.contacts" version="1.0.0">Stub in for backwards bb10 support</feature>
- <feature id="blackberry.bbm.platform" version="1.0.0">Stub in for backwards bb10 support</feature>
- </features>
-</library>
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/88ad654c/lib/cordova-blackberry/framework/ext/src/org/apache/cordova/CordovaExtension.java
----------------------------------------------------------------------
diff --git a/lib/cordova-blackberry/framework/ext/src/org/apache/cordova/CordovaExtension.java b/lib/cordova-blackberry/framework/ext/src/org/apache/cordova/CordovaExtension.java
deleted file mode 100644
index 62943b4..0000000
--- a/lib/cordova-blackberry/framework/ext/src/org/apache/cordova/CordovaExtension.java
+++ /dev/null
@@ -1,208 +0,0 @@
-/*
- * 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.
- *
- * Copyright (c) 2011, Research In Motion Limited.
- */
-package org.apache.cordova;
-
-import net.rim.device.api.browser.field2.BrowserField;
-import net.rim.device.api.script.ScriptEngine;
-import net.rim.device.api.system.Application;
-import net.rim.device.api.web.WidgetConfig;
-import net.rim.device.api.web.WidgetExtension;
-import net.rim.device.api.xml.parsers.DocumentBuilderFactory;
-
-import org.apache.cordova.api.PluginManager;
-import org.apache.cordova.api.PluginResult;
-import org.apache.cordova.notification.Notification;
-import org.apache.cordova.util.Log;
-import org.apache.cordova.util.Logger;
-import org.w3c.dom.Document;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-import java.lang.ref.WeakReference;
-
-/**
- * CordovaExtension is a BlackBerry WebWorks JavaScript extension. It
- * represents a single feature that can be used to access device capabilities.
- */
-public final class CordovaExtension implements WidgetExtension {
-
- // Weak reference encapsulating BrowserField object used to display the application
- // We use the weak reference because keeping a direct reference can
- // cause memory leak issues in WebWorks. Original solution described
- // and suggested by Tim Neil on the BlackBerry support forums.
- // Thanks Tim!
- protected static WeakReference browser = null;
-
- // Browser script engine
- //
- protected static ScriptEngine script;
-
- // Application name
- //
- protected static String appName;
-
- // Application GUID
- //
- protected static long appID;
-
- // Plugin Manager
- //
- protected PluginManager pluginManager;
-
- // Feature ID
- //
- private static final String FEATURE_ID ="org.apache.cordova";
-
- // Called when the BlackBerry Widget references this extension for the first time.
- // It provides a list of feature IDs exposed by this extension.
- //
- public String[] getFeatureList() {
- return new String[] {FEATURE_ID};
- }
-
- // Called whenever a widget loads a resource that requires a feature ID that is supplied
- // in the getFeatureList
- //
- public void loadFeature(String feature, String version, Document doc,
- ScriptEngine scriptEngine) throws Exception {
- script = scriptEngine;
- // Not sure why logger is not already enabled?
- Logger.enableLogging();
- if (feature.equals(FEATURE_ID)) {
- pluginManager = new PluginManager(this);
-
- // create and parse the plugins.xml
- Document c = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(Application.class.getResourceAsStream("/plugins.xml"));
-
- NodeList plugins = c.getElementsByTagName("plugin");
- if (plugins.getLength() == 0) {
- Logger.warn("If you are using any Cordova APIs you will need to "+
- "specify them in the config.xml using <gap:plugin name=\"MyPlugin\" "+
- "value=\"com.example.MyPlugin\"/>");
- }
- for(int i=0; i<plugins.getLength() ; i++){
- Node plugin = plugins.item(i);
- Logger.log("Found plugin " + plugin.getAttributes().getNamedItem("name").getNodeValue() + " = " +
- plugin.getAttributes().getNamedItem("value").getNodeValue());
- pluginManager.addService(plugin.getAttributes().getNamedItem("name").getNodeValue(),
- plugin.getAttributes().getNamedItem("value").getNodeValue());
- }
-
- scriptEngine.addExtension("org.apache.cordova.JavaPluginManager", pluginManager);
- scriptEngine.addExtension("org.apache.cordova.Logger", new Log());
-
- // let Cordova JavaScript know that extensions have been loaded
- // if this is premature, we at least set the _nativeReady flag to true
- // so that when the JS side is ready, it knows native side is too
- Logger.log(this.getClass().getName() + ": invoking Cordova.onNativeReady.fire()");
- scriptEngine.executeScript("try {cordova.require('cordova/channel').onNativeReady.fire();} catch(e) {_nativeReady = true;}", null);
- }
- }
-
- // Called so that the extension can get a reference to the configuration or browser field object
- //
- public void register(WidgetConfig widgetConfig, BrowserField browserField) {
- browser = new WeakReference(browserField);
-
- // grab widget application name and use it to generate a unique ID
- appName = widgetConfig.getName();
- appID = Long.parseLong(Math.abs(("org.apache.cordova."+appName).hashCode())+"",16);
-
- // create a notification profile for the application
- Notification.registerProfile();
- }
-
- /**
- * Called to clean up any features when the extension is unloaded. This is
- * invoked by the WebWorks Framework when another URL is loaded.
- *
- * @see net.rim.device.api.web.WidgetExtension#unloadFeatures(org.w3c.dom.Document)
- */
- public void unloadFeatures(Document doc) {
- // Cleanup plugin resources.
- if (pluginManager != null) {
- pluginManager.destroy();
- }
- }
-
- public static void invokeScript(final String js) {
- // Use a new thread so that JavaScript is invoked asynchronously.
- // Otherwise executeScript doesn't return until JavaScript call back
- // is finished.
- (new Thread() {
- public void run() {
- try {
- script.executeScript(js, null);
- } catch (Exception e) {
- // This is likely an IllegalStateException which is thrown
- // because the framework is in the process of being shutdown
- // so communication to JavaScript side is not allowed.
- Logger.log("Caught exception while executing script: "
- + e.getMessage());
- }
- }
- }).start();
- }
-
- /**
- * Invokes the Cordova success callback specified by callbackId.
- * @param callbackId unique callback ID
- * @param result Cordova PluginResult containing result
- */
- public static void invokeSuccessCallback(String callbackId, PluginResult result) {
- invokeScript(result.toSuccessCallbackString(callbackId));
- }
-
- /**
- * Invokes the Cordova error callback specified by callbackId.
- * @param callbackId unique callback ID
- * @param result Cordova PluginResult containing result
- */
- public static void invokeErrorCallback(String callbackId, PluginResult result) {
- invokeScript(result.toErrorCallbackString(callbackId));
- }
-
- /**
- * Provides access to the browser instance for the application.
- */
- public static BrowserField getBrowserField() {
- Object o = browser.get();
- if ( o instanceof BrowserField ) {
- return (BrowserField)o;
- } else {
- return null;
- }
- }
-
- /**
- * Returns the widget application name.
- */
- public static String getAppName() {
- return appName;
- }
-
- /**
- * Returns unique ID of the widget application.
- */
- public static long getAppID() {
- return appID;
- }
-}
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/88ad654c/lib/cordova-blackberry/framework/ext/src/org/apache/cordova/accelerometer/Accelerometer.java
----------------------------------------------------------------------
diff --git a/lib/cordova-blackberry/framework/ext/src/org/apache/cordova/accelerometer/Accelerometer.java b/lib/cordova-blackberry/framework/ext/src/org/apache/cordova/accelerometer/Accelerometer.java
deleted file mode 100644
index 2088122..0000000
--- a/lib/cordova-blackberry/framework/ext/src/org/apache/cordova/accelerometer/Accelerometer.java
+++ /dev/null
@@ -1,228 +0,0 @@
-/*
- * 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.
- */
-package org.apache.cordova.accelerometer;
-
-import java.util.Enumeration;
-import java.util.Hashtable;
-import java.util.Vector;
-
-import net.rim.device.api.system.AccelerometerData;
-import net.rim.device.api.system.AccelerometerListener;
-import net.rim.device.api.system.AccelerometerSensor;
-import net.rim.device.api.system.Application;
-
-import org.apache.cordova.api.Plugin;
-import org.apache.cordova.api.PluginResult;
-import org.apache.cordova.json4j.JSONArray;
-import org.apache.cordova.json4j.JSONException;
-import org.apache.cordova.json4j.JSONObject;
-import org.apache.cordova.util.Logger;
-
-public class Accelerometer extends Plugin implements AccelerometerListener {
- private static final String LOG_TAG = "Accelerometer: ";
-
- private static final String ACTION_START = "start";
- private static final String ACTION_STOP = "stop";
-
- private static final int STOPPED = 0;
- private static final int STARTING = 1;
- private static final int RUNNING = 2;
- private static final int ERROR_FAILED_TO_START = 3;
-
- // BlackBerry uses a value of 1000 (AccelerometerSensor.G_FORCE_VALUE) to
- // represent g force constant. Spec uses m/s^2. This constant is used
- // to normalize BlackBerry values to the spec.
- private static final short G_FORCE_NORMALIZE = 981;
-
- // the single channel to the device sensor
- private static AccelerometerSensor.Channel _rawDataChannel = null;
-
- private int state = STOPPED; // state of this listener
- private long initTime = 0;
-
- /**
- * Reference to single start callbackid
- */
- private String callbackId;
-
- public PluginResult execute(String action, JSONArray args, String callbackId) {
- PluginResult result;
- if (!AccelerometerSensor.isSupported()) {
- result = new PluginResult(
- PluginResult.Status.ILLEGAL_ACCESS_EXCEPTION,
- "Accelerometer sensor not supported");
- } else if (ACTION_START.equals(action)) {
- result = start(callbackId);
- } else if (ACTION_STOP.equals(action)) {
- result = stop();
- } else {
- result = new PluginResult(PluginResult.Status.INVALID_ACTION,
- "Accelerometer: Invalid action:" + action);
- }
-
- return result;
- }
-
- /**
- * Implements the AccelerometerListener method. We listen for the purpose of
- * closing the application's accelerometer sensor channel after timeout has
- * been exceeded.
- */
- public void onData(AccelerometerData accelData) {
- short x = accelData.getLastXAcceleration();
- short y = accelData.getLastYAcceleration();
- short z = accelData.getLastZAcceleration();
-
- // If any value is not zero, assume sensor is now active and set state.
- if (state == STARTING && (x != 0 || y != 0 || z != 0)) {
- state = RUNNING;
- }
-
- if (state == RUNNING) {
- // Send the new accelerometer data.
- JSONObject accel = new JSONObject();
- try {
- accel.put("x", normalize(x));
- accel.put("y", normalize(y));
- accel.put("z", normalize(z));
- accel.put("timestamp", accelData.getLastTimestamp());
- sendResult(true,
- new PluginResult(PluginResult.Status.OK, accel), true);
- } catch (JSONException e) {
- sendResult(false, new PluginResult(
- PluginResult.Status.JSON_EXCEPTION, "JSONException:"
- + e.getMessage()), false);
- }
- } else if ((System.currentTimeMillis() - initTime) > 2000) {
- // If the sensor does not become active within 2 seconds of
- // the request to start it, fail out.
- stop();
- state = ERROR_FAILED_TO_START;
- JSONObject errorObj = new JSONObject();
- try {
- errorObj.put("code", ERROR_FAILED_TO_START);
- errorObj.put("message", "Accelerometer could not be started.");
- } catch (JSONException e) {
- Logger.log(LOG_TAG
- + "Failed to build JSON object for ERROR_FAILED_TO_START.");
- }
- sendResult(false, new PluginResult(PluginResult.Status.ERROR,
- errorObj), false);
- }
- }
-
- /**
- * Called when Plugin is destroyed.
- */
- public void onDestroy() {
- stop();
- }
-
- /**
- * Adds a SystemListener to listen for changes to the battery state. The
- * listener is only registered if one has not already been added.
- */
- private PluginResult start(String callbackId) {
- this.callbackId = callbackId;
- if (_rawDataChannel == null || !_rawDataChannel.isOpen()) {
- _rawDataChannel = AccelerometerSensor
- .openRawDataChannel(Application.getApplication());
- Logger.log(LOG_TAG + "sensor channel opened");
-
- initTime = System.currentTimeMillis();
- state = STARTING;
- _rawDataChannel.setAccelerometerListener(this);
- Logger.log(LOG_TAG + "sensor listener added");
- }
-
- PluginResult result = new PluginResult(PluginResult.Status.NO_RESULT);
- result.setKeepCallback(true);
- return result;
- }
-
- /**
- * Normalize the range of values returned by BlackBerry to the agreed upon
- * cross platform range.
- *
- * @param value
- * @return normalized value
- */
- private double normalize(short value) {
- // Integer multiplication is less troublesome then floating point.
- StringBuffer buf = new StringBuffer(String.valueOf(value
- * G_FORCE_NORMALIZE));
-
- // Manipulate the string to properly insert zeros and decimal point so
- // something like -708910 becomes -7.08910 and 764 becomes .00764.
- // Due to the values returned by BlackBerry there will always be 5
- // decimal precision in the normalized value.
- int idx = buf.charAt(0) == '-' ? 1 : 0;
- while (buf.length() < (5 + idx)) {
- buf.insert(idx, '0');
- }
- buf.insert(buf.length() - 5, '.');
-
- return Double.parseDouble(buf.toString());
- }
-
- /**
- * Helper function to send a PluginResult to the saved call back ID.
- *
- * @param issuccess
- * true if this is a successful result, false otherwise.
- * @param result
- * the PluginResult to return
- * @param keepCallback
- * Boolean value indicating whether to keep the call back id
- * active.
- */
- private synchronized void sendResult(boolean issuccess,
- PluginResult result, boolean keepCallback) {
-
- if (result != null) {
- // Must keep the call back active for future watch events.
- result.setKeepCallback(keepCallback);
-
- if (issuccess) {
- success(result, this.callbackId);
- } else {
- error(result, this.callbackId);
- }
- }
- }
-
- /**
- * Stops accelerometer listener and closes the sensor channel.
- */
- private synchronized PluginResult stop() {
- if (_rawDataChannel != null && _rawDataChannel.isOpen()) {
-
- // Remove the battery listener.
- _rawDataChannel.removeAccelerometerListener();
- _rawDataChannel.close();
- _rawDataChannel = null;
-
- Logger.log(LOG_TAG + "sensor channel closed");
- }
-
- state = STOPPED;
-
- return new PluginResult(PluginResult.Status.OK);
- }
-}
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/88ad654c/lib/cordova-blackberry/framework/ext/src/org/apache/cordova/api/IPlugin.java
----------------------------------------------------------------------
diff --git a/lib/cordova-blackberry/framework/ext/src/org/apache/cordova/api/IPlugin.java b/lib/cordova-blackberry/framework/ext/src/org/apache/cordova/api/IPlugin.java
deleted file mode 100644
index 7e09d31..0000000
--- a/lib/cordova-blackberry/framework/ext/src/org/apache/cordova/api/IPlugin.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * 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.
- */
-package org.apache.cordova.api;
-
-import org.apache.cordova.CordovaExtension;
-import org.apache.cordova.json4j.JSONArray;
-
-/**
- * Plugin interface must be implemented by any plugin classes.
- *
- * The execute method is called by the PluginManager.
- */
-public interface IPlugin {
-
- /**
- * Executes the request and returns PluginResult.
- *
- * @param action The action to execute.
- * @param args JSONArry of arguments for the plugin.
- * @param callbackId The callback id used when calling back into JavaScript.
- * @return A PluginResult object with a status and message.
- */
- PluginResult execute(String action, JSONArray args, String callbackId);
-
- /**
- * Identifies if action to be executed returns a value and should be run synchronously.
- *
- * @param action The action to execute
- * @return T=returns value
- */
- public boolean isSynch(String action);
-
- /**
- * Sets the context of the Plugin. This can then be used to do things like
- * get file paths associated with the Activity.
- *
- * @param ctx The main application class.
- */
- void setContext(CordovaExtension ctx);
-
- /**
- * Called when the system is about to start resuming a previous activity.
- */
- void onPause();
-
- /**
- * Called when the activity will start interacting with the user.
- */
- void onResume();
-
- /**
- * The final call you receive before your activity is destroyed.
- */
- void onDestroy();
-}
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/88ad654c/lib/cordova-blackberry/framework/ext/src/org/apache/cordova/api/Plugin.java
----------------------------------------------------------------------
diff --git a/lib/cordova-blackberry/framework/ext/src/org/apache/cordova/api/Plugin.java b/lib/cordova-blackberry/framework/ext/src/org/apache/cordova/api/Plugin.java
deleted file mode 100644
index 6f70b85..0000000
--- a/lib/cordova-blackberry/framework/ext/src/org/apache/cordova/api/Plugin.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * 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.
- */
-package org.apache.cordova.api;
-
-import org.apache.cordova.CordovaExtension;
-import org.apache.cordova.json4j.JSONArray;
-
-/**
- * Plugin interface must be implemented by any plugin classes.
- *
- * The execute method is called by the PluginManager.
- */
-public abstract class Plugin implements IPlugin {
-
- public CordovaExtension ctx; // Main application object
-
- /**
- * Executes the request and returns PluginResult.
- *
- * @param action The action to execute.
- * @param args JSONArry of arguments for the plugin.
- * @param callbackId The callback id used when calling back into JavaScript.
- * @return A PluginResult object with a status and message.
- */
- public abstract PluginResult execute(String action, JSONArray args, String callbackId);
-
- /**
- * Identifies if action to be executed returns a value and should be run synchronously.
- *
- * @param action The action to execute
- * @return T=returns value
- */
- public boolean isSynch(String action) {
- return false;
- }
-
- /**
- * Sets the context of the Plugin. This can then be used to do things like
- * get file paths associated with the Activity.
- *
- * @param ctx The context of the main Activity.
- */
- public void setContext(CordovaExtension ctx) {
- this.ctx = ctx;
- }
-
- /**
- * Called when Plugin is paused.
- */
- public void onPause() {
- }
-
- /**
- * Called when Plugin is resumed.
- */
- public void onResume() {
- }
-
- /**
- * Called when Plugin is destroyed.
- */
- public void onDestroy() {
- }
-
- /**
- * Send generic JavaScript statement back to JavaScript.
- * success(...) and error(...) should be used instead where possible.
- *
- * @param statement
- */
- public void invokeScript(String statement) {
- CordovaExtension.invokeScript(statement);
- }
-
- /**
- * Call the JavaScript success callback for this plugin.
- *
- * This can be used if the execute code for the plugin is asynchronous meaning
- * that execute should return null and the callback from the async operation can
- * call success(...) or error(...)
- *
- * @param pluginResult The result to return.
- * @param callbackId The callback id used when calling back into JavaScript.
- */
- public static void success(PluginResult pluginResult, String callbackId) {
- CordovaExtension.invokeSuccessCallback(callbackId, pluginResult);
- }
-
- /**
- * Call the JavaScript error callback for this plugin.
- *
- * @param pluginResult The result to return.
- * @param callbackId The callback id used when calling back into JavaScript.
- */
- public static void error(PluginResult pluginResult, String callbackId) {
- CordovaExtension.invokeErrorCallback(callbackId, pluginResult);
- }
-}
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/88ad654c/lib/cordova-blackberry/framework/ext/src/org/apache/cordova/api/PluginManager.java
----------------------------------------------------------------------
diff --git a/lib/cordova-blackberry/framework/ext/src/org/apache/cordova/api/PluginManager.java b/lib/cordova-blackberry/framework/ext/src/org/apache/cordova/api/PluginManager.java
deleted file mode 100644
index a8e5e9b..0000000
--- a/lib/cordova-blackberry/framework/ext/src/org/apache/cordova/api/PluginManager.java
+++ /dev/null
@@ -1,168 +0,0 @@
-/*
- * 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.
- */
-package org.apache.cordova.api;
-
-import java.util.Hashtable;
-
-import org.apache.cordova.CordovaExtension;
-import org.apache.cordova.util.FileUtils;
-import org.apache.cordova.util.Logger;
-
-import net.rim.device.api.script.Scriptable;
-import net.rim.device.api.script.ScriptableFunction;
-
-/**
- * PluginManager represents an object in the script engine. It can be accessed
- * from the script environment using <code>cordova.PluginManager</code>.
- *
- * PluginManager provides a function, <code>exec</code>, that can be invoked
- * from the script environment: <code>cordova.PluginManager.exec(...)</code>.
- * Invoking this function causes the script engine to load the appropriate
- * Cordova Plugin and perform the specified action.
- */
-public final class PluginManager extends Scriptable {
-
- /**
- * Field used to invoke Plugin actions.
- */
- public static String FIELD_EXEC = "exec";
-
- /**
- * Field used to cleanup Plugins.
- */
- public static String FIELD_DESTROY = "destroy";
-
- /**
- * Field used to indicate application has been brought to foreground.
- */
- public static String FIELD_RESUME = "resume";
-
- /**
- * Field used to indicate application has been sent to background
- */
- public static String FIELD_PAUSE = "pause";
-
- /**
- * Field used to register a Plugin.
- */
- public static String FIELD_ADD_PLUGIN = "addPlugin";
-
- /**
- * Loads the appropriate Cordova Plugins and invokes their actions.
- */
- private final PluginManagerFunction pluginManagerFunction;
-
- /**
- * Maps available services to Java class names.
- */
- private Hashtable services = new Hashtable();
-
- /**
- * Constructor. Adds available Cordova services.
- * @param ext The Cordova JavaScript Extension
- */
- public PluginManager(CordovaExtension ext) {
- this.pluginManagerFunction = new PluginManagerFunction(ext, this);
- }
-
- /**
- * The following fields are supported from the script environment:
- *
- * <code>cordova.pluginManager.exec</code> - Loads the appropriate
- * Plugin and invokes the specified action.
- *
- * <code>cordova.pluginManager.destroy</code> - Invokes the <code>onDestroy</code>
- * method on all Plugins to give them a chance to cleanup before exit.
- */
- public Object getField(String name) throws Exception {
- if (name.equals(FIELD_EXEC)) {
- return this.pluginManagerFunction;
- }
- else if (name.equals(FIELD_DESTROY)) {
- return new ScriptableFunction() {
- public Object invoke(Object obj, Object[] oargs) throws Exception {
- destroy();
- return null;
- }
- };
- }
- else if (name.equals(FIELD_RESUME)) {
- final PluginManagerFunction plugin_mgr = this.pluginManagerFunction;
- return new ScriptableFunction() {
- public Object invoke(Object obj, Object[] oargs) throws Exception {
- plugin_mgr.onResume();
- return null;
- }
- };
- }
- else if (name.equals(FIELD_PAUSE)) {
- final PluginManagerFunction plugin_mgr = this.pluginManagerFunction;
- return new ScriptableFunction() {
- public Object invoke(Object obj, Object[] oargs) throws Exception {
- plugin_mgr.onPause();
- return null;
- }
- };
- }
- else if (name.equals(FIELD_ADD_PLUGIN)) {
- Logger.log("Plugins are now added through the plugins.xml in the application root.");
- }
- return super.getField(name);
- }
-
- /**
- * Add a class that implements a service.
- *
- * @param serviceName The service name.
- * @param className The Java class name that implements the service.
- */
- public void addService(String serviceName, String className) {
- this.services.put(serviceName, className);
- }
-
- /**
- * Cleanup the plugin resources and delete temporary directory that may have
- * been created.
- */
- public void destroy() {
- // allow plugins to clean up
- pluginManagerFunction.onDestroy();
-
- // delete temporary application directory
- // NOTE: doing this on a background thread doesn't work because the app
- // is closing and the thread is killed before it completes.
- try {
- FileUtils.deleteApplicationTempDirectory();
- } catch (Exception e) {
- Logger.log(this.getClass().getName()
- + ": error deleting application temp directory: "
- + e.getMessage());
- }
- }
-
- /**
- * Get the class that implements a service.
- *
- * @param serviceName The service name.
- * @return The Java class name that implements the service.
- */
- public String getClassForService(String serviceName) {
- return (String)this.services.get(serviceName);
- }
-}
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/88ad654c/lib/cordova-blackberry/framework/ext/src/org/apache/cordova/api/PluginManagerFunction.java
----------------------------------------------------------------------
diff --git a/lib/cordova-blackberry/framework/ext/src/org/apache/cordova/api/PluginManagerFunction.java b/lib/cordova-blackberry/framework/ext/src/org/apache/cordova/api/PluginManagerFunction.java
deleted file mode 100644
index 13a0e77..0000000
--- a/lib/cordova-blackberry/framework/ext/src/org/apache/cordova/api/PluginManagerFunction.java
+++ /dev/null
@@ -1,240 +0,0 @@
-/*
- * 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.
- */
-package org.apache.cordova.api;
-
-import java.util.Enumeration;
-import java.util.Hashtable;
-
-import net.rim.device.api.script.ScriptableFunction;
-
-import org.apache.cordova.CordovaExtension;
-import org.apache.cordova.json4j.JSONArray;
-import org.apache.cordova.json4j.JSONException;
-import org.apache.cordova.util.Logger;
-
-/**
- * PluginManagerFunction represents a function that can be invoked from the
- * script environment of the widget framework. It manages the plugins for
- * the Cordova JavaScript Extension.
- *
- * Calling <code>cordova.pluginManager.exec(...)</code> from JavaScript will
- * result in this class' <code>invoke()</code> method being called.
- */
-public class PluginManagerFunction extends ScriptableFunction {
-
- private final static int ARG_SERVICE = 0;
- private final static int ARG_ACTION = 1;
- private final static int ARG_CALLBACK_ID = 2;
- private final static int ARG_ARGS = 3;
- private final static int ARG_ASYNC = 4;
-
- private Hashtable plugins = new Hashtable();
-
- private final CordovaExtension ext;
- private final PluginManager pluginManager;
-
- /**
- * Constructor.
- * @param ext The Cordova JavaScript Extension
- * @param pluginManager The PluginManager that exposes the scriptable object.
- */
- public PluginManagerFunction(CordovaExtension ext, PluginManager pluginManager) {
- this.ext = ext;
- this.pluginManager = pluginManager;
- }
-
- /**
- * The invoke method is called when cordova.pluginManager.exec(...) is
- * used from the script environment. It instantiates the appropriate plugin
- * and invokes the specified action. JavaScript arguments are passed in
- * as an array of objects.
- *
- * @param service String containing the service to run
- * @param action String containing the action that the service is supposed to perform. This is
- * passed to the plugin execute method and it is up to the plugin developer
- * how to deal with it.
- * @param callbackId String containing the id of the callback that is executed in JavaScript if
- * this is an async plugin call.
- * @param args An Array literal string containing any arguments needed in the
- * plugin execute method.
- * @param async Boolean indicating whether the calling JavaScript code is expecting an
- * immediate return value. If true, either CordovaExtension.callbackSuccess(...) or
- * CordovaExtension.callbackError(...) is called once the plugin code has executed.
- *
- * @return JSON encoded string with a response message and status.
- *
- * @see net.rim.device.api.script.ScriptableFunction#invoke(java.lang.Object, java.lang.Object[])
- */
- public Object invoke(Object obj, Object[] oargs) throws Exception {
- final String service = (String)oargs[ARG_SERVICE];
- final String action = (String)oargs[ARG_ACTION];
- final String callbackId = (String)oargs[ARG_CALLBACK_ID];
- boolean async = (oargs[ARG_ASYNC].toString().equals("true") ? true : false);
- PluginResult pr = null;
-
- try {
- // action arguments
- final JSONArray args = new JSONArray((String)oargs[ARG_ARGS]);
-
- // get the class for the specified service
- String clazz = this.pluginManager.getClassForService(service);
- Class c = null;
- if (clazz != null) {
- c = getClassByName(clazz);
- }
-
- if (isCordovaPlugin(c)) {
- // Create a new instance of the plugin and set the context
- final Plugin plugin = this.loadPlugin(clazz, c);
- async = async && !plugin.isSynch(action);
- if (async) {
- // Run this async on a background thread so that JavaScript can continue on
- Thread thread = new Thread(new Runnable() {
- public void run() {
- // Call execute on the plugin so that it can do it's thing
- final PluginResult result = plugin.execute(action, args, callbackId);
-
- if (result != null) {
- int status = result.getStatus();
-
- // If plugin status is OK,
- // or plugin is not going to send an immediate result (NO_RESULT)
- if (status == PluginResult.Status.OK.ordinal() ||
- status == PluginResult.Status.NO_RESULT.ordinal()) {
- CordovaExtension.invokeSuccessCallback(callbackId, result);
- }
- // error
- else {
- CordovaExtension.invokeErrorCallback(callbackId, result);
- }
- }
- }
- });
- thread.start();
- return "";
- } else {
- // Call execute on the plugin so that it can do it's thing
- pr = plugin.execute(action, args, callbackId);
- }
- }
- } catch (ClassNotFoundException e) {
- Logger.log(this.getClass().getName() + ": " + e);
- pr = new PluginResult(PluginResult.Status.CLASS_NOT_FOUND_EXCEPTION, "ClassNotFoundException: " + e.getMessage());
- } catch (IllegalAccessException e) {
- Logger.log(this.getClass().getName() + ": " + e);
- pr = new PluginResult(PluginResult.Status.ILLEGAL_ACCESS_EXCEPTION, "IllegalAccessException:" + e.getMessage());
- } catch (InstantiationException e) {
- Logger.log(this.getClass().getName() + ": " + e);
- pr = new PluginResult(PluginResult.Status.INSTANTIATION_EXCEPTION, "InstantiationException: " + e.getMessage());
- } catch (JSONException e) {
- Logger.log(this.getClass().getName() + ": " + e);
- pr = new PluginResult(PluginResult.Status.JSON_EXCEPTION, "JSONException: " + e.getMessage());
- }
- // if async we have already returned at this point unless there was an error...
- if (async) {
- CordovaExtension.invokeErrorCallback(callbackId, pr);
- }
- return ( pr != null ? pr.getJSONString() : "{ status: 0, message: 'all good' }" );
- }
-
- /**
- * Get the class.
- *
- * @param clazz
- * @return
- * @throws ClassNotFoundException
- */
- private Class getClassByName(final String clazz) throws ClassNotFoundException {
- return Class.forName(clazz);
- }
-
- /**
- * Determines if the class implements org.apache.cordova.api.Plugin interface.
- *
- * @param c The class to check.
- * @return Boolean indicating if the class implements org.apache.cordova.api.Plugin
- */
- private boolean isCordovaPlugin(Class c) {
- if (c != null) {
- return org.apache.cordova.api.Plugin.class.isAssignableFrom(c) || org.apache.cordova.api.IPlugin.class.isAssignableFrom(c);
- }
- return false;
- }
-
- /**
- * Add plugin to be loaded and cached.
- * If plugin is already created, then just return it.
- *
- * @param className The class to load
- * @return The plugin
- */
- public Plugin loadPlugin(String className, Class clazz) throws IllegalAccessException, InstantiationException {
- if (this.plugins.containsKey(className)) {
- return this.getPlugin(className);
- }
- Logger.log(this.getClass().getName() + ": Loading plugin " + clazz);
- Plugin plugin = (Plugin)clazz.newInstance();
- this.plugins.put(className, plugin);
- plugin.setContext(this.ext);
- return plugin;
- }
-
- /**
- * Get the loaded plugin.
- *
- * @param className The class of the loaded plugin.
- * @return
- */
- public Plugin getPlugin(String className) {
- return (Plugin)this.plugins.get(className);
- }
-
- /**
- * Called when application is paused.
- */
- public void onPause() {
- Enumeration e = this.plugins.elements();
- while (e.hasMoreElements()) {
- Plugin plugin = (Plugin)e.nextElement();
- plugin.onPause();
- }
- }
-
- /**
- * Called when application is resumed.
- */
- public void onResume() {
- Enumeration e = this.plugins.elements();
- while (e.hasMoreElements()) {
- Plugin plugin = (Plugin)e.nextElement();
- plugin.onResume();
- }
- }
-
- /**
- * Called when application is destroyed.
- */
- public void onDestroy() {
- Enumeration e = this.plugins.elements();
- while (e.hasMoreElements()) {
- Plugin plugin = (Plugin)e.nextElement();
- plugin.onDestroy();
- }
- }
-}