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;
22 public final class CalendarParsedResult extends ParsedResult {
24 private final String summary;
25 private final String start;
26 private final String end;
27 private final String location;
28 private final String attendee;
29 private final String title;
31 public CalendarParsedResult(String summary,
37 super(ParsedResultType.CALENDAR);
38 // Start is required, end is not
40 throw new IllegalArgumentException();
44 this.summary = summary;
47 this.location = location;
48 this.attendee = attendee;
52 public String getSummary() {
57 * <p>We would return the start and end date as a {@link java.util.Date} except that this code
58 * needs to work under JavaME / MIDP and there is no date parsing library available there, such
59 * as <code>java.text.SimpleDateFormat</code>.</p> See validateDate() for the return format.
61 * @return start time formatted as a RFC 2445 DATE or DATE-TIME.</p>
63 public String getStart() {
68 * @see #getStart(). May return null if the event has no duration.
70 public String getEnd() {
74 public String getLocation() {
78 public String getAttendee() {
82 public String getTitle() {
86 public String getDisplayResult() {
87 StringBuffer result = new StringBuffer(100);
88 maybeAppend(summary, result);
89 maybeAppend(start, result);
90 maybeAppend(end, result);
91 maybeAppend(location, result);
92 maybeAppend(attendee, result);
93 maybeAppend(title, result);
94 return result.toString();
98 * RFC 2445 allows the start and end fields to be of type DATE (e.g. 20081021) or DATE-TIME
99 * (e.g. 20081021T123000 for local time, or 20081021T123000Z for UTC).
101 * @param date The string to validate
103 private static void validateDate(String date) {
105 int length = date.length();
106 if (length != 8 && length != 15 && length != 16) {
107 throw new IllegalArgumentException();
109 for (int i = 0; i < 8; i++) {
110 if (!Character.isDigit(date.charAt(i))) {
111 throw new IllegalArgumentException();
115 if (date.charAt(8) != 'T') {
116 throw new IllegalArgumentException();
118 for (int i = 9; i < 15; i++) {
119 if (!Character.isDigit(date.charAt(i))) {
120 throw new IllegalArgumentException();
123 if (length == 16 && date.charAt(15) != 'Z') {
124 throw new IllegalArgumentException();