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.
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, true);
42 String lastName = matchSingleDoCoMoPrefixedField("X:", rawText, true);
43 String fullName = buildName(firstName, lastName);
44 String title = matchSingleDoCoMoPrefixedField("T:", rawText, true);
45 String org = matchSingleDoCoMoPrefixedField("C:", rawText, true);
46 String address = matchSingleDoCoMoPrefixedField("A:", rawText, true);
47 String phoneNumber1 = matchSingleDoCoMoPrefixedField("B:", rawText, true);
48 String phoneNumber2 = matchSingleDoCoMoPrefixedField("M:", rawText, true);
49 String phoneNumber3 = matchSingleDoCoMoPrefixedField("F:", rawText, true);
50 String email = matchSingleDoCoMoPrefixedField("E:", rawText, true);
52 return new AddressBookParsedResult(maybeWrap(fullName),
54 buildPhoneNumbers(phoneNumber1, phoneNumber2, phoneNumber3),
64 private static String[] buildPhoneNumbers(String number1, String number2, String number3) {
65 Vector numbers = new Vector(3);
66 if (number1 != null) {
67 numbers.addElement(number1);
69 if (number2 != null) {
70 numbers.addElement(number2);
72 if (number3 != null) {
73 numbers.addElement(number3);
75 int size = numbers.size();
79 String[] result = new String[size];
80 for (int i = 0; i < size; i++) {
81 result[i] = (String) numbers.elementAt(i);
86 private static String buildName(String firstName, String lastName) {
87 if (firstName == null) {
90 return lastName == null ? firstName : firstName + ' ' + lastName;