KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > lib > cvsclient > command > history > HistoryCommand


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.history;
20
21 import java.util.*;
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 history command provides information history of activities in repository.
31  * @author Milos Kleint
32  */

33 public class HistoryCommand extends Command {
34     /**
35      * The requests that are sent and processed.
36      */

37     private final List requests = new LinkedList();
38
39     /**
40      * The event manager to use
41      */

42     private EventManager eventManager;
43
44     /** Holds value of property forAllUsers. */
45     private boolean forAllUsers;
46
47     /** Holds value of property goBackToRecord. */
48     private String JavaDoc showBackToRecordContaining;
49
50     /** Holds value of property reportCommits. */
51     private boolean reportCommits;
52
53     /** Holds value of property sinceDate. */
54     private String JavaDoc sinceDate;
55
56     /** Holds value of property reportEverything. */
57     private boolean reportEverything;
58
59     /** Holds value of property lastEventOfProject. */
60     private boolean lastEventOfProject;
61
62     /** Holds value of property reportCheckout. */
63     private boolean reportCheckouts;
64
65     /** Holds value of property sinceRevision. */
66     private String JavaDoc sinceRevision;
67
68     /** Holds value of property reportTags. */
69     private boolean reportTags;
70
71     /** Holds value of property sinceTag. */
72     private String JavaDoc sinceTag;
73
74     /** Holds value of property forWorkingDirectory. */
75     private boolean forWorkingDirectory;
76
77     /** Holds value of property reportEventType. */
78     private String JavaDoc reportEventType;
79
80     /** Holds value of property timeZone. */
81     private String JavaDoc timeZone;
82
83     /** Holds value of property lastEventForFile. */
84     private String JavaDoc[] lastEventForFile;
85
86     /** Holds value of property reportOnModule. */
87     private String JavaDoc[] reportOnModule;
88
89     /** Holds value of property reportLastEventForModule. */
90     private String JavaDoc[] reportLastEventForModule;
91
92     /** Holds value of property forUsers. */
93     private String JavaDoc[] forUsers;
94
95     /**
96      * Construct a new history command
97      */

98     public HistoryCommand() {
99     }
100
101     /**
102      * Create a builder for this command.
103      * @param eventMan the event manager used to receive events.
104      */

105     public Builder createBuilder(EventManager eventMan) {
106         return null;
107     }
108
109     /**
110      * Execute a command
111      * @param client the client services object that provides any necessary
112      * services to this command, including the ability to actually process
113      * all the requests.
114      */

115     public void execute(ClientServices client, EventManager em)
116             throws CommandException, AuthenticationException {
117
118         client.ensureConnection();
119
120         eventManager = em;
121         requests.clear();
122
123         super.execute(client, em);
124
125         try {
126             if (client.isFirstCommand()) {
127                 requests.add(new RootRequest(client.getRepository()));
128                 requests.add(new UseUnchangedRequest());
129             }
130
131             addBooleanArgument(requests, isForAllUsers(), "-a"); //NOI18N
132
addBooleanArgument(requests, isForWorkingDirectory(), "-w"); //NOI18N
133
addBooleanArgument(requests, isLastEventOfProject(), "-l"); //NOI18N
134
addBooleanArgument(requests, isReportCheckouts(), "-o"); //NOI18N
135
addBooleanArgument(requests, isReportCommits(), "-c"); //NOI18N
136
addBooleanArgument(requests, isReportEverything(), "-e"); //NOI18N
137
addBooleanArgument(requests, isReportTags(), "-T"); //NOI18N
138
addStringArgument(requests, getReportEventType(), "-x"); //NOI18N
139
addStringArgument(requests, getShowBackToRecordContaining(), "-b"); //NOI18N
140
addStringArgument(requests, getSinceDate(), "-D"); //NOI18N
141
addStringArgument(requests, getSinceRevision(), "-r"); //NOI18N
142
addStringArgument(requests, getSinceTag(), "-t"); //NOI18N
143
addStringArrayArgument(requests, getForUsers(), "-u"); //NOI18N
144
addStringArrayArgument(requests, getReportLastEventForModule(), "-n"); //NOI18N
145
addStringArrayArgument(requests, getReportOnModule(), "-m"); //NOI18N
146
addStringArrayArgument(requests, getLastEventForFile(), "-f"); //NOI18N
147
if (!isReportCheckouts() && !isReportCommits() && !isReportTags() &&
148                     !isReportEverything() && getReportEventType() == null && getReportOnModule() == null) {
149                 // this is the default switch if nothing else is specified.
150
addBooleanArgument(requests, true, "-c"); //NOI18N
151
}
152             if (getTimeZone() != null) {
153                 addStringArgument(requests, getTimeZone(), "-z"); //NOI18N
154
}
155             else {
156                 addStringArgument(requests, "+0000", "-z"); //NOI18N
157
}
158             requests.add(CommandRequest.HISTORY);
159             client.processRequests(requests);
160         }
161         catch (CommandException ex) {
162             throw ex;
163         }
164         catch (Exception JavaDoc ex) {
165             throw new CommandException(ex, ex.getLocalizedMessage());
166         }
167         finally {
168             requests.clear();
169         }
170     }
171
172     private void addStringArgument(List reqList, String JavaDoc property, String JavaDoc cvsSwitch) {
173         if (property != null) {
174             reqList.add(new ArgumentRequest(cvsSwitch));
175             reqList.add(new ArgumentRequest(property));
176         }
177     }
178
179     private void addStringArrayArgument(List reqList, String JavaDoc[] property, String JavaDoc cvsSwitch) {
180         if (property != null) {
181             for (int i = 0; i < property.length; i++) {
182                 reqList.add(new ArgumentRequest(cvsSwitch));
183                 reqList.add(new ArgumentRequest(property[i]));
184             }
185         }
186     }
187
188     private void addBooleanArgument(List reqList, boolean property, String JavaDoc cvsSwitch) {
189         if (property == true) {
190             reqList.add(new ArgumentRequest(cvsSwitch));
191         }
192     }
193
194     /** called when server responses with "ok" or "error", (when the command finishes)
195      */

196     public void commandTerminated(TerminationEvent e) {
197     }
198
199     /** This method returns how the command would looklike when typed on the command line.
200      * Each command is responsible for constructing this information.
201      * @returns <command's name> [<parameters>] files/dirs. Example: checkout -p CvsCommand.java
202      *
203      */

204     public String JavaDoc getCVSCommand() {
205         StringBuffer JavaDoc toReturn = new StringBuffer JavaDoc("history "); //NOI18N
206
toReturn.append(getCVSArguments());
207         return toReturn.toString();
208     }
209
210     /** takes the arguments and sets the command. To be mainly
211      * used for automatic settings (like parsing the .cvsrc file)
212      * @return true if the option (switch) was recognized and set
213      */

214     public boolean setCVSCommand(char opt, String JavaDoc optArg) {
215         if (opt == 'a') {
216             setForAllUsers(true);
217         }
218         else if (opt == 'b') {
219             setShowBackToRecordContaining(optArg);
220         }
221         else if (opt == 'c') {
222             setReportCommits(true);
223         }
224         else if (opt == 'D') {
225             setSinceDate(optArg);
226         }
227         else if (opt == 'e') {
228             setReportEverything(true);
229         }
230         else if (opt == 'l') {
231             setLastEventOfProject(true);
232         }
233         else if (opt == 'o') {
234             setReportCheckouts(true);
235         }
236         else if (opt == 'r') {
237             setSinceRevision(optArg);
238         }
239         else if (opt == 'T') {
240             setReportTags(true);
241         }
242         else if (opt == 't') {
243             setSinceTag(optArg);
244         }
245         else if (opt == 'w') {
246             setForWorkingDirectory(true);
247         }
248         else if (opt == 'x') {
249             setReportEventType(optArg);
250         }
251         else if (opt == 'z') {
252             setTimeZone(optArg);
253         }
254         else if (opt == 'f') {
255             addLastEventForFile(optArg);
256         }
257         else if (opt == 'm') {
258             addReportOnModule(optArg);
259         }
260         else if (opt == 'n') {
261             addReportLastEventForModule(optArg);
262         }
263         else if (opt == 'u') {
264             addForUsers(optArg);
265         }
266         else {
267             return false;
268         }
269         return true;
270     }
271
272     /**
273      * String returned by this method defines which options are available for this particular command
274      */

275     public String JavaDoc getOptString() {
276         return "ab:cD:ef:lm:n:or:Tt:u:wx:z:"; //NOI18N
277
}
278
279     /**
280      * resets all switches in the command. After calling this method,
281      * the command should have no switches defined and should behave defaultly.
282      */

283     public void resetCVSCommand() {
284         setForAllUsers(false);
285         setForUsers(null);
286         setForWorkingDirectory(false);
287         setLastEventForFile(null);
288         setLastEventOfProject(false);
289         setReportCheckouts(false);
290         setReportCommits(false);
291         setReportEventType(null);
292         setReportEverything(false);
293         setReportLastEventForModule(null);
294         setReportOnModule(null);
295         setReportTags(false);
296         setShowBackToRecordContaining(null);
297         setSinceDate(null);
298         setSinceRevision(null);
299         setSinceTag(null);
300         setTimeZone(null);
301     }
302
303     /**
304      * Returns the arguments of the command in the command-line style.
305      * Similar to getCVSCommand() however without the files and command's name
306      */

307     public String JavaDoc getCVSArguments() {
308         StringBuffer JavaDoc toReturn = new StringBuffer JavaDoc(""); //NOI18N
309
if (isForAllUsers()) {
310             toReturn.append("-a "); //NOI18N
311
}
312         if (isForWorkingDirectory()) {
313             toReturn.append("-w "); //NOI18N
314
}
315         if (isLastEventOfProject()) {
316             toReturn.append("-l "); //NOI18N
317
}
318         if (isReportCheckouts()) {
319             toReturn.append("-o "); //NOI18N
320
}
321         if (isReportCommits()) {
322             toReturn.append("-c "); //NOI18N
323
}
324         if (isReportEverything()) {
325             toReturn.append("-e "); //NOI18N
326
}
327         if (isReportTags()) {
328             toReturn.append("-T "); //NOI18N
329
}
330         if (getForUsers() != null) {
331             appendArrayToSwitches(toReturn, getForUsers(), "-u "); //NOI18N
332
}
333         if (getLastEventForFile() != null) {
334             appendArrayToSwitches(toReturn, getLastEventForFile(), "-f "); //NOI18N
335
}
336         if (getReportEventType() != null) {
337             toReturn.append("-x "); //NOI18N
338
toReturn.append(getReportEventType());
339             toReturn.append(" "); //NOI18N
340
}
341         if (getReportLastEventForModule() != null) {
342             appendArrayToSwitches(toReturn, getReportLastEventForModule(), "-n "); //NOI18N
343
}
344         if (getReportOnModule() != null) {
345             appendArrayToSwitches(toReturn, getReportOnModule(), "-m "); //NOI18N
346
}
347         if (getShowBackToRecordContaining() != null) {
348             toReturn.append("-b "); //NOI18N
349
toReturn.append(getShowBackToRecordContaining());
350             toReturn.append(" "); //NOI18N
351
}
352         if (getSinceDate() != null) {
353             toReturn.append("-D "); //NOI18N
354
toReturn.append(getSinceDate());
355             toReturn.append(" "); //NOI18N
356
}
357         if (getSinceRevision() != null) {
358             toReturn.append("-r "); //NOI18N
359
toReturn.append(getSinceRevision());
360             toReturn.append(" "); //NOI18N
361
}
362         if (getSinceTag() != null) {
363             toReturn.append("-t "); //NOI18N
364
toReturn.append(getSinceTag());
365             toReturn.append(" "); //NOI18N
366
}
367         if (getTimeZone() != null) {
368             toReturn.append("-z "); //NOI18N
369
toReturn.append(getTimeZone());
370             toReturn.append(" "); //NOI18N
371
}
372         return toReturn.toString();
373     }
374
375     private void appendArrayToSwitches(StringBuffer JavaDoc buff, String JavaDoc[] arr, String JavaDoc cvsSwitch) {
376         if (arr == null) {
377             return;
378         }
379
380         for (int i = 0; i < arr.length; i++) {
381             buff.append(cvsSwitch);
382             buff.append(arr[i]);
383             buff.append(" "); //NOI18N
384
}
385     }
386
387     /** Getter for property forAllUsers. (cvs switch -a)
388      * @return Value of property forAllUsers.
389      */

390     public boolean isForAllUsers() {
391         return this.forAllUsers;
392     }
393
394     /** Setter for property forAllUsers. (cvs switch -a)
395      * @param forAllUsers New value of property forAllUsers.
396      */

397     public void setForAllUsers(boolean forAllUsers) {
398         this.forAllUsers = forAllUsers;
399     }
400
401     /** Getter for property goBackToRecord. (cvs switch -b)
402      * @return Value of property goBackToRecord.
403      */

404     public String JavaDoc getShowBackToRecordContaining() {
405         return this.showBackToRecordContaining;
406     }
407
408     /** Setter for property goBackToRecord. (cvs switch -b)
409      * @param goBackToRecord New value of property goBackToRecord.
410      */

411     public void setShowBackToRecordContaining(String JavaDoc goBackToRecord) {
412         this.showBackToRecordContaining = goBackToRecord;
413     }
414
415     /** Getter for property reportCommits. (cvs switch -c)
416      * @return Value of property reportCommits.
417      */

418     public boolean isReportCommits() {
419         return this.reportCommits;
420     }
421
422     /** Setter for property reportCommits. (cvs switch -b)
423      * @param reportCommits New value of property reportCommits.
424      */

425     public void setReportCommits(boolean reportCommits) {
426         this.reportCommits = reportCommits;
427     }
428
429     /** Getter for property sinceDate. (cvs switch -D)
430      * @return Value of property sinceDate.
431      */

432     public String JavaDoc getSinceDate() {
433         return this.sinceDate;
434     }
435
436     /** Setter for property sinceDate. (cvs switch -D)
437      * @param sinceDate New value of property sinceDate.
438      */

439     public void setSinceDate(String JavaDoc sinceDate) {
440         this.sinceDate = sinceDate;
441     }
442
443     /** Getter for property reportEverything. (cvs switch -e)
444      * @return Value of property reportEverything.
445      */

446     public boolean isReportEverything() {
447         return this.reportEverything;
448     }
449
450     /** Setter for property reportEverything. (cvs switch -e)
451      * @param reportEverything New value of property reportEverything.
452      */

453     public void setReportEverything(boolean reportEverything) {
454         this.reportEverything = reportEverything;
455     }
456
457     /** Getter for property lastEventOfProject. (cvs switch -l)
458      * @return Value of property lastEventOfProject.
459      */

460     public boolean isLastEventOfProject() {
461         return this.lastEventOfProject;
462     }
463
464     /** Setter for property lastEventOfProject. (cvs switch -l)
465      * @param lastEventOfProject New value of property lastEventOfProject.
466      */

467     public void setLastEventOfProject(boolean lastEventOfProject) {
468         this.lastEventOfProject = lastEventOfProject;
469     }
470
471     /** Getter for property reportCheckout. (cvs switch -o)
472      * @return Value of property reportCheckout.
473      */

474     public boolean isReportCheckouts() {
475         return this.reportCheckouts;
476     }
477
478     /** Setter for property reportCheckout. (cvs switch -o)
479      * @param reportCheckout New value of property reportCheckout.
480      */

481     public void setReportCheckouts(boolean reportCheckout) {
482         this.reportCheckouts = reportCheckout;
483     }
484
485     /** Getter for property sinceRevision. (cvs switch -r)
486      * @return Value of property sinceRevision.
487      */

488     public String JavaDoc getSinceRevision() {
489         return this.sinceRevision;
490     }
491
492     /** Setter for property sinceRevision. (cvs switch -r)
493      * @param sinceRevision New value of property sinceRevision.
494      */

495     public void setSinceRevision(String JavaDoc sinceRevision) {
496         this.sinceRevision = sinceRevision;
497     }
498
499     /** Getter for property reportTags. (cvs switch -T)
500      * @return Value of property reportTags.
501      */

502     public boolean isReportTags() {
503         return this.reportTags;
504     }
505
506     /** Setter for property reportTags. (cvs switch -T)
507      * @param reportTags New value of property reportTags.
508      */

509     public void setReportTags(boolean reportTags) {
510         this.reportTags = reportTags;
511     }
512
513     /** Getter for property sinceTag. (cvs switch -t)
514      * @return Value of property sinceTag.
515      */

516     public String JavaDoc getSinceTag() {
517         return this.sinceTag;
518     }
519
520     /** Setter for property sinceTag. (cvs switch -t)
521      * @param sinceTag New value of property sinceTag.
522      */

523     public void setSinceTag(String JavaDoc sinceTag) {
524         this.sinceTag = sinceTag;
525     }
526
527     /** Getter for property forWorkingDirectory. (cvs switch -w)
528      * @return Value of property forWorkingDirectory.
529      */

530     public boolean isForWorkingDirectory() {
531         return this.forWorkingDirectory;
532     }
533
534     /** Setter for property forWorkingDirectory. (cvs switch -w)
535      * @param forWorkingDirectory New value of property forWorkingDirectory.
536      */

537     public void setForWorkingDirectory(boolean forWorkingDirectory) {
538         this.forWorkingDirectory = forWorkingDirectory;
539     }
540
541     /** Getter for property reportEventType. (cvs switch -x)
542      * @return Value of property reportEventType.
543      */

544     public String JavaDoc getReportEventType() {
545         return this.reportEventType;
546     }
547
548     /** Setter for property reportEventType. (cvs switch -x)
549      * @param reportEventType New value of property reportEventType.
550      */

551     public void setReportEventType(String JavaDoc reportEventType) {
552         this.reportEventType = reportEventType;
553     }
554
555     /** Getter for property timeZone. (cvs switch -z)
556      * @return Value of property timeZone.
557      */

558     public String JavaDoc getTimeZone() {
559         return this.timeZone;
560     }
561
562     /** Setter for property timeZone. (cvs switch -z)
563      * @param timeZone New value of property timeZone.
564      */

565     public void setTimeZone(String JavaDoc timeZone) {
566         this.timeZone = timeZone;
567     }
568
569     /** Getter for property lastEventForFile. (cvs switch -f)
570      * @return Value of property lastEventForFile.
571      */

572     public String JavaDoc[] getLastEventForFile() {
573         return this.lastEventForFile;
574     }
575
576     /** Setter for property lastEventForFile. (cvs switch -f)
577      * @param lastEventForFile New value of property lastEventForFile.
578      */

579     public void setLastEventForFile(String JavaDoc[] lastEventForFile) {
580         this.lastEventForFile = lastEventForFile;
581     }
582
583     public void addLastEventForFile(String JavaDoc newFile) {
584         this.lastEventForFile = addNewValue(this.lastEventForFile, newFile);
585     }
586
587     /** Getter for property reportOnModule. (cvs switch -m)
588      * @return Value of property reportOnModule.
589      */

590     public String JavaDoc[] getReportOnModule() {
591         return this.reportOnModule;
592     }
593
594     /** Setter for property reportOnModule. (cvs switch -m)
595      * @param reportOnModule New value of property reportOnModule.
596      */

597     public void setReportOnModule(String JavaDoc[] reportOnModule) {
598         this.reportOnModule = reportOnModule;
599     }
600
601     public void addReportOnModule(String JavaDoc newReportOnModule) {
602         this.reportOnModule = addNewValue(this.reportOnModule, newReportOnModule);
603     }
604
605     /** Getter for property reportLastEventForModule. (cvs switch -n)
606      * @return Value of property reportLastEventForModule.
607      */

608     public String JavaDoc[] getReportLastEventForModule() {
609         return this.reportLastEventForModule;
610     }
611
612     /** Setter for property reportLastEventForModule. (cvs switch -n)
613      * @param reportLastEventForModule New value of property reportLastEventForModule.
614      */

615     public void setReportLastEventForModule(String JavaDoc[] reportLastEventForModule) {
616         this.reportLastEventForModule = reportLastEventForModule;
617     }
618
619     public void addReportLastEventForModule(String JavaDoc newModule) {
620         this.reportLastEventForModule = addNewValue(this.reportLastEventForModule, newModule);
621     }
622
623     /** Getter for property forUsers. (cvs switch -u)
624      * @return Value of property forUsers.
625      */

626     public String JavaDoc[] getForUsers() {
627         return this.forUsers;
628     }
629
630     /** Setter for property forUsers. (cvs switch -u)
631      * @param forUsers New value of property forUsers.
632      */

633     public void setForUsers(String JavaDoc[] forUsers) {
634         this.forUsers = forUsers;
635     }
636
637     public void addForUsers(String JavaDoc forUser) {
638         this.forUsers = addNewValue(this.forUsers, forUser);
639     }
640
641     private String JavaDoc[] addNewValue(String JavaDoc[] arr, String JavaDoc newVal) {
642         if (arr == null) {
643             arr = new String JavaDoc[]{newVal};
644             return arr;
645         }
646         String JavaDoc[] newValue = new String JavaDoc[arr.length + 1];
647         for (int i = 0; i < arr.length; i++) {
648             newValue[i] = arr[i];
649         }
650         newValue[newValue.length] = newVal;
651         return newValue;
652     }
653 }
654
Popular Tags