1 88 89 package org.openejb.server.telnet; 90 91 92 93 import java.io.DataInputStream ; 94 95 import java.io.IOException ; 96 97 import java.io.InputStream ; 98 99 import java.io.PrintStream ; 100 101 import java.util.Properties ; 102 103 import java.util.StringTokenizer ; 104 105 import java.util.Vector ; 106 107 108 109 import org.openejb.util.Logger; 110 111 112 113 118 119 public class TextConsole { 120 121 122 123 Logger logger = Logger.getInstance( "OpenEJB.admin", "org.openejb.server.util.resources" ); 124 125 126 127 Properties props; 128 129 130 131 public TextConsole() { 132 133 } 134 135 136 137 public void init( Properties props ) throws Exception { 138 139 this.props = props; 140 141 } 142 143 144 145 boolean stop = false; 146 147 148 149 DataInputStream in = null; 150 151 PrintStream out = null; 152 153 154 155 public static final char ESC = ( char ) 27; 156 157 158 159 public static final String TTY_Reset = ESC + "[0m"; 160 161 public static final String TTY_Bright = ESC + "[1m"; 162 163 public static final String TTY_Dim = ESC + "[2m"; 164 165 public static final String TTY_Underscore = ESC + "[4m"; 166 167 public static final String TTY_Blink = ESC + "[5m"; 168 169 public static final String TTY_Reverse = ESC + "[7m"; 170 171 public static final String TTY_Hidden = ESC + "[8m"; 172 173 174 175 176 177 public static final String TTY_FG_Black = ESC + "[30m"; 178 179 public static final String TTY_FG_Red = ESC + "[31m"; 180 181 public static final String TTY_FG_Green = ESC + "[32m"; 182 183 public static final String TTY_FG_Yellow = ESC + "[33m"; 184 185 public static final String TTY_FG_Blue = ESC + "[34m"; 186 187 public static final String TTY_FG_Magenta = ESC + "[35m"; 188 189 public static final String TTY_FG_Cyan = ESC + "[36m"; 190 191 public static final String TTY_FG_White = ESC + "[37m"; 192 193 194 195 196 197 public static final String TTY_BG_Black = ESC + "[40m"; 198 199 public static final String TTY_BG_Red = ESC + "[41m"; 200 201 public static final String TTY_BG_Green = ESC + "[42m"; 202 203 public static final String TTY_BG_Yellow = ESC + "[43m"; 204 205 public static final String TTY_BG_Blue = ESC + "[44m"; 206 207 public static final String TTY_BG_Magenta = ESC + "[45m"; 208 209 public static final String TTY_BG_Cyan = ESC + "[46m"; 210 211 public static final String TTY_BG_White = ESC + "[47m"; 212 213 214 215 static String PROMPT = TTY_Reset + TTY_Bright + "[openejb]$ " + TTY_Reset; 216 217 218 219 protected void exec( InputStream input, PrintStream out ) { 220 221 DataInputStream in = new DataInputStream (input); 222 223 while (!stop) { 224 225 prompt(in,out); 226 227 } 228 229 230 231 } 232 233 234 235 protected void prompt( DataInputStream in, PrintStream out ) { 236 237 238 239 try { 240 241 out.print( PROMPT ); 242 243 out.flush(); 244 245 246 247 String commandline = in.readLine(); 248 249 logger.debug( "command: " + commandline ); 250 251 commandline = commandline.trim(); 252 253 254 255 if ( commandline.length() < 1 ) return; 256 257 258 259 String command = commandline; 260 261 Command.Arguments args = null; 262 263 264 265 int spacePosition = commandline.indexOf( ' ' ); 266 267 int tabPosition = commandline.indexOf( '\t' ); 268 269 if ( spacePosition != -1 || tabPosition != -1 ) { 270 271 int cutPosition = ( spacePosition > tabPosition ? spacePosition : tabPosition ); 272 273 command = commandline.substring( 0, cutPosition ); 274 275 args = new Command.Arguments( commandline.substring( cutPosition + 1 ) ); 276 277 } 278 279 280 281 Command cmd = Command.getCommand( command ); 282 283 284 285 if ( cmd == null ) { 286 287 out.print( command ); 288 289 out.println( ": command not found" ); 290 291 } else { 292 293 cmd.exec( args, in, out ); 294 295 } 296 297 } catch ( UnsupportedOperationException e ) { 298 299 this.stop = true; 300 301 } catch ( Throwable e ) { 302 303 e.printStackTrace( new PrintStream ( out ) ); 304 305 307 this.stop = true; 308 309 } 310 311 } 312 313 314 315 protected void badCommand( DataInputStream in, PrintStream out ) throws IOException 316 317 { 318 319 321 } 322 323 } 324 325 326 | Popular Tags |