Add geo: URL support (oh and removed an old moved file)
[zxing.git] / core / src / com / google / zxing / client / result / ParsedReaderResult.java
index f80bf71..cff844d 100644 (file)
 
 package com.google.zxing.client.result;
 
+import com.google.zxing.Result;
+
 /**
+ * <p>Abstract class representing the result of decoding a barcode, as more than
+ * a String -- as some type of structured data. This might be a subclass which represents
+ * a URL, or an e-mail address. {@link #parseReaderResult(Result)} will turn a raw
+ * decoded string into the most appropriate type of structured representation.</p>
+ *
+ * <p>Thanks to Jeff Griffin for proposing rewrite of these classes that relies less
+ * on exception-based mechanisms during parsing.</p>
+ *
  * @author srowen@google.com (Sean Owen)
  */
 public abstract class ParsedReaderResult {
 
   private final ParsedReaderResultType type;
 
-  ParsedReaderResult(ParsedReaderResultType type) {
+  public ParsedReaderResult(ParsedReaderResultType type) {
     this.type = type;
   }
 
@@ -33,41 +43,31 @@ public abstract class ParsedReaderResult {
 
   public abstract String getDisplayResult();
 
-  public static ParsedReaderResult parseReaderResult(String rawText) {
+  public static ParsedReaderResult parseReaderResult(Result theResult) {
     // This is a bit messy, but given limited options in MIDP / CLDC, this may well be the simplest
     // way to go about this. For example, we have no reflection available, really.
     // Order is important here.
-    try {
-      return new BookmarkDoCoMoResult(rawText);
-    } catch (IllegalArgumentException iae) {
-      // continue
-    }
-    try {
-      return new AddressBookDoCoMoResult(rawText);
-    } catch (IllegalArgumentException iae) {
-      // continue
-    }
-    try {
-      return new EmailDoCoMoResult(rawText);
-    } catch (IllegalArgumentException iae) {
-      // continue
-    }
-    try {
-      return new EmailAddressResult(rawText);
-    } catch (IllegalArgumentException iae) {
-      // continue
-    }
-    try {
-      return new URIParsedResult(rawText);
-    } catch (IllegalArgumentException iae) {
-      // continue
-    }
-    try {
-      return new UPCParsedResult(rawText);
-    } catch (IllegalArgumentException iae) {
-      // continue
+    ParsedReaderResult result;
+    if ((result = BookmarkDoCoMoResult.parse(theResult)) != null) {
+      return result;
+    } else if ((result = AddressBookDoCoMoResult.parse(theResult)) != null) {
+      return result;
+    } else if ((result = EmailDoCoMoResult.parse(theResult)) != null) {
+      return result;
+    } else if ((result = EmailAddressResult.parse(theResult)) != null) {
+      return result;
+    } else if ((result = AddressBookAUResult.parse(theResult)) != null) {
+      return result;
+    } else if ((result = GeoParsedResult.parse(theResult)) != null) {
+      return result;
+    } else if ((result = URLTOResult.parse(theResult)) != null) {
+      return result;
+    } else if ((result = URIParsedResult.parse(theResult)) != null) {
+      return result;
+    } else if ((result = UPCParsedResult.parse(theResult)) != null) {
+      return result;
     }
-    return new TextParsedResult(rawText);
+    return TextParsedResult.parse(theResult);
   }
 
   public String toString() {