1 18 package sync4j.exchange.items.task.model; 19 20 import java.text.MessageFormat ; 21 import java.text.ParseException ; 22 import java.text.SimpleDateFormat ; 23 24 import java.util.Date ; 25 import java.util.StringTokenizer ; 26 27 import sync4j.exchange.items.task.TaskParseException; 28 import sync4j.exchange.xml.XmlParser; 29 import sync4j.exchange.xml.XmlParseException; 30 import sync4j.exchange.util.StringTools; 31 import java.util.TimeZone ; 32 33 37 public class Task { 38 39 41 private static final String TAG_PP_ACTUAL_WORK = "ActualWork" ; 42 private static final String TAG_PP_BILLING_INFORMATION = "BillingInformation" ; 43 private static final String TAG_PP_CATEGORIES = "Categories" ; 44 private static final String TAG_PP_COMPANIES = "Companies" ; 45 private static final String TAG_PP_COMPLETE = "Complete" ; 46 private static final String TAG_PP_DATE_COMPLETED = "DateCompleted" ; 47 private static final String TAG_PP_DUE_DATE = "DueDate" ; 48 private static final String TAG_PP_IMPORTANCE = "Importance" ; 49 private static final String TAG_PP_MILEAGE = "Mileage" ; 50 private static final String TAG_PP_NOTE = "Body" ; 51 private static final String TAG_PP_OWNER = "Owner" ; 52 private static final String TAG_PP_PERCENT_COMPLETE = "PercentComplete" ; 53 private static final String TAG_PP_REMINDER_SET = "ReminderSet" ; 54 private static final String TAG_PP_REMINDER_TIME = "ReminderTime" ; 55 private static final String TAG_PP_SENSITIVITY = "Sensitivity" ; 56 private static final String TAG_PP_DATE = "StartDate" ; 57 private static final String TAG_PP_STATUS = "Status" ; 58 private static final String TAG_PP_SUBJECT = "Subject" ; 59 private static final String TAG_PP_TEAM_TASK = "TeamTask" ; 60 private static final String TAG_PP_TOTAL_WORK = "TotalWork" ; 61 62 private int actualWork = 0 ; 64 private String billingInformation = null ; 65 private String categories = null ; 66 private String companies = null ; 67 private boolean complete = false ; 68 private Date date = null ; 69 private Date dateCompleted = null ; 70 private Date dueDate = null ; 71 private String importance = null ; 72 private String mileage = null ; 73 private String owner = null ; 74 private String percentComplete = null ; 75 private boolean reminderSet = false ; 76 private Date reminderTime = null ; 77 private String sensitivity = null ; 78 private String status = null ; 79 private String subject = null ; 80 private boolean teamTask = false ; 81 private String textDescription = null ; 82 private int totalWork = 0 ; 83 84 private String href = null ; 85 86 private String username = null ; 87 private String id = null ; 88 89 private Date createDate = null ; 90 private Date lastModified = null ; 91 private char state = ' ' ; 92 93 95 99 public Task() { 100 } 101 102 107 public Task (String id) { 108 this.id = id; 109 } 110 111 117 public Task(String id, Date t) throws TaskParseException { 118 this.id = id; 119 this.lastModified = t ; 120 } 121 122 128 public Task(String id, char state) { 129 this.id = id ; 130 this.state = state; 131 } 132 133 141 public Task(String id , 142 String href , 143 char state , 144 Date lastModified) { 145 146 this.id = id ; 147 this.href = href ; 148 this.state = state ; 149 this.lastModified = lastModified; 150 } 151 152 159 public Task(String id, String content, Date t) throws TaskParseException { 160 getPPTask(id, content, t); 161 } 162 163 public String getId() { 165 return this.id; 166 } 167 168 public String getUsername() { 169 return this.username; 170 } 171 172 public Date getDate() { 173 return this.date; 174 } 175 176 public String getHref() { 177 return this.href; 178 } 179 180 public Date getLastModified() { 181 return this.lastModified; 182 } 183 184 public char getState() { 185 return this.state; 186 } 187 188 public int getActualWork() { 189 return this.actualWork; 190 } 191 192 public String getBillingInformation() { 193 return this.billingInformation; 194 } 195 196 public String getCompanies() { 197 return this.companies; 198 } 199 200 public String getCategories() { 201 return categories; 202 } 203 204 public Date getDateCompleted() { 205 return this.dateCompleted; 206 } 207 208 public Date getDueDate() { 209 return dueDate; 210 } 211 212 public String getImportance() { 213 return importance; 214 } 215 216 public String getMileage() { 217 return mileage; 218 } 219 220 public String getOwner() { 221 return this.owner; 222 } 223 224 public String getPercentComplete() { 225 return percentComplete; 226 } 227 228 public boolean getReminderSet() { 229 return reminderSet; 230 } 231 232 public Date getReminderTime() { 233 return reminderTime; 234 } 235 236 public String getSensitivity() { 237 return sensitivity; 238 } 239 240 public String getStatus() { 241 return status; 242 } 243 244 public String getSubject() { 245 return this.subject; 246 } 247 248 public boolean getTeamTask() { 249 return this.teamTask; 250 } 251 252 public boolean isTeamTask() { 253 return this.teamTask; 254 } 255 256 public String getTextDescription() { 257 return this.textDescription; 258 } 259 260 public int getTotalWork() { 261 return this.totalWork; 262 } 263 264 public boolean isComplete() { 265 return this.complete; 266 } 267 268 public void setId(String id) { 269 this.id = id; 270 } 271 272 public void setUsername(String username) { 273 this.username = username; 274 } 275 276 public void setState(char state) { 277 this.state = state; 278 } 279 280 public void setDate(Date date) { 281 this.date = date; 282 } 283 284 public void setHref(String href) { 285 this.href = href; 286 } 287 288 public void setLastModified(Date lastModified) { 289 this.lastModified = lastModified; 290 } 291 292 public void setActualWork(int actualWork) { 293 this.actualWork = actualWork; 294 } 295 296 public void setBillingInformation (String billingInformation) { 297 this.billingInformation = billingInformation; 298 } 299 300 public void setCompanies(String companies) { 301 this.companies = companies; 302 } 303 304 public void setComplete(boolean complete) { 305 this.complete = complete; 306 } 307 308 public void setCategories(String categories) { 309 this.categories = categories; 310 } 311 312 public void setDateCompleted(Date dateCompleted) { 313 this.dateCompleted = dateCompleted; 314 } 315 316 public void setDueDate(Date dueDate) { 317 this.dueDate = dueDate; 318 } 319 320 public void setImportance(String importance) { 321 this.importance = importance; 322 } 323 324 public void setMileage(String mileage) { 325 this.mileage = mileage ; 326 } 327 328 public void setOwner(String owner) { 329 this.owner = owner; 330 } 331 332 public void setPercentComplete(String percentComplete) { 333 this.percentComplete = percentComplete ; 334 } 335 336 public void setReminderSet(boolean reminderSet) { 337 this.reminderSet = reminderSet ; 338 } 339 340 public void setReminderTime(Date reminderTime) { 341 this.reminderTime = reminderTime; 342 } 343 344 public void setSensitivity(String sensitivity) { 345 this.sensitivity = sensitivity; 346 } 347 348 public void setStatus(String status) { 349 this.status = status; 350 } 351 352 public void setSubject(String subject) { 353 this.subject = subject; 354 } 355 356 public void setTeamTask(boolean teamTask) { 357 this.teamTask = teamTask; 358 } 359 360 public void setTextDescription(String textDescription) { 361 this.textDescription = textDescription; 362 } 363 364 public void setTotalWork(int totalWork) { 365 this.totalWork = totalWork; 366 } 367 374 public void getPPTask(String id, String content, Date t) 375 throws TaskParseException { 376 377 String dt = null; 378 String tmp = null; 379 380 this.id = id; 381 this.lastModified = t ; 382 383 try { 384 385 XmlParser p = new XmlParser(); 386 387 dt = p.getXMLInitTagValue(content, TAG_PP_DATE ); 388 this.date = getDate(dt); 389 390 tmp = p.getXMLInitTagValue(content, TAG_PP_ACTUAL_WORK); 391 if (tmp != null && tmp.length() > 0) { 392 this.actualWork = Integer.parseInt(tmp); 393 } 394 395 this.billingInformation = p.getXMLInitTagValue(content, TAG_PP_BILLING_INFORMATION); 396 this.categories = p.getXMLInitTagValue(content, TAG_PP_CATEGORIES); 397 this.companies = p.getXMLInitTagValue(content, TAG_PP_COMPANIES); 398 this.dateCompleted = getDate(p.getXMLInitTagValue(content, TAG_PP_DATE_COMPLETED )); 399 this.dueDate = getDate(p.getXMLInitTagValue(content, TAG_PP_DUE_DATE)); 400 this.importance = p.getXMLInitTagValue(content, TAG_PP_IMPORTANCE); 401 this.mileage = p.getXMLInitTagValue(content, TAG_PP_MILEAGE); 402 this.owner = p.getXMLInitTagValue(content, TAG_PP_OWNER); 403 this.percentComplete = p.getXMLInitTagValue(content, TAG_PP_PERCENT_COMPLETE); 404 405 this.complete = sifValueToBoolean(p.getXMLInitTagValue(content, TAG_PP_COMPLETE)); 406 this.reminderSet = sifValueToBoolean(p.getXMLInitTagValue(content, TAG_PP_REMINDER_SET)); 407 408 this.teamTask = sifValueToBoolean(p.getXMLInitTagValue(content, TAG_PP_TEAM_TASK));; 409 410 411 this.subject = p.getXMLInitTagValue(content, TAG_PP_SUBJECT); 412 this.textDescription = p.getXMLInitTagValue(content, TAG_PP_NOTE); 413 414 415 tmp = p.getXMLInitTagValue(content, TAG_PP_REMINDER_TIME); 416 if (tmp != null && !tmp.equals("")) { 417 this.reminderTime = p.clientDateToDate(tmp); 418 } 419 this.sensitivity = p.getXMLInitTagValue(content, TAG_PP_SENSITIVITY); 420 this.status = p.getXMLInitTagValue(content, TAG_PP_STATUS); 421 422 tmp = p.getXMLInitTagValue(content, TAG_PP_TOTAL_WORK); 423 424 if (tmp != null && tmp.length() > 0) { 425 this.totalWork = Integer.parseInt(tmp); 426 } 427 428 } catch (NumberFormatException e) { 429 throw new TaskParseException(e.getMessage()); 430 } catch (XmlParseException e) { 431 throw new TaskParseException(e.getMessage()); 432 } catch (Exception e) { 433 throw new TaskParseException(e.getMessage()); 434 } 435 436 } 437 438 443 public String toXml() throws TaskParseException { 444 445 StringBuffer xmlMsg = new StringBuffer (); 446 String date = null; 447 XmlParser p = new XmlParser(); 448 449 try { 450 451 452 xmlMsg.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><task>\n"); 453 454 xmlMsg.append("<" + TAG_PP_ACTUAL_WORK + ">"). 455 append(String.valueOf(actualWork)). 456 append("</" +TAG_PP_ACTUAL_WORK + ">"); 457 458 if (categories != null) { 459 xmlMsg.append("<" + TAG_PP_CATEGORIES + ">"); 460 xmlMsg.append(categories); 461 xmlMsg.append("</" + TAG_PP_CATEGORIES + ">"); 462 } 463 464 if (companies != null) { 465 xmlMsg.append("<" + TAG_PP_COMPANIES + ">"); 466 xmlMsg.append(companies); 467 xmlMsg.append("</" + TAG_PP_COMPANIES + ">"); 468 } 469 470 xmlMsg.append("<" + TAG_PP_COMPLETE + ">"). 471 append(booleanToSIFValue(complete)). 472 append("</" + TAG_PP_COMPLETE + ">"); 473 474 date = p.toClientDate(this.date); 475 476 if (date != null && date.length() > 0) { 477 xmlMsg.append("<" + TAG_PP_DATE + ">"); 478 xmlMsg.append(date); 479 xmlMsg.append("</" + TAG_PP_DATE + ">"); 480 } else { 481 xmlMsg.append("<" + TAG_PP_DATE + ">" + 482 "</" + TAG_PP_DATE + ">"); 483 } 484 485 if (dateCompleted != null) { 486 xmlMsg.append("<" + TAG_PP_DATE_COMPLETED + ">"); 487 xmlMsg.append(XmlParser.toClientDate(dateCompleted)); 488 xmlMsg.append("</" + TAG_PP_DATE_COMPLETED + ">"); 489 } 490 491 if (dueDate != null) { 492 xmlMsg.append("<" + TAG_PP_DUE_DATE + ">"); 493 xmlMsg.append(XmlParser.toClientDate(dueDate)); 494 xmlMsg.append("</" + TAG_PP_DUE_DATE + ">"); 495 } else { 496 xmlMsg.append("<" + TAG_PP_DUE_DATE + ">" + 497 "</" + TAG_PP_DUE_DATE + ">"); 498 } 499 500 if (importance != null) { 501 xmlMsg.append("<" + TAG_PP_IMPORTANCE + ">"); 502 xmlMsg.append(importance); 503 xmlMsg.append("</" + TAG_PP_IMPORTANCE + ">"); 504 } 505 506 if (mileage != null) { 507 xmlMsg.append("<" + TAG_PP_MILEAGE + ">"); 508 xmlMsg.append(mileage); 509 xmlMsg.append("</" + TAG_PP_MILEAGE + ">"); 510 } 511 512 if (owner != null) { 513 xmlMsg.append("<" + TAG_PP_OWNER + ">"); 514 xmlMsg.append(owner); 515 xmlMsg.append("</" + TAG_PP_OWNER + ">"); 516 } 517 518 if (percentComplete != null) { 519 xmlMsg.append("<" + TAG_PP_PERCENT_COMPLETE + ">"); 520 xmlMsg.append(percentComplete); 521 xmlMsg.append("</" + TAG_PP_PERCENT_COMPLETE + ">"); 522 } 523 524 xmlMsg.append("<" + TAG_PP_REMINDER_SET + ">"); 525 xmlMsg.append(booleanToSIFValue(reminderSet)); 526 xmlMsg.append("</" + TAG_PP_REMINDER_SET + ">"); 527 528 if (reminderTime != null) { 529 xmlMsg.append("<" + TAG_PP_REMINDER_TIME + ">"); 530 xmlMsg.append(XmlParser.toClientDate(reminderTime)); 531 xmlMsg.append("</" + TAG_PP_REMINDER_TIME + ">"); 532 } else { 533 xmlMsg.append("<" + TAG_PP_REMINDER_TIME + ">" + 534 "</" + TAG_PP_REMINDER_TIME + ">"); 535 } 536 537 if (sensitivity != null) { 538 xmlMsg.append("<" + TAG_PP_SENSITIVITY + ">"); 539 xmlMsg.append(sensitivity); 540 xmlMsg.append("</" + TAG_PP_SENSITIVITY + ">"); 541 } 542 543 if (status != null) { 544 xmlMsg.append("<" + TAG_PP_STATUS + ">"); 545 xmlMsg.append(status); 546 xmlMsg.append("</" + TAG_PP_STATUS + ">"); 547 } 548 549 if (subject != null) { 550 xmlMsg.append("<" + TAG_PP_SUBJECT + ">"); 551 xmlMsg.append(subject); 552 xmlMsg.append("</" + TAG_PP_SUBJECT + ">"); 553 } 554 555 556 xmlMsg.append("<" + TAG_PP_TEAM_TASK + ">"); 557 xmlMsg.append(booleanToSIFValue(this.teamTask)); 558 xmlMsg.append("</" + TAG_PP_TEAM_TASK + ">"); 559 560 if (textDescription != null) { 561 xmlMsg.append("<" + TAG_PP_NOTE + ">"); 562 xmlMsg.append(textDescription); 563 xmlMsg.append("</" + TAG_PP_NOTE + ">"); 564 } 565 566 xmlMsg.append("<" + TAG_PP_TOTAL_WORK + ">"). 567 append(String.valueOf(totalWork)). 568 append("</" +TAG_PP_TOTAL_WORK + ">"); 569 570 xmlMsg.append("</task>"); 571 572 } catch (Exception e) { 573 throw new TaskParseException("Error composing task Device: " + 574 e.getMessage()); 575 } 576 577 return xmlMsg.toString(); 578 } 579 580 private Date getDate(String sDate) throws Exception { 581 if (sDate == null || sDate.equals("")) { 582 return null; 583 } 584 SimpleDateFormat formatter = null; 585 String formatUtc = "yyyyMMdd'T'HHmmss'Z'"; 586 formatter = new SimpleDateFormat (formatUtc); 587 formatter.setTimeZone(TimeZone.getTimeZone("UTC")); 588 589 return formatter.parse(sDate); 590 } 591 592 598 private String booleanToSIFValue(boolean value) { 599 if (value) { 600 return "1"; 601 } else { 602 return "0"; 603 } 604 } 605 606 611 private boolean sifValueToBoolean(String value) { 612 if (value != null && value.equals("1")) { 613 return true; 614 } 615 return false; 616 } 617 } 618 | Popular Tags |