1 11 package org.eclipse.team.internal.ccvs.core.resources; 12 13 14 import java.text.ParseException ; 15 import java.text.SimpleDateFormat ; 16 import java.util.*; 17 18 import org.eclipse.core.runtime.IStatus; 19 import org.eclipse.team.internal.ccvs.core.*; 20 21 public class CVSEntryLineTag extends CVSTag { 22 23 27 private static final String ENTRY_LINE_DATE_TAG_FORMAT = "yyyy.MM.dd.HH.mm.ss"; 29 32 private static SimpleDateFormat entryLineDateTagFormatter = new SimpleDateFormat (ENTRY_LINE_DATE_TAG_FORMAT, Locale.US); 33 34 38 private static String getNameInInternalFormat(CVSTag tag) { 39 if(tag.getType() == DATE){ 40 String s = ensureEntryLineFormat(tag.getName()); 41 if(s != null){ 42 return s; 43 } 44 } 45 return tag.getName(); 46 } 47 48 52 private static synchronized String ensureEntryLineFormat(String text){ 53 if(text.length() == ENTRY_LINE_DATE_TAG_FORMAT.length()) return text; 54 Date date = tagNameToDate(text); 55 if (date == null) return text; 56 entryLineDateTagFormatter.setTimeZone(TimeZone.getTimeZone("GMT")); return entryLineDateTagFormatter.format(date); 58 } 59 60 static synchronized public Date entryLineToDate(String text){ 61 try { 62 entryLineDateTagFormatter.setTimeZone(TimeZone.getTimeZone("GMT")); return entryLineDateTagFormatter.parse(text); 64 } catch (ParseException e) { 65 CVSProviderPlugin.log(new CVSStatus(IStatus.ERROR, CVSStatus.ERROR, "Tag name " + text + " is not of the expected format " + ENTRY_LINE_DATE_TAG_FORMAT, e)); return null; 67 } 68 } 69 70 73 public CVSEntryLineTag(CVSTag tag) { 74 super(getNameInInternalFormat(tag), tag.getType()); 75 } 76 77 public CVSEntryLineTag(String entryLineTag) { 78 switch (entryLineTag.charAt(0)) { 79 case 'T' : type = BRANCH; break; 80 case 'N' : type = VERSION; break; 81 case 'D' : type = DATE; break; 82 default: type = HEAD; 83 } 84 name = entryLineTag.substring(1); 85 } 86 89 public String getName() { 90 if (getType() == DATE) { 91 Date date = asDate(); 93 if(date != null){ 94 return dateToTagName(date); 95 } 96 } 97 return name; 98 } 99 102 public int getType() { 103 return type; 104 } 105 106 public String toEntryLineFormat(boolean useSamePrefixForBranchAndTag) { 107 if (type == BRANCH || (type == VERSION && useSamePrefixForBranchAndTag)) 108 return "T" + name; else if (type == VERSION) 110 return "N" + name; else if (type == DATE) 112 return "D" + name; return ""; } 115 116 119 public String toString() { 120 return toEntryLineFormat(false); 121 } 122 123 126 public Date asDate() { 127 return entryLineToDate(name); 128 } 129 } 130 131 | Popular Tags |