Implemented Paul's solution to the basic/regular build problem -- a sort of pseudo...
[zxing.git] / core / src / com / google / zxing / client / result / optional / MobileTagSimpleContactParsedResult.java
1 /*
2  * Copyright 2008 ZXing authors
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package com.google.zxing.client.result.optional;
18
19 import com.google.zxing.BarcodeFormat;
20 import com.google.zxing.Result;
21 import com.google.zxing.client.result.ParsedReaderResultType;
22
23 /**
24  * <p>Represents a "simple contact" result encoded according to section 4.8 of the
25  * MobileTag Reader International Specification.</p>
26  *
27  * @author srowen@google.com (Sean Owen)
28  */
29 public final class MobileTagSimpleContactParsedResult extends AbstractMobileTagParsedResult {
30
31   public static final String SERVICE_TYPE = "02";
32
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;
42
43   private MobileTagSimpleContactParsedResult(String fullName,
44                                              String telephoneCell,
45                                              String telephone,
46                                              String email1,
47                                              String email2,
48                                              String address,
49                                              String org,
50                                              String birthday,
51                                              String title) {
52     super(ParsedReaderResultType.MOBILETAG_SIMPLE_CONTACT);
53     this.fullName = fullName;
54     this.telephoneCell = telephoneCell;
55     this.telephone = telephone;
56     this.email1 = email1;
57     this.email2 = email2;
58     this.address = address;
59     this.org = org;
60     this.birthday = birthday;
61     this.title = title;
62   }
63
64   public static MobileTagSimpleContactParsedResult parse(Result result) {
65     if (!result.getBarcodeFormat().equals(BarcodeFormat.DATAMATRIX)) {
66       return null;
67     }
68     String rawText = result.getText();
69     if (!rawText.startsWith(SERVICE_TYPE)) {
70       return null;
71     }
72
73     String[] matches = matchDelimitedFields(rawText.substring(2), 9);
74     if (matches == null || !isDigits(matches[7], 8)) {
75       return null;
76     }
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];
86
87     return new MobileTagSimpleContactParsedResult(fullName,
88                                                   telephoneCell,
89                                                   telephone,
90                                                   email1,
91                                                   email2,
92                                                   address,
93                                                   org,
94                                                   birthday,
95                                                   title);
96   }
97
98
99   public String getFullName() {
100     return fullName;
101   }
102
103   public String getTelephoneCell() {
104     return telephoneCell;
105   }
106
107   public String getTelephone() {
108     return telephone;
109   }
110
111   public String getEmail1() {
112     return email1;
113   }
114
115   public String getEmail2() {
116     return email2;
117   }
118
119   public String getAddress() {
120     return address;
121   }
122
123   public String getOrg() {
124     return org;
125   }
126
127   public String getBirthday() {
128     return birthday;
129   }
130
131   public String getTitle() {
132     return title;
133   }
134
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();
146   }
147
148 }