mirror of
https://github.com/zxing/zxing.git
synced 2025-03-05 20:48:51 -08:00
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:
parent
34cc1d2b9d
commit
94e3009849
|
@ -16,6 +16,8 @@
|
|||
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.Result;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
/**
|
||||
|
@ -43,7 +45,8 @@ public final class AddressBookAUResult extends ParsedReaderResult {
|
|||
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
|
||||
if (rawText.indexOf("MEMORY") < 0 || rawText.indexOf("\r\n") < 0) {
|
||||
return null;
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.Result;
|
||||
|
||||
/**
|
||||
* Implements the "MECARD" address book entry format.
|
||||
*
|
||||
|
@ -43,7 +45,8 @@ public final class AddressBookDoCoMoResult extends AbstractDoCoMoResult {
|
|||
this.address = address;
|
||||
}
|
||||
|
||||
public static AddressBookDoCoMoResult parse(String rawText) {
|
||||
public static AddressBookDoCoMoResult parse(Result result) {
|
||||
String rawText = result.getText();
|
||||
if (!rawText.startsWith("MECARD:")) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.Result;
|
||||
|
||||
/**
|
||||
* @author srowen@google.com (Sean Owen)
|
||||
*/
|
||||
|
@ -30,7 +32,8 @@ public final class BookmarkDoCoMoResult extends AbstractDoCoMoResult {
|
|||
this.uri = uri;
|
||||
}
|
||||
|
||||
public static BookmarkDoCoMoResult parse(String rawText) {
|
||||
public static BookmarkDoCoMoResult parse(Result result) {
|
||||
String rawText = result.getText();
|
||||
if (!rawText.startsWith("MEBKM:")) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
|
||||
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
|
||||
* 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;
|
||||
}
|
||||
|
||||
public static EmailAddressResult parse(String rawText) {
|
||||
public static EmailAddressResult parse(Result result) {
|
||||
String rawText = result.getText();
|
||||
String emailAddress;
|
||||
if (rawText.startsWith("mailto:")) {
|
||||
// If it starts with mailto:, assume it is definitely trying to be an email address
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.Result;
|
||||
|
||||
/**
|
||||
* Implements the "MATMSG" email message entry format.
|
||||
*
|
||||
|
@ -36,7 +38,8 @@ public final class EmailDoCoMoResult extends AbstractDoCoMoResult {
|
|||
this.body = body;
|
||||
}
|
||||
|
||||
public static EmailDoCoMoResult parse(String rawText) {
|
||||
public static EmailDoCoMoResult parse(Result result) {
|
||||
String rawText = result.getText();
|
||||
if (!rawText.startsWith("MATMSG:")) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
// way to go about this. For example, we have no reflection available, really.
|
||||
// Order is important here.
|
||||
String rawText = theResult.getText();
|
||||
ParsedReaderResult result;
|
||||
if ((result = BookmarkDoCoMoResult.parse(rawText)) != null) {
|
||||
if ((result = BookmarkDoCoMoResult.parse(theResult)) != null) {
|
||||
return result;
|
||||
} else if ((result = AddressBookDoCoMoResult.parse(rawText)) != null) {
|
||||
} else if ((result = AddressBookDoCoMoResult.parse(theResult)) != null) {
|
||||
return result;
|
||||
} else if ((result = EmailDoCoMoResult.parse(rawText)) != null) {
|
||||
} else if ((result = EmailDoCoMoResult.parse(theResult)) != null) {
|
||||
return result;
|
||||
} else if ((result = EmailAddressResult.parse(rawText)) != null) {
|
||||
} else if ((result = EmailAddressResult.parse(theResult)) != null) {
|
||||
return result;
|
||||
} else if ((result = AddressBookAUResult.parse(rawText)) != null) {
|
||||
} else if ((result = AddressBookAUResult.parse(theResult)) != null) {
|
||||
return result;
|
||||
} else if ((result = URLTOResult.parse(rawText)) != null) {
|
||||
} else if ((result = URLTOResult.parse(theResult)) != null) {
|
||||
return result;
|
||||
} else if ((result = URIParsedResult.parse(rawText)) != null) {
|
||||
} else if ((result = URIParsedResult.parse(theResult)) != null) {
|
||||
return result;
|
||||
} else if ((result = UPCParsedResult.parse(rawText)) != null) {
|
||||
} else if ((result = UPCParsedResult.parse(theResult)) != null) {
|
||||
return result;
|
||||
}
|
||||
return TextParsedResult.parse(rawText);
|
||||
return TextParsedResult.parse(theResult);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.Result;
|
||||
|
||||
/**
|
||||
* @author srowen@google.com (Sean Owen)
|
||||
*/
|
||||
|
@ -28,8 +30,8 @@ public final class TextParsedResult extends ParsedReaderResult {
|
|||
this.text = text;
|
||||
}
|
||||
|
||||
public static TextParsedResult parse(String rawText) {
|
||||
return new TextParsedResult(rawText);
|
||||
public static TextParsedResult parse(Result result) {
|
||||
return new TextParsedResult(result.getText());
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.Result;
|
||||
|
||||
/**
|
||||
* @author dswitkin@google.com (Daniel Switkin)
|
||||
*/
|
||||
|
@ -28,7 +30,8 @@ public final class UPCParsedResult extends ParsedReaderResult {
|
|||
this.upc = upc;
|
||||
}
|
||||
|
||||
public static UPCParsedResult parse(String rawText) {
|
||||
public static UPCParsedResult parse(Result result) {
|
||||
String rawText = result.getText();
|
||||
int length = rawText.length();
|
||||
if (length != 12 && length != 13) {
|
||||
return null;
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.Result;
|
||||
|
||||
/**
|
||||
* @author srowen@google.com (Sean Owen)
|
||||
*/
|
||||
|
@ -28,7 +30,8 @@ public final class URIParsedResult extends ParsedReaderResult {
|
|||
this.uri = uri;
|
||||
}
|
||||
|
||||
public static URIParsedResult parse(String rawText) {
|
||||
public static URIParsedResult parse(Result result) {
|
||||
String rawText = result.getText();
|
||||
if (!isBasicallyValidURI(rawText)) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.Result;
|
||||
|
||||
/**
|
||||
* "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
|
||||
|
@ -34,7 +36,8 @@ public final class URLTOResult extends ParsedReaderResult {
|
|||
this.uri = uri;
|
||||
}
|
||||
|
||||
public static URLTOResult parse(String rawText) {
|
||||
public static URLTOResult parse(Result result) {
|
||||
String rawText = result.getText();
|
||||
if (!rawText.startsWith("URLTO:")) {
|
||||
return null;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue