Escape the semicolons: this was easier than I imagined. Tested with an ssid containi...
authorvikrama <vikrama@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Thu, 17 Jun 2010 05:24:42 +0000 (05:24 +0000)
committervikrama <vikrama@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Thu, 17 Jun 2010 05:24:42 +0000 (05:24 +0000)
Still to be done:
1. Rename 'nopass' to something cleaner, so it looks crisp in Android's Barcode Scanner UI.

git-svn-id: http://zxing.googlecode.com/svn/trunk@1441 59b500cc-1b3d-0410-9834-0bbf25fbcc57

zxing.appspot.com/generator/src/com/google/zxing/web/generator/client/WifiGenerator.java

index 3702448..1c8a6bc 100644 (file)
@@ -32,12 +32,11 @@ public class WifiGenerator implements GeneratorSource {
   Grid table = null;
   TextBox ssid = new TextBox();
   TextBox password = new TextBox();
-  // Do not allow multiple selections, thus the false
-  ListBox networkType = new ListBox(false);
+  final boolean multipleSelections = false;
+  ListBox networkType = new ListBox(multipleSelections);
   TextBox[] widgets = {ssid, password };
   
-  public WifiGenerator(ChangeListener changeListener,
-      KeyPressHandler keyListener) {
+  public WifiGenerator(ChangeListener changeListener, KeyPressHandler keyListener) {
        networkType.addItem("WEP", "WEP");
        networkType.addItem("WPA/WPA2", "WPA");
        networkType.addItem("No encryption", "nopass");
@@ -58,15 +57,12 @@ public class WifiGenerator implements GeneratorSource {
     String networkType = getNetworkTypeField();
     
     // Build the output with obtained data.
-    // note that some informations may just be "" if they were not specified.
-    //return getVCard(name, company, tel, url, email, address, memo);
     return getWifiString(ssid, password, networkType);
   }
 
   private String getWifiString(String ssid, String password, String type) {
     StringBuilder output = new StringBuilder();
     output.append("WIFI:");
-    // TODO(vikrama): Escape the semicolons in ssid and password
     output.append("S:").append(ssid).append(';');
     maybeAppend(output, "T:", type);
     maybeAppend(output, "P:", password);
@@ -88,10 +84,7 @@ public class WifiGenerator implements GeneratorSource {
     if (input.contains("\n")) {
       throw new GeneratorException(name + " field must not contain \\n characters.");
     }
-    if (input.contains(";")) {
-       // TODO(viki): Escape semicolons and colons
-      throw new GeneratorException(name + " field must not contains ; characters");
-    }
+    input = input.replace(";", "\\;");
     return input;
   }