KickJava   Java API By Example, From Geeks To Geeks.

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


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
24 import org.netbeans.lib.cvsclient.*;
25 import org.netbeans.lib.cvsclient.command.*;
26 import org.netbeans.lib.cvsclient.connection.*;
27 import org.netbeans.lib.cvsclient.event.*;
28 import org.netbeans.lib.cvsclient.request.*;
29
30 /**
31  * The rlog command is similar to log, but doens't operate on currently checked
32  * out sources.
33  *
34  * @author MIlos Kleint
35  */

36 public class RlogCommand extends BasicCommand {
37
38
39     /**
40      * The modules to rlog.
41      */

42     private final List modules = new LinkedList();
43
44     /**
45      * Holds value of property defaultBranch.
46      */

47     private boolean defaultBranch;
48
49     /**
50      * Holds value of property dateFilter.
51      */

52     private String JavaDoc dateFilter;
53
54     /**
55      * Holds value of property headerOnly.
56      */

57     private boolean headerOnly;
58
59     /**
60       * Holds value of property suppressHeader.
61       */

62     private boolean suppressHeader;
63
64     /**
65      * Holds value of property noTags.
66      */

67     private boolean noTags;
68
69     /**
70      * Holds value of property revisionFilter.
71      */

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

77     private String JavaDoc stateFilter;
78
79     /**
80      * Holds value of property userFilter.
81      */

82     private String JavaDoc userFilter;
83
84     /**
85      * Holds value of property headerAndDescOnly.
86      */

87     private boolean headerAndDescOnly;
88
89     public RlogCommand() {
90         resetCVSCommand();
91     }
92
93     /**
94      * Set the modules to export.
95      * @param theModules the names of the modules to export
96      */

97     public void setModule(String JavaDoc module) {
98         modules.add(module);
99     }
100
101     /**
102      * clears the list of modules for export.
103      */

104
105     public void clearModules() {
106         this.modules.clear();
107     }
108
109     /**
110      * Set the modules to export.
111      * @param theModules the names of the modules to export
112      */

113     public void setModules(String JavaDoc[] modules) {
114         clearModules();
115         if (modules == null) {
116             return;
117         }
118         for (int i = 0; i < modules.length; i++) {
119             String JavaDoc module = modules[i];
120             this.modules.add(module);
121         }
122     }
123
124     public String JavaDoc[] getModules() {
125         String JavaDoc[] mods = new String JavaDoc[modules.size()];
126         mods = (String JavaDoc[])modules.toArray(mods);
127         return mods;
128     }
129
130     /**
131      * Getter for property defaultBranch, equals the command-line CVS switch
132      * "-b".
133      * @return Value of property defaultBranch.
134      */

135     public boolean isDefaultBranch() {
136         return defaultBranch;
137     }
138
139     /**
140      * Setter for property defaultBranch, equals the command-line CVS switch
141      * "-b".
142      * @param defaultBranch New value of property defaultBranch.
143      */

144     public void setDefaultBranch(boolean defaultBranch) {
145         this.defaultBranch = defaultBranch;
146     }
147
148     /**
149      * Getter for property dateFilter, equals the command-line CVS switch "-d".
150      * @return Value of property dateFilter.
151      */

152     public String JavaDoc getDateFilter() {
153         return dateFilter;
154     }
155
156     /** Setter for property dateFilter, equals the command-line CVS switch "-d".
157      * @param dateFilter New value of property dateFilter.
158      */

159     public void setDateFilter(String JavaDoc dateFilter) {
160         this.dateFilter = dateFilter;
161     }
162
163     /** Getter for property headerOnly, equals the command-line CVS switch "-h".
164      * @return Value of property headerOnly.
165      */

166     public boolean isHeaderOnly() {
167         return headerOnly;
168     }
169
170     /** Setter for property headerOnly, equals the command-line CVS switch "-h".
171      * @param headerOnly New value of property headerOnly.
172      */

173     public void setHeaderOnly(boolean headerOnly) {
174         this.headerOnly = headerOnly;
175     }
176
177     /** Getter for property suppressHeader, equals the command-line CVS switch "-S".
178      * @return Value of property suppressHeader.
179      */

180     public boolean isSuppressHeader() {
181         return suppressHeader;
182     }
183
184     /** Setter for property headerOnly, equals the command-line CVS switch "-S".
185      * @param suppressHeader New value of property suppressHeader.
186      */

187     public void setSuppressHeader(boolean suppressHeader) {
188         this.suppressHeader = suppressHeader;
189     }
190
191     /** Getter for property noTags, equals the command-line CVS switch "-N".
192      * @return Value of property noTags.
193      */

194     public boolean isNoTags() {
195         return noTags;
196     }
197
198     /** Setter for property noTags, equals the command-line CVS switch "-N".
199      * @param noTags New value of property noTags.
200      */

201     public void setNoTags(boolean noTags) {
202         this.noTags = noTags;
203     }
204
205     /** Getter for property revisionFilter, equals the command-line CVS switch "-r".
206      * @return Value of property revisionFilter.
207      */

208     public String JavaDoc getRevisionFilter() {
209         return revisionFilter;
210     }
211
212     /** Setter for property revisionFilter, equals the command-line CVS switch "-r".
213      * @param revisionFilter New value of property revisionFilter.
214      empty string means latest revision of default branch.
215      */

216     public void setRevisionFilter(String JavaDoc revisionFilter) {
217         this.revisionFilter = revisionFilter;
218     }
219
220     /** Getter for property stateFilter, equals the command-line CVS switch "-s".
221      * @return Value of property stateFilter.
222      */

223     public String JavaDoc getStateFilter() {
224         return stateFilter;
225     }
226
227     /** Setter for property stateFilter, equals the command-line CVS switch "-s".
228      * @param stateFilter New value of property stateFilter.
229      */

230     public void setStateFilter(String JavaDoc stateFilter) {
231         this.stateFilter = stateFilter;
232     }
233
234     /** Getter for property userFilter, equals the command-line CVS switch "-w".
235      * @return Value of property userFilter, empty string means the current user.
236      */

237     public String JavaDoc getUserFilter() {
238         return userFilter;
239     }
240
241     /** Setter for property userFilter, equals the command-line CVS switch "-w".
242      * @param userFilter New value of property userFilter.
243      */

244     public void setUserFilter(String JavaDoc userFilter) {
245         this.userFilter = userFilter;
246     }
247
248     /** Getter for property headerAndDescOnly, equals the command-line CVS switch "-t".
249      * @return Value of property headerAndDescOnly.
250      */

251     public boolean isHeaderAndDescOnly() {
252         return headerAndDescOnly;
253     }
254
255     /** Setter for property headerAndDescOnly, equals the command-line CVS switch "-t".
256      * @param headerAndDescOnly New value of property headerAndDescOnly.
257      */

258     public void setHeaderAndDescOnly(boolean headerAndDescOnly) {
259         this.headerAndDescOnly = headerAndDescOnly;
260     }
261     
262
263     /**
264      * Execute this command.
265      * @param client the client services object that provides any necessary
266      * services to this command, including the ability to actually process
267      * all the requests
268      */

269     public void execute(ClientServices client, EventManager em)
270             throws CommandException, AuthenticationException {
271
272         client.ensureConnection();
273         super.execute(client, em);
274
275         //
276
// moved modules code to the end of the other arguments --GAR
277
//
278
if (!isRecursive())
279         {
280             requests.add(new ArgumentRequest("-l")); //NOI18N
281
}
282         // first send out all possible parameters..
283
if (defaultBranch) {
284             requests.add(new ArgumentRequest("-b")); //NOI18N
285
}
286         if (headerAndDescOnly) {
287             requests.add(new ArgumentRequest("-t")); //NOI18N
288
}
289         if (headerOnly) {
290             requests.add(new ArgumentRequest("-h")); //NOI18N
291
}
292         if (suppressHeader) {
293             requests.add(new ArgumentRequest("-S")); //NOI18IN
294
}
295         if (noTags) {
296             requests.add(new ArgumentRequest("-N")); //NOI18N
297
}
298         if (userFilter != null) {
299             requests.add(new ArgumentRequest("-w" + userFilter)); //NOI18N
300
}
301         if (revisionFilter != null) {
302             requests.add(new ArgumentRequest("-r" + revisionFilter)); //NOI18N
303
}
304         if (stateFilter != null) {
305             requests.add(new ArgumentRequest("-s" + stateFilter)); //NOI18N
306
}
307         if (dateFilter != null) {
308             requests.add(new ArgumentRequest("-d" + dateFilter)); //NOI18N
309
}
310
311         for (Iterator it = modules.iterator(); it.hasNext();) {
312             String JavaDoc module = (String JavaDoc)it.next();
313             requests.add(new ArgumentRequest(module));
314         }
315
316         requests.add(CommandRequest.RLOG);
317         try {
318             client.processRequests(requests);
319             requests.clear();
320
321         }
322         catch (CommandException ex) {
323             throw ex;
324         }
325         catch (Exception JavaDoc ex) {
326             throw new CommandException(ex, ex.getLocalizedMessage());
327         }
328     }
329
330     /**
331      * Don't send status of local files prior to executing command, as it's not
332      * needed.
333      */

334     protected boolean assumeLocalPathWhenUnspecified() {
335       return false;
336     }
337     
338     public String JavaDoc getCVSCommand() {
339         StringBuffer JavaDoc toReturn = new StringBuffer JavaDoc("rlog "); //NOI18N
340
toReturn.append(getCVSArguments());
341         if (modules != null && modules.size() > 0) {
342             for (Iterator it = modules.iterator(); it.hasNext();) {
343                 String JavaDoc module = (String JavaDoc)it.next();
344                 toReturn.append(module);
345                 toReturn.append(' ');
346             }
347         }
348         else {
349             String JavaDoc localizedMsg = CommandException.getLocalMessage("ExportCommand.moduleEmpty.text"); //NOI18N
350
toReturn.append(" "); //NOI18N
351
toReturn.append(localizedMsg);
352         }
353         return toReturn.toString();
354     }
355
356     public String JavaDoc getCVSArguments() {
357         StringBuffer JavaDoc toReturn = new StringBuffer JavaDoc(""); //NOI18N
358
if (isDefaultBranch()) {
359             toReturn.append("-b "); //NOI18N
360
}
361         if (isHeaderAndDescOnly()) {
362             toReturn.append("-t "); //NOI18N
363
}
364         if (isHeaderOnly()) {
365             toReturn.append("-h "); //NOI18N
366
}
367         if (isSuppressHeader()) {
368             toReturn.append("-S "); //NOI18N
369
}
370         if (isNoTags()) {
371             toReturn.append("-N "); //NOI18N
372
}
373         if (!isRecursive()) {
374             toReturn.append("-l "); //NOI18N
375
}
376         if (userFilter != null) {
377             toReturn.append("-w"); //NOI18N
378
toReturn.append(userFilter);
379             toReturn.append(' ');
380         }
381         if (revisionFilter != null) {
382             toReturn.append("-r"); //NOI18N
383
toReturn.append(revisionFilter);
384             toReturn.append(' ');
385         }
386         if (stateFilter != null) {
387             toReturn.append("-s"); //NOI18N
388
toReturn.append(stateFilter);
389             toReturn.append(' ');
390         }
391         if (dateFilter != null) {
392             toReturn.append("-d"); //NOI18N
393
toReturn.append(dateFilter);
394             toReturn.append(' ');
395         }
396         return toReturn.toString();
397     }
398
399     public boolean setCVSCommand(char opt, String JavaDoc optArg) {
400         if (opt == 'R') {
401             setRecursive(true);
402         }
403         else if (opt == 'l') {
404             setRecursive(false);
405         }
406         else if (opt == 'b') {
407             setDefaultBranch(true);
408         }
409         else if (opt == 'h') {
410             setHeaderOnly(true);
411         }
412         else if (opt == 't') {
413             setHeaderAndDescOnly(true);
414         }
415         else if (opt == 'S') {
416             setSuppressHeader(true);
417         }
418         else if (opt == 'N') {
419             setNoTags(true);
420         }
421         else if (opt == 'd') {
422             setDateFilter(optArg);
423         }
424         else if (opt == 'r') {
425             setRevisionFilter(optArg == null ? "" : optArg); //NOI18N
426
// for switches with optional args do that.. ^^^^
427
}
428         else if (opt == 's') {
429             setStateFilter(optArg);
430         }
431         else if (opt == 'w') {
432             setUserFilter(optArg == null ? "" : optArg); //NOI18N
433
}
434         else {
435             return false;
436         }
437         return true;
438     }
439
440     public void resetCVSCommand() {
441         setRecursive(true);
442         setDefaultBranch(false);
443         setHeaderOnly(false);
444         setHeaderAndDescOnly(false);
445         setSuppressHeader(false);
446         setNoTags(false);
447         setDateFilter(null);
448         setRevisionFilter(null);
449         setStateFilter(null);
450         setUserFilter(null);
451     }
452
453     /**
454      * String returned by this method defines which options are available for this particular command
455      */

456     public String JavaDoc getOptString() {
457         return "RlbhStNd:r:s:w:"; //NOI18N4
458
}
459
460
461     /**
462      * Create a builder for this command.
463      * @param eventMan the event manager used to receive events.
464      */

465     public Builder createBuilder(EventManager eventMan) {
466         return new LogBuilder(eventMan, this);
467     }
468 }
469
Popular Tags