1 package com.coldcore.coloradoftp.command.impl.ftp; 2 3 import com.coldcore.coloradoftp.command.impl.AbstractCommand; 4 import com.coldcore.coloradoftp.command.Reply; 5 import com.coldcore.coloradoftp.command.CommandFactory; 6 import com.coldcore.coloradoftp.command.Command; 7 import com.coldcore.coloradoftp.factory.ObjectFactory; 8 import com.coldcore.coloradoftp.factory.ObjectName; 9 import org.apache.log4j.Logger; 10 11 import java.util.List ; 12 import java.util.ArrayList ; 13 import java.util.Collections ; 14 import java.util.Comparator ; 15 16 22 public class OptsCommand extends AbstractCommand { 23 24 private static Logger log = Logger.getLogger(OptsCommand.class); 25 26 27 public Reply execute() { 28 Reply reply = getReply(); 29 30 String pcmd = getParameter().toUpperCase(); 31 if (pcmd.equals("")) { 32 reply.setCode("501"); 33 reply.setText("Send another command as parameter."); 34 return reply; 35 } 36 37 CommandFactory commandFactory = (CommandFactory) ObjectFactory.getObject(ObjectName.COMMAND_FACTORY); 39 List <String > commandNames = new ArrayList <String >(commandFactory.listNames()); 40 41 String tpcmd = pcmd; 42 int ind = tpcmd.indexOf(" "); 43 if (ind != -1) tpcmd = tpcmd.substring(0, ind); 44 45 if (commandNames.contains(tpcmd)) { 46 log.debug("Command "+tpcmd+" is supported"); 48 replyOnExistingCommand(pcmd); 49 return reply; 50 } else { 51 log.debug("Command "+tpcmd+" is not supported"); 53 replyOnUnexistingCommand(pcmd); 54 return reply; 55 } 56 57 } 58 59 60 63 protected void replyOnExistingCommand(String command) { 64 CommandFactory commandFactory = (CommandFactory) ObjectFactory.getObject(ObjectName.COMMAND_FACTORY); 66 Command cmd = commandFactory.create(command+"\r\n"); 67 cmd.setConnection(getConnection()); 68 69 Reply reply = getReply(); 70 71 Reply rpl = cmd.executeOnParent(this); 73 if (rpl != null) { 74 reply.setCode(rpl.getCode()); 76 reply.setText(rpl.getText()); 77 } else { 78 reply.setCode("504"); 80 reply.setText("Command not implemented for that parameter."); 81 } 82 } 83 84 85 88 protected void replyOnUnexistingCommand(String command) { 89 Reply reply = getReply(); 90 reply.setCode("504"); 91 reply.setText("Command not implemented for that parameter."); 92 } 93 94 } 95 | Popular Tags |