Issue 294, don't actually generate nonstandard ORG value for MECARD
[zxing.git] / zxing.appspot.com / generator / src / com / google / zxing / web / generator / client / ContactInfoGenerator.java
index d3d9934..97c2f54 100644 (file)
@@ -16,6 +16,7 @@
 
 package com.google.zxing.web.generator.client;
 
+import com.google.gwt.event.dom.client.KeyPressHandler;
 import com.google.gwt.user.client.ui.ChangeListener;
 import com.google.gwt.user.client.ui.Grid;
 import com.google.gwt.user.client.ui.TextBox;
@@ -38,9 +39,11 @@ public class ContactInfoGenerator implements GeneratorSource {
   TextBox memo = new TextBox();
   TextBox[] widgets = {name, company, tel, url, email, address, address2, memo};
   
-  public ContactInfoGenerator(ChangeListener changeListener) {
+  public ContactInfoGenerator(ChangeListener changeListener,
+      KeyPressHandler keyListener) {
     for (TextBox w: widgets) {
       w.addChangeListener(changeListener);
+      w.addKeyPressHandler(keyListener);
     }
   }
   
@@ -50,7 +53,7 @@ public class ContactInfoGenerator implements GeneratorSource {
 
   public String getText() throws GeneratorException {
     String name = getNameField();
-    String company = getCompanyField();
+    //String company = getCompanyField();
     String tel = getTelField();
     String url = getUrlField();
     String email = getEmailField();
@@ -61,15 +64,15 @@ public class ContactInfoGenerator implements GeneratorSource {
     // 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 getMeCard(name, company, tel, url, email, address, address2, memo);
+    return getMeCard(name, tel, url, email, address, address2, memo);
   }
 
-  private String getMeCard(String name, String company, String tel, String url,
+  private String getMeCard(String name, String tel, String url,
       String email, String address, String address2, String memo) {
     StringBuilder output = new StringBuilder();
     output.append("MECARD:");
     output.append("N:").append(name).append(';');
-    maybeAppend(output, "ORG:", company);
+    //maybeAppend(output, "ORG:", company); // Not standard; don't generate
     maybeAppend(output, "TEL:", tel);
     maybeAppend(output, "URL:", url);
     maybeAppend(output, "EMAIL:", email);
@@ -116,26 +119,30 @@ public class ContactInfoGenerator implements GeneratorSource {
   }
   */
 
-  private static String parseTextField(TextBox textBox) throws GeneratorException {
+  private static String parseTextField(String name, TextBox textBox) throws GeneratorException {
     String input = textBox.getText();
     if (input.length() < 1) {
       return "";
     }
     if (input.contains("\n")) {
-      throw new GeneratorException("Field must not contain \\n characters.");
+      throw new GeneratorException(name + " field must not contain \\n characters.");
     }
     if (input.contains(";")) {
-      throw new GeneratorException("Field must not contains ; characters");
+      throw new GeneratorException(name + " field must not contains ; characters");
     }
     return input;
   }
   
   private String getNameField() throws GeneratorException {
-    return parseTextField(name);
+    String input = name.getText();
+    if (input.length() < 1) {
+      throw new GeneratorException("Name must be at least 1 character.");
+    }
+    return parseTextField("Name", name);
   }
   
   private String getCompanyField() throws GeneratorException {
-    return parseTextField(company);
+    return parseTextField("Company", company);
   }
 
   private String getTelField() throws GeneratorException {
@@ -171,15 +178,15 @@ public class ContactInfoGenerator implements GeneratorSource {
   }
   
   private String getAddressField() throws GeneratorException {
-    return parseTextField(address);
+    return parseTextField("Address", address);
   }
 
   private String getAddress2Field() throws GeneratorException {
-    return parseTextField(address2);
+    return parseTextField("Address 2", address2);
   }
   
   private String getMemoField() throws GeneratorException {
-    return parseTextField(memo);
+    return parseTextField("Memo", memo);
   }
   
   public Grid getWidget() {