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