mirror of
https://github.com/zxing/zxing.git
synced 2025-01-12 11:47:26 -08:00
Fixed naming convention. Everything should be a "ParsedResult"
git-svn-id: https://zxing.googlecode.com/svn/trunk@289 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
c3b3254cf6
commit
cc06bc326b
|
@ -21,16 +21,16 @@ import android.net.ContentURI;
|
|||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.provider.Contacts;
|
||||
import com.google.zxing.client.result.AddressBookAUResult;
|
||||
import com.google.zxing.client.result.AddressBookDoCoMoResult;
|
||||
import com.google.zxing.client.result.BookmarkDoCoMoResult;
|
||||
import com.google.zxing.client.result.EmailAddressResult;
|
||||
import com.google.zxing.client.result.EmailDoCoMoResult;
|
||||
import com.google.zxing.client.result.AddressBookAUParsedResult;
|
||||
import com.google.zxing.client.result.AddressBookDoCoMoParsedResult;
|
||||
import com.google.zxing.client.result.BookmarkDoCoMoParsedResult;
|
||||
import com.google.zxing.client.result.EmailAddressParsedResult;
|
||||
import com.google.zxing.client.result.EmailDoCoMoParsedResult;
|
||||
import com.google.zxing.client.result.ParsedReaderResult;
|
||||
import com.google.zxing.client.result.ParsedReaderResultType;
|
||||
import com.google.zxing.client.result.UPCParsedResult;
|
||||
import com.google.zxing.client.result.URIParsedResult;
|
||||
import com.google.zxing.client.result.URLTOResult;
|
||||
import com.google.zxing.client.result.URLTOParsedResult;
|
||||
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
|
@ -55,7 +55,7 @@ final class ResultHandler extends Handler {
|
|||
Intent intent = null;
|
||||
ParsedReaderResultType type = result.getType();
|
||||
if (type.equals(ParsedReaderResultType.ADDRESSBOOK)) {
|
||||
AddressBookDoCoMoResult addressResult = (AddressBookDoCoMoResult) result;
|
||||
AddressBookDoCoMoParsedResult addressResult = (AddressBookDoCoMoParsedResult) result;
|
||||
intent = new Intent(Contacts.Intents.Insert.ACTION, Contacts.People.CONTENT_URI);
|
||||
putExtra(intent, Contacts.Intents.Insert.NAME, addressResult.getName());
|
||||
putExtra(intent, Contacts.Intents.Insert.PHONE, addressResult.getPhoneNumbers());
|
||||
|
@ -63,7 +63,7 @@ final class ResultHandler extends Handler {
|
|||
putExtra(intent, Contacts.Intents.Insert.NOTES, addressResult.getNote());
|
||||
putExtra(intent, Contacts.Intents.Insert.POSTAL, addressResult.getAddress());
|
||||
} else if (type.equals(ParsedReaderResultType.ADDRESSBOOK_AU)) {
|
||||
AddressBookAUResult addressResult = (AddressBookAUResult) result;
|
||||
AddressBookAUParsedResult addressResult = (AddressBookAUParsedResult) result;
|
||||
intent = new Intent(Contacts.Intents.Insert.ACTION, Contacts.People.CONTENT_URI);
|
||||
putExtra(intent, Contacts.Intents.Insert.NAME, addressResult.getNames());
|
||||
putExtra(intent, Contacts.Intents.Insert.PHONE, addressResult.getPhoneNumbers());
|
||||
|
@ -73,16 +73,16 @@ final class ResultHandler extends Handler {
|
|||
} else if (type.equals(ParsedReaderResultType.BOOKMARK)) {
|
||||
// For now, we can only open the browser, and not actually add a bookmark
|
||||
try {
|
||||
intent = new Intent(Intent.VIEW_ACTION, new ContentURI(((BookmarkDoCoMoResult) result).getURI()));
|
||||
intent = new Intent(Intent.VIEW_ACTION, new ContentURI(((BookmarkDoCoMoParsedResult) result).getURI()));
|
||||
} catch (URISyntaxException e) {
|
||||
}
|
||||
} else if (type.equals(ParsedReaderResultType.URLTO)) {
|
||||
try {
|
||||
intent = new Intent(Intent.VIEW_ACTION, new ContentURI(((URLTOResult) result).getURI()));
|
||||
intent = new Intent(Intent.VIEW_ACTION, new ContentURI(((URLTOParsedResult) result).getURI()));
|
||||
} catch (URISyntaxException e) {
|
||||
}
|
||||
} else if (type.equals(ParsedReaderResultType.EMAIL)) {
|
||||
EmailDoCoMoResult emailResult = (EmailDoCoMoResult) result;
|
||||
EmailDoCoMoParsedResult emailResult = (EmailDoCoMoParsedResult) result;
|
||||
try {
|
||||
intent = new Intent(Intent.SENDTO_ACTION, new ContentURI(emailResult.getTo()));
|
||||
} catch (URISyntaxException e) {
|
||||
|
@ -90,7 +90,7 @@ final class ResultHandler extends Handler {
|
|||
putExtra(intent, "subject", emailResult.getSubject());
|
||||
putExtra(intent, "body", emailResult.getBody());
|
||||
} else if (type.equals(ParsedReaderResultType.EMAIL_ADDRESS)) {
|
||||
EmailAddressResult emailResult = (EmailAddressResult) result;
|
||||
EmailAddressParsedResult emailResult = (EmailAddressParsedResult) result;
|
||||
try {
|
||||
intent = new Intent(Intent.SENDTO_ACTION, new ContentURI(emailResult.getEmailAddress()));
|
||||
} catch (URISyntaxException e) {
|
||||
|
|
|
@ -0,0 +1,135 @@
|
|||
/*
|
||||
* Copyright 2007 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
/**
|
||||
* <p>See
|
||||
* <a href="http://www.nttdocomo.co.jp/english/service/imode/make/content/barcode/about/s2.html">
|
||||
* DoCoMo's documentation</a> about the result types represented by subclasses of this class.</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)
|
||||
*/
|
||||
abstract class AbstractDoCoMoParsedResult extends ParsedReaderResult {
|
||||
|
||||
AbstractDoCoMoParsedResult(ParsedReaderResultType type) {
|
||||
super(type);
|
||||
}
|
||||
|
||||
// This could as well be implemented with java.util.regex. It was already implemented partially
|
||||
// to run in a J2ME enviroment, where this unavailable.
|
||||
|
||||
static String[] matchPrefixedField(String prefix, String rawText) {
|
||||
return matchPrefixedField(prefix, rawText, ';');
|
||||
}
|
||||
|
||||
static String[] matchPrefixedField(String prefix, String rawText, char endChar) {
|
||||
Vector matches = null;
|
||||
int i = 0;
|
||||
int max = rawText.length();
|
||||
while (i < max) {
|
||||
i = rawText.indexOf(prefix, i);
|
||||
if (i < 0) {
|
||||
break;
|
||||
}
|
||||
i += prefix.length(); // Skip past this prefix we found to start
|
||||
int start = i; // Found the start of a match here
|
||||
boolean done = false;
|
||||
while (!done) {
|
||||
i = rawText.indexOf((int) endChar, i);
|
||||
if (i < 0) {
|
||||
// No terminating end character? uh, done. Set i such that loop terminates and break
|
||||
i = rawText.length();
|
||||
done = true;
|
||||
} else if (rawText.charAt(i - 1) == '\\') {
|
||||
// semicolon was escaped so continue
|
||||
i++;
|
||||
} else {
|
||||
// found a match
|
||||
if (matches == null) {
|
||||
matches = new Vector(3); // lazy init
|
||||
}
|
||||
matches.addElement(unescape(rawText.substring(start, i)));
|
||||
i++;
|
||||
done = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (matches == null || matches.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
int size = matches.size();
|
||||
String[] result = new String[size];
|
||||
for (int j = 0; j < size; j++) {
|
||||
result[j] = (String) matches.elementAt(j);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static String matchSinglePrefixedField(String prefix, String rawText) {
|
||||
return matchSinglePrefixedField(prefix, rawText, ';');
|
||||
}
|
||||
|
||||
static String matchSinglePrefixedField(String prefix, String rawText, char endChar) {
|
||||
String[] matches = matchPrefixedField(prefix, rawText, endChar);
|
||||
return matches == null ? null : matches[0];
|
||||
}
|
||||
|
||||
private static String unescape(String escaped) {
|
||||
if (escaped != null) {
|
||||
int backslash = escaped.indexOf((int) '\\');
|
||||
if (backslash >= 0) {
|
||||
int max = escaped.length();
|
||||
StringBuffer unescaped = new StringBuffer(max - 1);
|
||||
unescaped.append(escaped.toCharArray(), 0, backslash);
|
||||
boolean nextIsEscaped = false;
|
||||
for (int i = backslash; i < max; i++) {
|
||||
char c = escaped.charAt(i);
|
||||
if (nextIsEscaped || c != '\\') {
|
||||
unescaped.append(c);
|
||||
nextIsEscaped = false;
|
||||
} else {
|
||||
nextIsEscaped = true;
|
||||
}
|
||||
}
|
||||
return unescaped.toString();
|
||||
}
|
||||
}
|
||||
return escaped;
|
||||
}
|
||||
|
||||
static void maybeAppend(String value, StringBuffer result) {
|
||||
if (value != null) {
|
||||
result.append('\n');
|
||||
result.append(value);
|
||||
}
|
||||
}
|
||||
|
||||
static void maybeAppend(String[] value, StringBuffer result) {
|
||||
if (value != null) {
|
||||
for (int i = 0; i < value.length; i++) {
|
||||
result.append('\n');
|
||||
result.append(value[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,114 @@
|
|||
/*
|
||||
* Copyright 2008 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.Result;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
/**
|
||||
* Implements KDDI AU's address book format. See
|
||||
* <a href="http://www.au.kddi.com/ezfactory/tec/two_dimensions/index.html">
|
||||
* http://www.au.kddi.com/ezfactory/tec/two_dimensions/index.html</a>.
|
||||
* (Thanks to Yuzo for translating!)
|
||||
*
|
||||
* @author srowen@google.com (Sean Owen)
|
||||
*/
|
||||
public final class AddressBookAUParsedResult extends ParsedReaderResult {
|
||||
|
||||
private final String[] names;
|
||||
private final String[] phoneNumbers;
|
||||
private final String[] emails;
|
||||
private final String note;
|
||||
private final String address;
|
||||
|
||||
private AddressBookAUParsedResult(String[] names, String[] phoneNumbers, String[] emails, String note, String address) {
|
||||
super(ParsedReaderResultType.ADDRESSBOOK_AU);
|
||||
this.names = names;
|
||||
this.phoneNumbers = phoneNumbers;
|
||||
this.emails = emails;
|
||||
this.note = note;
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public static AddressBookAUParsedResult 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;
|
||||
}
|
||||
String[] names = matchMultipleValuePrefix("NAME", 2, rawText);
|
||||
String[] phoneNumbers = matchMultipleValuePrefix("TEL", 3, rawText);
|
||||
String[] emails = matchMultipleValuePrefix("MAIL", 3, rawText);
|
||||
String note = AbstractDoCoMoParsedResult.matchSinglePrefixedField("MEMORY", rawText, '\r');
|
||||
String address = AbstractDoCoMoParsedResult.matchSinglePrefixedField("ADD", rawText, '\r');
|
||||
return new AddressBookAUParsedResult(names, phoneNumbers, emails, note, address);
|
||||
}
|
||||
|
||||
private static String[] matchMultipleValuePrefix(String prefix, int max, String rawText) {
|
||||
Vector values = null;
|
||||
for (int i = 1; i <= max; i++) {
|
||||
String value = AbstractDoCoMoParsedResult.matchSinglePrefixedField(prefix + i, rawText, '\r');
|
||||
if (value == null) {
|
||||
break;
|
||||
}
|
||||
if (values == null) {
|
||||
values = new Vector(max); // lazy init
|
||||
}
|
||||
values.addElement(value);
|
||||
}
|
||||
if (values == null) {
|
||||
return null;
|
||||
}
|
||||
String[] result = new String[values.size()];
|
||||
for (int i = 0; i < result.length; i++) {
|
||||
result[i] = (String) values.elementAt(i);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public String[] getNames() {
|
||||
return names;
|
||||
}
|
||||
|
||||
public String[] getPhoneNumbers() {
|
||||
return phoneNumbers;
|
||||
}
|
||||
|
||||
public String[] getEmails() {
|
||||
return emails;
|
||||
}
|
||||
|
||||
public String getNote() {
|
||||
return note;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public String getDisplayResult() {
|
||||
StringBuffer result = new StringBuffer();
|
||||
AbstractDoCoMoParsedResult.maybeAppend(names, result);
|
||||
AbstractDoCoMoParsedResult.maybeAppend(emails, result);
|
||||
AbstractDoCoMoParsedResult.maybeAppend(address, result);
|
||||
AbstractDoCoMoParsedResult.maybeAppend(phoneNumbers, result);
|
||||
AbstractDoCoMoParsedResult.maybeAppend(note, result);
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,103 @@
|
|||
/*
|
||||
* Copyright 2007 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.Result;
|
||||
|
||||
/**
|
||||
* Implements the "MECARD" address book entry format.
|
||||
*
|
||||
* Supported keys: N, TEL, EMAIL, NOTE, ADR Unsupported keys: SOUND, TEL-AV, BDAY, URL, NICKNAME
|
||||
*
|
||||
* Except for TEL, multiple values for keys are also not supported;
|
||||
* the first one found takes precedence.
|
||||
*
|
||||
* @author srowen@google.com (Sean Owen)
|
||||
*/
|
||||
public final class AddressBookDoCoMoParsedResult extends AbstractDoCoMoParsedResult {
|
||||
|
||||
private final String name;
|
||||
private final String[] phoneNumbers;
|
||||
private final String email;
|
||||
private final String note;
|
||||
private final String address;
|
||||
|
||||
private AddressBookDoCoMoParsedResult(String name, String[] phoneNumbers, String email, String note, String address) {
|
||||
super(ParsedReaderResultType.ADDRESSBOOK);
|
||||
this.name = name;
|
||||
this.phoneNumbers = phoneNumbers;
|
||||
this.email = email;
|
||||
this.note = note;
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public static AddressBookDoCoMoParsedResult parse(Result result) {
|
||||
String rawText = result.getText();
|
||||
if (!rawText.startsWith("MECARD:")) {
|
||||
return null;
|
||||
}
|
||||
String[] rawName = matchPrefixedField("N:", rawText);
|
||||
if (rawName == null) {
|
||||
return null;
|
||||
}
|
||||
String name = parseName(rawName[0]);
|
||||
String[] phoneNumbers = matchPrefixedField("TEL:", rawText);
|
||||
String email = matchSinglePrefixedField("EMAIL:", rawText);
|
||||
String note = matchSinglePrefixedField("NOTE:", rawText);
|
||||
String address = matchSinglePrefixedField("ADR:", rawText);
|
||||
return new AddressBookDoCoMoParsedResult(name, phoneNumbers, email, note, address);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String[] getPhoneNumbers() {
|
||||
return phoneNumbers;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public String getNote() {
|
||||
return note;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public String getDisplayResult() {
|
||||
StringBuffer result = new StringBuffer(name);
|
||||
maybeAppend(email, result);
|
||||
maybeAppend(address, result);
|
||||
maybeAppend(phoneNumbers, result);
|
||||
maybeAppend(note, result);
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
private static String parseName(String name) {
|
||||
int comma = name.indexOf((int) ',');
|
||||
if (comma >= 0) {
|
||||
// Format may be last,first; switch it around
|
||||
return name.substring(comma + 1) + ' ' + name.substring(0, comma);
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* Copyright 2007 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.Result;
|
||||
|
||||
/**
|
||||
* @author srowen@google.com (Sean Owen)
|
||||
*/
|
||||
public final class BookmarkDoCoMoParsedResult extends AbstractDoCoMoParsedResult {
|
||||
|
||||
private final String title;
|
||||
private final String uri;
|
||||
|
||||
private BookmarkDoCoMoParsedResult(String title, String uri) {
|
||||
super(ParsedReaderResultType.BOOKMARK);
|
||||
this.title = title;
|
||||
this.uri = uri;
|
||||
}
|
||||
|
||||
public static BookmarkDoCoMoParsedResult parse(Result result) {
|
||||
String rawText = result.getText();
|
||||
if (!rawText.startsWith("MEBKM:")) {
|
||||
return null;
|
||||
}
|
||||
String title = matchSinglePrefixedField("TITLE:", rawText);
|
||||
String[] rawUri = matchPrefixedField("URL:", rawText);
|
||||
if (rawUri == null) {
|
||||
return null;
|
||||
}
|
||||
String uri = rawUri[0];
|
||||
if (!URIParsedResult.isBasicallyValidURI(uri)) {
|
||||
return null;
|
||||
}
|
||||
return new BookmarkDoCoMoParsedResult(title, uri);
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public String getURI() {
|
||||
return uri;
|
||||
}
|
||||
|
||||
public String getDisplayResult() {
|
||||
if (title == null) {
|
||||
return uri;
|
||||
} else {
|
||||
return title + '\n' + uri;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* Copyright 2007 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
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".
|
||||
*
|
||||
* @author srowen@google.com (Sean Owen)
|
||||
*/
|
||||
public final class EmailAddressParsedResult extends AbstractDoCoMoParsedResult {
|
||||
|
||||
private final String emailAddress;
|
||||
|
||||
private EmailAddressParsedResult(String emailAddress) {
|
||||
super(ParsedReaderResultType.EMAIL_ADDRESS);
|
||||
this.emailAddress = emailAddress;
|
||||
}
|
||||
|
||||
public static EmailAddressParsedResult 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
|
||||
emailAddress = rawText.substring(7);
|
||||
} else {
|
||||
if (!EmailDoCoMoParsedResult.isBasicallyValidEmailAddress(rawText)) {
|
||||
return null;
|
||||
}
|
||||
emailAddress = rawText;
|
||||
}
|
||||
return new EmailAddressParsedResult(emailAddress);
|
||||
}
|
||||
|
||||
public String getEmailAddress() {
|
||||
return emailAddress;
|
||||
}
|
||||
|
||||
public String getDisplayResult() {
|
||||
return emailAddress;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,89 @@
|
|||
/*
|
||||
* Copyright 2007 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.Result;
|
||||
|
||||
/**
|
||||
* Implements the "MATMSG" email message entry format.
|
||||
*
|
||||
* Supported keys: TO, SUB, BODY
|
||||
*
|
||||
* @author srowen@google.com (Sean Owen)
|
||||
*/
|
||||
public final class EmailDoCoMoParsedResult extends AbstractDoCoMoParsedResult {
|
||||
|
||||
private final String to;
|
||||
private final String subject;
|
||||
private final String body;
|
||||
|
||||
private EmailDoCoMoParsedResult(String to, String subject, String body) {
|
||||
super(ParsedReaderResultType.EMAIL);
|
||||
this.to = to;
|
||||
this.subject = subject;
|
||||
this.body = body;
|
||||
}
|
||||
|
||||
public static EmailDoCoMoParsedResult parse(Result result) {
|
||||
String rawText = result.getText();
|
||||
if (!rawText.startsWith("MATMSG:")) {
|
||||
return null;
|
||||
}
|
||||
String[] rawTo = matchPrefixedField("TO:", rawText);
|
||||
if (rawTo == null) {
|
||||
return null;
|
||||
}
|
||||
String to = rawTo[0];
|
||||
if (!isBasicallyValidEmailAddress(to)) {
|
||||
return null;
|
||||
}
|
||||
String subject = matchSinglePrefixedField("SUB:", rawText);
|
||||
String body = matchSinglePrefixedField("BODY:", rawText);
|
||||
return new EmailDoCoMoParsedResult(to, subject, body);
|
||||
}
|
||||
|
||||
public String getTo() {
|
||||
return to;
|
||||
}
|
||||
|
||||
public String getSubject() {
|
||||
return subject;
|
||||
}
|
||||
|
||||
public String getBody() {
|
||||
return body;
|
||||
}
|
||||
|
||||
public String getDisplayResult() {
|
||||
StringBuffer result = new StringBuffer(to);
|
||||
maybeAppend(subject, result);
|
||||
maybeAppend(body, result);
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* This implements only the most basic checking for an email address's validity -- that it contains
|
||||
* an '@' and a '.' somewhere after that, and that it contains no space.
|
||||
* We want to generally be lenient here since this class is only intended to encapsulate what's
|
||||
* in a barcode, not "judge" it.
|
||||
*/
|
||||
static boolean isBasicallyValidEmailAddress(String email) {
|
||||
int atIndex = email.indexOf('@');
|
||||
return atIndex >= 0 && email.indexOf('.') > atIndex && email.indexOf(' ') < 0;
|
||||
}
|
||||
|
||||
}
|
|
@ -48,19 +48,19 @@ public abstract class ParsedReaderResult {
|
|||
// way to go about this. For example, we have no reflection available, really.
|
||||
// Order is important here.
|
||||
ParsedReaderResult result;
|
||||
if ((result = BookmarkDoCoMoResult.parse(theResult)) != null) {
|
||||
if ((result = BookmarkDoCoMoParsedResult.parse(theResult)) != null) {
|
||||
return result;
|
||||
} else if ((result = AddressBookDoCoMoResult.parse(theResult)) != null) {
|
||||
} else if ((result = AddressBookDoCoMoParsedResult.parse(theResult)) != null) {
|
||||
return result;
|
||||
} else if ((result = EmailDoCoMoResult.parse(theResult)) != null) {
|
||||
} else if ((result = EmailDoCoMoParsedResult.parse(theResult)) != null) {
|
||||
return result;
|
||||
} else if ((result = EmailAddressResult.parse(theResult)) != null) {
|
||||
} else if ((result = EmailAddressParsedResult.parse(theResult)) != null) {
|
||||
return result;
|
||||
} else if ((result = AddressBookAUResult.parse(theResult)) != null) {
|
||||
} else if ((result = AddressBookAUParsedResult.parse(theResult)) != null) {
|
||||
return result;
|
||||
} else if ((result = GeoParsedResult.parse(theResult)) != null) {
|
||||
return result;
|
||||
} else if ((result = URLTOResult.parse(theResult)) != null) {
|
||||
} else if ((result = URLTOParsedResult.parse(theResult)) != null) {
|
||||
return result;
|
||||
} else if ((result = URIParsedResult.parse(theResult)) != null) {
|
||||
return result;
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* Copyright 2007 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
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
|
||||
* on its origin or official format?
|
||||
*
|
||||
* @author srowen@google.com (Sean Owen)
|
||||
*/
|
||||
public final class URLTOParsedResult extends ParsedReaderResult {
|
||||
|
||||
private final String title;
|
||||
private final String uri;
|
||||
|
||||
private URLTOParsedResult(String title, String uri) {
|
||||
super(ParsedReaderResultType.URLTO);
|
||||
this.title = title;
|
||||
this.uri = uri;
|
||||
}
|
||||
|
||||
public static URLTOParsedResult parse(Result result) {
|
||||
String rawText = result.getText();
|
||||
if (!rawText.startsWith("URLTO:")) {
|
||||
return null;
|
||||
}
|
||||
int titleEnd = rawText.indexOf(':', 6);
|
||||
if (titleEnd < 0) {
|
||||
return null;
|
||||
}
|
||||
String title = rawText.substring(6, titleEnd);
|
||||
String uri = rawText.substring(titleEnd + 1);
|
||||
return new URLTOParsedResult(title, uri);
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public String getURI() {
|
||||
return uri;
|
||||
}
|
||||
|
||||
public String getDisplayResult() {
|
||||
if (title == null) {
|
||||
return uri;
|
||||
} else {
|
||||
return title + '\n' + uri;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -17,14 +17,14 @@
|
|||
package com.google.zxing.client.j2me;
|
||||
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.client.result.BookmarkDoCoMoResult;
|
||||
import com.google.zxing.client.result.EmailAddressResult;
|
||||
import com.google.zxing.client.result.EmailDoCoMoResult;
|
||||
import com.google.zxing.client.result.BookmarkDoCoMoParsedResult;
|
||||
import com.google.zxing.client.result.EmailAddressParsedResult;
|
||||
import com.google.zxing.client.result.EmailDoCoMoParsedResult;
|
||||
import com.google.zxing.client.result.ParsedReaderResult;
|
||||
import com.google.zxing.client.result.ParsedReaderResultType;
|
||||
import com.google.zxing.client.result.UPCParsedResult;
|
||||
import com.google.zxing.client.result.URIParsedResult;
|
||||
import com.google.zxing.client.result.URLTOResult;
|
||||
import com.google.zxing.client.result.URLTOParsedResult;
|
||||
|
||||
import javax.microedition.io.ConnectionNotFoundException;
|
||||
import javax.microedition.lcdui.Alert;
|
||||
|
@ -196,16 +196,16 @@ public final class ZXingMIDlet extends MIDlet {
|
|||
String uri = ((URIParsedResult) result).getURI();
|
||||
showOpenURL("Open Web Page?", uri, uri);
|
||||
} else if (type.equals(ParsedReaderResultType.BOOKMARK)) {
|
||||
String uri = ((BookmarkDoCoMoResult) result).getURI();
|
||||
String uri = ((BookmarkDoCoMoParsedResult) result).getURI();
|
||||
showOpenURL("Open Web Page?", uri, uri);
|
||||
} else if (type.equals(ParsedReaderResultType.URLTO)) {
|
||||
String uri = ((URLTOResult) result).getURI();
|
||||
String uri = ((URLTOParsedResult) result).getURI();
|
||||
showOpenURL("Open Web Page?", uri, uri);
|
||||
} else if (type.equals(ParsedReaderResultType.EMAIL)) {
|
||||
String email = ((EmailDoCoMoResult) result).getTo();
|
||||
String email = ((EmailDoCoMoParsedResult) result).getTo();
|
||||
showOpenURL("Compose E-mail?", email, "mailto:" + email);
|
||||
} else if (type.equals(ParsedReaderResultType.EMAIL_ADDRESS)) {
|
||||
String email = ((EmailAddressResult) result).getEmailAddress();
|
||||
String email = ((EmailAddressParsedResult) result).getEmailAddress();
|
||||
showOpenURL("Compose E-mail?", email, "mailto:" + email);
|
||||
//} else if (type.equals(ParsedReaderResultType.GEO)) {
|
||||
// GeoParsedResult geoResult = (GeoParsedResult) result;
|
||||
|
|
Loading…
Reference in a new issue