KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > cli > commands > HelpCommand


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.cli.commands;
25
26 import com.sun.enterprise.cli.framework.*;
27
28 //jdk
29
import java.util.Iterator JavaDoc;
30 import java.io.Reader JavaDoc;
31 import java.io.Writer JavaDoc;
32 import java.io.OutputStreamWriter JavaDoc;
33 import java.io.IOException JavaDoc;
34 import java.io.InputStreamReader JavaDoc;
35
36 /**
37  * The help command will display the help text for all the commands and their
38  * options
39  */

40 public class HelpCommand extends Command
41 {
42
43   private static final int DEFAULT_PAGE_LENGTH = 50;
44   private static final int NO_PAGE_LENGTH = -1;
45   private static final String JavaDoc DEFAULT_HELP_PAGE = "help";
46
47         /** Creates new HelpCommand */
48   public HelpCommand()
49   {
50   }
51
52         /**
53          * override abstract method validateOptions()
54          */

55     public boolean validateOptions() throws CommandValidationException
56     {
57         return true;
58     }
59     
60       /**
61        * Executes the command
62        * @throws CommandException
63        */

64   public void runCommand() throws CommandException, CommandValidationException
65   {
66
67     try {
68       
69     final More m = new More(getPageLength(),
70                             getSource(),
71                             getDestination(),
72                             getUserInput(),
73                             getUserOutput(),
74                             getQuitChar(),
75                             getPrompt());
76     }
77     catch (IOException JavaDoc ioe){
78       throw new CommandException(ioe);
79     }
80   }
81
82   private String JavaDoc getCommandName(){
83     return (operands.size() > 0
84             ? (String JavaDoc) getOperands().get(0)
85             : DEFAULT_HELP_PAGE);
86   }
87
88   private Writer JavaDoc getDestination(){
89     return new OutputStreamWriter JavaDoc(System.out);
90   }
91
92   private int getPageLength(){
93       if ((getOption("isMultiMode")!=null &&
94           getBooleanOption("isMultiMode")) &&
95           (getOption("interactive")!=null &&
96            getBooleanOption("interactive")) )
97           return DEFAULT_PAGE_LENGTH;
98       else
99           return NO_PAGE_LENGTH;
100   }
101
102   private String JavaDoc getPrompt(){
103       return getLocalizedString("ManpagePrompt");
104   }
105   
106   private String JavaDoc getQuitChar(){
107       return getLocalizedString("ManpageQuit");
108   }
109
110   private Reader JavaDoc getSource(){
111     CLIManFileFinder c = new CLIManFileFinder();
112     return c.getCommandManFile(getCommandName());
113   }
114
115   
116   private Reader JavaDoc getUserInput(){
117     return new InputStreamReader JavaDoc(System.in);
118   }
119
120   private Writer JavaDoc getUserOutput(){
121     return new OutputStreamWriter JavaDoc(System.err);
122   }
123
124 }
125
Popular Tags