1c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair/* 2c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair * Copyright 2007 the original author or authors. 3c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair * 4c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair * Licensed under the Apache License, Version 2.0 (the "License"); 5c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair * you may not use this file except in compliance with the License. 6c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair * You may obtain a copy of the License at 7c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair * 8c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair * http://www.apache.org/licenses/LICENSE-2.0 9c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair * 10c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair * Unless required by applicable law or agreed to in writing, software 11c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair * distributed under the License is distributed on an "AS IS" BASIS, 12c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair * See the License for the specific language governing permissions and 14c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair * limitations under the License. 15c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair */ 16c1de24f1bfa6699e54b069e300af5e4246b34a34chrismairpackage org.mockftpserver.stub.command; 17c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair 18c1de24f1bfa6699e54b069e300af5e4246b34a34chrismairimport org.mockftpserver.core.command.Command; 19c1de24f1bfa6699e54b069e300af5e4246b34a34chrismairimport org.mockftpserver.core.command.CommandHandler; 20c1de24f1bfa6699e54b069e300af5e4246b34a34chrismairimport org.mockftpserver.core.command.InvocationRecord; 21c1de24f1bfa6699e54b069e300af5e4246b34a34chrismairimport org.mockftpserver.core.command.ReplyCodes; 22c1de24f1bfa6699e54b069e300af5e4246b34a34chrismairimport org.mockftpserver.core.session.Session; 23c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair 24c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair/** 25c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair * CommandHandler for the STAT (Status) command. By default, return empty status information, 26c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair * along with a reply code of 211 if no pathname parameter is specified or 213 if a 27c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair * pathname is specified. You can customize the returned status information by setting 28c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair * the <code>status</code> property. 29c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair * <p> 30c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair * Each invocation record stored by this CommandHandler includes the following data element key/values: 31c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair * <ul> 32c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair * <li>{@link #PATHNAME_KEY} ("pathname") - the pathname of the directory (or file) submitted on the 33c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair * invocation (the first command parameter); this parameter is optional, so the value may be null. 34c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair * </ul> 35c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair * 36c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair * @author Chris Mair 37c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair * @version $Revision$ - $Date$ 38c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair * @see SystCommandHandler 39c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair */ 40c1de24f1bfa6699e54b069e300af5e4246b34a34chrismairpublic class StatCommandHandler extends AbstractStubCommandHandler implements CommandHandler { 41c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair 42c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair public static final String PATHNAME_KEY = "pathname"; 43c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair 44c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair private String status = ""; 45c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair 46c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair /** 47c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair * Constructor. 48c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair */ 49c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair public StatCommandHandler() { 50c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair // Do not initialize replyCode -- will be set dynamically 51c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair } 52c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair 53c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair public void handleCommand(Command command, Session session, InvocationRecord invocationRecord) { 54c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair String pathname = command.getOptionalString(0); 55c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair invocationRecord.set(PATHNAME_KEY, pathname); 56c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair 57c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair // Only use dynamic reply code if the replyCode property was NOT explicitly set 58c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair if (replyCode == 0) { 59c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair int code = (pathname == null) ? ReplyCodes.STAT_SYSTEM_OK : ReplyCodes.STAT_FILE_OK; 60c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair sendReply(session, code, replyMessageKey, replyText, new String[]{status}); 61c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair } else { 62c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair sendReply(session, status); 63c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair } 64c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair } 65c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair 66c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair /** 67c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair * Set the contents of the status to send back as the reply text for this command 68c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair * 69c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair * @param status - the status 70c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair */ 71c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair public void setStatus(String status) { 72c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair this.status = status; 73c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair } 74c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair 75c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair} 76