001: /**
002: * EventImpl.java
003: * Created on 08.03.2003, 13:20:13 Alex
004: * Package: net.sf.memoranda
005: *
006: * @author Alex V. Alishevskikh, alex@openmechanics.net
007: * Copyright (c) 2003 Memoranda Team. http://memoranda.sf.net
008: */package net.sf.memoranda;
009:
010: import java.util.Calendar;
011: import java.util.Date;
012: import java.util.GregorianCalendar;
013: import net.sf.memoranda.date.CalendarDate;
014: import net.sf.memoranda.util.Local;
015: import nu.xom.Attribute;
016: import nu.xom.Element;
017:
018: /**
019: *
020: */
021: /*$Id: EventImpl.java,v 1.9 2004/10/06 16:00:11 ivanrise Exp $*/
022: public class EventImpl implements Event, Comparable {
023:
024: private Element _elem = null;
025:
026: /**
027: * Constructor for EventImpl.
028: */
029: public EventImpl(Element elem) {
030: _elem = elem;
031: }
032:
033: /**
034: * @see net.sf.memoranda.Event#getHour()
035: */
036: public int getHour() {
037: return new Integer(_elem.getAttribute("hour").getValue())
038: .intValue();
039: }
040:
041: /**
042: * @see net.sf.memoranda.Event#getMinute()
043: */
044: public int getMinute() {
045: return new Integer(_elem.getAttribute("min").getValue())
046: .intValue();
047: }
048:
049: public String getTimeString() {
050: return Local.getTimeString(getHour(), getMinute());
051: }
052:
053: /**
054: * @see net.sf.memoranda.Event#getText()
055: */
056: public String getText() {
057: return _elem.getValue();
058: }
059:
060: /**
061: * @see net.sf.memoranda.Event#getContent()
062: */
063: public Element getContent() {
064: return _elem;
065: }
066:
067: /**
068: * @see net.sf.memoranda.Event#isRepeatable()
069: */
070: public boolean isRepeatable() {
071: return getStartDate() != null;
072: }
073:
074: /**
075: * @see net.sf.memoranda.Event#getStartDate()
076: */
077: public CalendarDate getStartDate() {
078: Attribute a = _elem.getAttribute("startDate");
079: if (a != null)
080: return new CalendarDate(a.getValue());
081: return null;
082: }
083:
084: /**
085: * @see net.sf.memoranda.Event#getEndDate()
086: */
087: public CalendarDate getEndDate() {
088: Attribute a = _elem.getAttribute("endDate");
089: if (a != null)
090: return new CalendarDate(a.getValue());
091: return null;
092: }
093:
094: /**
095: * @see net.sf.memoranda.Event#getPeriod()
096: */
097: public int getPeriod() {
098: Attribute a = _elem.getAttribute("period");
099: if (a != null)
100: return new Integer(a.getValue()).intValue();
101: return 0;
102: }
103:
104: /**
105: * @see net.sf.memoranda.Event#getId()
106: */
107: public String getId() {
108: Attribute a = _elem.getAttribute("id");
109: if (a != null)
110: return a.getValue();
111: return null;
112: }
113:
114: /**
115: * @see net.sf.memoranda.Event#getRepeat()
116: */
117: public int getRepeat() {
118: Attribute a = _elem.getAttribute("repeat-type");
119: if (a != null)
120: return new Integer(a.getValue()).intValue();
121: return 0;
122: }
123:
124: /**
125: * @see net.sf.memoranda.Event#getTime()
126: */
127: public Date getTime() {
128: //Deprecated methods
129: //Date d = new Date();
130: //d.setHours(getHour());
131: //d.setMinutes(getMinute());
132: //d.setSeconds(0);
133: //End deprecated methods
134:
135: Date d = new Date(); //Revision to fix deprecated methods (jcscoobyrs) 12-NOV-2003 14:26:00
136: Calendar calendar = new GregorianCalendar(Local
137: .getCurrentLocale()); //Revision to fix deprecated methods (jcscoobyrs) 12-NOV-2003 14:26:00
138: calendar.setTime(d); //Revision to fix deprecated methods (jcscoobyrs) 12-NOV-2003 14:26:00
139: calendar.set(Calendar.HOUR_OF_DAY, getHour()); //Revision to fix deprecated methods (jcscoobyrs) 12-NOV-2003 14:26:00
140: calendar.set(Calendar.MINUTE, getMinute()); //Revision to fix deprecated methods (jcscoobyrs) 12-NOV-2003 14:26:00
141: calendar.set(Calendar.SECOND, 0); //Revision to fix deprecated methods (jcscoobyrs) 12-NOV-2003 14:26:00
142: d = calendar.getTime(); //Revision to fix deprecated methods (jcscoobyrs) 12-NOV-2003 14:26:00
143: return d;
144: }
145:
146: /**
147: * @see net.sf.memoranda.Event#getWorkinDays()
148: */
149: public boolean getWorkingDays() {
150: Attribute a = _elem.getAttribute("workingDays");
151: if (a != null && a.getValue().equals("true"))
152: return true;
153: return false;
154: }
155:
156: public int compareTo(Object o) {
157: Event event = (Event) o;
158: return (getHour() * 60 + getMinute())
159: - (event.getHour() * 60 + event.getMinute());
160: }
161:
162: }
|