KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > jftp > system > CommandLine


1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15  */

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 JavaDoc, 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 JavaDoc(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 JavaDoc 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)); // make the quit command spawn this event?
70
}
71
72     public static void main(String JavaDoc[] argv)
73     {
74         CommandLine ftp = new CommandLine();
75     }
76 }
77
Popular Tags