185efb15529d45e32fea8de03c38a968c157c8262chrismair/* 285efb15529d45e32fea8de03c38a968c157c8262chrismair * Copyright 2007 the original author or authors. 385efb15529d45e32fea8de03c38a968c157c8262chrismair * 485efb15529d45e32fea8de03c38a968c157c8262chrismair * Licensed under the Apache License, Version 2.0 (the "License"); 585efb15529d45e32fea8de03c38a968c157c8262chrismair * you may not use this file except in compliance with the License. 685efb15529d45e32fea8de03c38a968c157c8262chrismair * You may obtain a copy of the License at 785efb15529d45e32fea8de03c38a968c157c8262chrismair * 885efb15529d45e32fea8de03c38a968c157c8262chrismair * http://www.apache.org/licenses/LICENSE-2.0 985efb15529d45e32fea8de03c38a968c157c8262chrismair * 1085efb15529d45e32fea8de03c38a968c157c8262chrismair * Unless required by applicable law or agreed to in writing, software 1185efb15529d45e32fea8de03c38a968c157c8262chrismair * distributed under the License is distributed on an "AS IS" BASIS, 1285efb15529d45e32fea8de03c38a968c157c8262chrismair * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1385efb15529d45e32fea8de03c38a968c157c8262chrismair * See the License for the specific language governing permissions and 1485efb15529d45e32fea8de03c38a968c157c8262chrismair * limitations under the License. 1585efb15529d45e32fea8de03c38a968c157c8262chrismair */ 1685efb15529d45e32fea8de03c38a968c157c8262chrismairpackage org.mockftpserver.stub.command; 1785efb15529d45e32fea8de03c38a968c157c8262chrismair 1885efb15529d45e32fea8de03c38a968c157c8262chrismairimport org.mockftpserver.core.command.Command; 1985efb15529d45e32fea8de03c38a968c157c8262chrismairimport org.mockftpserver.core.command.CommandHandler; 2085efb15529d45e32fea8de03c38a968c157c8262chrismairimport org.mockftpserver.core.command.InvocationRecord; 2185efb15529d45e32fea8de03c38a968c157c8262chrismairimport org.mockftpserver.core.session.Session; 2285efb15529d45e32fea8de03c38a968c157c8262chrismair 2385efb15529d45e32fea8de03c38a968c157c8262chrismair/** 2485efb15529d45e32fea8de03c38a968c157c8262chrismair * CommandHandler for the LIST command. Return the configured directory listing on the data 2585efb15529d45e32fea8de03c38a968c157c8262chrismair * connection, along with two replies on the control connection: a reply code of 150 and 2685efb15529d45e32fea8de03c38a968c157c8262chrismair * another of 226. By default, return an empty directory listing. You can customize the 2785efb15529d45e32fea8de03c38a968c157c8262chrismair * returned directory listing by setting the <code>directoryListing</code> property. 2885efb15529d45e32fea8de03c38a968c157c8262chrismair * <p> 2985efb15529d45e32fea8de03c38a968c157c8262chrismair * The interpretation of the value returned from this command is dependent upon the value returned 3085efb15529d45e32fea8de03c38a968c157c8262chrismair * by the SYST command. The format of the directory listing should match the format associated with 3185efb15529d45e32fea8de03c38a968c157c8262chrismair * the system named by the SYST command. For example, if the SYST command returns "WINDOWS", then 3285efb15529d45e32fea8de03c38a968c157c8262chrismair * the directory listing value from this command should match the Windows-specific format. 3385efb15529d45e32fea8de03c38a968c157c8262chrismair * <p> 3485efb15529d45e32fea8de03c38a968c157c8262chrismair * Each invocation record stored by this CommandHandler includes the following data element key/values: 3585efb15529d45e32fea8de03c38a968c157c8262chrismair * <ul> 3685efb15529d45e32fea8de03c38a968c157c8262chrismair * <li>{@link #PATHNAME_KEY} ("pathname") - the pathname of the directory (or file) submitted on the 3785efb15529d45e32fea8de03c38a968c157c8262chrismair * invocation (the first command parameter); this parameter is optional, so the value may be null. 3885efb15529d45e32fea8de03c38a968c157c8262chrismair * </ul> 3985efb15529d45e32fea8de03c38a968c157c8262chrismair * 4085efb15529d45e32fea8de03c38a968c157c8262chrismair * @see SystCommandHandler 4185efb15529d45e32fea8de03c38a968c157c8262chrismair * 4285efb15529d45e32fea8de03c38a968c157c8262chrismair * @version $Revision$ - $Date$ 4385efb15529d45e32fea8de03c38a968c157c8262chrismair * 4485efb15529d45e32fea8de03c38a968c157c8262chrismair * @author Chris Mair 4585efb15529d45e32fea8de03c38a968c157c8262chrismair */ 4685efb15529d45e32fea8de03c38a968c157c8262chrismairpublic final class ListCommandHandler extends AbstractStubDataCommandHandler implements CommandHandler { 4785efb15529d45e32fea8de03c38a968c157c8262chrismair 4885efb15529d45e32fea8de03c38a968c157c8262chrismair public static final String PATHNAME_KEY = "pathname"; 4985efb15529d45e32fea8de03c38a968c157c8262chrismair 5085efb15529d45e32fea8de03c38a968c157c8262chrismair private String directoryListing = ""; 5185efb15529d45e32fea8de03c38a968c157c8262chrismair 5285efb15529d45e32fea8de03c38a968c157c8262chrismair /** 5385efb15529d45e32fea8de03c38a968c157c8262chrismair * @see org.mockftpserver.stub.command.AbstractStubDataCommandHandler#beforeProcessData(org.mockftpserver.core.command.Command, org.mockftpserver.core.session.Session, org.mockftpserver.core.command.InvocationRecord) 5485efb15529d45e32fea8de03c38a968c157c8262chrismair */ 5585efb15529d45e32fea8de03c38a968c157c8262chrismair protected void beforeProcessData(Command command, Session session, InvocationRecord invocationRecord) throws Exception { 5685efb15529d45e32fea8de03c38a968c157c8262chrismair invocationRecord.set(PATHNAME_KEY, command.getOptionalString(0)); 5785efb15529d45e32fea8de03c38a968c157c8262chrismair } 5885efb15529d45e32fea8de03c38a968c157c8262chrismair 5985efb15529d45e32fea8de03c38a968c157c8262chrismair /** 6085efb15529d45e32fea8de03c38a968c157c8262chrismair * @see org.mockftpserver.stub.command.AbstractStubDataCommandHandler#processData(org.mockftpserver.core.command.Command, org.mockftpserver.core.session.Session, org.mockftpserver.core.command.InvocationRecord) 6185efb15529d45e32fea8de03c38a968c157c8262chrismair */ 6285efb15529d45e32fea8de03c38a968c157c8262chrismair protected void processData(Command command, Session session, InvocationRecord invocationRecord) { 6385efb15529d45e32fea8de03c38a968c157c8262chrismair session.sendData(directoryListing.getBytes(), directoryListing.length()); 6485efb15529d45e32fea8de03c38a968c157c8262chrismair } 6585efb15529d45e32fea8de03c38a968c157c8262chrismair 6685efb15529d45e32fea8de03c38a968c157c8262chrismair /** 6785efb15529d45e32fea8de03c38a968c157c8262chrismair * Set the contents of the directoryListing to send back on the data connection for this command. 6885efb15529d45e32fea8de03c38a968c157c8262chrismair * The passed-in value is trimmed automatically. 6985efb15529d45e32fea8de03c38a968c157c8262chrismair * @param directoryListing - the directoryListing to set 7085efb15529d45e32fea8de03c38a968c157c8262chrismair */ 7185efb15529d45e32fea8de03c38a968c157c8262chrismair public void setDirectoryListing(String directoryListing) { 7285efb15529d45e32fea8de03c38a968c157c8262chrismair this.directoryListing = directoryListing.trim(); 7385efb15529d45e32fea8de03c38a968c157c8262chrismair } 7485efb15529d45e32fea8de03c38a968c157c8262chrismair 7585efb15529d45e32fea8de03c38a968c157c8262chrismair} 76