1 18 19 package sync4j.exchange.items.note.model; 20 21 22 import java.text.MessageFormat ; 23 import java.text.ParseException ; 24 import java.text.SimpleDateFormat ; 25 26 import java.util.Date ; 27 import java.util.StringTokenizer ; 28 29 import sync4j.exchange.items.note.NoteParseException; 30 import sync4j.exchange.xml.XmlParser; 31 import sync4j.exchange.xml.XmlParseException; 32 33 37 38 public class Note { 39 40 42 private static final String TAG_PP_DATE = "Date" ; 43 private static final String TAG_PP_SUBJECT = "Subject" ; 44 private static final String TAG_PP_NOTE 45 = "Body" ; 46 47 private static final String MSG_PP = 48 "<note>\r\n" + 49 "<Subject>{0}</Subject>\r\n" + 50 "<Body>{1}</Body>\r\n" + 51 "<Date>{2}</Date>\r\n" + 52 "</note>" ; 53 54 56 private String id = null ; 57 58 private String username = null ; 59 60 private String subject = null ; 61 62 private String textDescription = null ; 63 64 private Date date = null ; 65 66 private String href = null ; 67 68 private Date lastModified = null ; 69 private char state = ' ' ; 70 71 73 77 public Note () { 78 79 } 80 81 88 public Note (String id) { 89 90 this.id = id ; 91 92 } 93 94 102 public Note (String id, Date t) 103 throws NoteParseException { 104 105 this.id = id ; 106 this.lastModified = t ; 107 108 } 109 110 118 public Note (String id, char state) { 119 120 this.id = id ; 121 this.state = state ; 122 123 } 124 125 135 public Note (String id , 136 String href , 137 char state , 138 Date lastModified) { 139 140 this.id = id ; 141 this.href = href ; 142 this.state = state ; 143 this.lastModified = lastModified ; 144 145 } 146 147 156 public Note (String id, String content, Date t) 157 throws NoteParseException { 158 159 getPPNote (id, content, t); 160 161 } 162 163 165 166 public String getId() { 167 return this.id; 168 } 169 170 public String getUsername() { 171 return this.username; 172 } 173 174 public String getSubject() { 175 return this.subject; 176 } 177 178 public String getTextDescription() { 179 return this.textDescription; 180 } 181 182 public Date getDate() { 183 return this.date; 184 } 185 186 187 public Date getLastModified() { 188 return this.lastModified; 189 } 190 191 public String getHref() { 192 return this.href; 193 } 194 195 public char getState() { 196 return this.state; 197 } 198 199 public void setId(String id) { 200 this.id = id; 201 } 202 203 public void setUsername(String username) { 204 this.username = username; 205 } 206 207 public void setSubject(String subject) { 208 this.subject = subject; 209 } 210 211 public void setTextDescription(String textDescription) { 212 this.textDescription = textDescription; 213 } 214 215 public void setDate(Date date) { 216 this.date = date; 217 } 218 219 public void setLastModified(Date lastModified) { 220 this.lastModified = lastModified; 221 } 222 223 public void setHref(String href) { 224 this.href = href; 225 } 226 227 public void setState(char state) { 228 this.state = state; 229 } 230 231 240 public void getPPNote (String id, String content, Date t) 241 throws NoteParseException { 242 243 String dt = null ; 244 245 this.id = id ; 246 this.lastModified = t ; 247 248 try { 249 250 XmlParser p = new XmlParser(); 251 252 dt = p.getXMLInitTagValue(content, TAG_PP_DATE ); 253 254 this.date = p.clientDateToDate (dt); 255 256 this.subject = p.getXMLInitTagValue (content, TAG_PP_SUBJECT ); 257 258 this.textDescription 259 = p.getXMLInitTagValue (content, TAG_PP_NOTE); 260 261 } catch (NumberFormatException e) { 262 throw new NoteParseException(e.getMessage()); 263 } catch (XmlParseException e) { 264 throw new NoteParseException(e.getMessage()); 265 } 266 267 } 268 269 275 public String toXML() 276 throws NoteParseException { 277 278 String ppMsg = null ; 279 String date = null ; 280 281 XmlParser p = new XmlParser(); 282 283 try { 284 285 date = p.toClientDate (this.date) ; 286 287 ppMsg = MessageFormat.format(MSG_PP, 288 new Object [] { 289 p.getString(subject ) , 290 p.getString(textDescription ) , 291 p.getString(date ) 292 293 } 294 ); 295 296 } catch (Exception e) { 297 throw new NoteParseException ("Error composing calendar Device: " + 298 e.getMessage()); 299 } 300 301 return ppMsg; 302 303 } 304 305 } 306 | Popular Tags |