* @author dswitkin@google.com (Daniel Switkin)
*/
public final class CalendarResultHandler extends ResultHandler {
+
private static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyyMMdd");
private static final DateFormat DATE_TIME_FORMAT = new SimpleDateFormat("yyyyMMdd'T'HHmmss");
addCalendarEvent(calendarResult.getSummary(),
calendarResult.getStart(),
calendarResult.getEnd(),
- calendarResult.getLocation());
+ calendarResult.getLocation(),
+ calendarResult.getDescription());
}
}
ParsedResult.maybeAppend(calResult.getLocation(), result);
ParsedResult.maybeAppend(calResult.getAttendee(), result);
- ParsedResult.maybeAppend(calResult.getTitle(), result);
+ ParsedResult.maybeAppend(calResult.getDescription(), result);
return result.toString();
}
* @param start The start time as yyyyMMdd or yyyyMMdd'T'HHmmss or yyyyMMdd'T'HHmmss'Z'
* @param end The end time as yyyyMMdd or yyyyMMdd'T'HHmmss or yyyyMMdd'T'HHmmss'Z'
* @param location a text description of the event location
+ * @param description a text description of the event itself
*/
- final void addCalendarEvent(String summary, String start, String end, String location) {
+ final void addCalendarEvent(String summary,
+ String start,
+ String end,
+ String location,
+ String description) {
Intent intent = new Intent(Intent.ACTION_EDIT);
intent.setType("vnd.android.cursor.item/event");
intent.putExtra("beginTime", calculateMilliseconds(start));
intent.putExtra("endTime", calculateMilliseconds(end));
intent.putExtra("title", summary);
intent.putExtra("eventLocation", location);
+ intent.putExtra("description", description);
launchIntent(intent);
}
private final String end;
private final String location;
private final String attendee;
- private final String title;
+ private final String description;
public CalendarParsedResult(String summary,
String start,
String end,
String location,
String attendee,
- String title) {
+ String description) {
super(ParsedResultType.CALENDAR);
// Start is required, end is not
if (start == null) {
throw new IllegalArgumentException();
}
validateDate(start);
- validateDate(end);
+ if (end == null) {
+ end = start;
+ } else {
+ validateDate(end);
+ }
this.summary = summary;
this.start = start;
this.end = end;
this.location = location;
this.attendee = attendee;
- this.title = title;
+ this.description = description;
}
public String getSummary() {
return attendee;
}
- public String getTitle() {
- return title;
+ public String getDescription() {
+ return description;
}
public String getDisplayResult() {
maybeAppend(end, result);
maybeAppend(location, result);
maybeAppend(attendee, result);
- maybeAppend(title, result);
+ maybeAppend(description, result);
return result.toString();
}
}
i++; // skip colon
int start = i; // Found the start of a match here
- i = rawText.indexOf((int) '\n', i); // Really, ends in \r\n
+ while ((i = rawText.indexOf((int) '\n', i)) >= 0 && // Really, ends in \r\n
+ i < rawText.length() - 1 && // But if followed by tab or space,
+ (rawText.charAt(i+1) == ' ' || // this is only a continuation
+ rawText.charAt(i+1) == '\t')) {
+ i += 2;
+ }
if (i < 0) {
// No terminating end character? uh, done. Set i such that loop terminates and break
i = max;
if (matches == null) {
matches = new Vector(3); // lazy init
}
+ if (rawText.charAt(i-1) == '\r') {
+ i--; // Back up over \r, which really should be there
+ }
String element = rawText.substring(start, i);
if (trim) {
element = element.trim();
}
+ element = stripContinuationCRLF(element);
matches.addElement(element);
i++;
} else {
return toStringArray(matches);
}
+ private static String stripContinuationCRLF(String value) {
+ int length = value.length();
+ StringBuffer result = new StringBuffer(length);
+ boolean lastWasLF = false;
+ for (int i = 0; i < length; i++) {
+ if (lastWasLF) {
+ lastWasLF = false;
+ continue;
+ }
+ char c = value.charAt(i);
+ lastWasLF = false;
+ switch (c) {
+ case '\n':
+ lastWasLF = true;
+ break;
+ case '\r':
+ break;
+ default:
+ result.append(c);
+ }
+ }
+ return result.toString();
+ }
+
static String matchSingleVCardPrefixedField(String prefix, String rawText, boolean trim) {
String[] values = matchVCardPrefixedField(prefix, rawText, trim);
return values == null ? null : values[0];
String start = VCardResultParser.matchSingleVCardPrefixedField("DTSTART", rawText, true);
String end = VCardResultParser.matchSingleVCardPrefixedField("DTEND", rawText, true);
String location = VCardResultParser.matchSingleVCardPrefixedField("LOCATION", rawText, true);
+ String description = VCardResultParser.matchSingleVCardPrefixedField("DESCRIPTION", rawText, true);
try {
- return new CalendarParsedResult(summary, start, end, location, null, null);
+ return new CalendarParsedResult(summary, start, end, location, null, description);
} catch (IllegalArgumentException iae) {
return null;
}
*/
public final class CalendarParsedResultTestCase extends TestCase {
- public void testVEvent() {
+ public void testStartEnd() {
doTest(
- "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nSUMMARY:foo\r\nDTSTART:20080504T123456Z\r\n" +
- "DTEND:20080505T234555Z\r\nLOCATION:Miami\r\n" +
+ "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\n" +
+ "DTSTART:20080504T123456Z\r\n" +
+ "DTEND:20080505T234555Z\r\n" +
"END:VEVENT\r\nEND:VCALENDAR",
- null, "foo", "Miami", "20080504T123456Z", "20080505T234555Z", null);
+ null, null, null, "20080504T123456Z", "20080505T234555Z", null);
+ }
+
+ public void testStart() {
+ doTest(
+ "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\n" +
+ "DTSTART:20080504T123456Z\r\n" +
+ "END:VEVENT\r\nEND:VCALENDAR",
+ null, null, null, "20080504T123456Z", "20080504T123456Z", null);
+ }
+
+ public void testSummary() {
+ doTest(
+ "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\n" +
+ "SUMMARY:foo\r\n" +
+ "DTSTART:20080504T123456Z\r\n" +
+ "END:VEVENT\r\nEND:VCALENDAR",
+ null, "foo", null, "20080504T123456Z", "20080504T123456Z", null);
+ }
+
+ public void testLocation() {
+ doTest(
+ "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\n" +
+ "LOCATION:Miami\r\n" +
+ "DTSTART:20080504T123456Z\r\n" +
+ "END:VEVENT\r\nEND:VCALENDAR",
+ null, null, "Miami", "20080504T123456Z", "20080504T123456Z", null);
+ }
+
+ public void testDescription() {
+ doTest(
+ "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\n" +
+ "DTSTART:20080504T123456Z\r\n" +
+ "DESCRIPTION:This is a test\r\n" +
+ "END:VEVENT\r\nEND:VCALENDAR",
+ "This is a test", null, null, "20080504T123456Z", "20080504T123456Z", null);
+ doTest(
+ "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\n" +
+ "DTSTART:20080504T123456Z\r\n" +
+ "DESCRIPTION:This is a test\r\n\t with a continuation\r\n" +
+ "END:VEVENT\r\nEND:VCALENDAR",
+ "This is a test with a continuation", null, null, "20080504T123456Z", "20080504T123456Z", null);
}
private static void doTest(String contents,
- String title,
+ String description,
String summary,
String location,
String start,
ParsedResult result = ResultParser.parseResult(fakeResult);
assertSame(ParsedResultType.CALENDAR, result.getType());
CalendarParsedResult calResult = (CalendarParsedResult) result;
- assertEquals(title, calResult.getTitle());
+ assertEquals(description, calResult.getDescription());
assertEquals(summary, calResult.getSummary());
assertEquals(location, calResult.getLocation());
assertEquals(start, calResult.getStart());