Coverage Report - org.mockftpserver.fake.command.HelpCommandHandler
 
Classes in this File Line Coverage Branch Coverage Complexity
HelpCommandHandler
100%
8/8
100%
2/2
2
 
 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: 182 $ - $Date: 2008-11-30 21:37:49 -0500 (Sun, 30 Nov 2008) $
 39  
  * @see org.mockftpserver.fake.ServerConfiguration
 40  
  * @see org.mockftpserver.fake.FakeFtpServer
 41  
  */
 42  78
 public class HelpCommandHandler extends AbstractFakeCommandHandler {
 43  
 
 44  
     protected void handle(Command command, Session session) {
 45  7
         List parameters = Arrays.asList(command.getParameters());
 46  7
         String key = StringUtil.join(parameters, " ");
 47  7
         String help = getServerConfiguration().getHelpText(key);
 48  7
         if (help == null) {
 49  2
             sendReply(session, ReplyCodes.HELP_OK, "help.noHelpTextDefined", list(key));
 50  
         } else {
 51  5
             sendReply(session, ReplyCodes.HELP_OK, "help", list(help));
 52  
         }
 53  7
     }
 54  
 
 55  
 }