001/*
002 * (C) Copyright 2012 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     Arnaud Kervern
018 */
019package org.nuxeo.ecm.agenda;
020
021import java.io.Serializable;
022import java.util.Date;
023import java.util.HashMap;
024import java.util.Map;
025
026/**
027 * @author <a href="mailto:akervern@nuxeo.com">Arnaud Kervern</a>
028 */
029public class AgendaEventBuilder {
030    protected String summary;
031
032    protected Date dtStart;
033
034    protected Date dtEnd;
035
036    protected String location;
037
038    protected String description;
039
040    private static final String SCHEMA_PREFIX = "vevent:";
041
042    protected AgendaEventBuilder() {
043        // Empty constructor, just protected to be hidden
044    }
045
046    public static AgendaEventBuilder build(String summary, Date dtStart, Date dtEnd) {
047        AgendaEventBuilder AgendaEvent = new AgendaEventBuilder();
048        AgendaEvent.summary(summary);
049        AgendaEvent.startDate(dtStart);
050        AgendaEvent.endDate(dtEnd);
051        return AgendaEvent;
052    }
053
054    public AgendaEventBuilder summary(String summary) {
055        this.summary = summary;
056        return this;
057    }
058
059    public AgendaEventBuilder startDate(Date dtStart) {
060        this.dtStart = checkDate(dtStart);
061        return this;
062    }
063
064    public AgendaEventBuilder endDate(Date dtEnd) {
065        this.dtEnd = checkDate(dtEnd);
066        return this;
067    }
068
069    public AgendaEventBuilder location(String location) {
070        this.location = location;
071        return this;
072    }
073
074    public AgendaEventBuilder description(String description) {
075        this.description = description;
076        return this;
077    }
078
079    public Map<String, Serializable> toMap() {
080        Map<String, Serializable> properties = new HashMap<String, Serializable>();
081        properties.put("dc:title", summary);
082        properties.put("dc:description", description);
083        properties.put(SCHEMA_PREFIX + "dtstart", dtStart);
084        properties.put(SCHEMA_PREFIX + "dtend", dtEnd);
085        properties.put(SCHEMA_PREFIX + "location", location);
086        return properties;
087    }
088
089    protected Date checkDate(Date date) {
090        return date;
091    }
092}