chrismair | 00dc7bd | 2014-05-11 21:21:28 +0000 | [diff] [blame] | 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 | */
|
| 16 | package org.mockftpserver.fake.command;
|
| 17 |
|
| 18 | import org.mockftpserver.core.command.Command;
|
| 19 | import org.mockftpserver.core.command.ReplyCodes;
|
| 20 | import org.mockftpserver.core.session.Session;
|
| 21 | import org.mockftpserver.core.util.StringUtil;
|
| 22 |
|
| 23 | import java.util.Arrays;
|
| 24 | import 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$ - $Date$
|
| 39 | * @see org.mockftpserver.fake.ServerConfiguration
|
| 40 | * @see org.mockftpserver.fake.FakeFtpServer
|
| 41 | */
|
| 42 | public 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 | } |