2 * Copyright 2008 ZXing authors
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;
19 import com.google.zxing.Result;
21 import java.util.Vector;
24 * Implements the "BIZCARD" address book entry format, though this has been
25 * largely reverse-engineered from examples observed in the wild -- still
26 * looking for a definitive reference.
28 * @author srowen@google.com (Sean Owen)
30 final class BizcardResultParser extends AbstractDoCoMoResultParser {
32 // Yes, we extend AbstractDoCoMoResultParser since the format is very much
33 // like the DoCoMo MECARD format, but this is not technically one of
34 // DoCoMo's proposed formats
36 public static AddressBookParsedResult parse(Result result) {
37 String rawText = result.getText();
38 if (rawText == null || !rawText.startsWith("BIZCARD:")) {
41 String firstName = matchSingleDoCoMoPrefixedField("N:", rawText);
42 String lastName = matchSingleDoCoMoPrefixedField("X:", rawText);
43 String fullName = buildName(firstName, lastName);
44 String title = matchSingleDoCoMoPrefixedField("T:", rawText);
45 String org = matchSingleDoCoMoPrefixedField("C:", rawText);
46 String address = matchSingleDoCoMoPrefixedField("A:", rawText);
47 String phoneNumber1 = matchSingleDoCoMoPrefixedField("B:", rawText);
48 String phoneNumber2 = matchSingleDoCoMoPrefixedField("M:", rawText);
49 String phoneNumber3 = matchSingleDoCoMoPrefixedField("F:", rawText);
50 String email = matchSingleDoCoMoPrefixedField("E:", rawText);
52 return new AddressBookParsedResult(maybeWrap(fullName),
53 buildPhoneNumbers(phoneNumber1, phoneNumber2, phoneNumber3),
62 private static String[] buildPhoneNumbers(String number1, String number2, String number3) {
63 Vector numbers = new Vector(3);
64 if (number1 != null) {
65 numbers.addElement(number1);
67 if (number2 != null) {
68 numbers.addElement(number2);
70 if (number3 != null) {
71 numbers.addElement(number3);
73 int size = numbers.size();
77 String[] result = new String[size];
78 for (int i = 0; i < size; i++) {
79 result[i] = (String) numbers.elementAt(i);
84 private static String buildName(String firstName, String lastName) {
85 if (firstName == null) {
88 return lastName == null ? firstName : firstName + ' ' + lastName;