01: /*
02: * This program is free software; you can redistribute it and/or
03: * modify it under the terms of the GNU General Public License
04: * as published by the Free Software Foundation; either version 2
05: * of the License, or (at your option) any later version.
06: *
07: * This program is distributed in the hope that it will be useful,
08: * but WITHOUT ANY WARRANTY; without even the implied warranty of
09: * 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: public class CommandLine implements Runnable, EventHandler,
30: FtpEventConstants {
31: private EventCollector eventCollector;
32:
33: public CommandLine() {
34: Log.setLogger(new SystemLogger());
35: eventCollector = new EventCollector();
36: EventProcessor.addHandler(FTPCommand, new FtpEventHandler());
37: EventProcessor.addHandler(FTPPrompt, this );
38: new Thread(this ).start();
39: }
40:
41: public boolean handle(Event e) {
42: System.out.print("ftp> ");
43:
44: return true;
45: }
46:
47: public void run() {
48: BufferedReader in = new BufferedReader(new InputStreamReader(
49: System.in));
50: String line = null;
51:
52: do {
53: try {
54: eventCollector.accept(new FtpEvent(FTPPrompt));
55: line = in.readLine();
56: eventCollector.accept(new FtpEvent(FTPCommand, line));
57: } catch (IOException e) {
58: }
59: } while (!line.toLowerCase().startsWith("quit"));
60:
61: eventCollector.accept(new FtpEvent(FTPShutdown)); // make the quit command spawn this event?
62: }
63:
64: public static void main(String[] argv) {
65: CommandLine ftp = new CommandLine();
66: }
67: }
|