Implemented Paul's solution to the basic/regular build problem -- a sort of pseudo...
[zxing.git] / core / src / com / google / zxing / client / result / optional / MobileTagSMSParsedResult.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 "SMS" result encoded according to section 4.6 of the
25  * MobileTag Reader International Specification.</p>
26  *
27  * @author srowen@google.com (Sean Owen)
28  */
29 public final class MobileTagSMSParsedResult extends AbstractMobileTagParsedResult {
30
31   public static final String SERVICE_TYPE = "03";
32
33   private final String to;
34   private final String body;
35   private final String title;
36
37   private MobileTagSMSParsedResult(String to, String body, String title) {
38     super(ParsedReaderResultType.MOBILETAG_SMS);
39     this.to = to;
40     this.body = body;
41     this.title = title;
42   }
43
44   public static MobileTagSMSParsedResult parse(Result result) {
45     if (!result.getBarcodeFormat().equals(BarcodeFormat.DATAMATRIX)) {
46       return null;
47     }
48     String rawText = result.getText();
49     if (!rawText.startsWith(SERVICE_TYPE)) {
50       return null;
51     }
52
53     String[] matches = matchDelimitedFields(rawText.substring(2), 3);
54     if (matches == null) {
55       return null;
56     }
57     String to = matches[0];
58     String body = matches[1];
59     String title = matches[2];
60
61     return new MobileTagSMSParsedResult(to, body, title);
62   }
63
64   public String getTo() {
65     return to;
66   }
67
68   public String getBody() {
69     return body;
70   }
71
72   public String getTitle() {
73     return title;
74   }
75
76   public String getDisplayResult() {
77     StringBuffer result = new StringBuffer(to);
78     maybeAppend(title, result);
79     maybeAppend(body, result);
80     return result.toString();
81   }
82
83 }