1 19 20 package org.netbeans.modules.tasklist.bugs.bugzilla; 21 22 import java.io.*; 23 import java.net.URL ; 24 import java.util.*; 25 import java.util.Date ; 26 27 import javax.xml.parsers.SAXParserFactory ; 28 import javax.xml.parsers.SAXParser ; 29 import javax.xml.parsers.ParserConfigurationException ; 30 import org.xml.sax.SAXException ; 31 32 33 61 public final class Issue extends Object implements Comparable { 62 static final String ISSUE_TYPE = "bug_severity"; 64 static final String SHORT_DESC = "short_desc"; 65 static final String LONG_DESC = "long_desc"; 66 static final String COMMENT = "comment"; 67 static final String ISSUE_ID = "bug_id"; 68 static final String ISSUE_STATUS = "bug_status"; 69 static final String RESOLUTION = "resolution"; 70 static final String COMPONENT = "product"; 71 static final String REPORTER = "reporter"; 72 static final String VERSION = "version"; 73 static final String SUBCOMPONENT = "component"; 74 static final String REP_PLATFORM = "rep_platform"; 75 static final String OP_SYS = "op_sys"; 76 static final String PRIORITY = "priority"; 77 static final String ASSIGNED_TO = "assigned_to"; 78 static final String CREATED = "creation_ts"; 82 85 86 static final String TARGET_MILESTONE = "target_milestone"; 87 88 89 static final String LONG_DESC_LIST = "long_desc_list"; 90 91 private HashMap attributes = new HashMap (49); 92 93 94 99 public int getId() { 100 Object id = getAttribute(ISSUE_ID); 101 try { 102 return Integer.parseInt ((String ) id); 103 } catch (Exception ex) { 104 return -1; 105 } 106 } 107 108 111 public String getAssignedTo () { 112 return string (ASSIGNED_TO); 113 } 114 115 118 public String getReportedBy () { 119 return string (REPORTER); 120 } 121 122 125 public String [] getObservedBy () { 126 return new String [0]; 131 } 133 134 137 public String getStatus () { 138 return string (ISSUE_STATUS); 139 } 140 141 144 public String getResolution () { 145 return string (RESOLUTION); 146 } 147 148 151 public String getType () { 152 return string (ISSUE_TYPE); 153 } 154 155 158 public int getPriority () { 159 String s = string (PRIORITY); 160 if (s.length () == 2 && s.charAt (0) == 'P') { 161 return s.charAt (1) - '0'; 162 } else { 163 return -1; 164 } 165 } 166 167 170 public Date getCreated () { 171 Date d = (Date )getAttribute (CREATED); 172 return d == null ? new Date (0) : d; 173 } 174 175 178 public String getSummary () { 179 return string (SHORT_DESC); 180 } 181 182 185 public Description[] getDescriptions () { 186 Object obj = getAttribute(LONG_DESC_LIST); 187 if (obj == null) { 188 return new Description[0]; 189 } 190 191 return (Description[])((List)obj).toArray (new Description[0]); 192 } 193 194 197 201 204 208 211 public String getTargetMilestone () { 212 return string (TARGET_MILESTONE); 213 } 214 215 218 public String getComponent () { 219 return string (COMPONENT); 220 } 221 222 225 public String getSubcomponent () { 226 return string (SUBCOMPONENT); 227 } 228 229 232 241 244 252 256 266 277 278 280 private String string (String name) { 281 Object o = getAttribute (name); 282 return o instanceof String ? (String )o : ""; 283 } 284 285 287 private int[] ints (String name) { 288 List l = (List)getAttribute (name); 289 if (l == null) { 290 return new int[0]; 291 } 292 293 int[] arr = new int[l.size ()]; 294 for (int i = 0; i < arr.length; i++) { 295 arr[i] = Integer.parseInt ((String )l.get (i)); 296 } 297 return arr; 298 } 299 300 303 Object getAttribute(String name) { 304 if (name.equals(LONG_DESC)) { 305 return formatLongDescriptions(); 306 } else { 307 return attributes.get(name); 308 } 309 } 310 311 312 313 void setAttribute(String name, Object value) { 314 attributes.put(name, value); 315 } 316 317 322 private Map attributes() { 323 return attributes; 324 } 325 326 329 public String toString() { 330 StringBuffer buffer; 331 if (attributes == null) { 332 return "Empty BugBase"; 333 } 334 Iterator it = attributes.entrySet().iterator(); 335 buffer = new StringBuffer (); 336 buffer.append(this.getClass().getName() 337 + " containing these name/value attribute pairs:\n"); 338 while (it.hasNext()) { 339 Map.Entry entry = (Map.Entry) it.next(); 340 buffer.append("NAME : " + entry.getKey() + "\n"); 341 buffer.append("VALUE : " + entry.getValue() + "\n"); 342 } 343 return buffer.toString(); 344 } 345 346 348 public int compareTo (Object o) { 349 Issue i = (Issue)o; 350 return getId () - i.getId (); 351 } 352 353 358 private String formatLongDescriptions() { 359 if (attributes.get (Issue.LONG_DESC) == null) { 360 StringBuffer buffer = new StringBuffer (""); 361 Object obj = getAttribute(LONG_DESC_LIST); 362 List descriptions; 363 if (obj == null) { 364 return null; 365 } 366 descriptions = (List) obj; 367 Iterator it = descriptions.iterator(); 368 while (it.hasNext()) { 369 Description ld = (Description) it.next(); 370 buffer.append(ld.toString()); 371 } 372 attributes.put (LONG_DESC, buffer.toString()); 373 } 374 return attributes.get (LONG_DESC).toString(); 375 } 376 377 378 379 382 public final static class Description { 383 static final String WHO = "who"; 384 static final String ISSUE_WHEN = "bug_when"; 385 static final String BODY = "thetext"; 386 static final String THETEXT = "thetext"; 387 388 389 private String who; 390 391 392 private Date when; 393 394 395 private String body; 396 397 400 public String getWho() { 401 return who; 402 } 403 404 407 void setWho(String who) { 408 this.who = who; 409 } 410 411 414 public java.util.Date getWhen() { 415 return when; 416 } 417 418 421 void setIssueWhen(Date when) { 422 this.when = when; 423 } 424 425 428 public String getBody() { 429 return body; 430 } 431 432 435 public String toString() { 436 StringBuffer buffer = new StringBuffer (); 437 buffer.append(getWho()); 438 buffer.append(", "); 439 buffer.append(getWhen()); 440 buffer.append(" : \n"); 441 buffer.append(getBody()); 442 buffer.append("\n\n"); 443 return buffer.toString(); 444 } 445 446 447 448 449 450 451 452 453 454 455 456 459 void setBody(String body) { 460 this.body = body; 461 } 462 463 void setAtribute(String name, String value) { 464 if (name.equalsIgnoreCase(WHO)) { 465 setWho(value); 466 } else if (name.equalsIgnoreCase(BODY) 467 || name.equalsIgnoreCase(THETEXT)) { 468 setBody(value); 469 } 470 } 471 472 private String getAttribute(String name) { 473 if (name.equalsIgnoreCase(WHO)) { 474 return who; 475 } else if (name.equalsIgnoreCase(BODY) 476 || name.equalsIgnoreCase(THETEXT)) { 477 return body; 478 } else { 479 return null; 480 } 481 } 482 483 } 484 485 } 486 | Popular Tags |