1 19 20 package org.netbeans.modules.tasklist.bugs.issuezilla; 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 55 public final class Issue extends Object implements Comparable { 56 static final String ISSUE_TYPE = "issue_type"; 58 static final String SHORT_DESC = "short_desc"; 59 static final String LONG_DESC = "long_desc"; 60 static final String COMMENT = "comment"; 61 static final String ISSUE_ID = "issue_id"; 62 static final String ISSUE_STATUS = "issue_status"; 63 static final String RESOLUTION = "resolution"; 64 static final String COMPONENT = "component"; 65 static final String REPORTER = "reporter"; 66 static final String VERSION = "version"; 67 static final String SUBCOMPONENT = "subcomponent"; 68 static final String REP_PLATFORM = "rep_platform"; 69 static final String OP_SYS = "op_sys"; 70 static final String PRIORITY = "priority"; 71 static final String ASSIGNED_TO = "assigned_to"; 72 static final String CC = "cc"; 73 static final String DEPENDS_ON = "dependson"; 74 static final String BLOCKS = "blocks"; 75 static final String CREATED = "creation_ts"; 76 static final String VOTES = "votes"; 77 static final String KEYWORDS = "keywords"; 78 79 80 static final String TARGET_MILESTONE = "target_milestone"; 81 82 83 static final String LONG_DESC_LIST = "long_desc_list"; 84 85 private HashMap attributes = new HashMap (49); 86 87 88 93 public int getId() { 94 Object id = getAttribute(ISSUE_ID); 95 try { 96 return Integer.parseInt ((String ) id); 97 } catch (Exception ex) { 98 return -1; 99 } 100 } 101 102 105 public String getAssignedTo () { 106 return string (ASSIGNED_TO); 107 } 108 109 112 public String getReportedBy () { 113 return string (REPORTER); 114 } 115 116 119 public String [] getObservedBy () { 120 java.util.List l = (java.util.List )getAttribute (CC); 121 if (l != null) { 122 return (String [])l.toArray (new String [0]); 123 } else { 124 return new String [0]; 125 } 126 } 127 128 131 public String getStatus () { 132 return string (ISSUE_STATUS); 133 } 134 135 138 public String getResolution () { 139 return string (RESOLUTION); 140 } 141 142 145 public String getType () { 146 return string (ISSUE_TYPE); 147 } 148 149 152 public int getPriority () { 153 String s = string (PRIORITY); 154 if (s.length () == 2 && s.charAt (0) == 'P') { 155 return s.charAt (1) - '0'; 156 } else { 157 return -1; 158 } 159 } 160 161 164 public Date getCreated () { 165 Date d = (Date )getAttribute (CREATED); 166 return d == null ? new Date (0) : d; 167 } 168 169 172 public String getSummary () { 173 return string (SHORT_DESC); 174 } 175 176 179 public Description[] getDescriptions () { 180 Object obj = getAttribute(LONG_DESC_LIST); 181 if (obj == null) { 182 return new Description[0]; 183 } 184 185 return (Description[])((List)obj).toArray (new Description[0]); 186 } 187 188 191 public int[] getDependsOn () { 192 return ints (DEPENDS_ON); 193 } 194 195 198 public int[] getBlocks () { 199 return ints (BLOCKS); 200 } 201 202 205 public String getTargetMilestone () { 206 return string (TARGET_MILESTONE); 207 } 208 209 212 public String getComponent () { 213 return string (COMPONENT); 214 } 215 216 219 public String getSubcomponent () { 220 return string (SUBCOMPONENT); 221 } 222 223 226 public int getVotes () { 227 try { 228 String s = string (VOTES); 229 return Integer.parseInt (s); 230 } catch (Exception ex) { 231 return 0; 232 } 233 } 234 235 238 public String getKeywords () { 239 try { 240 return string (KEYWORDS); 241 } catch (Exception ex) { 242 return ""; 243 } 244 } 245 246 250 public boolean containsKeyword (String keyword) { 251 StringTokenizer tokenizer = new StringTokenizer(getKeywords()); 252 while (tokenizer.hasMoreTokens()) { 253 String current = tokenizer.nextToken(); 254 if (current.equals(keyword)) 255 return true; 256 } 257 return false; 258 } 259 260 271 272 274 private String string (String name) { 275 Object o = getAttribute (name); 276 return o instanceof String ? (String )o : ""; 277 } 278 279 281 private int[] ints (String name) { 282 List l = (List)getAttribute (name); 283 if (l == null) { 284 return new int[0]; 285 } 286 287 int[] arr = new int[l.size ()]; 288 for (int i = 0; i < arr.length; i++) { 289 arr[i] = Integer.parseInt ((String )l.get (i)); 290 } 291 return arr; 292 } 293 294 297 Object getAttribute(String name) { 298 if (name.equals(LONG_DESC)) { 299 return formatLongDescriptions(); 300 } else { 301 return attributes.get(name); 302 } 303 } 304 305 306 307 void setAttribute(String name, Object value) { 308 attributes.put(name, value); 309 } 310 311 316 private Map attributes() { 317 return attributes; 318 } 319 320 323 public String toString() { 324 StringBuffer buffer; 325 if (attributes == null) { 326 return "Empty BugBase"; 327 } 328 Iterator it = attributes.entrySet().iterator(); 329 buffer = new StringBuffer (); 330 buffer.append(this.getClass().getName() 331 + " containing these name/value attribute pairs:\n"); 332 while (it.hasNext()) { 333 Map.Entry entry = (Map.Entry) it.next(); 334 buffer.append("NAME : " + entry.getKey() + "\n"); 335 buffer.append("VALUE : " + entry.getValue() + "\n"); 336 } 337 return buffer.toString(); 338 } 339 340 342 public int compareTo (Object o) { 343 Issue i = (Issue)o; 344 return getId () - i.getId (); 345 } 346 347 352 private String formatLongDescriptions() { 353 if (attributes.get (Issue.LONG_DESC) == null) { 354 StringBuffer buffer = new StringBuffer (""); 355 Object obj = getAttribute(LONG_DESC_LIST); 356 List descriptions; 357 if (obj == null) { 358 return null; 359 } 360 descriptions = (List) obj; 361 Iterator it = descriptions.iterator(); 362 while (it.hasNext()) { 363 Description ld = (Description) it.next(); 364 buffer.append(ld.toString()); 365 } 366 attributes.put (LONG_DESC, buffer.toString()); 367 } 368 return attributes.get (LONG_DESC).toString(); 369 } 370 371 372 373 376 public final static class Description { 377 static final String WHO = "who"; 378 static final String ISSUE_WHEN = "issue_when"; 379 static final String BODY = "body"; 380 static final String THETEXT = "thetext"; 381 382 383 private String who; 384 385 386 private Date when; 387 388 389 private String body; 390 391 394 public String getWho() { 395 return who; 396 } 397 398 401 void setWho(String who) { 402 this.who = who; 403 } 404 405 408 public java.util.Date getWhen() { 409 return when; 410 } 411 412 415 void setIssueWhen(Date when) { 416 this.when = when; 417 } 418 419 422 public String getBody() { 423 return body; 424 } 425 426 429 public String toString() { 430 StringBuffer buffer = new StringBuffer (); 431 buffer.append(getWho()); 432 buffer.append(", "); 433 buffer.append(getWhen()); 434 buffer.append(" : \n"); 435 buffer.append(getBody()); 436 buffer.append("\n\n"); 437 return buffer.toString(); 438 } 439 440 441 442 443 444 445 446 447 448 449 450 453 void setBody(String body) { 454 this.body = body; 455 } 456 457 void setAtribute(String name, String value) { 458 if (name.equalsIgnoreCase(WHO)) { 459 setWho(value); 460 } else if (name.equalsIgnoreCase(BODY) 461 || name.equalsIgnoreCase(THETEXT)) { 462 setBody(value); 463 } 464 } 465 466 private String getAttribute(String name) { 467 if (name.equalsIgnoreCase(WHO)) { 468 return who; 469 } else if (name.equalsIgnoreCase(BODY) 470 || name.equalsIgnoreCase(THETEXT)) { 471 return body; 472 } else { 473 return null; 474 } 475 } 476 477 } 478 479 } 480 | Popular Tags |