This repository has been archived by the owner on Sep 4, 2019. It is now read-only.
forked from zxing/zxing
/
MobileTagSimpleCalendarParsedResult.java
131 lines (113 loc) · 3.94 KB
/
MobileTagSimpleCalendarParsedResult.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
* Copyright 2008 ZXing authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.zxing.client.result.optional;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.Result;
import com.google.zxing.client.result.ParsedReaderResultType;
/**
* <p>Represents a "simple calendar" result encoded according to section 4.9 of the
* MobileTag Reader International Specification.</p>
*
* @author srowen@google.com (Sean Owen)
*/
public final class MobileTagSimpleCalendarParsedResult extends AbstractMobileTagParsedResult {
public static final String SERVICE_TYPE = "07";
private final String summary;
private final String start;
private final String end;
private final String location;
private final String attendee;
private final String title;
private MobileTagSimpleCalendarParsedResult(String summary,
String start,
String end,
String location,
String attendee,
String title) {
super(ParsedReaderResultType.MOBILETAG_SIMPLE_CALENDAR);
this.summary = summary;
this.start = start;
this.end = end;
this.location = location;
this.attendee = attendee;
this.title = title;
}
public static MobileTagSimpleCalendarParsedResult parse(Result result) {
if (!result.getBarcodeFormat().equals(BarcodeFormat.DATAMATRIX)) {
return null;
}
String rawText = result.getText();
if (!rawText.startsWith(SERVICE_TYPE)) {
return null;
}
String[] matches = matchDelimitedFields(rawText.substring(2), 6);
if (matches == null || !isDigits(matches[1], 10) || !isDigits(matches[2], 10)) {
return null;
}
String summary = matches[0];
String start = expandDateString(matches[1]);
String end = expandDateString(matches[2]);
String location = matches[3];
String attendee = matches[4];
String title = matches[5];
return new MobileTagSimpleCalendarParsedResult(summary, start, end, location, attendee, title);
}
public String getSummary() {
return summary;
}
/**
* <p>We would return the start and end date as a {@link java.util.Date} except that this code
* needs to work under JavaME / MIDP and there is no date parsing library available there, such
* as <code>java.text.SimpleDateFormat</code>.</p>
*
* <p>However we do translate the date from its encoded format of, say, "0602212156" to its full
* text representation of "20060221T215600Z", per the specification.</p>
*/
public String getStart() {
return start;
}
/**
* @see #getStart()
*/
public String getEnd() {
return end;
}
public String getLocation() {
return location;
}
public String getAttendee() {
return attendee;
}
public String getTitle() {
return title;
}
public String getDisplayResult() {
StringBuffer result = new StringBuffer(summary);
maybeAppend(start, result);
maybeAppend(end, result);
maybeAppend(location, result);
maybeAppend(attendee, result);
maybeAppend(title, result);
return result.toString();
}
private static String expandDateString(String date) {
if (date == null) {
return null;
}
// Input is of form YYMMddHHmmss, and needs to be YYYYMMdd'T'HHmmss'Z'
return "20" + date.substring(0, 6) + 'T' + date.substring(6) + "00Z";
}
}