1 19 20 package org.netbeans.nbbuild; 21 22 import java.io.*; 23 import java.util.*; 24 import java.util.Date ; 25 26 31 public final class Issue extends Object implements Comparable { 32 static final String ISSUE_TYPE = "issue_type"; 34 static final String SHORT_DESC = "short_desc"; 35 static final String LONG_DESC = "long_desc"; 36 static final String COMMENT = "comment"; 37 static final String ISSUE_ID = "issue_id"; 38 static final String ISSUE_STATUS = "issue_status"; 39 static final String RESOLUTION = "resolution"; 40 static final String COMPONENT = "component"; 41 static final String REPORTER = "reporter"; 42 static final String VERSION = "version"; 43 static final String SUBCOMPONENT = "subcomponent"; 44 static final String REP_PLATFORM = "rep_platform"; 45 static final String OP_SYS = "op_sys"; 46 static final String PRIORITY = "priority"; 47 static final String ASSIGNED_TO = "assigned_to"; 48 static final String CC = "cc"; 49 static final String DEPENDS_ON = "dependson"; 50 static final String BLOCKS = "blocks"; 51 static final String CREATED = "creation_ts"; 52 static final String VOTES = "votes"; 53 static final String KEYWORDS = "keywords"; 54 static final String STATUS_WHITEBOARD = "status_whiteboard"; 55 56 57 static final String TARGET_MILESTONE = "target_milestone"; 58 59 60 static final String LONG_DESC_LIST = "long_desc_list"; 61 62 private Map<String ,Object > attributes = new HashMap<String ,Object >(49); 63 64 65 70 public int getId() { 71 Object id = getAttribute(ISSUE_ID); 72 try { 73 return Integer.parseInt ((String ) id); 74 } catch (Exception ex) { 75 return -1; 76 } 77 } 78 79 82 public String getAssignedTo () { 83 return string (ASSIGNED_TO); 84 } 85 86 89 public String getReportedBy () { 90 return string (REPORTER); 91 } 92 93 96 public String [] getObservedBy () { 97 List<?> l = (List<?>) getAttribute (CC); 98 if (l != null) { 99 return l.toArray(new String [0]); 100 } else { 101 return new String [0]; 102 } 103 } 104 105 108 public String getStatus () { 109 return string (ISSUE_STATUS); 110 } 111 112 115 public String getResolution () { 116 return string (RESOLUTION); 117 } 118 119 122 public String getType () { 123 return string (ISSUE_TYPE); 124 } 125 126 129 public int getPriority () { 130 String s = string (PRIORITY); 131 if (s.length () == 2 && s.charAt (0) == 'P') { 132 return s.charAt (1) - '0'; 133 } else { 134 return -1; 135 } 136 } 137 138 141 public Date getCreated () { 142 Date d = (Date )getAttribute (CREATED); 143 return d == null ? new Date (0) : d; 144 } 145 146 149 public String getSummary () { 150 return string (SHORT_DESC); 151 } 152 153 156 public Description[] getDescriptions () { 157 Object obj = getAttribute(LONG_DESC_LIST); 158 if (obj == null) { 159 return new Description[0]; 160 } 161 162 return ((List<?>) obj).toArray(new Description[0]); 163 } 164 165 168 public int[] getDependsOn () { 169 return ints (DEPENDS_ON); 170 } 171 172 175 public int[] getBlocks () { 176 return ints (BLOCKS); 177 } 178 179 182 public String getTargetMilestone () { 183 return string (TARGET_MILESTONE); 184 } 185 186 189 public String getComponent () { 190 return string (COMPONENT); 191 } 192 193 196 public String getSubcomponent () { 197 return string (SUBCOMPONENT); 198 } 199 200 203 @Deprecated 204 public String getDuration () { 205 String val = getWhiteboardAttribute("duration"); 206 return val == null ? "" : val; 207 } 208 209 216 public final String getWhiteboardAttribute(String attribute) { 217 String ret = null; 218 String swb = string (STATUS_WHITEBOARD); 219 StringTokenizer st = new StringTokenizer (swb); 220 while (st.hasMoreTokens()) { 221 String token = st.nextToken(); 222 if ( token.startsWith (attribute + '=') ) { 223 ret = token.substring (token.indexOf ('=') + 1); 224 break; 225 } 226 } 227 return ret; 228 } 229 230 233 public int getVotes () { 234 try { 235 String s = string (VOTES); 236 return Integer.parseInt (s); 237 } catch (Exception ex) { 238 return 0; 239 } 240 } 241 242 245 public String getKeywords () { 246 try { 247 return string (KEYWORDS); 248 } catch (Exception ex) { 249 return ""; 250 } 251 } 252 253 257 public boolean containsKeyword (String keyword) { 258 StringTokenizer tokenizer = new StringTokenizer(getKeywords()); 259 while (tokenizer.hasMoreTokens()) { 260 String current = tokenizer.nextToken(); 261 if (current.equals(keyword)) 262 return true; 263 } 264 return false; 265 } 266 267 278 279 281 private String string (String name) { 282 Object o = getAttribute (name); 283 return o instanceof String ? (String )o : ""; 284 } 285 286 288 private int[] ints (String name) { 289 List l = (List)getAttribute (name); 290 if (l == null) { 291 return new int[0]; 292 } 293 294 int[] arr = new int[l.size ()]; 295 for (int i = 0; i < arr.length; i++) { 296 arr[i] = Integer.parseInt ((String )l.get (i)); 297 } 298 return arr; 299 } 300 301 304 Object getAttribute(String name) { 305 if (name.equals(LONG_DESC)) { 306 return formatLongDescriptions(); 307 } else { 308 return attributes.get(name); 309 } 310 } 311 312 313 314 void setAttribute(String name, Object value) { 315 attributes.put(name, value); 316 } 317 318 323 private Map attributes() { 324 return attributes; 325 } 326 327 330 public String toString() { 331 StringBuffer buffer; 332 if (attributes == null) { 333 return "Empty BugBase"; 334 } 335 Iterator it = attributes.entrySet().iterator(); 336 buffer = new StringBuffer (); 337 buffer.append(this.getClass().getName() 338 + " containing these name/value attribute pairs:\n"); 339 while (it.hasNext()) { 340 Map.Entry entry = (Map.Entry) it.next(); 341 buffer.append("NAME : " + entry.getKey() + "\n"); 342 buffer.append("VALUE : " + entry.getValue() + "\n"); 343 } 344 return buffer.toString(); 345 } 346 347 349 public int compareTo (Object o) { 350 Issue i = (Issue)o; 351 return getId () - i.getId (); 352 } 353 354 359 private String formatLongDescriptions() { 360 if (attributes.get (Issue.LONG_DESC) == null) { 361 StringBuffer buffer = new StringBuffer (""); 362 Object obj = getAttribute(LONG_DESC_LIST); 363 List descriptions; 364 if (obj == null) { 365 return null; 366 } 367 descriptions = (List) obj; 368 Iterator it = descriptions.iterator(); 369 while (it.hasNext()) { 370 Description ld = (Description) it.next(); 371 buffer.append(ld.toString()); 372 } 373 attributes.put (LONG_DESC, buffer.toString()); 374 } 375 return attributes.get (LONG_DESC).toString(); 376 } 377 378 379 380 383 public final static class Description { 384 static final String WHO = "who"; 385 static final String ISSUE_WHEN = "issue_when"; 386 static final String BODY = "body"; 387 static final String THETEXT = "thetext"; 388 389 390 private String who; 391 392 393 private Date when; 394 395 396 private String body; 397 398 401 public String getWho() { 402 return who; 403 } 404 405 408 void setWho(String who) { 409 this.who = who; 410 } 411 412 415 public java.util.Date getWhen() { 416 return when; 417 } 418 419 422 void setIssueWhen(Date when) { 423 this.when = when; 424 } 425 426 429 public String getBody() { 430 return body; 431 } 432 433 436 public String toString() { 437 StringBuffer buffer = new StringBuffer (); 438 buffer.append(getWho()); 439 buffer.append(", "); 440 buffer.append(getWhen()); 441 buffer.append(" : \n"); 442 buffer.append(getBody()); 443 buffer.append("\n\n"); 444 return buffer.toString(); 445 } 446 447 448 449 450 451 452 453 454 455 456 457 460 void setBody(String body) { 461 this.body = body; 462 } 463 464 void setAtribute(String name, String value) { 465 if (name.equalsIgnoreCase(WHO)) { 466 setWho(value); 467 } else if (name.equalsIgnoreCase(BODY) 468 || name.equalsIgnoreCase(THETEXT)) { 469 setBody(value); 470 } 471 } 472 473 private String getAttribute(String name) { 474 if (name.equalsIgnoreCase(WHO)) { 475 return who; 476 } else if (name.equalsIgnoreCase(BODY) 477 || name.equalsIgnoreCase(THETEXT)) { 478 return body; 479 } else { 480 return null; 481 } 482 } 483 484 } 485 486 } 487 | Popular Tags |