cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From i..@apache.org
Subject [6/8] android commit: Refactor ConfigXmlParser to allow subclasses
Date Wed, 11 Feb 2015 19:02:26 GMT
Refactor ConfigXmlParser to allow subclasses


Project: http://git-wip-us.apache.org/repos/asf/cordova-android/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-android/commit/18e5e9dc
Tree: http://git-wip-us.apache.org/repos/asf/cordova-android/tree/18e5e9dc
Diff: http://git-wip-us.apache.org/repos/asf/cordova-android/diff/18e5e9dc

Branch: refs/heads/unplug-whitelist-4.0.0
Commit: 18e5e9dcc5ea2f68d6f89136744623c647ca345c
Parents: c8f44ab
Author: Ian Clelland <iclelland@chromium.org>
Authored: Wed Oct 22 16:26:41 2014 -0400
Committer: Ian Clelland <iclelland@chromium.org>
Committed: Wed Feb 11 14:01:11 2015 -0500

----------------------------------------------------------------------
 .../src/org/apache/cordova/ConfigXmlParser.java | 129 ++++++++++---------
 1 file changed, 69 insertions(+), 60 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-android/blob/18e5e9dc/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 0b1f529..5dd9ff8 100644
--- a/framework/src/org/apache/cordova/ConfigXmlParser.java
+++ b/framework/src/org/apache/cordova/ConfigXmlParser.java
@@ -59,7 +59,7 @@ public class ConfigXmlParser {
     public String getLaunchUrl() {
         return launchUrl;
     }
-    
+
     public void parse(Activity action) {
         // First checking the class namespace for config.xml
         int id = action.getResources().getIdentifier("config", "xml", action.getClass().getPackage().getName());
@@ -74,11 +74,12 @@ public class ConfigXmlParser {
         parse(action.getResources().getXml(id));
     }
 
+    boolean insideFeature = false;
+    String service = "", pluginClass = "", paramType = "";
+    boolean onload = false;
+
     public void parse(XmlResourceParser xml) {
         int eventType = -1;
-        String service = "", pluginClass = "", paramType = "";
-        boolean onload = false;
-        boolean insideFeature = false;
 
         // Add implicitly allowed URLs
         internalWhitelist.addWhiteListEntry("file:///*", false);
@@ -87,65 +88,11 @@ public class ConfigXmlParser {
 
         while (eventType != XmlResourceParser.END_DOCUMENT) {
             if (eventType == XmlResourceParser.START_TAG) {
-                String strNode = xml.getName();
-                if (strNode.equals("feature")) {
-                    //Check for supported feature sets  aka. plugins (Accelerometer, Geolocation,
etc)
-                    //Set the bit for reading params
-                    insideFeature = true;
-                    service = xml.getAttributeValue(null, "name");
-                }
-                else if (insideFeature && strNode.equals("param")) {
-                    paramType = xml.getAttributeValue(null, "name");
-                    if (paramType.equals("service")) // check if it is using the older service
param
-                        service = xml.getAttributeValue(null, "value");
-                    else if (paramType.equals("package") || paramType.equals("android-package"))
-                        pluginClass = xml.getAttributeValue(null,"value");
-                    else if (paramType.equals("onload"))
-                        onload = "true".equals(xml.getAttributeValue(null, "value"));
-                }
-                else if (strNode.equals("access")) {
-                    String origin = xml.getAttributeValue(null, "origin");
-                    String subdomains = xml.getAttributeValue(null, "subdomains");
-                    boolean external = (xml.getAttributeValue(null, "launch-external") !=
null);
-                    if (origin != null) {
-                        if (external) {
-                            externalWhitelist.addWhiteListEntry(origin, (subdomains != null)
&& (subdomains.compareToIgnoreCase("true") == 0));
-                        } else {
-                            if ("*".equals(origin)) {
-                                // Special-case * origin to mean http and https when used
for internal
-                                // whitelist. This prevents external urls like sms: and geo:
from being
-                                // handled internally.
-                                internalWhitelist.addWhiteListEntry("http://*/*", false);
-                                internalWhitelist.addWhiteListEntry("https://*/*", false);
-                            } else {
-                                internalWhitelist.addWhiteListEntry(origin, (subdomains !=
null) && (subdomains.compareToIgnoreCase("true") == 0));
-                            }
-                        }
-                    }
-                }
-                else if (strNode.equals("preference")) {
-                    String name = xml.getAttributeValue(null, "name").toLowerCase(Locale.ENGLISH);
-                    String value = xml.getAttributeValue(null, "value");
-                    prefs.set(name, value);
-                }
-                else if (strNode.equals("content")) {
-                    String src = xml.getAttributeValue(null, "src");
-                    if (src != null) {
-                        setStartUrl(src);
-                    }
-                }
+                handleStartTag(xml);
             }
             else if (eventType == XmlResourceParser.END_TAG)
             {
-                String strNode = xml.getName();
-                if (strNode.equals("feature")) {
-                    pluginEntries.add(new PluginEntry(service, pluginClass, onload));
-
-                    service = "";
-                    pluginClass = "";
-                    insideFeature = false;
-                    onload = false;
-                }
+                handleEndTag(xml);
             }
             try {
                 eventType = xml.next();
@@ -157,6 +104,68 @@ public class ConfigXmlParser {
         }
     }
 
+    public void handleStartTag(XmlResourceParser xml) {
+        String strNode = xml.getName();
+        if (strNode.equals("feature")) {
+            //Check for supported feature sets  aka. plugins (Accelerometer, Geolocation,
etc)
+            //Set the bit for reading params
+            insideFeature = true;
+            service = xml.getAttributeValue(null, "name");
+        }
+        else if (insideFeature && strNode.equals("param")) {
+            paramType = xml.getAttributeValue(null, "name");
+            if (paramType.equals("service")) // check if it is using the older service param
+                service = xml.getAttributeValue(null, "value");
+            else if (paramType.equals("package") || paramType.equals("android-package"))
+                pluginClass = xml.getAttributeValue(null,"value");
+            else if (paramType.equals("onload"))
+                onload = "true".equals(xml.getAttributeValue(null, "value"));
+        }
+        else if (strNode.equals("access")) {
+            String origin = xml.getAttributeValue(null, "origin");
+            String subdomains = xml.getAttributeValue(null, "subdomains");
+            boolean external = (xml.getAttributeValue(null, "launch-external") != null);
+            if (origin != null) {
+                if (external) {
+                    externalWhitelist.addWhiteListEntry(origin, (subdomains != null) &&
(subdomains.compareToIgnoreCase("true") == 0));
+                } else {
+                    if ("*".equals(origin)) {
+                        // Special-case * origin to mean http and https when used for internal
+                        // whitelist. This prevents external urls like sms: and geo: from
being
+                        // handled internally.
+                        internalWhitelist.addWhiteListEntry("http://*/*", false);
+                        internalWhitelist.addWhiteListEntry("https://*/*", false);
+                    } else {
+                        internalWhitelist.addWhiteListEntry(origin, (subdomains != null)
&& (subdomains.compareToIgnoreCase("true") == 0));
+                    }
+                }
+            }
+        }
+        else if (strNode.equals("preference")) {
+            String name = xml.getAttributeValue(null, "name").toLowerCase(Locale.ENGLISH);
+            String value = xml.getAttributeValue(null, "value");
+            prefs.set(name, value);
+        }
+        else if (strNode.equals("content")) {
+            String src = xml.getAttributeValue(null, "src");
+            if (src != null) {
+                setStartUrl(src);
+            }
+        }
+    }
+
+    public void handleEndTag(XmlResourceParser xml) {
+        String strNode = xml.getName();
+        if (strNode.equals("feature")) {
+            pluginEntries.add(new PluginEntry(service, pluginClass, onload));
+
+            service = "";
+            pluginClass = "";
+            insideFeature = false;
+            onload = false;
+        }
+    }
+
     private void setStartUrl(String src) {
         Pattern schemeRegex = Pattern.compile("^[a-z-]+://");
         Matcher matcher = schemeRegex.matcher(src);


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


Mime
View raw message