Issue 439: be more lax and don't look for END
[zxing.git] / core / src / com / google / zxing / client / result / VEventResultParser.java
1 /*
2  * Copyright 2008 ZXing authors
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package com.google.zxing.client.result;
18
19 import com.google.zxing.Result;
20
21 /**
22  * Partially implements the iCalendar format's "VEVENT" format for specifying a
23  * calendar event. See RFC 2445. This supports SUMMARY, LOCATION, DTSTART and DTEND fields.
24  *
25  * @author Sean Owen
26  */
27 final class VEventResultParser extends ResultParser {
28
29   private VEventResultParser() {
30   }
31
32   public static CalendarParsedResult parse(Result result) {
33     String rawText = result.getText();
34     if (rawText == null) {
35       return null;
36     }
37     int vEventStart = rawText.indexOf("BEGIN:VEVENT");
38     if (vEventStart < 0) {
39       return null;
40     }
41
42     String summary = VCardResultParser.matchSingleVCardPrefixedField("SUMMARY", rawText, true);
43     String start = VCardResultParser.matchSingleVCardPrefixedField("DTSTART", rawText, true);
44     String end = VCardResultParser.matchSingleVCardPrefixedField("DTEND", rawText, true);
45     String location = VCardResultParser.matchSingleVCardPrefixedField("LOCATION", rawText, true);
46     String description = VCardResultParser.matchSingleVCardPrefixedField("DESCRIPTION", rawText, true);
47     try {
48       return new CalendarParsedResult(summary, start, end, location, null, description);
49     } catch (IllegalArgumentException iae) {
50       return null;
51     }
52   }
53
54 }