1 22 package org.netbeans.lib.cvsclient.admin; 23 24 import java.text.*; 25 import java.util.*; 26 27 34 public final class Entry { 35 39 public static final String DUMMY_TIMESTAMP = "dummy timestamp"; public static final String DUMMY_TIMESTAMP_NEW_ENTRY = "dummy timestamp from new-entry"; 42 public static final String MERGE_TIMESTAMP = "Result of merge"; 44 47 private static final String TAG = "T"; 49 52 private static final String DATE = "D"; 54 57 private static SimpleDateFormat stickyDateFormatter; 58 59 62 private static SimpleDateFormat getStickyDateFormatter() { 63 if (stickyDateFormatter == null) { 64 stickyDateFormatter = new SimpleDateFormat("yyyy.MM.dd.hh.mm.ss"); } 66 return stickyDateFormatter; 67 } 68 69 72 private static final String BINARY_FILE = "-kb"; 74 77 private static final String NO_USER_FILE = ""; 79 82 private static final String NEW_USER_FILE = "0"; 84 87 private static final String REMOVE_USER_FILE = "-"; 89 93 private static SimpleDateFormat lastModifiedDateFormatter; 94 95 98 public static SimpleDateFormat getLastModifiedDateFormatter() { 99 if (lastModifiedDateFormatter == null) { 100 lastModifiedDateFormatter = 101 new SimpleDateFormat("EEE MMM dd HH:mm:ss yyyy", Locale.US); lastModifiedDateFormatter.setTimeZone(getTimeZone()); 103 } 104 return lastModifiedDateFormatter; 105 } 106 107 110 public static TimeZone getTimeZone() { 111 return TimeZone.getTimeZone("GMT"); } 113 114 117 public static final char HAD_CONFLICTS = '+'; 118 119 122 public static final char TIMESTAMP_MATCHES_FILE = '='; 123 124 128 public static final String HAD_CONFLICTS_AND_TIMESTAMP_MATCHES_FILE = "+="; 129 130 133 private static final String DIRECTORY_PREFIX = "D/"; 134 135 138 private String name; 139 140 144 private String revision; 145 146 150 private String conflict; 151 152 155 private Date lastModified; 156 157 160 private String options; 161 162 165 private String tag; 166 167 170 private Date date; 171 172 175 private boolean directory; 176 177 180 public Entry(String entryLine) { 181 init(entryLine); 182 } 183 184 187 public Entry() { 188 } 189 190 194 protected void init(String entryLine) { 195 199 if (entryLine.startsWith(DIRECTORY_PREFIX)) { 200 directory = true; 201 entryLine = entryLine.substring(1); 202 } 203 204 final int[] slashPositions = new int[5]; 207 208 try { 209 slashPositions[0] = 0; 210 for (int i = 1; i < 5; i++) { 211 slashPositions[i] = entryLine.indexOf('/', 212 slashPositions[i - 1] + 1); 213 } 214 215 if (slashPositions[1] > 0) { 219 name = entryLine.substring(slashPositions[0] + 1, 222 slashPositions[1]); 223 revision = entryLine.substring(slashPositions[1] + 1, 224 slashPositions[2]); 225 if ((slashPositions[3] - slashPositions[2]) > 1) { 226 String conflict = entryLine.substring(slashPositions[2] + 1, 227 slashPositions[3]); 228 setConflict(conflict); 229 } 230 if ((slashPositions[4] - slashPositions[3]) > 1) { 231 options = entryLine.substring(slashPositions[3] + 1, 232 slashPositions[4]); 233 } 234 if (slashPositions[4] != (entryLine.length() - 1)) { 235 String tagOrDate = entryLine.substring(slashPositions[4] 236 + 1); 237 if (tagOrDate.startsWith(TAG)) { 238 setTag(tagOrDate.substring(1)); 239 } 240 else if (tagOrDate.startsWith(DATE)) { 241 try { 245 String dateString = tagOrDate.substring(DATE.length()); 246 Date stickyDate = getStickyDateFormatter(). 247 parse(dateString); 248 setDate(stickyDate); 249 } 250 catch (ParseException exc) { 251 System.err.println("We got another inconsistency in the library's date formatting."); } 253 } 254 } 255 } 256 } 257 catch (Exception e) { 258 System.err.println("Error parsing entry line: " + e); e.printStackTrace(); 260 throw new IllegalArgumentException ("Invalid entry line: " + entryLine); 262 } 263 } 264 265 269 public String getName() { 270 return name; 271 } 272 273 277 public void setName(String name) { 278 this.name = name; 279 } 280 281 285 public String getRevision() { 286 return revision; 287 } 288 289 293 public void setRevision(String revision) { 294 this.revision = revision; 295 } 296 297 302 public Date getLastModified() { 303 return lastModified; 304 } 305 306 310 public String getConflict() { 311 return conflict; 312 } 313 314 318 public void setConflict(String conflict) { 319 this.conflict = conflict; 320 this.lastModified = null; 321 322 if (conflict == null 323 || conflict.equals(DUMMY_TIMESTAMP) 324 || conflict.equals(MERGE_TIMESTAMP) 325 || conflict.equals(DUMMY_TIMESTAMP_NEW_ENTRY)) { 326 return; 327 } 328 329 String dateString = conflict; 330 331 int conflictIndex = dateString.indexOf(HAD_CONFLICTS); 333 if (conflictIndex >= 0) { 334 int timeMatchIndex = dateString.indexOf(TIMESTAMP_MATCHES_FILE); 337 conflictIndex = Math.max(conflictIndex, timeMatchIndex); 338 } 339 340 if (conflictIndex >= 0) { 343 dateString = dateString.substring(conflictIndex + 1); 344 } 345 346 if (dateString.length() == 0) { 348 return; 349 } 350 351 try { 352 this.lastModified = getLastModifiedDateFormatter().parse(dateString); 353 } 354 catch (Exception ex) { 355 lastModified = null; 356 } 358 } 359 360 364 public String getOptions() { 365 return options; 366 } 367 368 372 public void setOptions(String options) { 373 this.options = options; 374 } 375 376 380 public String getStickyInformation() { 381 if (tag != null) { 382 return tag; 383 } 384 return getDateFormatted(); 385 } 386 387 394 public String getTag() { 395 return tag; 396 } 397 398 403 public void setTag(String tag) { 404 this.tag = tag; 405 date = null; 406 } 407 408 415 public Date getDate() { 416 return date; 417 } 418 419 423 public String getDateFormatted() { 424 if (getDate() == null) { 425 return null; 426 } 427 SimpleDateFormat format = getStickyDateFormatter(); 428 String dateFormatted = format.format(getDate()); 429 return dateFormatted; 430 } 431 432 437 public void setDate(Date date) { 438 this.date = date; 439 tag = null; 440 } 441 442 446 public boolean hasDate() { 447 return (date != null); 448 } 449 450 454 public boolean hasTag() { 455 return (tag != null); 456 } 457 458 461 public boolean isBinary() { 462 return options != null 463 && options.equals(BINARY_FILE); 464 } 465 466 470 public boolean isNoUserFile() { 471 return revision == null 472 || revision.equals(NO_USER_FILE); 473 } 474 475 479 public boolean isNewUserFile() { 480 return revision != null 481 && revision.startsWith(NEW_USER_FILE); 482 } 483 484 488 public boolean isUserFileToBeRemoved() { 489 return revision != null 490 && revision.startsWith(REMOVE_USER_FILE); 491 } 492 493 497 public boolean isValid() { 498 return getName() != null && 499 getName().length() > 0; 500 } 501 502 505 public boolean isDirectory() { 506 return directory; 507 } 508 509 512 public void setDirectory(boolean directory) { 513 this.directory = directory; 514 } 515 516 520 public boolean hadConflicts() { 521 if (conflict != null) { 522 return conflict.indexOf(HAD_CONFLICTS) >= 0; 523 } 524 else { 525 return false; 526 } 527 } 528 529 533 public boolean timestampMatchesFile() { 534 return (conflict.charAt(1) == TIMESTAMP_MATCHES_FILE); 535 } 536 537 545 public String toString() { 546 StringBuffer buf = new StringBuffer (); 547 if (directory) { 548 buf.append(DIRECTORY_PREFIX); 549 } 550 else { 551 buf.append('/'); 552 } 553 if (name != null) { 556 buf.append(name); 557 buf.append('/'); 558 if (revision != null) { 559 buf.append(revision); 560 } 561 buf.append('/'); 562 if (conflict != null) { 563 buf.append(conflict); 564 } 565 buf.append('/'); 566 if (options != null) { 567 buf.append(options); 568 } 569 buf.append('/'); 570 if (tag != null && date == null) { 573 if ("HEAD".equals(tag) == false) { 574 buf.append(TAG); 575 buf.append(getTag()); 576 } 577 } 578 else if (tag == null && date != null) { 579 String dateString = getDateFormatted(); 580 buf.append(DATE); 581 buf.append(dateString); 582 } 583 } 584 return buf.toString(); 585 } 586 } 587 | Popular Tags |