KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > lib > cvsclient > command > log > LogInformation


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.lib.cvsclient.command.log;
20
21 import java.io.*;
22 import java.util.*;
23 import java.text.SimpleDateFormat JavaDoc;
24
25 import org.netbeans.lib.cvsclient.command.*;
26 import org.netbeans.lib.cvsclient.util.*;
27
28 /**
29  * Describes log information for a file. This is the result of doing a
30  * cvs log command. The fields in instances of this object are populated
31  * by response handlers.
32  * @author Milos Kleint
33  */

34 public class LogInformation extends FileInfoContainer {
35     private static final SimpleDateFormat JavaDoc DATE_FORMAT = new SimpleDateFormat JavaDoc("yyyy-MM-dd HH:mm:ss Z"); //NOI18N
36
private File file;
37     private String JavaDoc repositoryFilename;
38     private String JavaDoc headRevision;
39     private String JavaDoc branch;
40     private String JavaDoc accessList;
41     private String JavaDoc keywordSubstitution;
42     private String JavaDoc totalRevisions;
43     private String JavaDoc selectedRevisions;
44     private String JavaDoc description;
45     private String JavaDoc locks;
46     private final List revisions = new ArrayList();
47     private final List symbolicNames = new ArrayList();
48
49     public LogInformation() {
50     }
51
52     /** Getter for property file.
53      * @return Value of property file.
54      */

55     public File getFile() {
56         return file;
57     }
58
59     /** Setter for property file.
60      * @param file New value of property file.
61      */

62     public void setFile(File file) {
63         this.file = file;
64     }
65
66     /** Getter for property repositoryFilename.
67      * @return Value of property repositoryFilename.
68      */

69     public String JavaDoc getRepositoryFilename() {
70         return repositoryFilename;
71     }
72
73     /** Setter for property repositoryFilename.
74      * @param repositoryFilename New value of property repositoryFilename.
75      */

76     public void setRepositoryFilename(String JavaDoc repositoryFilename) {
77         this.repositoryFilename = repositoryFilename;
78     }
79
80     /** Getter for property headRevision.
81      * @return Value of property headRevision.
82      */

83     public String JavaDoc getHeadRevision() {
84         return headRevision;
85     }
86
87     /** Setter for property headRevision.
88      * @param headRevision New value of property headRevision.
89      */

90     public void setHeadRevision(String JavaDoc headRevision) {
91         this.headRevision = headRevision;
92     }
93
94     /** Getter for property branch.
95      * @return Value of property branch.
96      */

97     public String JavaDoc getBranch() {
98         return branch;
99     }
100
101     /** Setter for property branch.
102      * @param branch New value of property branch.
103      */

104     public void setBranch(String JavaDoc branch) {
105         this.branch = branch;
106     }
107
108     /** Getter for property accessList.
109      * @return Value of property accessList.
110      */

111     public String JavaDoc getAccessList() {
112         return accessList;
113     }
114
115     /** Setter for property accessList.
116      * @param accessList New value of property accessList.
117      */

118     public void setAccessList(String JavaDoc accessList) {
119         this.accessList = accessList;
120     }
121
122     /** Getter for property keywordSubstitution.
123      * @return Value of property keywordSubstitution.
124      */

125     public String JavaDoc getKeywordSubstitution() {
126         return keywordSubstitution;
127     }
128
129     /** Setter for property keywordSubstitution.
130      * @param keywordSubstitution New value of property keywordSubstitution.
131      */

132     public void setKeywordSubstitution(String JavaDoc keywordSubstitution) {
133         this.keywordSubstitution = keywordSubstitution;
134     }
135
136     /** Getter for property totalRevisions.
137      * @return Value of property totalRevisions.
138      */

139     public String JavaDoc getTotalRevisions() {
140         return totalRevisions;
141     }
142
143     /** Setter for property totalRevisions.
144      * @param totalRevisions New value of property totalRevisions.
145      */

146     public void setTotalRevisions(String JavaDoc totalRevisions) {
147         this.totalRevisions = totalRevisions;
148     }
149
150     /** Getter for property selectedRevisions.
151      * @return Value of property selectedRevisions.
152      */

153     public String JavaDoc getSelectedRevisions() {
154         return selectedRevisions;
155     }
156
157     /** Setter for property selectedRevisions.
158      * @param selectedRevisions New value of property selectedRevisions.
159      */

160     public void setSelectedRevisions(String JavaDoc selectedRevisions) {
161         this.selectedRevisions = selectedRevisions;
162     }
163
164     /** Getter for property description.
165      * @return Value of property description.
166      */

167     public String JavaDoc getDescription() {
168         return description;
169     }
170
171     /** Setter for property description.
172      * @param description New value of property description.
173      */

174     public void setDescription(String JavaDoc description) {
175         this.description = description;
176     }
177
178     /** Getter for property locks.
179      * @return Value of property locks.
180      */

181     public String JavaDoc getLocks() {
182         return locks;
183     }
184
185     /** Setter for property locks.
186      * @param locks New value of property locks.
187      */

188     public void setLocks(String JavaDoc locks) {
189         this.locks = locks;
190     }
191
192     /** adds a revision info to the LogInformation instance
193      */

194
195     public void addRevision(LogInformation.Revision newRevision) {
196         revisions.add(newRevision);
197     }
198
199     /** return the all revisions attached to this log
200      * (if more sophisticated method are supplied, this might get obsolete)
201      */

202     public List getRevisionList() {
203         return revisions;
204     }
205
206     /** Search the revisions by number of revision. If not found, return null.
207      */

208     public LogInformation.Revision getRevision(String JavaDoc number) {
209         Iterator it = revisions.iterator();
210         LogInformation.Revision item;
211         while (it.hasNext()) {
212             item = (LogInformation.Revision)it.next();
213             if (item.getNumber().equals(number)) {
214                 return item;
215             }
216         }
217         return null;
218     }
219
220     /**
221      * Add a symbolic name to the list of names and attaches it to a revision number.
222      */

223     public void addSymbolicName(String JavaDoc symName, String JavaDoc revisionNumber) {
224         SymName newName = new SymName();
225         newName.setName(symName);
226         newName.setRevision(revisionNumber);
227         symbolicNames.add(newName);
228     }
229
230     public List getAllSymbolicNames() {
231         return symbolicNames;
232     }
233
234     /** Search the symbolic names by number of revision. If not found, return null.
235      */

236     public List getSymNamesForRevision(String JavaDoc revNumber) {
237         Iterator it = symbolicNames.iterator();
238         LogInformation.SymName item;
239         List list = new LinkedList();
240         while (it.hasNext()) {
241             item = (LogInformation.SymName)it.next();
242             if (item.getRevision().equals(revNumber)) {
243                 list.add(item);
244             }
245         }
246         return list;
247     }
248
249     /** Search the symbolic names by name of tag (symbolic name). If not found, return null.
250      */

251     public LogInformation.SymName getSymName(String JavaDoc symName) {
252         Iterator it = symbolicNames.iterator();
253         LogInformation.SymName item;
254         while (it.hasNext()) {
255             item = (LogInformation.SymName)it.next();
256             if (item.getName().equals(symName)) {
257                 return item;
258             }
259         }
260         return null;
261     }
262
263     public Revision createNewRevision(String JavaDoc number) {
264         Revision rev = new Revision();
265         rev.setNumber(number);
266         return rev;
267     }
268
269     /**
270      * Return a string representation of this object. Useful for debugging.
271      */

272     public String JavaDoc toString() {
273         StringBuffer JavaDoc buf = new StringBuffer JavaDoc(30);
274         buf.append("\nFile: " + ((file != null)?file.getAbsolutePath():"null")); //NOI18N
275
buf.append("\nRepositoryFile: " + repositoryFilename); //NOI18N
276
buf.append("\nHead revision: " + headRevision); //NOI18N
277
return buf.toString();
278     }
279
280     public class SymName {
281         private String JavaDoc name;
282         private String JavaDoc revision;
283
284         public SymName() {
285         }
286
287         public String JavaDoc getName() {
288             return name;
289         }
290
291         public void setName(String JavaDoc symName) {
292             name = symName;
293         }
294
295         public void setRevision(String JavaDoc rev) {
296             revision = rev;
297         }
298
299         public String JavaDoc getRevision() {
300             return revision;
301         }
302
303         /**
304          * Determines if given name represents a branch tag
305          * test is based on revision num parsing and looking
306          * for trailing <tt>0.#</tt> (1.1.0.2, 1.2.4.5.0.6, ,..).
307          */

308         public final boolean isBranch() {
309             boolean branch = false;
310             String JavaDoc[] nums = revision.split("\\.");
311             if (nums.length > 2 && (nums.length % 2) == 0) {
312                 String JavaDoc lastButOne = nums[nums.length -2];
313                 branch = "0".equals(lastButOne); // NOI18N
314
}
315             return branch;
316         }
317     }
318
319     public class Revision {
320
321         /**
322          * The revision number.
323          */

324         private String JavaDoc number;
325         /**
326          * The parsed date.
327          */

328         private Date date;
329         /**
330          * The String representation of the date.
331          */

332         private String JavaDoc dateString;
333         /**
334          * The author of the revision.
335          */

336         private String JavaDoc author;
337         /**
338          * The state.
339          */

340         private String JavaDoc state;
341         /**
342          * The added/removed lines.
343          */

344         private String JavaDoc lines;
345         /**
346          * The commit ID, as generated and reported by some servers.
347          */

348         private String JavaDoc commitID;
349         /**
350          * The commit log-message.
351          */

352         private String JavaDoc message;
353         /**
354          * The branches for this revision.
355          */

356         private String JavaDoc branches;
357
358         public Revision() {
359 /**
360  * Since these have to be initialized when correctly parsing the
361  * command's output, then initializing them to empty strings
362  * is a safety measure against bad parsing errors.
363  * what about backward compatibility here??
364  *
365             state = "";
366             lines = "";
367             message = "";
368             branches = "";
369  */

370         }
371
372         
373         public LogInformation getLogInfoHeader() {
374             return LogInformation.this;
375         }
376         
377         public String JavaDoc getNumber() {
378             return number;
379         }
380
381         public void setNumber(String JavaDoc number) {
382             this.number = number;
383         }
384
385         public Date getDate() {
386             return date;
387         }
388
389         public String JavaDoc getDateString() {
390             return dateString;
391         }
392
393         /**
394          * @deprecated This method uses a static parser to parse dates which is not thread safe, use #setDate instead
395          */

396         public void setDateString(String JavaDoc dateString) {
397             this.dateString = dateString;
398
399             if (dateString == null) {
400                 this.date = null;
401                 return;
402             }
403
404             // Parse the date ...
405
try {
406              // some servers use dashes to separate date components, so replace with slashes
407
// also add a default GMT timezone at the end, if the server already put one in this one will be ignored by the parser
408
dateString = dateString.replace('/', '-') + " +0000";
409              this.date = DATE_FORMAT.parse(dateString);
410             }
411             catch (Exception JavaDoc ex) {
412                 BugLog.getInstance().bug("Couldn't parse date " + dateString);
413             }
414         }
415
416         public void setDate(Date date, String JavaDoc dateString) {
417             this.dateString = dateString;
418             this.date = date;
419         }
420        
421         public String JavaDoc getAuthor() {
422             return author;
423         }
424
425         public void setAuthor(String JavaDoc author) {
426             this.author = author;
427         }
428
429         public String JavaDoc getState() {
430             return state;
431         }
432
433         public void setState(String JavaDoc state) {
434             this.state = state;
435         }
436
437         public String JavaDoc getLines() {
438             return lines;
439         }
440
441         public void setLines(String JavaDoc lines) {
442             this.lines = lines;
443         }
444         
445         public String JavaDoc getCommitID() {
446                return commitID;
447         }
448         
449         public void setCommitID(String JavaDoc commitID) {
450                this.commitID = commitID;
451           }
452         /**
453          * Returns how many lines were added in this revision.
454          */

455         public int getAddedLines() {
456             if (lines != null) {
457                 int start = lines.indexOf('+');
458                 int end = lines.indexOf(' ');
459                 if (start >= 0 && end > start) {
460                     String JavaDoc added = lines.substring(start + 1, end);
461                     try {
462                         int toReturn = Integer.parseInt(added);
463                         return toReturn;
464                     } catch (NumberFormatException JavaDoc exc) {
465                         //TODO BUGLog..
466
}
467                 }
468             }
469             return 0;
470         }
471         
472         public int getRemovedLines() {
473             if (lines != null) {
474                 int start = lines.indexOf('-');
475                 if (start >= 0) {
476                     String JavaDoc removed = lines.substring(start + 1);
477                     try {
478                         int toReturn = Integer.parseInt(removed);
479                         return toReturn;
480                     } catch (NumberFormatException JavaDoc exc) {
481                         //TODO BUGLog..
482
}
483                 }
484             }
485             return 0;
486             
487         }
488
489         public String JavaDoc getMessage() {
490             return message;
491         }
492
493         public void setMessage(String JavaDoc message) {
494             this.message = message;
495         }
496
497         public String JavaDoc getBranches() {
498             return branches;
499         }
500
501         public void setBranches(String JavaDoc branches) {
502             this.branches = branches;
503         }
504     }
505 }
506
Popular Tags