001: /**
002: * NoteImpl.java
003: * Created on 13.02.2003, 15:36:55 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 net.sf.memoranda.date.CalendarDate;
011: import nu.xom.Attribute;
012: import nu.xom.Element;
013:
014: /**
015: *
016: */
017: /*$Id: NoteImpl.java,v 1.6 2004/10/06 19:15:44 ivanrise Exp $*/
018: public class NoteImpl implements Note, Comparable {
019:
020: private Element _el = null;
021: private Project _project;
022:
023: /**
024: * Constructor for NoteImpl.
025: */
026: public NoteImpl(Element el, Project project) {
027: _el = el;
028: _project = project;
029: }
030:
031: /**
032: * @see net.sf.memoranda.Note#getDate()
033: */
034: public CalendarDate getDate() {
035: Element day = (Element) _el.getParent();
036: Element month = (Element) day.getParent();
037: Element year = (Element) month.getParent();
038:
039: // return new CalendarDate(day.getAttribute("date").getValue());
040:
041: return new CalendarDate(new Integer(day.getAttribute("day")
042: .getValue()).intValue(), new Integer(month
043: .getAttribute("month").getValue()).intValue(),
044: new Integer(year.getAttribute("year").getValue())
045: .intValue());
046:
047: }
048:
049: public Project getProject() {
050: return _project;
051: }
052:
053: /**
054: * @see net.sf.memoranda.Note#getTitle()
055: */
056: public String getTitle() {
057: Attribute ta = _el.getAttribute("title");
058: if (ta == null)
059: return "";
060: return _el.getAttribute("title").getValue();
061: }
062:
063: /**
064: * @see net.sf.memoranda.Note#setTitle(java.lang.String)
065: */
066: public void setTitle(String s) {
067: Attribute ta = _el.getAttribute("title");
068: if (ta == null)
069: _el.addAttribute(new Attribute("title", s));
070: else
071: ta.setValue(s);
072: }
073:
074: /**
075: * @see net.sf.memoranda.Note#getId
076: */
077:
078: public String getId() {
079: Attribute id = _el.getAttribute("refid");
080: if (id == null)
081: return "";
082: return _el.getAttribute("refid").getValue();
083: }
084:
085: /**
086: * @see net.sf.memoranda.Note#setId(java.lang.String)
087: */
088:
089: public void setId(String s) {
090: Attribute id = _el.getAttribute("refid");
091: if (id == null)
092: _el.addAttribute(new Attribute("refid", s));
093: }
094:
095: /**
096: * @see net.sf.memoranda.Note#isMarked()
097: */
098: public boolean isMarked() {
099: return _el.getAttribute("bookmark") != null;
100: }
101:
102: /**
103: * @see net.sf.memoranda.Note#setMark(boolean)
104: */
105: public void setMark(boolean mark) {
106: Attribute ma = _el.getAttribute("bookmark");
107: if (ma == null) {
108: if (mark)
109: _el.addAttribute(new Attribute("bookmark", "yes"));
110: return;
111: } else if (!mark)
112: _el.removeAttribute(ma);
113: }
114:
115: /*
116: * Comparable interface
117: */
118: public int compareTo(Object o) {
119: Note note = (Note) o;
120: if (getDate().getDate().getTime() > note.getDate().getDate()
121: .getTime())
122: return 1;
123: else if (getDate().getDate().getTime() < note.getDate()
124: .getDate().getTime())
125: return -1;
126: else
127: return 0;
128: }
129:
130: }
|