BrightSide Workbench Full Report + Source Code
ContactCalendar.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2011 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 package org.turro.contacts.cal;
19 
20 import java.io.File;
21 import java.util.Date;
22 import java.util.List;
23 import org.turro.elephant.context.ElephantContext;
24 import org.turro.elephant.impl.abstracts.AbstractImplementation;
25 import org.turro.i18n.I_;
26 import org.turro.plugin.calendar.ICalendarEvent;
27 import org.turro.plugin.calendar.ICalendarModel;
28 import org.turro.plugin.contacts.IContact;
29 import org.turro.reflection.Serializer;
30 import org.turro.util.IdGenerator;
31 import org.zkoss.lang.Strings;
32 
37 public class ContactCalendar extends AbstractImplementation implements ICalendarModel {
38 
39  private final static String PATH_CALENDAR = "/WEB-INF/calendars";
40 
41  private IContact contact;
42 
43  @Override
44  public String getName() {
45  return "My calendar";
46  }
47 
48  @Override
49  public String getLabelName() {
50  return I_.get(getName());
51  }
52 
53  @Override
54  public String getHeaderColor() {
55  return "#3467CE";
56  }
57 
58  @Override
59  public String getContentColor() {
60  return "#668CD9";
61  }
62 
63  @Override
64  public List<ICalendarEvent> getEvents() {
65  File root = new File(ElephantContext.getRealPath(PATH_CALENDAR));
66  if(!root.exists()) root.mkdir();
67  File cal = new File(root.getAbsolutePath() + "/" + contact.getId());
68  return (List<ICalendarEvent>) Serializer.deserialize(cal);
69  }
70 
71  @Override
72  public List<ICalendarEvent> getEvents(Date from, Date to) {
73  // TODO clear out-of-date events
74  return getEvents();
75  }
76 
77  @Override
78  public void setEvents(List<ICalendarEvent> events) {
79  File root = new File(ElephantContext.getRealPath(PATH_CALENDAR));
80  if(!root.exists()) root.mkdir();
81  File cal = new File(root.getAbsolutePath() + "/" + contact.getId());
82  Serializer.serialize(cal, events);
83  }
84 
85  @Override
86  public void setEvent(ICalendarEvent event) {
87  if(Strings.isBlank(event.getEventId())) {
88  event.setEventId(IdGenerator.generate());
89  }
90  // save on setEvents
91  }
92 
93  @Override
95  ICalendarEvent event = new ContactEvent();
96  event.setEventId(IdGenerator.generate());
97  return event;
98  }
99 
100  @Override
101  public void setIContact(IContact contact) {
102  this.contact = contact;
103  }
104 
105 }
void setEvents(List< ICalendarEvent > events)
void setEvent(ICalendarEvent event)
List< ICalendarEvent > getEvents(Date from, Date to)
static String get(String msg)
Definition: I_.java:41