2 * Copyright 2007 Google Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.google.zxing.client.result;
20 * Implements the "MECARD" address book entry format.
22 * Supported keys: N, TEL, EMAIL, NOTE, ADR Unsupported keys: SOUND, TEL-AV, BDAY, URL, NICKNAME
24 * Except for TEL, multiple values for keys are also not supported;
25 * the first one found takes precedence.
27 * @author srowen@google.com (Sean Owen)
29 public final class AddressBookDoCoMoResult extends AbstractDoCoMoResult {
31 private final String name;
32 private final String[] phoneNumbers;
33 private final String email;
34 private final String note;
35 private final String address;
37 private AddressBookDoCoMoResult(String name, String[] phoneNumbers, String email, String note, String address) {
38 super(ParsedReaderResultType.ADDRESSBOOK);
40 this.phoneNumbers = phoneNumbers;
43 this.address = address;
46 public static AddressBookDoCoMoResult parse(String rawText) {
47 if (!rawText.startsWith("MECARD:")) {
50 String[] rawName = matchPrefixedField("N:", rawText);
51 if (rawName == null) {
54 String name = parseName(rawName[0]);
55 String[] phoneNumbers = matchPrefixedField("TEL:", rawText);
56 String email = matchSinglePrefixedField("EMAIL:", rawText);
57 String note = matchSinglePrefixedField("NOTE:", rawText);
58 String address = matchSinglePrefixedField("ADR:", rawText);
59 return new AddressBookDoCoMoResult(name, phoneNumbers, email, note, address);
62 public String getName() {
66 public String[] getPhoneNumbers() {
70 public String getEmail() {
74 public String getNote() {
78 public String getAddress() {
82 public String getDisplayResult() {
83 StringBuffer result = new StringBuffer(name);
84 maybeAppend(email, result);
85 maybeAppend(address, result);
86 maybeAppend(phoneNumbers, result);
87 maybeAppend(note, result);
88 return result.toString();
91 private static String parseName(String name) {
92 int comma = name.indexOf((int) ',');
94 // Format may be last,first; switch it around
95 return name.substring(comma + 1) + ' ' + name.substring(0, comma);