All pastes #368968 Raw Edit

Miscellany

public text v1 · immutable
#368968 ·published 2007-02-23 14:06 UTC
rendered paste body
public CommandResponse doSITE_HELP(CommandRequest request) {
  BaseFtpConnection conn = request.getConnection();
  Map handlers = conn.getCommandManager().getCommandHandlersMap();
  Hashtable<String,String> cmds = FtpConfig.getFtpConfig().getFtpCommands();
  if (request.hasArgument()) {
    String cmd = request.getArgument().toLowerCase();
    for (String ftpCMD : cmds.keySet()) {
      if (ftpCMD.contains("SITE " + cmd.toUpperCase())) {
        Object[] objs = (Object[]) handlers.get(cmds.get(ftpCMD));
        CommandInterface hnd = (CommandInterface) objs[1];
        if (!conn.getGlobalContext().getConfig().checkPathPermission(cmd, conn.getUserNull(), conn.getCurrentDirectory(), true)) {
          return new CommandResponse(501, "You do not have permissions for that command");
        }
        try {
          CommandResponse response = StandardCommandManager.genericResponse("RESPONSE_200_COMMAND_OK");
          response.addComment(ResourceBundle.getBundle(hnd.getClass().getName()).getString("help." + cmd + ".specific"));
          return response;
        } catch (MissingResourceException e) {
          //logger.info(cmd + " in " + hnd.getClass().getName() + " does not have any specific help, bug your siteop", e);
          return new CommandResponse(501, cmd + " in " + hnd.getClass().getName() + " does not have any specific help, bug your siteop");
        }
      }
    }
    return new CommandResponse(501, "The " + cmd + " command does not exist.");
  }
  // global list of commands with help
  HashMap<String, String> helpInfo = new HashMap<String, String>();
  String pad = "            ";
  for (String cmd : cmds.keySet()) {
    Object[] objs = (Object[]) handlers.get(cmds.get(cmd));
    CommandInterface hnd = (CommandInterface) objs[1];
    try {
      cmd = cmd.substring("SITE ".length()).toLowerCase();
      if (!conn.getGlobalContext().getConfig().checkPathPermission(cmd, conn.getUserNull(), conn.getCurrentDirectory(), true)) {
        continue;
      }
      try {
        String help = ResourceBundle.getBundle(hnd.getClass().getName()).getString("help." + cmd);
        helpInfo.put(cmd, pad.substring(cmd.length()) + cmd.toUpperCase() + " : " + help);
      } catch (MissingResourceException e) {
        helpInfo.put(cmd, cmd + " in " + hnd.getClass().getName() + " does not have any help, bug your siteop!");
      }
    } catch (StringIndexOutOfBoundsException e) {
    }
  }
  ArrayList<String> sortedList = new ArrayList<String>(helpInfo.keySet());
  Collections.sort(sortedList);
  CommandResponse response = StandardCommandManager.genericResponse("RESPONSE_200_COMMAND_OK");
  try {
    response.addComment(ResourceBundle.getBundle(Misc.class.getName()).getString("help.header"));
  } catch (MissingResourceException e) {
    response.addComment("Help has no header");
  }
  for (Iterator i = sortedList.iterator(); i.hasNext();) {
    response.addComment(helpInfo.get(i.next()));
  }
  try {
    response.addComment(ResourceBundle.getBundle(Misc.class.getName()).getString("help.footer"));
  } catch (MissingResourceException e) {
    response.addComment("Help has no footer");
  }
  return response;
}