KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > nbbuild > utils > cvsutils > Entry


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
20 /************************************************************************
21
22         FILENAME: Entry.java
23
24         AUTHOR: Erica Grevemeyer DATE: Jan 7 11:21:09 PST 2002
25
26 ************************************************************************/

27 package org.netbeans.nbbuild.utils.cvsutils;
28
29 import java.util.*;
30
31 /**
32  * This CVS utility class will parse a single line in a
33  * CVS/Entries file.
34  *
35  * @author Erica Grevemeyer
36  * @version 1.1 Jan 7 11:21:09 PST 2002
37  */

38
39 public class Entry {
40     private static final String JavaDoc DEFAULT_SEPARATOR = "/";
41     private String JavaDoc filename, filetype, revno, timestamp;
42
43     // Constructor Methods
44
/** Create an Entry instance when all information is already available.
45     * @param ft - File type. (Value will be either "F" or "D" indicating file or directory).
46     * @param fn - filename listed in the entry
47     * @param revno - latest revision number listedx.
48     * @param ts - the time stamp string. (ex. Sat Dec 22 00:31:24 2001)
49     * This may have additional information if the file is not up to date.
50     */

51     public Entry(String JavaDoc ft, String JavaDoc fn, String JavaDoc revno, String JavaDoc ts) {
52         setFiletype(ft);
53         setFilename(fn);
54         setRevno(revno);
55         setTimestamp(ts);
56     }
57
58     /**
59     * @param line - line from the read in file.
60     * @param separator - separator used in this file. CVS generated files will use "/"
61     */

62     public Entry(String JavaDoc line, String JavaDoc separator) {
63     /*
64         We use the separator here instead of always
65         defaulting to CVS's "/" so that we can use
66         this class to parse files which are
67         organized the same way, but don't use the '/'.
68
69     */

70         StringTokenizer st = new StringTokenizer(line, separator);
71
72         int index = 0;
73         String JavaDoc[] item=new String JavaDoc[6];
74
75         while (st.hasMoreTokens()) {
76             String JavaDoc ftstr = "";
77             String JavaDoc tok = st.nextToken();
78             
79             // Typical CVS/Entries file lines:
80
// D/dirname////
81
// /filename/1.3/Sat Dec 22 00:31:24 2001//
82

83             if (index == 0 ) {
84                 if ( ! tok.equals("D") ) {
85                     item[index++]="F";
86                 }
87             }
88             item[index++]=tok;
89             //item[0] = filetype
90
//item[1] = filename
91
//item[2] = revno
92
//item[3] = timestamp
93
//item[4] = other
94
//item[5] = other1
95

96         } //while more tokens
97
this.setFiletype(item[0]);
98         this.setFilename(item[1]);
99         this.setRevno(item[2]);
100         this.setTimestamp(item[3]);
101         
102     }
103         
104     public Entry(String JavaDoc line) {
105         this(line, DEFAULT_SEPARATOR);
106     }
107     
108     public boolean hasName(String JavaDoc queryFilename) {
109         return this.getFilename().trim().equals(queryFilename.trim());
110     }
111
112     //Display Methods
113
public String JavaDoc toString() {
114         String JavaDoc fn, ft, revno, ts;
115
116         fn=this.getFilename();
117         ft=this.getFiletype();
118         revno=this.getRevno();
119         ts=this.getTimestamp();
120
121         String JavaDoc fullEntry="FileName:\t"
122             +fn+"\nFileType:\t"+ft +"\nRevno:\t"+revno
123             +"\nTimeStamp:\t" +ts+"\n";
124         return fullEntry;
125     }
126
127     // Accessor Methods
128
public void setFilename(String JavaDoc str) {
129         this.filename=str;
130     }
131
132     public String JavaDoc getFilename() {
133         return filename;
134     }
135
136     public void setFiletype(String JavaDoc str) {
137         this.filetype=str;
138     }
139
140     public String JavaDoc getFiletype() {
141         return filetype;
142     }
143
144     public void setRevno(String JavaDoc str) {
145         this.revno=str;
146     }
147
148     public String JavaDoc getRevno() {
149         return revno;
150     }
151
152     public void setTimestamp(String JavaDoc str) {
153         this.timestamp=str;
154     }
155
156     public String JavaDoc getTimestamp() {
157         return timestamp;
158     }
159     
160 }
161
Popular Tags