1 16 package net.sf.jftp.system; 17 18 import net.sf.jftp.config.Settings; 19 import net.sf.jftp.event.*; 20 import net.sf.jftp.net.*; 21 import net.sf.jftp.system.logging.Log; 22 import net.sf.jftp.system.logging.SystemLogger; 23 import net.sf.jftp.util.*; 24 25 import java.io.*; 26 27 import java.net.*; 28 29 30 public class CommandLine implements Runnable , EventHandler, FtpEventConstants 31 { 32 private EventCollector eventCollector; 33 34 public CommandLine() 35 { 36 Log.setLogger(new SystemLogger()); 37 eventCollector = new EventCollector(); 38 EventProcessor.addHandler(FTPCommand, new FtpEventHandler()); 39 EventProcessor.addHandler(FTPPrompt, this); 40 new Thread (this).start(); 41 } 42 43 public boolean handle(Event e) 44 { 45 System.out.print("ftp> "); 46 47 return true; 48 } 49 50 public void run() 51 { 52 BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); 53 String line = null; 54 55 do 56 { 57 try 58 { 59 eventCollector.accept(new FtpEvent(FTPPrompt)); 60 line = in.readLine(); 61 eventCollector.accept(new FtpEvent(FTPCommand, line)); 62 } 63 catch(IOException e) 64 { 65 } 66 } 67 while(!line.toLowerCase().startsWith("quit")); 68 69 eventCollector.accept(new FtpEvent(FTPShutdown)); } 71 72 public static void main(String [] argv) 73 { 74 CommandLine ftp = new CommandLine(); 75 } 76 } 77 | Popular Tags |