Changed signature of parse() to take in more general Result

git-svn-id: https://zxing.googlecode.com/svn/trunk@279 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
srowen 2008-03-14 18:53:25 +00:00
parent 34cc1d2b9d
commit 94e3009849
10 changed files with 45 additions and 20 deletions

View file

@ -16,6 +16,8 @@
package com.google.zxing.client.result; package com.google.zxing.client.result;
import com.google.zxing.Result;
import java.util.Vector; import java.util.Vector;
/** /**
@ -43,7 +45,8 @@ public final class AddressBookAUResult extends ParsedReaderResult {
this.address = address; this.address = address;
} }
public static AddressBookAUResult parse(String rawText) { public static AddressBookAUResult parse(Result result) {
String rawText = result.getText();
// MEMORY is mandatory; seems like a decent indicator, as does end-of-record separator CR/LF // MEMORY is mandatory; seems like a decent indicator, as does end-of-record separator CR/LF
if (rawText.indexOf("MEMORY") < 0 || rawText.indexOf("\r\n") < 0) { if (rawText.indexOf("MEMORY") < 0 || rawText.indexOf("\r\n") < 0) {
return null; return null;

View file

@ -16,6 +16,8 @@
package com.google.zxing.client.result; package com.google.zxing.client.result;
import com.google.zxing.Result;
/** /**
* Implements the "MECARD" address book entry format. * Implements the "MECARD" address book entry format.
* *
@ -43,7 +45,8 @@ public final class AddressBookDoCoMoResult extends AbstractDoCoMoResult {
this.address = address; this.address = address;
} }
public static AddressBookDoCoMoResult parse(String rawText) { public static AddressBookDoCoMoResult parse(Result result) {
String rawText = result.getText();
if (!rawText.startsWith("MECARD:")) { if (!rawText.startsWith("MECARD:")) {
return null; return null;
} }

View file

@ -16,6 +16,8 @@
package com.google.zxing.client.result; package com.google.zxing.client.result;
import com.google.zxing.Result;
/** /**
* @author srowen@google.com (Sean Owen) * @author srowen@google.com (Sean Owen)
*/ */
@ -30,7 +32,8 @@ public final class BookmarkDoCoMoResult extends AbstractDoCoMoResult {
this.uri = uri; this.uri = uri;
} }
public static BookmarkDoCoMoResult parse(String rawText) { public static BookmarkDoCoMoResult parse(Result result) {
String rawText = result.getText();
if (!rawText.startsWith("MEBKM:")) { if (!rawText.startsWith("MEBKM:")) {
return null; return null;
} }

View file

@ -16,6 +16,8 @@
package com.google.zxing.client.result; package com.google.zxing.client.result;
import com.google.zxing.Result;
/** /**
* Represents a result that encodes an e-mail address, either as a plain address * Represents a result that encodes an e-mail address, either as a plain address
* like "joe@example.org" or a mailto: URL like "mailto:joe@example.org". * like "joe@example.org" or a mailto: URL like "mailto:joe@example.org".
@ -31,7 +33,8 @@ public final class EmailAddressResult extends AbstractDoCoMoResult {
this.emailAddress = emailAddress; this.emailAddress = emailAddress;
} }
public static EmailAddressResult parse(String rawText) { public static EmailAddressResult parse(Result result) {
String rawText = result.getText();
String emailAddress; String emailAddress;
if (rawText.startsWith("mailto:")) { if (rawText.startsWith("mailto:")) {
// If it starts with mailto:, assume it is definitely trying to be an email address // If it starts with mailto:, assume it is definitely trying to be an email address

View file

@ -16,6 +16,8 @@
package com.google.zxing.client.result; package com.google.zxing.client.result;
import com.google.zxing.Result;
/** /**
* Implements the "MATMSG" email message entry format. * Implements the "MATMSG" email message entry format.
* *
@ -36,7 +38,8 @@ public final class EmailDoCoMoResult extends AbstractDoCoMoResult {
this.body = body; this.body = body;
} }
public static EmailDoCoMoResult parse(String rawText) { public static EmailDoCoMoResult parse(Result result) {
String rawText = result.getText();
if (!rawText.startsWith("MATMSG:")) { if (!rawText.startsWith("MATMSG:")) {
return null; return null;
} }

View file

@ -47,26 +47,25 @@ public abstract class ParsedReaderResult {
// This is a bit messy, but given limited options in MIDP / CLDC, this may well be the simplest // 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. // way to go about this. For example, we have no reflection available, really.
// Order is important here. // Order is important here.
String rawText = theResult.getText();
ParsedReaderResult result; ParsedReaderResult result;
if ((result = BookmarkDoCoMoResult.parse(rawText)) != null) { if ((result = BookmarkDoCoMoResult.parse(theResult)) != null) {
return result; return result;
} else if ((result = AddressBookDoCoMoResult.parse(rawText)) != null) { } else if ((result = AddressBookDoCoMoResult.parse(theResult)) != null) {
return result; return result;
} else if ((result = EmailDoCoMoResult.parse(rawText)) != null) { } else if ((result = EmailDoCoMoResult.parse(theResult)) != null) {
return result; return result;
} else if ((result = EmailAddressResult.parse(rawText)) != null) { } else if ((result = EmailAddressResult.parse(theResult)) != null) {
return result; return result;
} else if ((result = AddressBookAUResult.parse(rawText)) != null) { } else if ((result = AddressBookAUResult.parse(theResult)) != null) {
return result; return result;
} else if ((result = URLTOResult.parse(rawText)) != null) { } else if ((result = URLTOResult.parse(theResult)) != null) {
return result; return result;
} else if ((result = URIParsedResult.parse(rawText)) != null) { } else if ((result = URIParsedResult.parse(theResult)) != null) {
return result; return result;
} else if ((result = UPCParsedResult.parse(rawText)) != null) { } else if ((result = UPCParsedResult.parse(theResult)) != null) {
return result; return result;
} }
return TextParsedResult.parse(rawText); return TextParsedResult.parse(theResult);
} }
public String toString() { public String toString() {

View file

@ -16,6 +16,8 @@
package com.google.zxing.client.result; package com.google.zxing.client.result;
import com.google.zxing.Result;
/** /**
* @author srowen@google.com (Sean Owen) * @author srowen@google.com (Sean Owen)
*/ */
@ -28,8 +30,8 @@ public final class TextParsedResult extends ParsedReaderResult {
this.text = text; this.text = text;
} }
public static TextParsedResult parse(String rawText) { public static TextParsedResult parse(Result result) {
return new TextParsedResult(rawText); return new TextParsedResult(result.getText());
} }
public String getText() { public String getText() {

View file

@ -16,6 +16,8 @@
package com.google.zxing.client.result; package com.google.zxing.client.result;
import com.google.zxing.Result;
/** /**
* @author dswitkin@google.com (Daniel Switkin) * @author dswitkin@google.com (Daniel Switkin)
*/ */
@ -28,7 +30,8 @@ public final class UPCParsedResult extends ParsedReaderResult {
this.upc = upc; this.upc = upc;
} }
public static UPCParsedResult parse(String rawText) { public static UPCParsedResult parse(Result result) {
String rawText = result.getText();
int length = rawText.length(); int length = rawText.length();
if (length != 12 && length != 13) { if (length != 12 && length != 13) {
return null; return null;

View file

@ -16,6 +16,8 @@
package com.google.zxing.client.result; package com.google.zxing.client.result;
import com.google.zxing.Result;
/** /**
* @author srowen@google.com (Sean Owen) * @author srowen@google.com (Sean Owen)
*/ */
@ -28,7 +30,8 @@ public final class URIParsedResult extends ParsedReaderResult {
this.uri = uri; this.uri = uri;
} }
public static URIParsedResult parse(String rawText) { public static URIParsedResult parse(Result result) {
String rawText = result.getText();
if (!isBasicallyValidURI(rawText)) { if (!isBasicallyValidURI(rawText)) {
return null; return null;
} }

View file

@ -16,6 +16,8 @@
package com.google.zxing.client.result; package com.google.zxing.client.result;
import com.google.zxing.Result;
/** /**
* "URLTO" result format, which is of the form "URLTO:[title]:[url]". * "URLTO" result format, which is of the form "URLTO:[title]:[url]".
* This seems to be used sometimes, but I am not able to find documentation * This seems to be used sometimes, but I am not able to find documentation
@ -34,7 +36,8 @@ public final class URLTOResult extends ParsedReaderResult {
this.uri = uri; this.uri = uri;
} }
public static URLTOResult parse(String rawText) { public static URLTOResult parse(Result result) {
String rawText = result.getText();
if (!rawText.startsWith("URLTO:")) { if (!rawText.startsWith("URLTO:")) {
return null; return null;
} }