1 23 24 package com.sun.enterprise.cli.commands; 25 26 import com.sun.enterprise.cli.framework.*; 27 28 import java.util.Iterator ; 30 import java.io.Reader ; 31 import java.io.Writer ; 32 import java.io.OutputStreamWriter ; 33 import java.io.IOException ; 34 import java.io.InputStreamReader ; 35 36 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 DEFAULT_HELP_PAGE = "help"; 46 47 48 public HelpCommand() 49 { 50 } 51 52 55 public boolean validateOptions() throws CommandValidationException 56 { 57 return true; 58 } 59 60 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 ioe){ 78 throw new CommandException(ioe); 79 } 80 } 81 82 private String getCommandName(){ 83 return (operands.size() > 0 84 ? (String ) getOperands().get(0) 85 : DEFAULT_HELP_PAGE); 86 } 87 88 private Writer getDestination(){ 89 return new OutputStreamWriter (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 getPrompt(){ 103 return getLocalizedString("ManpagePrompt"); 104 } 105 106 private String getQuitChar(){ 107 return getLocalizedString("ManpageQuit"); 108 } 109 110 private Reader getSource(){ 111 CLIManFileFinder c = new CLIManFileFinder(); 112 return c.getCommandManFile(getCommandName()); 113 } 114 115 116 private Reader getUserInput(){ 117 return new InputStreamReader (System.in); 118 } 119 120 private Writer getUserOutput(){ 121 return new OutputStreamWriter (System.err); 122 } 123 124 } 125 | Popular Tags |