1bda3441225e0607b5ced8b538123fd7c7a417910chrismair/*
2bda3441225e0607b5ced8b538123fd7c7a417910chrismair * Copyright 2007 the original author or authors.
3bda3441225e0607b5ced8b538123fd7c7a417910chrismair *
4bda3441225e0607b5ced8b538123fd7c7a417910chrismair * Licensed under the Apache License, Version 2.0 (the "License");
5bda3441225e0607b5ced8b538123fd7c7a417910chrismair * you may not use this file except in compliance with the License.
6bda3441225e0607b5ced8b538123fd7c7a417910chrismair * You may obtain a copy of the License at
7bda3441225e0607b5ced8b538123fd7c7a417910chrismair *
8bda3441225e0607b5ced8b538123fd7c7a417910chrismair *      http://www.apache.org/licenses/LICENSE-2.0
9bda3441225e0607b5ced8b538123fd7c7a417910chrismair *
10bda3441225e0607b5ced8b538123fd7c7a417910chrismair * Unless required by applicable law or agreed to in writing, software
11bda3441225e0607b5ced8b538123fd7c7a417910chrismair * distributed under the License is distributed on an "AS IS" BASIS,
12bda3441225e0607b5ced8b538123fd7c7a417910chrismair * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13bda3441225e0607b5ced8b538123fd7c7a417910chrismair * See the License for the specific language governing permissions and
14bda3441225e0607b5ced8b538123fd7c7a417910chrismair * limitations under the License.
15bda3441225e0607b5ced8b538123fd7c7a417910chrismair */
16bda3441225e0607b5ced8b538123fd7c7a417910chrismairpackage org.mockftpserver.stub.command;
17bda3441225e0607b5ced8b538123fd7c7a417910chrismair
18bda3441225e0607b5ced8b538123fd7c7a417910chrismairimport org.mockftpserver.core.command.ReplyCodes;
19bda3441225e0607b5ced8b538123fd7c7a417910chrismairimport org.mockftpserver.core.session.Session;
20bda3441225e0607b5ced8b538123fd7c7a417910chrismair
21bda3441225e0607b5ced8b538123fd7c7a417910chrismair/**
22bda3441225e0607b5ced8b538123fd7c7a417910chrismair * CommandHandler for the STOU (Store Unique) command. Send back two replies on the control connection: a
23bda3441225e0607b5ced8b538123fd7c7a417910chrismair * reply code of 150 and another of 226. The text accompanying the final reply (226) is the
24bda3441225e0607b5ced8b538123fd7c7a417910chrismair * unique filename, which is "" by default. You can customize the returned filename by setting
25bda3441225e0607b5ced8b538123fd7c7a417910chrismair * the <code>filename</code> property.
26bda3441225e0607b5ced8b538123fd7c7a417910chrismair * <p/>
27bda3441225e0607b5ced8b538123fd7c7a417910chrismair * Each invocation record stored by this CommandHandler includes the following data element key/values:
28bda3441225e0607b5ced8b538123fd7c7a417910chrismair * <ul>
29bda3441225e0607b5ced8b538123fd7c7a417910chrismair * <li>{@link #FILE_CONTENTS_KEY} ("fileContents") - the file contents (<code>byte[]</code>) sent on the data connection
30bda3441225e0607b5ced8b538123fd7c7a417910chrismair * </ul>
31bda3441225e0607b5ced8b538123fd7c7a417910chrismair *
32bda3441225e0607b5ced8b538123fd7c7a417910chrismair * @author Chris Mair
33bda3441225e0607b5ced8b538123fd7c7a417910chrismair * @version $Revision$ - $Date$
34bda3441225e0607b5ced8b538123fd7c7a417910chrismair */
35bda3441225e0607b5ced8b538123fd7c7a417910chrismairpublic class StouCommandHandler extends AbstractStorCommandHandler {
36bda3441225e0607b5ced8b538123fd7c7a417910chrismair
37bda3441225e0607b5ced8b538123fd7c7a417910chrismair    private static final String FINAL_REPLY_TEXT_KEY = "226.WithFilename";
38bda3441225e0607b5ced8b538123fd7c7a417910chrismair
39bda3441225e0607b5ced8b538123fd7c7a417910chrismair    private String filename = "";
40bda3441225e0607b5ced8b538123fd7c7a417910chrismair
41bda3441225e0607b5ced8b538123fd7c7a417910chrismair    /**
42bda3441225e0607b5ced8b538123fd7c7a417910chrismair     * Override the default implementation to send a custom reply text that includes the STOU response filename
43bda3441225e0607b5ced8b538123fd7c7a417910chrismair     *
44bda3441225e0607b5ced8b538123fd7c7a417910chrismair     * @see org.mockftpserver.stub.command.AbstractStubDataCommandHandler#sendFinalReply(org.mockftpserver.core.session.Session)
45bda3441225e0607b5ced8b538123fd7c7a417910chrismair     */
46bda3441225e0607b5ced8b538123fd7c7a417910chrismair    protected void sendFinalReply(Session session) {
47bda3441225e0607b5ced8b538123fd7c7a417910chrismair        final String[] ARGS = {filename};
48bda3441225e0607b5ced8b538123fd7c7a417910chrismair        sendReply(session, ReplyCodes.TRANSFER_DATA_FINAL_OK, FINAL_REPLY_TEXT_KEY, null, ARGS);
49bda3441225e0607b5ced8b538123fd7c7a417910chrismair    }
50bda3441225e0607b5ced8b538123fd7c7a417910chrismair
51bda3441225e0607b5ced8b538123fd7c7a417910chrismair    /**
52bda3441225e0607b5ced8b538123fd7c7a417910chrismair     * Set the filename returned with the final reply of the STOU command
53bda3441225e0607b5ced8b538123fd7c7a417910chrismair     *
54bda3441225e0607b5ced8b538123fd7c7a417910chrismair     * @param filename - the filename
55bda3441225e0607b5ced8b538123fd7c7a417910chrismair     */
56bda3441225e0607b5ced8b538123fd7c7a417910chrismair    public void setFilename(String filename) {
57bda3441225e0607b5ced8b538123fd7c7a417910chrismair        this.filename = filename;
58bda3441225e0607b5ced8b538123fd7c7a417910chrismair    }
59bda3441225e0607b5ced8b538123fd7c7a417910chrismair
60bda3441225e0607b5ced8b538123fd7c7a417910chrismair}
61