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 calendar" result encoded according to section 4.9 of the
25 * MobileTag Reader International Specification.</p>
27 * @author srowen@google.com (Sean Owen)
29 public final class MobileTagSimpleCalendarParsedResult extends AbstractMobileTagParsedResult {
31 public static final String SERVICE_TYPE = "07";
33 private final String summary;
34 private final String start;
35 private final String end;
36 private final String location;
37 private final String attendee;
38 private final String title;
40 private MobileTagSimpleCalendarParsedResult(String summary,
46 super(ParsedReaderResultType.MOBILETAG_SIMPLE_CALENDAR);
47 this.summary = summary;
50 this.location = location;
51 this.attendee = attendee;
55 public static MobileTagSimpleCalendarParsedResult parse(Result result) {
56 if (!result.getBarcodeFormat().equals(BarcodeFormat.DATAMATRIX)) {
59 String rawText = result.getText();
60 if (!rawText.startsWith(SERVICE_TYPE)) {
64 String[] matches = matchDelimitedFields(rawText.substring(2), 6);
65 if (matches == null || !isDigits(matches[1], 10) || !isDigits(matches[2], 10)) {
68 String summary = matches[0];
69 String start = expandDateString(matches[1]);
70 String end = expandDateString(matches[2]);
71 String location = matches[3];
72 String attendee = matches[4];
73 String title = matches[5];
75 return new MobileTagSimpleCalendarParsedResult(summary, start, end, location, attendee, title);
78 public String getSummary() {
83 * <p>We would return the start and end date as a {@link java.util.Date} except that this code
84 * needs to work under JavaME / MIDP and there is no date parsing library available there, such
85 * as <code>java.text.SimpleDateFormat</code>.</p>
87 * <p>However we do translate the date from its encoded format of, say, "0602212156" to its full
88 * text representation of "20060221T215600Z", per the specification.</p>
90 public String getStart() {
97 public String getEnd() {
101 public String getLocation() {
105 public String getAttendee() {
109 public String getTitle() {
113 public String getDisplayResult() {
114 StringBuffer result = new StringBuffer(summary);
115 maybeAppend(start, result);
116 maybeAppend(end, result);
117 maybeAppend(location, result);
118 maybeAppend(attendee, result);
119 maybeAppend(title, result);
120 return result.toString();
123 private static String expandDateString(String date) {
127 // Input is of form YYMMddHHmmss, and needs to be YYYYMMdd'T'HHmmss'Z'
128 return "20" + date.substring(0, 6) + 'T' + date.substring(6) + "00Z";