001package org.nuxeo.ecm.agenda; 002 003import java.io.Serializable; 004import java.util.Date; 005import java.util.HashMap; 006import java.util.Map; 007 008/** 009 * @author <a href="mailto:akervern@nuxeo.com">Arnaud Kervern</a> 010 */ 011public class AgendaEventBuilder { 012 protected String summary; 013 014 protected Date dtStart; 015 016 protected Date dtEnd; 017 018 protected String location; 019 020 protected String description; 021 022 private static final String SCHEMA_PREFIX = "vevent:"; 023 024 protected AgendaEventBuilder() { 025 // Empty constructor, just protected to be hidden 026 } 027 028 public static AgendaEventBuilder build(String summary, Date dtStart, Date dtEnd) { 029 AgendaEventBuilder AgendaEvent = new AgendaEventBuilder(); 030 AgendaEvent.summary(summary); 031 AgendaEvent.startDate(dtStart); 032 AgendaEvent.endDate(dtEnd); 033 return AgendaEvent; 034 } 035 036 public AgendaEventBuilder summary(String summary) { 037 this.summary = summary; 038 return this; 039 } 040 041 public AgendaEventBuilder startDate(Date dtStart) { 042 this.dtStart = checkDate(dtStart); 043 return this; 044 } 045 046 public AgendaEventBuilder endDate(Date dtEnd) { 047 this.dtEnd = checkDate(dtEnd); 048 return this; 049 } 050 051 public AgendaEventBuilder location(String location) { 052 this.location = location; 053 return this; 054 } 055 056 public AgendaEventBuilder description(String description) { 057 this.description = description; 058 return this; 059 } 060 061 public Map<String, Serializable> toMap() { 062 Map<String, Serializable> properties = new HashMap<String, Serializable>(); 063 properties.put("dc:title", summary); 064 properties.put("dc:description", description); 065 properties.put(SCHEMA_PREFIX + "dtstart", dtStart); 066 properties.put(SCHEMA_PREFIX + "dtend", dtEnd); 067 properties.put(SCHEMA_PREFIX + "location", location); 068 return properties; 069 } 070 071 protected Date checkDate(Date date) { 072 return date; 073 } 074}