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.core.command;
17bda3441225e0607b5ced8b538123fd7c7a417910chrismair
18bda3441225e0607b5ced8b538123fd7c7a417910chrismairimport org.apache.log4j.Logger;
19bda3441225e0607b5ced8b538123fd7c7a417910chrismairimport org.mockftpserver.core.util.Assert;
20bda3441225e0607b5ced8b538123fd7c7a417910chrismair
21bda3441225e0607b5ced8b538123fd7c7a417910chrismairimport java.util.ResourceBundle;
22bda3441225e0607b5ced8b538123fd7c7a417910chrismair
23bda3441225e0607b5ced8b538123fd7c7a417910chrismair/**
24bda3441225e0607b5ced8b538123fd7c7a417910chrismair * The abstract superclass for CommandHandler classes.
25bda3441225e0607b5ced8b538123fd7c7a417910chrismair *
26bda3441225e0607b5ced8b538123fd7c7a417910chrismair * @author Chris Mair
27bda3441225e0607b5ced8b538123fd7c7a417910chrismair * @version $Revision$ - $Date$
28bda3441225e0607b5ced8b538123fd7c7a417910chrismair */
29bda3441225e0607b5ced8b538123fd7c7a417910chrismairpublic abstract class AbstractCommandHandler implements CommandHandler, ReplyTextBundleAware {
30bda3441225e0607b5ced8b538123fd7c7a417910chrismair
31bda3441225e0607b5ced8b538123fd7c7a417910chrismair    protected final Logger LOG = Logger.getLogger(getClass());
32bda3441225e0607b5ced8b538123fd7c7a417910chrismair
33bda3441225e0607b5ced8b538123fd7c7a417910chrismair    private ResourceBundle replyTextBundle;
34bda3441225e0607b5ced8b538123fd7c7a417910chrismair
35bda3441225e0607b5ced8b538123fd7c7a417910chrismair    //-------------------------------------------------------------------------
36bda3441225e0607b5ced8b538123fd7c7a417910chrismair    // Support for reply text ResourceBundle
37bda3441225e0607b5ced8b538123fd7c7a417910chrismair    //-------------------------------------------------------------------------
38bda3441225e0607b5ced8b538123fd7c7a417910chrismair
39bda3441225e0607b5ced8b538123fd7c7a417910chrismair    /**
40bda3441225e0607b5ced8b538123fd7c7a417910chrismair     * Return the ResourceBundle containing the reply text messages
41bda3441225e0607b5ced8b538123fd7c7a417910chrismair     *
42bda3441225e0607b5ced8b538123fd7c7a417910chrismair     * @return the replyTextBundle
43bda3441225e0607b5ced8b538123fd7c7a417910chrismair     * @see ReplyTextBundleAware#getReplyTextBundle()
44bda3441225e0607b5ced8b538123fd7c7a417910chrismair     */
45bda3441225e0607b5ced8b538123fd7c7a417910chrismair    public ResourceBundle getReplyTextBundle() {
46bda3441225e0607b5ced8b538123fd7c7a417910chrismair        return replyTextBundle;
47bda3441225e0607b5ced8b538123fd7c7a417910chrismair    }
48bda3441225e0607b5ced8b538123fd7c7a417910chrismair
49bda3441225e0607b5ced8b538123fd7c7a417910chrismair    /**
50bda3441225e0607b5ced8b538123fd7c7a417910chrismair     * Set the ResourceBundle containing the reply text messages
51bda3441225e0607b5ced8b538123fd7c7a417910chrismair     *
52bda3441225e0607b5ced8b538123fd7c7a417910chrismair     * @param replyTextBundle - the replyTextBundle to set
53bda3441225e0607b5ced8b538123fd7c7a417910chrismair     * @see ReplyTextBundleAware#setReplyTextBundle(java.util.ResourceBundle)
54bda3441225e0607b5ced8b538123fd7c7a417910chrismair     */
55bda3441225e0607b5ced8b538123fd7c7a417910chrismair    public void setReplyTextBundle(ResourceBundle replyTextBundle) {
56bda3441225e0607b5ced8b538123fd7c7a417910chrismair        this.replyTextBundle = replyTextBundle;
57bda3441225e0607b5ced8b538123fd7c7a417910chrismair    }
58bda3441225e0607b5ced8b538123fd7c7a417910chrismair
59bda3441225e0607b5ced8b538123fd7c7a417910chrismair    // -------------------------------------------------------------------------
60bda3441225e0607b5ced8b538123fd7c7a417910chrismair    // Utility methods for subclasses
61bda3441225e0607b5ced8b538123fd7c7a417910chrismair    // -------------------------------------------------------------------------
62bda3441225e0607b5ced8b538123fd7c7a417910chrismair
63bda3441225e0607b5ced8b538123fd7c7a417910chrismair    /**
64bda3441225e0607b5ced8b538123fd7c7a417910chrismair     * Return the specified text surrounded with double quotes
65bda3441225e0607b5ced8b538123fd7c7a417910chrismair     *
66bda3441225e0607b5ced8b538123fd7c7a417910chrismair     * @param text - the text to surround with quotes
67bda3441225e0607b5ced8b538123fd7c7a417910chrismair     * @return the text with leading and trailing double quotes
68bda3441225e0607b5ced8b538123fd7c7a417910chrismair     * @throws org.mockftpserver.core.util.AssertFailedException
69bda3441225e0607b5ced8b538123fd7c7a417910chrismair     *          - if text is null
70bda3441225e0607b5ced8b538123fd7c7a417910chrismair     */
71bda3441225e0607b5ced8b538123fd7c7a417910chrismair    protected static String quotes(String text) {
72bda3441225e0607b5ced8b538123fd7c7a417910chrismair        Assert.notNull(text, "text");
73bda3441225e0607b5ced8b538123fd7c7a417910chrismair        final String QUOTES = "\"";
74bda3441225e0607b5ced8b538123fd7c7a417910chrismair        return QUOTES + text + QUOTES;
75bda3441225e0607b5ced8b538123fd7c7a417910chrismair    }
76bda3441225e0607b5ced8b538123fd7c7a417910chrismair
77bda3441225e0607b5ced8b538123fd7c7a417910chrismair    /**
78bda3441225e0607b5ced8b538123fd7c7a417910chrismair     * Assert that the specified number is a valid reply code
79bda3441225e0607b5ced8b538123fd7c7a417910chrismair     *
80bda3441225e0607b5ced8b538123fd7c7a417910chrismair     * @param replyCode - the reply code to check
81bda3441225e0607b5ced8b538123fd7c7a417910chrismair     * @throws org.mockftpserver.core.util.AssertFailedException
82bda3441225e0607b5ced8b538123fd7c7a417910chrismair     *          - if the replyCode is invalid
83bda3441225e0607b5ced8b538123fd7c7a417910chrismair     */
84bda3441225e0607b5ced8b538123fd7c7a417910chrismair    protected void assertValidReplyCode(int replyCode) {
85bda3441225e0607b5ced8b538123fd7c7a417910chrismair        Assert.isTrue(replyCode > 0, "The number [" + replyCode + "] is not a valid reply code");
86bda3441225e0607b5ced8b538123fd7c7a417910chrismair    }
87bda3441225e0607b5ced8b538123fd7c7a417910chrismair
88bda3441225e0607b5ced8b538123fd7c7a417910chrismair}