HelpCommandHandler.java revision bd576ae311a45a994ae6b457fb2e5bb0ffe0d6b5
1/* 2 * Copyright 2008 the original author or authors. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16package org.mockftpserver.fake.command; 17 18import org.mockftpserver.core.command.Command; 19import org.mockftpserver.core.command.ReplyCodes; 20import org.mockftpserver.core.session.Session; 21import org.mockftpserver.core.util.StringUtil; 22 23import java.util.Arrays; 24import java.util.List; 25 26/** 27 * CommandHandler for the HELP command. Handler logic: 28 * <ol> 29 * <li>If the optional command-name parameter is specified, then reply with 214 along with the 30 * help text configured for that command (or empty if none)</li> 31 * <li>Otherwise, reply with 214 along with the configured default help text that has been configured 32 * (or empty if none)</li> 33 * </ol> 34 * 35 * @author Chris Mair 36 * @version $Revision: 89 $ - $Date: 2008-08-02 08:07:44 -0400 (Sat, 02 Aug 2008) $ 37 * @see org.mockftpserver.fake.ServerConfiguration 38 * @see org.mockftpserver.fake.FakeFtpServer 39 */ 40public class HelpCommandHandler extends AbstractFakeCommandHandler { 41 42 protected void handle(Command command, Session session) { 43 List parameters = Arrays.asList(command.getParameters()); 44 String key = StringUtil.join(parameters, " "); 45 String help = getServerConfiguration().getHelpText(key); 46 if (help == null) { 47 sendReply(session, ReplyCodes.HELP_OK, "help.noHelpTextDefined", list(key)); 48 ; 49 } else { 50 sendReply(session, ReplyCodes.HELP_OK, "help", list(help)); 51 } 52 } 53 54}