KickJava   Java API By Example, From Geeks To Geeks.

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


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
23 import org.netbeans.lib.cvsclient.*;
24 import org.netbeans.lib.cvsclient.command.*;
25 import org.netbeans.lib.cvsclient.connection.*;
26 import org.netbeans.lib.cvsclient.event.*;
27 import org.netbeans.lib.cvsclient.request.*;
28
29 /**
30  * The log command looks up the log(history) of file(s) in the repository
31  * @author Milos Kleint
32  */

33 public class LogCommand extends BasicCommand {
34     /**
35      * The event manager to use.
36      */

37     protected EventManager eventManager;
38
39     /**
40      * Holds value of property defaultBranch.
41      */

42     private boolean defaultBranch;
43
44     /**
45      * Holds value of property dateFilter.
46      */

47     private String JavaDoc dateFilter;
48
49     /**
50      * Holds value of property headerOnly.
51      */

52     private boolean headerOnly;
53
54     /**
55      * Holds value of property noTags.
56      */

57     private boolean noTags;
58
59     /**
60      * Holds value of property revisionFilter.
61      */

62     private String JavaDoc revisionFilter;
63
64     /**
65      * Holds value of property stateFilter.
66      */

67     private String JavaDoc stateFilter;
68
69     /**
70      * Holds value of property userFilter.
71      */

72     private String JavaDoc userFilter;
73
74     /**
75      * Holds value of property headerAndDescOnly.
76      */

77     private boolean headerAndDescOnly;
78
79     /**
80      * Construct a new status command
81      */

82     public LogCommand() {
83         resetCVSCommand();
84     }
85
86     /**
87      * Create a builder for this command.
88      * @param eventMan the event manager used to receive events.
89      */

90     public Builder createBuilder(EventManager eventMan) {
91         return new LogBuilder(eventMan, this);
92     }
93
94     /**
95      * Execute a command
96      * @param client the client services object that provides any necessary
97      * services to this command, including the ability to actually process
98      * all the requests.
99      */

100     public void execute(ClientServices client, EventManager em)
101             throws CommandException, AuthenticationException {
102         client.ensureConnection();
103
104         eventManager = em;
105
106         super.execute(client, em);
107
108         try {
109             // first send out all possible parameters..
110
if (defaultBranch) {
111                 requests.add(1, new ArgumentRequest("-b")); //NOI18N
112
}
113             if (headerAndDescOnly) {
114                 requests.add(1, new ArgumentRequest("-t")); //NOI18N
115
}
116             if (headerOnly) {
117                 requests.add(1, new ArgumentRequest("-h")); //NOI18N
118
}
119             if (noTags) {
120                 requests.add(1, new ArgumentRequest("-N")); //NOI18N
121
}
122             if (userFilter != null) {
123                 requests.add(1, new ArgumentRequest("-w" + userFilter)); //NOI18N
124
}
125             if (revisionFilter != null) {
126                 requests.add(1, new ArgumentRequest("-r" + revisionFilter)); //NOI18N
127
}
128             if (stateFilter != null) {
129                 requests.add(1, new ArgumentRequest("-s" + stateFilter)); //NOI18N
130
}
131             if (dateFilter != null) {
132                 requests.add(1, new ArgumentRequest("-d" + dateFilter)); //NOI18N
133
}
134             addRequestForWorkingDirectory(client);
135             addArgumentRequests();
136             addRequest(CommandRequest.LOG);
137
138             client.processRequests(requests);
139         }
140         catch (CommandException ex) {
141             throw ex;
142         }
143         catch (Exception JavaDoc ex) {
144             throw new CommandException(ex, ex.getLocalizedMessage());
145         }
146         finally {
147             requests.clear();
148             if (!isBuilderSet()) {
149                 builder = null;
150             }
151         }
152     }
153
154     /**
155      * called when server responses with "ok" or "error", (when the command
156      * finishes)
157      */

158     public void commandTerminated(TerminationEvent e) {
159         if (builder != null) {
160             builder.outputDone();
161         }
162     }
163
164     /**
165      * Getter for property defaultBranch, equals the command-line CVS switch
166      * "-b".
167      * @return Value of property defaultBranch.
168      */

169     public boolean isDefaultBranch() {
170         return defaultBranch;
171     }
172
173     /**
174      * Setter for property defaultBranch, equals the command-line CVS switch
175      * "-b".
176      * @param defaultBranch New value of property defaultBranch.
177      */

178     public void setDefaultBranch(boolean defaultBranch) {
179         this.defaultBranch = defaultBranch;
180     }
181
182     /**
183      * Getter for property dateFilter, equals the command-line CVS switch "-d".
184      * @return Value of property dateFilter.
185      */

186     public String JavaDoc getDateFilter() {
187         return dateFilter;
188     }
189
190     /** Setter for property dateFilter, equals the command-line CVS switch "-d".
191      * @param dateFilter New value of property dateFilter.
192      */

193     public void setDateFilter(String JavaDoc dateFilter) {
194         this.dateFilter = dateFilter;
195     }
196
197     /** Getter for property headerOnly, equals the command-line CVS switch "-h".
198      * @return Value of property headerOnly.
199      */

200     public boolean isHeaderOnly() {
201         return headerOnly;
202     }
203
204     /** Setter for property headerOnly, equals the command-line CVS switch "-h".
205      * @param headerOnly New value of property headerOnly.
206      */

207     public void setHeaderOnly(boolean headerOnly) {
208         this.headerOnly = headerOnly;
209     }
210
211     /** Getter for property noTags, equals the command-line CVS switch "-N".
212      * @return Value of property noTags.
213      */

214     public boolean isNoTags() {
215         return noTags;
216     }
217
218     /** Setter for property noTags, equals the command-line CVS switch "-N".
219      * @param noTags New value of property noTags.
220      */

221     public void setNoTags(boolean noTags) {
222         this.noTags = noTags;
223     }
224
225     /** Getter for property revisionFilter, equals the command-line CVS switch "-r".
226      * @return Value of property revisionFilter.
227      */

228     public String JavaDoc getRevisionFilter() {
229         return revisionFilter;
230     }
231
232     /** Setter for property revisionFilter, equals the command-line CVS switch "-r".
233      * @param revisionFilter New value of property revisionFilter.
234      empty string means latest revision of default branch.
235      */

236     public void setRevisionFilter(String JavaDoc revisionFilter) {
237         this.revisionFilter = revisionFilter;
238     }
239
240     /** Getter for property stateFilter, equals the command-line CVS switch "-s".
241      * @return Value of property stateFilter.
242      */

243     public String JavaDoc getStateFilter() {
244         return stateFilter;
245     }
246
247     /** Setter for property stateFilter, equals the command-line CVS switch "-s".
248      * @param stateFilter New value of property stateFilter.
249      */

250     public void setStateFilter(String JavaDoc stateFilter) {
251         this.stateFilter = stateFilter;
252     }
253
254     /** Getter for property userFilter, equals the command-line CVS switch "-w".
255      * @return Value of property userFilter, empty string means the current user.
256      */

257     public String JavaDoc getUserFilter() {
258         return userFilter;
259     }
260
261     /** Setter for property userFilter, equals the command-line CVS switch "-w".
262      * @param userFilter New value of property userFilter.
263      */

264     public void setUserFilter(String JavaDoc userFilter) {
265         this.userFilter = userFilter;
266     }
267
268     /** Getter for property headerAndDescOnly, equals the command-line CVS switch "-t".
269      * @return Value of property headerAndDescOnly.
270      */

271     public boolean isHeaderAndDescOnly() {
272         return headerAndDescOnly;
273     }
274
275     /** Setter for property headerAndDescOnly, equals the command-line CVS switch "-t".
276      * @param headerAndDescOnly New value of property headerAndDescOnly.
277      */

278     public void setHeaderAndDescOnly(boolean headerAndDescOnly) {
279         this.headerAndDescOnly = headerAndDescOnly;
280     }
281
282     /** This method returns how the command would looklike when typed on the command line.
283      * Each command is responsible for constructing this information.
284      * @returns <command's name> [<parameters>] files/dirs. Example: checkout -p CvsCommand.java
285      *
286      */

287     public String JavaDoc getCVSCommand() {
288         StringBuffer JavaDoc toReturn = new StringBuffer JavaDoc("log "); //NOI18N
289
toReturn.append(getCVSArguments());
290         File[] files = getFiles();
291         if (files != null) {
292             for (int index = 0; index < files.length; index++) {
293                 toReturn.append(files[index].getName());
294                 toReturn.append(' ');
295             }
296         }
297         return toReturn.toString();
298     }
299
300     /** takes the arguments and sets the command. To be mainly
301      * used for automatic settings (like parsing the .cvsrc file)
302      * @return true if the option (switch) was recognized and set
303      */

304     public boolean setCVSCommand(char opt, String JavaDoc optArg) {
305         if (opt == 'R') {
306             setRecursive(true);
307         }
308         else if (opt == 'l') {
309             setRecursive(false);
310         }
311         else if (opt == 'b') {
312             setDefaultBranch(true);
313         }
314         else if (opt == 'h') {
315             setHeaderOnly(true);
316         }
317         else if (opt == 't') {
318             setHeaderAndDescOnly(true);
319         }
320         else if (opt == 'N') {
321             setNoTags(true);
322         }
323         else if (opt == 'd') {
324             setDateFilter(optArg);
325         }
326         else if (opt == 'r') {
327             setRevisionFilter(optArg == null ? "" : optArg); //NOI18N
328
// for switches with optional args do that.. ^^^^
329
}
330         else if (opt == 's') {
331             setStateFilter(optArg);
332         }
333         else if (opt == 'w') {
334             setUserFilter(optArg == null ? "" : optArg); //NOI18N
335
}
336         else {
337             return false;
338         }
339         return true;
340     }
341
342     public void resetCVSCommand() {
343         setRecursive(true);
344         setDefaultBranch(false);
345         setHeaderOnly(false);
346         setHeaderAndDescOnly(false);
347         setNoTags(false);
348         setDateFilter(null);
349         setRevisionFilter(null);
350         setStateFilter(null);
351         setUserFilter(null);
352     }
353
354     /**
355      * String returned by this method defines which options are available for this particular command
356      */

357     public String JavaDoc getOptString() {
358         return "RlbhtNd:r:s:w:"; //NOI18N4
359
}
360
361     /**
362      * Returns the arguments of the command in the command-line style.
363      * Similar to getCVSCommand() however without the files and command's name
364      */

365     public String JavaDoc getCVSArguments() {
366         StringBuffer JavaDoc toReturn = new StringBuffer JavaDoc(""); //NOI18N
367
if (isDefaultBranch()) {
368             toReturn.append("-b "); //NOI18N
369
}
370         if (isHeaderAndDescOnly()) {
371             toReturn.append("-t "); //NOI18N
372
}
373         if (isHeaderOnly()) {
374             toReturn.append("-h "); //NOI18N
375
}
376         if (isNoTags()) {
377             toReturn.append("-N "); //NOI18N
378
}
379         if (!isRecursive()) {
380             toReturn.append("-l "); //NOI18N
381
}
382         if (userFilter != null) {
383             toReturn.append("-w"); //NOI18N
384
toReturn.append(userFilter);
385             toReturn.append(' ');
386         }
387         if (revisionFilter != null) {
388             toReturn.append("-r"); //NOI18N
389
toReturn.append(revisionFilter);
390             toReturn.append(' ');
391         }
392         if (stateFilter != null) {
393             toReturn.append("-s"); //NOI18N
394
toReturn.append(stateFilter);
395             toReturn.append(' ');
396         }
397         if (dateFilter != null) {
398             toReturn.append("-d"); //NOI18N
399
toReturn.append(dateFilter);
400             toReturn.append(' ');
401         }
402         return toReturn.toString();
403     }
404
405 }
406
Popular Tags