1 // Copyright 2007 The Android Open Source Project 2 3 package com.google.wireless.gdata.calendar.data; 4 5 import com.google.wireless.gdata.data.Entry; 6 7 import java.util.Hashtable; 8 import java.util.Vector; 9 import java.util.Enumeration; 10 11 /** 12 * Entry containing information about an event in a calendar. 13 */ 14 public class EventEntry extends Entry { 15 16 // TODO: pack all of these enums into an int 17 18 /** 19 * Status constant indicating that a user's attendance at an event is 20 * tentative. 21 */ 22 public static final byte STATUS_TENTATIVE = 0; 23 24 /** 25 * Status constant indicating that a user's attendance at an event is 26 * confirmed. 27 */ 28 public static final byte STATUS_CONFIRMED = 1; 29 30 /** 31 * Status constant indicating that an event has been cancelled. 32 */ 33 public static final byte STATUS_CANCELED = 2; 34 35 /** 36 * Visibility constant indicating that an event uses the user's default 37 * visibility. 38 */ 39 public static final byte VISIBILITY_DEFAULT = 0; 40 41 /** 42 * Visibility constant indicating that an event has been marked 43 * confidential. 44 */ 45 public static final byte VISIBILITY_CONFIDENTIAL = 1; 46 47 /** 48 * Visibility constant indicating that an event has been marked private. 49 */ 50 public static final byte VISIBILITY_PRIVATE = 2; 51 52 /** 53 * Visibility constant indicating that an event has been marked public. 54 */ 55 public static final byte VISIBILITY_PUBLIC = 3; 56 57 /** 58 * Transparency constant indicating that an event has been marked opaque. 59 */ 60 public static final byte TRANSPARENCY_OPAQUE = 0; 61 62 /** 63 * Transparency constant indicating that an event has been marked 64 * transparent. 65 */ 66 public static final byte TRANSPARENCY_TRANSPARENT = 1; 67 68 private byte status = STATUS_TENTATIVE; 69 private String recurrence = null; 70 private byte visibility = VISIBILITY_DEFAULT; 71 private byte transparency = TRANSPARENCY_OPAQUE; 72 private Vector attendees = new Vector(); 73 private boolean sendEventNotifications = false; 74 private boolean guestsCanModify = false; 75 private boolean guestsCanInviteOthers = true; 76 private boolean guestsCanSeeGuests = true; 77 private String organizer = null; 78 private Vector whens = new Vector(); 79 private Vector reminders = null; 80 private String originalEventId = null; 81 private String originalEventStartTime = null; 82 private String where = null; 83 private String commentsUri = null; 84 private Hashtable extendedProperties = null; 85 private boolean quickAdd = false; 86 87 /** 88 * Creates a new empty event entry. 89 */ EventEntry()90 public EventEntry() { 91 } 92 93 /* 94 * (non-Javadoc) 95 * @see com.google.wireless.gdata.data.Entry#clear() 96 */ clear()97 public void clear() { 98 super.clear(); 99 status = STATUS_TENTATIVE; 100 recurrence = null; 101 visibility = VISIBILITY_DEFAULT; 102 transparency = TRANSPARENCY_OPAQUE; 103 sendEventNotifications = false; 104 guestsCanModify = false; 105 guestsCanInviteOthers = true; 106 guestsCanSeeGuests = true; 107 organizer = null; 108 attendees.removeAllElements(); 109 whens.removeAllElements(); 110 reminders = null; 111 originalEventId = null; 112 originalEventStartTime = null; 113 where = null; 114 commentsUri = null; 115 extendedProperties = null; 116 quickAdd = false; 117 } 118 119 /** 120 * @return the recurrence 121 */ getRecurrence()122 public String getRecurrence() { 123 return recurrence; 124 } 125 126 /** 127 * @param recurrence the recurrence to set 128 */ setRecurrence(String recurrence)129 public void setRecurrence(String recurrence) { 130 this.recurrence = recurrence; 131 } 132 133 /** 134 * @return the status 135 */ getStatus()136 public byte getStatus() { 137 return status; 138 } 139 140 /** 141 * @param status the status to set 142 */ setStatus(byte status)143 public void setStatus(byte status) { 144 this.status = status; 145 } 146 147 /** 148 * @return the transparency 149 */ getTransparency()150 public byte getTransparency() { 151 return transparency; 152 } 153 154 /** 155 * @param transparency the transparency to set 156 */ setTransparency(byte transparency)157 public void setTransparency(byte transparency) { 158 this.transparency = transparency; 159 } 160 161 /** 162 * @return the visibility 163 */ getVisibility()164 public byte getVisibility() { 165 return visibility; 166 } 167 168 /** 169 * @param visibility the visibility to set 170 */ setVisibility(byte visibility)171 public void setVisibility(byte visibility) { 172 this.visibility = visibility; 173 } 174 getSendEventNotifications()175 public boolean getSendEventNotifications() { 176 return sendEventNotifications; 177 } 178 setSendEventNotifications(boolean sendEventNotifications)179 public void setSendEventNotifications(boolean sendEventNotifications) { 180 this.sendEventNotifications = sendEventNotifications; 181 } 182 getGuestsCanModify()183 public boolean getGuestsCanModify() { 184 return guestsCanModify; 185 } 186 setGuestsCanModify(boolean guestsCanModify)187 public void setGuestsCanModify(boolean guestsCanModify) { 188 this.guestsCanModify = guestsCanModify; 189 } 190 getGuestsCanInviteOthers()191 public boolean getGuestsCanInviteOthers() { 192 return guestsCanInviteOthers; 193 } 194 setGuestsCanInviteOthers(boolean guestsCanInviteOthers)195 public void setGuestsCanInviteOthers(boolean guestsCanInviteOthers) { 196 this.guestsCanInviteOthers = guestsCanInviteOthers; 197 } 198 getGuestsCanSeeGuests()199 public boolean getGuestsCanSeeGuests() { 200 return guestsCanSeeGuests; 201 } 202 setGuestsCanSeeGuests(boolean guestsCanSeeGuests)203 public void setGuestsCanSeeGuests(boolean guestsCanSeeGuests) { 204 this.guestsCanSeeGuests = guestsCanSeeGuests; 205 } 206 getOrganizer()207 public String getOrganizer() { 208 return organizer; 209 } 210 setOrganizer(String organizer)211 public void setOrganizer(String organizer) { 212 this.organizer = organizer; 213 } 214 clearAttendees()215 public void clearAttendees() { 216 attendees.clear(); 217 } 218 addAttendee(Who attendee)219 public void addAttendee(Who attendee) { 220 attendees.add(attendee); 221 } 222 getAttendees()223 public Vector getAttendees() { 224 return attendees; 225 } 226 clearWhens()227 public void clearWhens() { 228 whens.clear(); 229 } 230 addWhen(When when)231 public void addWhen(When when) { 232 whens.add(when); 233 } 234 getWhens()235 public Vector getWhens() { 236 return whens; 237 } 238 getFirstWhen()239 public When getFirstWhen() { 240 if (whens.isEmpty()) { 241 return null; 242 } 243 return (When) whens.elementAt(0); 244 } 245 getReminders()246 public Vector getReminders() { 247 return reminders; 248 } 249 addReminder(Reminder reminder)250 public void addReminder(Reminder reminder) { 251 if (reminders == null) { 252 reminders = new Vector(); 253 } 254 reminders.add(reminder); 255 } 256 clearReminders()257 public void clearReminders() { 258 reminders = null; 259 } 260 getOriginalEventId()261 public String getOriginalEventId() { 262 return originalEventId; 263 } 264 setOriginalEventId(String originalEventId)265 public void setOriginalEventId(String originalEventId) { 266 this.originalEventId = originalEventId; 267 } 268 getOriginalEventStartTime()269 public String getOriginalEventStartTime() { 270 return originalEventStartTime; 271 } 272 setOriginalEventStartTime(String originalEventStartTime)273 public void setOriginalEventStartTime(String originalEventStartTime) { 274 this.originalEventStartTime = originalEventStartTime; 275 } 276 277 /** 278 * @return the where 279 */ getWhere()280 public String getWhere() { 281 return where; 282 } 283 284 /** 285 * @param where the where to set 286 */ setWhere(String where)287 public void setWhere(String where) { 288 this.where = where; 289 } 290 getExtendedProperties()291 public Hashtable getExtendedProperties() { 292 return extendedProperties; 293 } 294 getExtendedProperty(String name)295 public String getExtendedProperty(String name) { 296 if (extendedProperties == null) { 297 return null; 298 } 299 String value = null; 300 if (extendedProperties.containsKey(name)) { 301 value = (String) extendedProperties.get(name); 302 } 303 return value; 304 } 305 addExtendedProperty(String name, String value)306 public void addExtendedProperty(String name, String value) { 307 if (extendedProperties == null) { 308 extendedProperties = new Hashtable(); 309 } 310 extendedProperties.put(name, value); 311 } 312 clearExtendedProperties()313 public void clearExtendedProperties() { 314 extendedProperties = null; 315 } 316 getCommentsUri()317 public String getCommentsUri() { 318 return commentsUri; 319 } 320 setCommentsUri(String commentsUri)321 public void setCommentsUri(String commentsUri) { 322 this.commentsUri = commentsUri; 323 } 324 isQuickAdd()325 public boolean isQuickAdd() { 326 return quickAdd; 327 } 328 setQuickAdd(boolean quickAdd)329 public void setQuickAdd(boolean quickAdd) { 330 this.quickAdd = quickAdd; 331 } 332 toString(StringBuffer sb)333 public void toString(StringBuffer sb) { 334 super.toString(sb); 335 sb.append("STATUS: " + status + "\n"); 336 appendIfNotNull(sb, "RECURRENCE", recurrence); 337 sb.append("VISIBILITY: " + visibility + "\n"); 338 sb.append("TRANSPARENCY: " + transparency + "\n"); 339 340 appendIfNotNull(sb, "ORIGINAL_EVENT_ID", originalEventId); 341 appendIfNotNull(sb, "ORIGINAL_START_TIME", originalEventStartTime); 342 sb.append("QUICK_ADD: " + (quickAdd ? "true" : "false")); 343 sb.append("SEND_EVENT_NOTIFICATIONS: " + (sendEventNotifications ? "true" : "false")); 344 sb.append("GUESTS_CAN_MODIFY: " + (guestsCanModify ? "true" : "false")); 345 sb.append("GUESTS_CAN_INVITE_OTHERS: " + (guestsCanInviteOthers ? "true" : "false")); 346 sb.append("GUESTS_CAN_SEE_GUESTS: " + (guestsCanSeeGuests ? "true" : "false")); 347 appendIfNotNull(sb, "ORGANIZER", organizer); 348 349 Enumeration whos = this.attendees.elements(); 350 while (whos.hasMoreElements()) { 351 Who who = (Who) whos.nextElement(); 352 who.toString(sb); 353 } 354 355 Enumeration times = this.whens.elements(); 356 while (times.hasMoreElements()) { 357 When when = (When) times.nextElement(); 358 when.toString(sb); 359 } 360 if (reminders != null) { 361 Enumeration alarms = reminders.elements(); 362 while (alarms.hasMoreElements()) { 363 Reminder reminder = (Reminder) alarms.nextElement(); 364 reminder.toString(sb); 365 } 366 } 367 appendIfNotNull(sb, "WHERE", where); 368 appendIfNotNull(sb, "COMMENTS", commentsUri); 369 if (extendedProperties != null) { 370 Enumeration entryNames = extendedProperties.keys(); 371 while (entryNames.hasMoreElements()) { 372 String name = (String) entryNames.nextElement(); 373 String value = (String) extendedProperties.get(name); 374 sb.append(name); 375 sb.append(':'); 376 sb.append(value); 377 sb.append('\n'); 378 } 379 } 380 } 381 } 382