KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > core > resources > CVSEntryLineTag


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.team.internal.ccvs.core.resources;
12
13
14 import java.text.ParseException JavaDoc;
15 import java.text.SimpleDateFormat JavaDoc;
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     /*
24      * This is the format of a date as it appears in the entry line. The date in an entry
25      * line is always in GMT.
26      */

27     private static final String JavaDoc ENTRY_LINE_DATE_TAG_FORMAT = "yyyy.MM.dd.HH.mm.ss"; //$NON-NLS-1$
28

29     /*
30      * This is a formatter that will translate dates to and from text as it appears in the entry line
31      */

32     private static SimpleDateFormat JavaDoc entryLineDateTagFormatter = new SimpleDateFormat JavaDoc(ENTRY_LINE_DATE_TAG_FORMAT, Locale.US);
33     
34     /*
35      * Convert the tag name as it appears as an argument to a command
36      * into the format that appears in the entry line of a folder or file
37      */

38     private static String JavaDoc getNameInInternalFormat(CVSTag tag) {
39         if(tag.getType() == DATE){
40             String JavaDoc s = ensureEntryLineFormat(tag.getName());
41             if(s != null){
42                 return s;
43             }
44         }
45         return tag.getName();
46     }
47     
48     /*
49      * Helper for converting the tag name as it appears as an argument to a command
50      * into the format that appears in the entry line of a folder or file
51      */

52     private static synchronized String JavaDoc ensureEntryLineFormat(String JavaDoc 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")); //$NON-NLS-1$
57
return entryLineDateTagFormatter.format(date);
58     }
59     
60     static synchronized public Date entryLineToDate(String JavaDoc text){
61         try {
62             entryLineDateTagFormatter.setTimeZone(TimeZone.getTimeZone("GMT")); //$NON-NLS-1$
63
return entryLineDateTagFormatter.parse(text);
64         } catch (ParseException JavaDoc 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)); //$NON-NLS-1$ //$NON-NLS-2$
66
return null;
67         }
68     }
69     
70     /*
71      * The parameter tag must not be null.
72      */

73     public CVSEntryLineTag(CVSTag tag) {
74         super(getNameInInternalFormat(tag), tag.getType());
75     }
76     
77     public CVSEntryLineTag(String JavaDoc 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     /*
87      * Returns the tag name
88      */

89     public String JavaDoc getName() {
90         if (getType() == DATE) {
91             // Use same format as CVSTag when the name is requested
92
Date date = asDate();
93             if(date != null){
94                 return dateToTagName(date);
95             }
96         }
97         return name;
98     }
99     /*
100      * Returns the tag type
101      */

102     public int getType() {
103         return type;
104     }
105     
106     public String JavaDoc toEntryLineFormat(boolean useSamePrefixForBranchAndTag) {
107         if (type == BRANCH || (type == VERSION && useSamePrefixForBranchAndTag))
108             return "T" + name;//$NON-NLS-1$
109
else if (type == VERSION)
110             return "N" + name;//$NON-NLS-1$
111
else if (type == DATE)
112             return "D" + name;//$NON-NLS-1$
113
return "";//$NON-NLS-1$
114
}
115
116     /*
117      * For debugging purposes.
118      */

119     public String JavaDoc toString() {
120         return toEntryLineFormat(false);
121     }
122     
123     /* (non-Javadoc)
124      * @see org.eclipse.team.internal.ccvs.core.CVSTag#asDate()
125      */

126     public Date asDate() {
127         return entryLineToDate(name);
128     }
129 }
130
131
Popular Tags