Coverage Report - org.mockftpserver.stub.command.StatCommandHandler
 
Classes in this File Line Coverage Branch Coverage Complexity
StatCommandHandler
100%
13/13
100%
4/4
1.667
 
 1  
 /*
 2  
  * Copyright 2007 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.stub.command;
 17  
 
 18  
 import org.mockftpserver.core.command.Command;
 19  
 import org.mockftpserver.core.command.CommandHandler;
 20  
 import org.mockftpserver.core.command.InvocationRecord;
 21  
 import org.mockftpserver.core.command.ReplyCodes;
 22  
 import org.mockftpserver.core.session.Session;
 23  
 
 24  
 /**
 25  
  * CommandHandler for the STAT (Status) command. By default, return empty status information,
 26  
  * along with a reply code of 211 if no pathname parameter is specified or 213 if a
 27  
  * pathname is specified. You can customize the returned status information by setting
 28  
  * the <code>status</code> property.
 29  
  * <p>
 30  
  * Each invocation record stored by this CommandHandler includes the following data element key/values:
 31  
  * <ul>
 32  
  * <li>{@link #PATHNAME_KEY} ("pathname") - the pathname of the directory (or file) submitted on the
 33  
  * invocation (the first command parameter); this parameter is optional, so the value may be null.
 34  
  * </ul>
 35  
  *
 36  
  * @author Chris Mair
 37  
  * @version $Revision: 194 $ - $Date: 2008-12-07 08:53:58 -0500 (Sun, 07 Dec 2008) $
 38  
  * @see SystCommandHandler
 39  
  */
 40  
 public class StatCommandHandler extends AbstractStubCommandHandler implements CommandHandler {
 41  
 
 42  
     public static final String PATHNAME_KEY = "pathname";
 43  
 
 44  61
     private String status = "";
 45  
 
 46  
     /**
 47  
      * Constructor.
 48  
      */
 49  61
     public StatCommandHandler() {
 50  
         // Do not initialize replyCode -- will be set dynamically
 51  61
     }
 52  
 
 53  
     public void handleCommand(Command command, Session session, InvocationRecord invocationRecord) {
 54  5
         String pathname = command.getOptionalString(0);
 55  5
         invocationRecord.set(PATHNAME_KEY, pathname);
 56  
 
 57  
         // Only use dynamic reply code if the replyCode property was NOT explicitly set
 58  5
         if (replyCode == 0) {
 59  4
             int code = (pathname == null) ? ReplyCodes.STAT_SYSTEM_OK : ReplyCodes.STAT_FILE_OK;
 60  4
             sendReply(session, code, replyMessageKey, replyText, new String[]{status});
 61  4
         } else {
 62  1
             sendReply(session, status);
 63  
         }
 64  5
     }
 65  
 
 66  
     /**
 67  
      * Set the contents of the status to send back as the reply text for this command
 68  
      *
 69  
      * @param status - the status
 70  
      */
 71  
     public void setStatus(String status) {
 72  5
         this.status = status;
 73  5
     }
 74  
 
 75  
 }