1 18 package net.sf.drftpd.master.command.plugins; 19 20 import java.io.BufferedReader ; 21 import java.io.FileInputStream ; 22 import java.io.FileNotFoundException ; 23 import java.io.IOException ; 24 import java.io.InputStreamReader ; 25 26 import net.sf.drftpd.master.BaseFtpConnection; 27 import net.sf.drftpd.master.FtpReply; 28 import net.sf.drftpd.master.command.CommandManager; 29 import net.sf.drftpd.master.command.CommandManagerFactory; 30 31 import org.drftpd.commands.CommandHandler; 32 import org.drftpd.commands.CommandHandlerFactory; 33 import org.drftpd.commands.UnhandledCommandException; 34 import org.tanesha.replacer.FormatterException; 35 import org.tanesha.replacer.ReplacerEnvironment; 36 import org.tanesha.replacer.SimplePrintf; 37 38 import f00f.net.irc.martyr.IRCConnection; 39 import f00f.net.irc.martyr.commands.MessageCommand; 40 41 45 public class Textoutput implements CommandHandlerFactory, CommandHandler { 46 47 public static void addTextToResponse(FtpReply reply, String file) 48 throws FileNotFoundException , IOException { 49 reply.addComment( 50 new BufferedReader ( 51 new InputStreamReader ( 52 new FileInputStream ("text/" + file + ".txt"), 53 "ISO-8859-1"))); 54 } 55 protected static void sendTextToIRC( 56 IRCConnection conn, 57 String destination, 58 BufferedReader in) 59 throws IOException { 60 String line; 61 while ((line = in.readLine()) != null) { 62 ReplacerEnvironment env = new ReplacerEnvironment(); 63 try { 64 conn.sendCommand( 65 new MessageCommand( 66 destination, 67 SimplePrintf.jprintf(line, env))); 68 } catch (FormatterException e1) { 69 conn.sendCommand( 70 new MessageCommand( 71 destination, 72 "Error in formatting of line - " + line)); 73 } 74 } 75 } 76 77 public static void sendTextToIRC( 78 IRCConnection conn, 79 String destination, 80 String file) { 81 BufferedReader fileReader = null; 82 try { 83 fileReader = 84 new BufferedReader ( 85 new InputStreamReader ( 86 new FileInputStream ("text/" + file + ".txt"))); 87 sendTextToIRC(conn, destination, fileReader); 88 } catch (IOException e) { 89 conn.sendCommand( 90 new MessageCommand( 91 destination, 92 "IOException opening text/" + file + ".txt")); 93 return; 94 } 95 } 96 97 public FtpReply execute(BaseFtpConnection conn) 98 throws UnhandledCommandException { 99 100 if (conn.getRequest().hasArgument()) { 101 return FtpReply.RESPONSE_501_SYNTAX_ERROR; 102 } 103 104 try { 105 FtpReply reply = new FtpReply(200); 106 addTextToResponse( 107 reply, 108 conn 109 .getRequest() 110 .getCommand() 111 .substring("SITE ".length()) 112 .toLowerCase()); 113 return reply; 114 } catch (IOException e) { 115 return new FtpReply(200, "IO Error: " + e.getMessage()); 116 } 117 } 118 119 public String [] getFeatReplies() { 120 return null; 121 } 122 public CommandHandler initialize( 123 BaseFtpConnection conn, 124 CommandManager initializer) { 125 return this; 126 } 127 public void load(CommandManagerFactory initializer) { 128 } 129 public void unload() { 130 } 131 } 132 | Popular Tags |