Return-Path: X-Original-To: apmail-cordova-commits-archive@www.apache.org Delivered-To: apmail-cordova-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 5297C1122B for ; Mon, 7 Jul 2014 17:10:10 +0000 (UTC) Received: (qmail 30265 invoked by uid 500); 7 Jul 2014 17:10:10 -0000 Delivered-To: apmail-cordova-commits-archive@cordova.apache.org Received: (qmail 30232 invoked by uid 500); 7 Jul 2014 17:10:10 -0000 Mailing-List: contact commits-help@cordova.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cordova.apache.org Delivered-To: mailing list commits@cordova.apache.org Received: (qmail 30138 invoked by uid 99); 7 Jul 2014 17:10:10 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 07 Jul 2014 17:10:10 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id DB3799A7D1F; Mon, 7 Jul 2014 17:10:09 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: agrieve@apache.org To: commits@cordova.apache.org Date: Mon, 07 Jul 2014 17:10:11 -0000 Message-Id: <03db73e54d884fb1a5ab5e89b614572d@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [3/7] android commit: Refactor: Move url-filter information into PluginEntry. Refactor: Move url-filter information into PluginEntry. Project: http://git-wip-us.apache.org/repos/asf/cordova-android/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-android/commit/af77977f Tree: http://git-wip-us.apache.org/repos/asf/cordova-android/tree/af77977f Diff: http://git-wip-us.apache.org/repos/asf/cordova-android/diff/af77977f Branch: refs/heads/master Commit: af77977fda281e912b9e8805d1d89a44e5ba1f52 Parents: e74baf1 Author: Andrew Grieve Authored: Fri Jul 4 14:52:31 2014 -0400 Committer: Andrew Grieve Committed: Fri Jul 4 14:53:00 2014 -0400 ---------------------------------------------------------------------- .../src/org/apache/cordova/ConfigXmlParser.java | 19 +++----- .../src/org/apache/cordova/PluginEntry.java | 49 +++++++++++--------- .../src/org/apache/cordova/PluginManager.java | 25 +++++----- 3 files changed, 46 insertions(+), 47 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-android/blob/af77977f/framework/src/org/apache/cordova/ConfigXmlParser.java ---------------------------------------------------------------------- diff --git a/framework/src/org/apache/cordova/ConfigXmlParser.java b/framework/src/org/apache/cordova/ConfigXmlParser.java index 8062168..a5958ef 100644 --- a/framework/src/org/apache/cordova/ConfigXmlParser.java +++ b/framework/src/org/apache/cordova/ConfigXmlParser.java @@ -21,8 +21,6 @@ package org.apache.cordova; import java.io.IOException; import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; import java.util.Locale; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -41,7 +39,6 @@ public class ConfigXmlParser { private CordovaPreferences prefs = new CordovaPreferences(); private Whitelist whitelist = new Whitelist(); private ArrayList pluginEntries = new ArrayList(20); - private HashMap> urlMap = new HashMap>(); public Whitelist getWhitelist() { return whitelist; @@ -59,10 +56,6 @@ public class ConfigXmlParser { return launchUrl; } - public HashMap> getPluginUrlMap() { - return urlMap; - } - public void parse(Activity action) { // First checking the class namespace for config.xml int id = action.getResources().getIdentifier("config", "xml", action.getClass().getPackage().getName()); @@ -82,16 +75,17 @@ public class ConfigXmlParser { String service = "", pluginClass = "", paramType = ""; boolean onload = false; boolean insideFeature = false; + ArrayList urlMap = null; + while (eventType != XmlResourceParser.END_DOCUMENT) { if (eventType == XmlResourceParser.START_TAG) { String strNode = xml.getName(); if (strNode.equals("url-filter")) { Log.w(TAG, "Plugin " + service + " is using deprecated tag "); - if (urlMap.get(service) == null) { - urlMap.put(service, new ArrayList(2)); + if (urlMap == null) { + urlMap = new ArrayList(2); } - List filters = urlMap.get(service); - filters.add(xml.getAttributeValue(null, "value")); + urlMap.add(xml.getAttributeValue(null, "value")); } else if (strNode.equals("feature")) { //Check for supported feature sets aka. plugins (Accelerometer, Geolocation, etc) //Set the bit for reading params @@ -130,12 +124,13 @@ public class ConfigXmlParser { { String strNode = xml.getName(); if (strNode.equals("feature")) { - pluginEntries.add(new PluginEntry(service, pluginClass, onload)); + pluginEntries.add(new PluginEntry(service, pluginClass, onload, urlMap)); service = ""; pluginClass = ""; insideFeature = false; onload = false; + urlMap = null; } } try { http://git-wip-us.apache.org/repos/asf/cordova-android/blob/af77977f/framework/src/org/apache/cordova/PluginEntry.java ---------------------------------------------------------------------- diff --git a/framework/src/org/apache/cordova/PluginEntry.java b/framework/src/org/apache/cordova/PluginEntry.java index dcc1974..c54f6cb 100755 --- a/framework/src/org/apache/cordova/PluginEntry.java +++ b/framework/src/org/apache/cordova/PluginEntry.java @@ -18,12 +18,12 @@ */ package org.apache.cordova; +import java.util.List; + import org.apache.cordova.CordovaWebView; import org.apache.cordova.CordovaInterface; import org.apache.cordova.CordovaPlugin; -//import android.content.Context; -//import android.webkit.WebView; /** * This class represents a service entry object. @@ -52,30 +52,36 @@ public class PluginEntry { */ public boolean onload = false; + private List urlFilters; + + /** + * @param service The name of the service + * @param plugin The plugin associated with this entry + */ + public PluginEntry(String service, CordovaPlugin plugin) { + this(service, plugin.getClass().getName(), true, null); + this.plugin = plugin; + } + /** - * Constructor - * * @param service The name of the service * @param pluginClass The plugin class name * @param onload Create plugin object when HTML page is loaded */ public PluginEntry(String service, String pluginClass, boolean onload) { + this(service, pluginClass, onload, null); + } + + + public PluginEntry(String service, String pluginClass, boolean onload, List urlFilters) { this.service = service; this.pluginClass = pluginClass; this.onload = onload; + this.urlFilters = urlFilters; } - /** - * Alternate constructor - * - * @param service The name of the service - * @param plugin The plugin associated with this entry - */ - public PluginEntry(String service, CordovaPlugin plugin) { - this.service = service; - this.plugin = plugin; - this.pluginClass = plugin.getClass().getName(); - this.onload = false; + public List getUrlFilters() { + return urlFilters; } /** @@ -89,8 +95,7 @@ public class PluginEntry { return this.plugin; } try { - @SuppressWarnings("rawtypes") - Class c = getClassByName(this.pluginClass); + Class c = getClassByName(this.pluginClass); if (isCordovaPlugin(c)) { this.plugin = (CordovaPlugin) c.newInstance(); this.plugin.initialize(ctx, webView); @@ -110,9 +115,8 @@ public class PluginEntry { * @return a reference to the named class * @throws ClassNotFoundException */ - @SuppressWarnings("rawtypes") - private Class getClassByName(final String clazz) throws ClassNotFoundException { - Class c = null; + private Class getClassByName(final String clazz) throws ClassNotFoundException { + Class c = null; if ((clazz != null) && !("".equals(clazz))) { c = Class.forName(clazz); } @@ -122,10 +126,9 @@ public class PluginEntry { /** * Returns whether the given class extends CordovaPlugin. */ - @SuppressWarnings("rawtypes") - private boolean isCordovaPlugin(Class c) { + private boolean isCordovaPlugin(Class c) { if (c != null) { - return org.apache.cordova.CordovaPlugin.class.isAssignableFrom(c); + return CordovaPlugin.class.isAssignableFrom(c); } return false; } http://git-wip-us.apache.org/repos/asf/cordova-android/blob/af77977f/framework/src/org/apache/cordova/PluginManager.java ---------------------------------------------------------------------- diff --git a/framework/src/org/apache/cordova/PluginManager.java b/framework/src/org/apache/cordova/PluginManager.java index c5ffd6c..410cc6e 100755 --- a/framework/src/org/apache/cordova/PluginManager.java +++ b/framework/src/org/apache/cordova/PluginManager.java @@ -19,7 +19,6 @@ package org.apache.cordova; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import org.apache.cordova.CordovaWebView; @@ -86,12 +85,12 @@ public class PluginManager { * Load plugins from res/xml/config.xml */ public void loadPlugins() { - ConfigXmlParser parser = new ConfigXmlParser(); - parser.parse(ctx.getActivity()); - for (PluginEntry entry : parser.getPluginEntries()) { - addService(entry); - } - urlMap = parser.getPluginUrlMap(); + ConfigXmlParser parser = new ConfigXmlParser(); + parser.parse(ctx.getActivity()); + urlMap = new HashMap>(); + for (PluginEntry entry : parser.getPluginEntries()) { + addService(entry); + } } /** @@ -206,6 +205,10 @@ public class PluginManager { */ public void addService(PluginEntry entry) { this.entries.put(entry.service, entry); + List urlFilters = entry.getUrlFilters(); + if (urlFilters != null) { + urlMap.put(entry.service, urlFilters); + } } /** @@ -311,11 +314,9 @@ public class PluginManager { * Called when the app navigates or refreshes. */ public void onReset() { - Iterator it = this.entries.values().iterator(); - while (it.hasNext()) { - CordovaPlugin plugin = it.next().plugin; - if (plugin != null) { - plugin.onReset(); + for (PluginEntry entry : this.entries.values()) { + if (entry.plugin != null) { + entry.plugin.onReset(); } } }