HelpCommandHandler.java revision c561a9b3509b5021ddb2e2f8165e903909281269
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 * <p/>
35 * The help text is configured within the {@link org.mockftpserver.fake.FakeFtpServer}.
36 *
37 * @author Chris Mair
38 * @version $Revision: 89 $ - $Date: 2008-08-02 08:07:44 -0400 (Sat, 02 Aug 2008) $
39 * @see org.mockftpserver.fake.ServerConfiguration
40 * @see org.mockftpserver.fake.FakeFtpServer
41 */
42public class HelpCommandHandler extends AbstractFakeCommandHandler {
43
44    protected void handle(Command command, Session session) {
45        List parameters = Arrays.asList(command.getParameters());
46        String key = StringUtil.join(parameters, " ");
47        String help = getServerConfiguration().getHelpText(key);
48        if (help == null) {
49            sendReply(session, ReplyCodes.HELP_OK, "help.noHelpTextDefined", list(key));
50        } else {
51            sendReply(session, ReplyCodes.HELP_OK, "help", list(help));
52        }
53    }
54
55}