mirror of
https://github.com/zxing/zxing.git
synced 2025-03-05 20:48:51 -08:00
Added support for URL to MECARD and VCARD.
git-svn-id: https://zxing.googlecode.com/svn/trunk@622 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
394fb04c81
commit
77d29c3d7a
|
@ -41,7 +41,7 @@ final class AddressBookAUResultParser extends ResultParser {
|
|||
String[] emails = matchMultipleValuePrefix("MAIL", 3, rawText, true);
|
||||
String note = matchSinglePrefixedField("MEMORY:", rawText, '\r', false);
|
||||
String address = matchSinglePrefixedField("ADD:", rawText, '\r', true);
|
||||
return new AddressBookParsedResult(names, phoneNumbers, emails, note, address, null, null, null);
|
||||
return new AddressBookParsedResult(names, phoneNumbers, emails, note, address, null, null, null, null);
|
||||
}
|
||||
|
||||
private static String[] matchMultipleValuePrefix(String prefix, int max, String rawText, boolean trim) {
|
||||
|
|
|
@ -21,11 +21,16 @@ 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
|
||||
* Supported keys: N, TEL, EMAIL, NOTE, ADR, BDAY, URL, plus ORG
|
||||
* Unsupported keys: SOUND, TEL-AV, NICKNAME
|
||||
*
|
||||
* Except for TEL, multiple values for keys are also not supported;
|
||||
* the first one found takes precedence.
|
||||
*
|
||||
* Our understanding of the MECARD format is based on this document:
|
||||
*
|
||||
* http://www.mobicode.org.tw/files/OMIA%20Mobile%20Bar%20Code%20Standard%20v3.2.1.doc
|
||||
*
|
||||
* @author srowen@google.com (Sean Owen)
|
||||
*/
|
||||
final class AddressBookDoCoMoResultParser extends AbstractDoCoMoResultParser {
|
||||
|
@ -46,16 +51,24 @@ final class AddressBookDoCoMoResultParser extends AbstractDoCoMoResultParser {
|
|||
String address = matchSingleDoCoMoPrefixedField("ADR:", rawText, true);
|
||||
String birthday = matchSingleDoCoMoPrefixedField("BDAY:", rawText, true);
|
||||
if (birthday != null && !isStringOfDigits(birthday, 8)) {
|
||||
return null;
|
||||
// No reason to throw out the whole card because the birthday is formatted wrong.
|
||||
birthday = null;
|
||||
}
|
||||
String url = matchSingleDoCoMoPrefixedField("URL:", rawText, true);
|
||||
|
||||
// Although ORG may not be strictly legal in MECARD, it does exist in VCARD and we might as well
|
||||
// honor it when found in the wild.
|
||||
String org = matchSingleDoCoMoPrefixedField("ORG:", rawText, true);
|
||||
|
||||
return new AddressBookParsedResult(maybeWrap(name),
|
||||
phoneNumbers,
|
||||
maybeWrap(email),
|
||||
note,
|
||||
address,
|
||||
null,
|
||||
org,
|
||||
birthday,
|
||||
null);
|
||||
null,
|
||||
url);
|
||||
}
|
||||
|
||||
private static String parseName(String name) {
|
||||
|
|
|
@ -29,6 +29,7 @@ public final class AddressBookParsedResult extends ParsedResult {
|
|||
private final String org;
|
||||
private final String birthday;
|
||||
private final String title;
|
||||
private final String url;
|
||||
|
||||
public AddressBookParsedResult(String[] names,
|
||||
String[] phoneNumbers,
|
||||
|
@ -37,7 +38,8 @@ public final class AddressBookParsedResult extends ParsedResult {
|
|||
String address,
|
||||
String org,
|
||||
String birthday,
|
||||
String title) {
|
||||
String title,
|
||||
String url) {
|
||||
super(ParsedResultType.ADDRESSBOOK);
|
||||
this.names = names;
|
||||
this.phoneNumbers = phoneNumbers;
|
||||
|
@ -47,6 +49,7 @@ public final class AddressBookParsedResult extends ParsedResult {
|
|||
this.org = org;
|
||||
this.birthday = birthday;
|
||||
this.title = title;
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String[] getNames() {
|
||||
|
@ -77,6 +80,10 @@ public final class AddressBookParsedResult extends ParsedResult {
|
|||
return org;
|
||||
}
|
||||
|
||||
public String getURL() {
|
||||
return url;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return birthday formatted as yyyyMMdd (e.g. 19780917)
|
||||
*/
|
||||
|
@ -94,6 +101,7 @@ public final class AddressBookParsedResult extends ParsedResult {
|
|||
maybeAppend(org, result);
|
||||
maybeAppend(birthday, result);
|
||||
maybeAppend(title, result);
|
||||
maybeAppend(url, result);
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
|
|
|
@ -56,7 +56,8 @@ final class BizcardResultParser extends AbstractDoCoMoResultParser {
|
|||
address,
|
||||
org,
|
||||
null,
|
||||
title);
|
||||
title,
|
||||
null);
|
||||
}
|
||||
|
||||
private static String[] buildPhoneNumbers(String number1, String number2, String number3) {
|
||||
|
|
|
@ -53,7 +53,9 @@ final class VCardResultParser extends ResultParser {
|
|||
return null;
|
||||
}
|
||||
String title = matchSingleVCardPrefixedField("TITLE", rawText, true);
|
||||
return new AddressBookParsedResult(names, phoneNumbers, emails, note, address, org, birthday, title);
|
||||
String url = matchSingleVCardPrefixedField("URL", rawText, true);
|
||||
return new AddressBookParsedResult(names, phoneNumbers, emails, note, address, org, birthday,
|
||||
title, url);
|
||||
}
|
||||
|
||||
private static String[] matchVCardPrefixedField(String prefix, String rawText, boolean trim) {
|
||||
|
|
|
@ -63,7 +63,8 @@ final class MobileTagSimpleContactResultParser extends AbstractMobileTagResultPa
|
|||
address,
|
||||
org,
|
||||
birthday,
|
||||
title);
|
||||
title,
|
||||
null);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue