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.optional;
19 import com.google.zxing.BarcodeFormat;
20 import com.google.zxing.Result;
21 import com.google.zxing.client.result.ParsedReaderResultType;
24 * <p>Represents a "simple contact" result encoded according to section 4.8 of the
25 * MobileTag Reader International Specification.</p>
27 * @author srowen@google.com (Sean Owen)
29 public final class MobileTagSimpleContactParsedResult extends AbstractMobileTagParsedResult {
31 public static final String SERVICE_TYPE = "02";
33 private final String fullName;
34 private final String telephoneCell;
35 private final String telephone;
36 private final String email1;
37 private final String email2;
38 private final String address;
39 private final String org;
40 private final String birthday;
41 private final String title;
43 private MobileTagSimpleContactParsedResult(String fullName,
52 super(ParsedReaderResultType.MOBILETAG_SIMPLE_CONTACT);
53 this.fullName = fullName;
54 this.telephoneCell = telephoneCell;
55 this.telephone = telephone;
58 this.address = address;
60 this.birthday = birthday;
64 public static MobileTagSimpleContactParsedResult parse(Result result) {
65 if (!result.getBarcodeFormat().equals(BarcodeFormat.DATAMATRIX)) {
68 String rawText = result.getText();
69 if (!rawText.startsWith(SERVICE_TYPE)) {
73 String[] matches = matchDelimitedFields(rawText.substring(2), 9);
74 if (matches == null || !isDigits(matches[7], 8)) {
77 String fullName = matches[0];
78 String telephoneCell = matches[1];
79 String telephone = matches[2];
80 String email1 = matches[3];
81 String email2 = matches[4];
82 String address = matches[5];
83 String org = matches[6];
84 String birthday = matches[7];
85 String title = matches[8];
87 return new MobileTagSimpleContactParsedResult(fullName,
99 public String getFullName() {
103 public String getTelephoneCell() {
104 return telephoneCell;
107 public String getTelephone() {
111 public String getEmail1() {
115 public String getEmail2() {
119 public String getAddress() {
123 public String getOrg() {
127 public String getBirthday() {
131 public String getTitle() {
135 public String getDisplayResult() {
136 StringBuffer result = new StringBuffer(fullName);
137 maybeAppend(telephoneCell, result);
138 maybeAppend(telephone, result);
139 maybeAppend(email1, result);
140 maybeAppend(email2, result);
141 maybeAppend(address, result);
142 maybeAppend(org, result);
143 maybeAppend(birthday, result);
144 maybeAppend(title, result);
145 return result.toString();