public abstract class AbstractFakeCommandHandler extends AbstractCommandHandler implements ServerConfigurationAware
Modifier and Type | Field and Description |
---|---|
protected static String |
INTERNAL_ERROR_KEY |
protected int |
replyCodeForFileSystemException
Reply code sent back when a FileSystemException is caught by the
handleCommand(Command, Session)
This defaults to ReplyCodes.EXISTING_FILE_ERROR (550). |
LOG
Constructor and Description |
---|
AbstractFakeCommandHandler() |
Modifier and Type | Method and Description |
---|---|
protected String |
defaultIfNullOrEmpty(String string,
String defaultString)
Return the string unless it is null or empty, in which case return the defaultString.
|
protected String |
endOfLine()
Return the end-of-line character(s) used when building multi-line responses
|
protected FileSystem |
getFileSystem()
Convenience method to return the FileSystem stored in the ServerConfiguration
|
protected String |
getRealPath(Session session,
String path)
Return the full, absolute path for the specified abstract pathname.
|
protected Object |
getRequiredSessionAttribute(Session session,
String name)
Return the value of the named attribute within the session.
|
ServerConfiguration |
getServerConfiguration() |
protected UserAccount |
getUserAccount(Session session) |
protected abstract void |
handle(Command command,
Session session)
Handle the specified command for the session.
|
void |
handleCommand(Command command,
Session session)
Use template method to centralize and ensure common validation
|
protected List |
list(Object item)
Convenience method to return a List with the specified single item
|
protected List |
list(Object item1,
Object item2)
Convenience method to return a List with the specified two items
|
protected void |
login(UserAccount userAccount,
Session session,
int replyCode,
String replyMessageKey)
Log in the specified user for the current session.
|
protected boolean |
notNullOrEmpty(String string)
Return true if the specified string is null or empty
|
protected void |
sendReply(Session session,
int replyCode)
Send a reply for this command on the control connection.
|
protected void |
sendReply(Session session,
int replyCode,
List args)
Send a reply for this command on the control connection.
|
protected void |
sendReply(Session session,
int replyCode,
String messageKey)
Send a reply for this command on the control connection.
|
protected void |
sendReply(Session session,
int replyCode,
String messageKey,
List args)
Send a reply for this command on the control connection.
|
void |
setServerConfiguration(ServerConfiguration serverConfiguration) |
protected boolean |
validateUserAccount(String username,
Session session)
Validate the UserAccount for the specified username.
|
protected void |
verifyExecutePermission(Session session,
String path)
Verify that the current user has execute permission to the specified path
|
protected void |
verifyFileSystemCondition(boolean condition,
String path,
String messageKey)
Verify that the specified condition related to the file system is true,
otherwise throw a FileSystemException.
|
protected void |
verifyLoggedIn(Session session)
Verify that the current user (if any) has already logged in successfully.
|
protected void |
verifyReadPermission(Session session,
String path)
Verify that the current user has read permission to the specified path
|
protected void |
verifyWritePermission(Session session,
String path)
Verify that the current user has write permission to the specified path
|
assertValidReplyCode, getReplyTextBundle, quotes, setReplyTextBundle
protected static final String INTERNAL_ERROR_KEY
protected int replyCodeForFileSystemException
handleCommand(Command, Session)
This defaults to ReplyCodes.EXISTING_FILE_ERROR (550).public ServerConfiguration getServerConfiguration()
getServerConfiguration
in interface ServerConfigurationAware
public void setServerConfiguration(ServerConfiguration serverConfiguration)
setServerConfiguration
in interface ServerConfigurationAware
public void handleCommand(Command command, Session session)
handleCommand
in interface CommandHandler
command
- - the Command to be handledsession
- - the session on which the Command was submittedprotected FileSystem getFileSystem()
protected abstract void handle(Command command, Session session)
command
- - the Command to be handledsession
- - the session on which the Command was submittedprotected void sendReply(Session session, int replyCode, String messageKey)
The reply code is designated by the replyCode
property, and the reply text
is retrieved from the replyText
ResourceBundle, using the specified messageKey.
session
- - the SessionreplyCode
- - the reply codemessageKey
- - the resource bundle key for the reply textAssertionError
- - if session is nullMessageFormat
protected void sendReply(Session session, int replyCode, String messageKey, List args)
The reply code is designated by the replyCode
property, and the reply text
is retrieved from the replyText
ResourceBundle, using the specified messageKey.
session
- - the SessionreplyCode
- - the reply codemessageKey
- - the resource bundle key for the reply textargs
- - the optional message arguments; defaults to []AssertionError
- - if session is nullMessageFormat
protected void sendReply(Session session, int replyCode)
The reply code is designated by the replyCode
property, and the reply text
is retrieved from the replyText
ResourceBundle, using the reply code as the key.
session
- - the SessionreplyCode
- - the reply codeAssertionError
- - if session is nullMessageFormat
protected void sendReply(Session session, int replyCode, List args)
The reply code is designated by the replyCode
property, and the reply text
is retrieved from the replyText
ResourceBundle, using the reply code as the key.
session
- - the SessionreplyCode
- - the reply codeargs
- - the optional message arguments; defaults to []AssertionError
- - if session is nullMessageFormat
protected Object getRequiredSessionAttribute(Session session, String name)
session
- - the Sessionname
- - the name of the session attribute to retrieveIllegalStateException
- - if the Session does not contain the named attributeprotected void verifyLoggedIn(Session session)
session
- - the Sessionprotected UserAccount getUserAccount(Session session)
session
- - the Sessionprotected void verifyFileSystemCondition(boolean condition, String path, String messageKey)
condition
- - the condition that must be truepath
- - the path involved in the operation; this will be included in the
error message if the condition is not true.messageKey
- - the message key for the exception messageFileSystemException
- - if the condition is not trueprotected void verifyExecutePermission(Session session, String path)
session
- - the Sessionpath
- - the file system pathFileSystemException
- - if the condition is not trueprotected void verifyWritePermission(Session session, String path)
session
- - the Sessionpath
- - the file system pathFileSystemException
- - if the condition is not trueprotected void verifyReadPermission(Session session, String path)
session
- - the Sessionpath
- - the file system pathFileSystemException
- - if the condition is not trueprotected String getRealPath(Session session, String path)
session
- - the Sessionpath
- - the abstract pathname; may be nullprotected String endOfLine()
protected boolean validateUserAccount(String username, Session session)
username
- - the usernamesession
- - the session; used to send back an error reply if necessaryprotected void login(UserAccount userAccount, Session session, int replyCode, String replyMessageKey)
userAccount
- - the userAccount for the user to be logged insession
- - the sessionreplyCode
- - the reply code to sendreplyMessageKey
- - the message key for the reply textprotected List list(Object item)
item
- - the single item in the returned Listprotected List list(Object item1, Object item2)
item1
- - the first item in the returned Listitem2
- - the second item in the returned Listprotected boolean notNullOrEmpty(String string)
string
- - the String to check; may be nullprotected String defaultIfNullOrEmpty(String string, String defaultString)
string
- - the String to check; may be nulldefaultString
- - the value to return if string is null or emptyCopyright © 2016. All rights reserved.