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 "SMS" result encoded according to section 4.6 of the
25 * MobileTag Reader International Specification.</p>
27 * @author srowen@google.com (Sean Owen)
29 public final class MobileTagSMSParsedResult extends AbstractMobileTagParsedResult {
31 public static final String SERVICE_TYPE = "03";
33 private final String to;
34 private final String body;
35 private final String title;
37 private MobileTagSMSParsedResult(String to, String body, String title) {
38 super(ParsedReaderResultType.MOBILETAG_SMS);
44 public static MobileTagSMSParsedResult parse(Result result) {
45 if (!result.getBarcodeFormat().equals(BarcodeFormat.DATAMATRIX)) {
48 String rawText = result.getText();
49 if (!rawText.startsWith(SERVICE_TYPE)) {
53 String[] matches = matchDelimitedFields(rawText.substring(2), 3);
54 if (matches == null) {
57 String to = matches[0];
58 String body = matches[1];
59 String title = matches[2];
61 return new MobileTagSMSParsedResult(to, body, title);
64 public String getTo() {
68 public String getBody() {
72 public String getTitle() {
76 public String getDisplayResult() {
77 StringBuffer result = new StringBuffer(to);
78 maybeAppend(title, result);
79 maybeAppend(body, result);
80 return result.toString();