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 description;
31 public CalendarParsedResult(String summary,
37 super(ParsedResultType.CALENDAR);
38 // Start is required, end is not
40 throw new IllegalArgumentException();
48 this.summary = summary;
51 this.location = location;
52 this.attendee = attendee;
53 this.description = description;
56 public String getSummary() {
61 * <p>We would return the start and end date as a {@link java.util.Date} except that this code
62 * needs to work under JavaME / MIDP and there is no date parsing library available there, such
63 * as <code>java.text.SimpleDateFormat</code>.</p> See validateDate() for the return format.
65 * @return start time formatted as a RFC 2445 DATE or DATE-TIME.</p>
67 public String getStart() {
72 * @see #getStart(). May return null if the event has no duration.
74 public String getEnd() {
78 public String getLocation() {
82 public String getAttendee() {
86 public String getDescription() {
90 public String getDisplayResult() {
91 StringBuffer result = new StringBuffer(100);
92 maybeAppend(summary, result);
93 maybeAppend(start, result);
94 maybeAppend(end, result);
95 maybeAppend(location, result);
96 maybeAppend(attendee, result);
97 maybeAppend(description, result);
98 return result.toString();
102 * RFC 2445 allows the start and end fields to be of type DATE (e.g. 20081021) or DATE-TIME
103 * (e.g. 20081021T123000 for local time, or 20081021T123000Z for UTC).
105 * @param date The string to validate
107 private static void validateDate(String date) {
109 int length = date.length();
110 if (length != 8 && length != 15 && length != 16) {
111 throw new IllegalArgumentException();
113 for (int i = 0; i < 8; i++) {
114 if (!Character.isDigit(date.charAt(i))) {
115 throw new IllegalArgumentException();
119 if (date.charAt(8) != 'T') {
120 throw new IllegalArgumentException();
122 for (int i = 9; i < 15; i++) {
123 if (!Character.isDigit(date.charAt(i))) {
124 throw new IllegalArgumentException();
127 if (length == 16 && date.charAt(15) != 'Z') {
128 throw new IllegalArgumentException();