You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by rw...@apache.org on 2018/04/23 20:08:09 UTC

svn commit: r1829940 - in /pivot/trunk/wtk/src/org/apache/pivot/wtk: BrowserApplicationContext.java DesktopApplicationContext.java

Author: rwhitcomb
Date: Mon Apr 23 20:08:08 2018
New Revision: 1829940

URL: http://svn.apache.org/viewvc?rev=1829940&view=rev
Log:
PIVOT-1033:  Update the parsing of command line options in BrowserApplicationContext
and DesktopApplicationContext to allow the "--option" form, which sets the value in
the "properties" map to "TRUE".  Syntax error if there is "key=" (i.e., with no value
after the "=") or there is more than one "=", or the key itself is empty.

Modified:
    pivot/trunk/wtk/src/org/apache/pivot/wtk/BrowserApplicationContext.java
    pivot/trunk/wtk/src/org/apache/pivot/wtk/DesktopApplicationContext.java

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/BrowserApplicationContext.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/BrowserApplicationContext.java?rev=1829940&r1=1829939&r2=1829940&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/BrowserApplicationContext.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/BrowserApplicationContext.java Mon Apr 23 20:08:08 2018
@@ -130,21 +130,32 @@ public final class BrowserApplicationCon
                 if (startupPropertiesParameter != null) {
                     String[] arguments = startupPropertiesParameter.split("&");
 
-                    for (int i = 0, n = arguments.length; i < n; i++) {
-                        String argument = arguments[i];
-                        String[] property = argument.split("=");
+                    for (String argument : arguments) {
+                        String[] property = argument.split("=", -1);
 
-                        if (property.length == 2) {
-                            String key = property[0].trim();
-                            String value;
-                            try {
-                                value = URLDecoder.decode(property[1].trim(), "UTF-8");
-                            } catch (UnsupportedEncodingException exception) {
-                                throw new RuntimeException(exception);
-                            }
-                            HostApplet.this.startupProperties.put(key, value);
-                        } else {
+                        String key = property[0].trim();
+                        if (key.isEmpty()) {
                             System.err.println(argument + " is not a valid startup property.");
+                        } else {
+                            if (property.length == 2) {
+                                String propertyValue = property[1].trim();
+                                if (propertyValue.isEmpty()) {
+                                    System.err.println(argument + " is not a valid startup property.");
+                                } else {
+                                    String value;
+                                    try {
+                                        value = URLDecoder.decode(propertyValue, "UTF-8");
+                                    } catch (UnsupportedEncodingException exception) {
+                                        throw new RuntimeException(exception);
+                                    }
+                                    HostApplet.this.startupProperties.put(key, value);
+                                }
+                            } else if (property.length == 1) {
+                                // Options of the form "--option" have a value of TRUE
+                                HostApplet.this.startupProperties.put(key, Boolean.TRUE.toString());
+                            } else {
+                                System.err.println(argument + " is not a valid startup property.");
+                            }
                         }
                     }
                 }

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/DesktopApplicationContext.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/DesktopApplicationContext.java?rev=1829940&r1=1829939&r2=1829940&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/DesktopApplicationContext.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/DesktopApplicationContext.java Mon Apr 23 20:08:08 2018
@@ -389,7 +389,7 @@ public final class DesktopApplicationCon
     public static final String USE_APPLICATION_INSTANCE_ARGUMENT = "useApplicationInstance";
 
     private static final String INVALID_PROPERTY_FORMAT_MESSAGE = "\"%s\" is not a valid startup "
-        + "property (expected format is \"--name=value\").";
+        + "property (expected format is \"--name[=value]\").";
     private static final String INVALID_PROPERTY_VALUE_MESSAGE = "\"%s\" is not a valid value for "
         + "startup property \"%s\".";
 
@@ -513,62 +513,68 @@ public final class DesktopApplicationCon
             System.err.println("Unable to retrieve startup preferences: " + exception);
         }
 
-        for (int i = 1, n = args.length; i < n; i++) {
+        for (int i = 1; i < args.length; i++) {
             String arg = args[i];
 
             if (arg.startsWith("--")) {
                 arg = arg.substring(2);
-                String[] property = arg.split("=");
+                String[] property = arg.split("=", -1);
 
+                String key = property[0];
                 if (property.length == 2) {
-                    String key = property[0];
                     String value = property[1];
-
-                    try {
-                        switch (key) {
-                            case X_ARGUMENT:
-                                x = Integer.parseInt(value);
-                                break;
-                            case Y_ARGUMENT:
-                                y = Integer.parseInt(value);
-                                break;
-                            case WIDTH_ARGUMENT:
-                                width = Integer.parseInt(value);
-                                break;
-                            case HEIGHT_ARGUMENT:
-                                height = Integer.parseInt(value);
-                                break;
-                            case CENTER_ARGUMENT:
-                                center = StringUtils.toBoolean(value);
-                                break;
-                            case RESIZABLE_ARGUMENT:
-                                resizable = StringUtils.toBoolean(value);
-                                break;
-                            case MAXIMIZED_ARGUMENT:
-                                maximized = StringUtils.toBoolean(value);
-                                break;
-                            case UNDECORATED_ARGUMENT:
-                                undecorated = StringUtils.toBoolean(value);
-                                break;
-                            case FULL_SCREEN_ARGUMENT:
-                                fullScreen = StringUtils.toBoolean(value);
-                                break;
-                            case PRESERVE_SPLASH_SCREEN_ARGUMENT:
-                                preserveSplashScreen = StringUtils.toBoolean(value);
-                                break;
-                            case ORIGIN_ARGUMENT:
-                                origin = new URL(value);
-                                break;
-                            case USE_APPLICATION_INSTANCE_ARGUMENT:
-                                useApplicationInstance = StringUtils.toBoolean(value);
-                                break;
-                            default:
-                                properties.put(key, value);
-                                break;
+                    if (value.isEmpty()) {
+                        System.err.println(String.format(INVALID_PROPERTY_FORMAT_MESSAGE, arg));
+                    } else {
+                        try {
+                            switch (key) {
+                                case X_ARGUMENT:
+                                    x = Integer.parseInt(value);
+                                    break;
+                                case Y_ARGUMENT:
+                                    y = Integer.parseInt(value);
+                                    break;
+                                case WIDTH_ARGUMENT:
+                                    width = Integer.parseInt(value);
+                                    break;
+                                case HEIGHT_ARGUMENT:
+                                    height = Integer.parseInt(value);
+                                    break;
+                                case CENTER_ARGUMENT:
+                                    center = StringUtils.toBoolean(value);
+                                    break;
+                                case RESIZABLE_ARGUMENT:
+                                    resizable = StringUtils.toBoolean(value);
+                                    break;
+                                case MAXIMIZED_ARGUMENT:
+                                    maximized = StringUtils.toBoolean(value);
+                                    break;
+                                case UNDECORATED_ARGUMENT:
+                                    undecorated = StringUtils.toBoolean(value);
+                                    break;
+                                case FULL_SCREEN_ARGUMENT:
+                                    fullScreen = StringUtils.toBoolean(value);
+                                    break;
+                                case PRESERVE_SPLASH_SCREEN_ARGUMENT:
+                                    preserveSplashScreen = StringUtils.toBoolean(value);
+                                    break;
+                                case ORIGIN_ARGUMENT:
+                                    origin = new URL(value);
+                                    break;
+                                case USE_APPLICATION_INSTANCE_ARGUMENT:
+                                    useApplicationInstance = StringUtils.toBoolean(value);
+                                    break;
+                                default:
+                                    properties.put(key, value);
+                                    break;
+                            }
+                        } catch (Exception exception) {
+                            System.err.println(String.format(INVALID_PROPERTY_VALUE_MESSAGE, value, key));
                         }
-                    } catch (Exception exception) {
-                        System.err.println(String.format(INVALID_PROPERTY_VALUE_MESSAGE, value, key));
                     }
+                } else if (property.length == 1) {
+                    // Options of the form "--option" have a value of TRUE
+                    properties.put(key, Boolean.TRUE.toString());
                 } else {
                     System.err.println(String.format(INVALID_PROPERTY_FORMAT_MESSAGE, arg));
                 }