This is an automated email from the ASF dual-hosted git repository. elecharny pushed a commit to branch 1.2.X in repository https://gitbox.apache.org/repos/asf/mina-ftpserver.git
commit ad722570fe33968cf8d686ca21112a8d120c36f3 Author: emmanuel lecharny <[email protected]> AuthorDate: Mon Jan 6 12:33:07 2025 +0100 o Fixed some checkstyle warnings o Use switch with String o Added some javadoc o Added a default protected constructor o Minor code refactoring for clarity --- .../nativefs/NativeFileSystemFactory.java | 30 ++- .../org/apache/ftpserver/ftplet/DefaultFtplet.java | 281 ++++++++++++--------- .../apache/ftpserver/ftplet/FileSystemFactory.java | 4 +- .../apache/ftpserver/ftplet/FileSystemView.java | 16 +- 4 files changed, 188 insertions(+), 143 deletions(-) diff --git a/core/src/main/java/org/apache/ftpserver/filesystem/nativefs/NativeFileSystemFactory.java b/core/src/main/java/org/apache/ftpserver/filesystem/nativefs/NativeFileSystemFactory.java index 7f318de2..49d4c347 100644 --- a/core/src/main/java/org/apache/ftpserver/filesystem/nativefs/NativeFileSystemFactory.java +++ b/core/src/main/java/org/apache/ftpserver/filesystem/nativefs/NativeFileSystemFactory.java @@ -35,9 +35,7 @@ import org.slf4j.LoggerFactory; * @author <a href="http://mina.apache.org">Apache MINA Project</a> */ public class NativeFileSystemFactory implements FileSystemFactory { - - private final Logger LOG = LoggerFactory - .getLogger(NativeFileSystemFactory.class); + private final Logger LOG = LoggerFactory.getLogger(NativeFileSystemFactory.class); private boolean createHome; @@ -45,7 +43,8 @@ public class NativeFileSystemFactory implements FileSystemFactory { /** * Should the home directories be created automatically - * @return true if the file system will create the home directory if not available + * + * @return <code>true</code> if the file system will create the home directory if not available */ public boolean isCreateHome() { return createHome; @@ -53,7 +52,8 @@ public class NativeFileSystemFactory implements FileSystemFactory { /** * Set if the home directories be created automatically - * @param createHome true if the file system will create the home directory if not available + * + * @param createHome <code>true</code> if the file system will create the home directory if not available */ public void setCreateHome(boolean createHome) { @@ -63,7 +63,8 @@ public class NativeFileSystemFactory implements FileSystemFactory { /** * Is this file system case insensitive. * Enabling might cause problems when working against case-sensitive file systems, like on Linux - * @return true if this file system is case insensitive + * + * @return <code>true</code> if this file system is case insensitive */ public boolean isCaseInsensitive() { return caseInsensitive; @@ -72,7 +73,8 @@ public class NativeFileSystemFactory implements FileSystemFactory { /** * Should this file system be case insensitive. * Enabling might cause problems when working against case-sensitive file systems, like on Linux - * @param caseInsensitive true if this file system should be case insensitive + * + * @param caseInsensitive <code>true</code> if this file system should be case insensitive */ public void setCaseInsensitive(boolean caseInsensitive) { this.caseInsensitive = caseInsensitive; @@ -89,21 +91,21 @@ public class NativeFileSystemFactory implements FileSystemFactory { if (createHome) { String homeDirStr = user.getHomeDirectory(); File homeDir = new File(homeDirStr); + if (homeDir.isFile()) { - LOG.warn("Not a directory :: " + homeDirStr); + LOG.warn("Not a directory :: {}", homeDirStr); throw new FtpException("Not a directory :: " + homeDirStr); } + if ((!homeDir.exists()) && (!homeDir.mkdirs())) { - LOG.warn("Cannot create user home :: " + homeDirStr); - throw new FtpException("Cannot create user home :: " - + homeDirStr); + LOG.warn("Cannot create user home :: {}", homeDirStr); + throw new FtpException("Cannot create user home :: " + homeDirStr); } } - FileSystemView fsView = new NativeFileSystemView(user, - caseInsensitive); + FileSystemView fsView = new NativeFileSystemView(user, caseInsensitive); + return fsView; } } - } diff --git a/ftplet-api/src/main/java/org/apache/ftpserver/ftplet/DefaultFtplet.java b/ftplet-api/src/main/java/org/apache/ftpserver/ftplet/DefaultFtplet.java index c411feb5..0d60a282 100644 --- a/ftplet-api/src/main/java/org/apache/ftpserver/ftplet/DefaultFtplet.java +++ b/ftplet-api/src/main/java/org/apache/ftpserver/ftplet/DefaultFtplet.java @@ -29,312 +29,351 @@ import java.io.IOException; * @author <a href="http://mina.apache.org">Apache MINA Project</a> */ public class DefaultFtplet implements Ftplet { + /** + * A default constructor that does nothing + */ + protected DefaultFtplet() { + } + /** + * {@inheritDoc} + */ public void init(FtpletContext ftpletContext) throws FtpException { } + /** + * {@inheritDoc} + */ public void destroy() { } - public FtpletResult onConnect(FtpSession session) throws FtpException, - IOException { + /** + * {@inheritDoc} + */ + public FtpletResult onConnect(FtpSession session) throws FtpException, IOException { return null; } - public FtpletResult onDisconnect(FtpSession session) throws FtpException, - IOException { + /** + * {@inheritDoc} + */ + public FtpletResult onDisconnect(FtpSession session) throws FtpException, IOException { return null; } - public FtpletResult beforeCommand(FtpSession session, FtpRequest request) - throws FtpException, IOException { + /** + * {@inheritDoc} + */ + public FtpletResult beforeCommand(FtpSession session, FtpRequest request) throws FtpException, IOException { String command = request.getCommand().toUpperCase(); - if ("DELE".equals(command)) { - return onDeleteStart(session, request); - } else if ("STOR".equals(command)) { - return onUploadStart(session, request); - } else if ("RETR".equals(command)) { - return onDownloadStart(session, request); - } else if ("RMD".equals(command)) { - return onRmdirStart(session, request); - } else if ("MKD".equals(command)) { - return onMkdirStart(session, request); - } else if ("APPE".equals(command)) { - return onAppendStart(session, request); - } else if ("STOU".equals(command)) { - return onUploadUniqueStart(session, request); - } else if ("RNTO".equals(command)) { - return onRenameStart(session, request); - } else if ("SITE".equals(command)) { - return onSite(session, request); - } else { - // TODO should we call a catch all? - return null; + switch (command) { + case "DELE": + return onDeleteStart(session, request); + + case "STOR": + return onUploadStart(session, request); + + case "RETR": + return onDownloadStart(session, request); + + case "RMD": + return onRmdirStart(session, request); + + case "MKD": + return onMkdirStart(session, request); + + case "APPE": + return onAppendStart(session, request); + + case "STOU": + return onUploadUniqueStart(session, request); + + case "RNTO": + return onRenameStart(session, request); + + case "SITE": + return onSite(session, request); + + default: + return null; } } + /** + * {@inheritDoc} + */ public FtpletResult afterCommand(FtpSession session, FtpRequest request, FtpReply reply) throws FtpException, IOException { - // the reply is ignored for these callbacks String command = request.getCommand().toUpperCase(); - if ("PASS".equals(command)) { - return onLogin(session, request); - } else if ("DELE".equals(command)) { - return onDeleteEnd(session, request); - } else if ("STOR".equals(command)) { - return onUploadEnd(session, request); - } else if ("RETR".equals(command)) { - return onDownloadEnd(session, request); - } else if ("RMD".equals(command)) { - return onRmdirEnd(session, request); - } else if ("MKD".equals(command)) { - return onMkdirEnd(session, request); - } else if ("APPE".equals(command)) { - return onAppendEnd(session, request); - } else if ("STOU".equals(command)) { - return onUploadUniqueEnd(session, request); - } else if ("RNTO".equals(command)) { - return onRenameEnd(session, request); - } else { - // TODO should we call a catch all? - return null; + switch (command) { + case "PASS": + return onLogin(session, request); + + case "DELE": + return onDeleteEnd(session, request); + + case "STOR": + return onUploadEnd(session, request); + + case "RETR": + return onDownloadEnd(session, request); + + case "RMD": + return onRmdirEnd(session, request); + + case "MKD": + return onMkdirEnd(session, request); + + case "APPE": + return onAppendEnd(session, request); + + case "STOU": + return onUploadUniqueEnd(session, request); + + case "RNTO": + return onRenameEnd(session, request); + + default: + // TODO should we call a catch all? + return null; + } } /** * Override this method to intercept user logins + * * @param session The current {@link FtpSession} * @param request The current {@link FtpRequest} * @return The action for the container to take - * @throws FtpException - * @throws IOException + * @throws FtpException If a FTP error occurred + * @throws IOException If an IO error occurred */ - public FtpletResult onLogin(FtpSession session, FtpRequest request) - throws FtpException, IOException { + public FtpletResult onLogin(FtpSession session, FtpRequest request) throws FtpException, IOException { return null; } /** * Override this method to intercept deletions + * * @param session The current {@link FtpSession} * @param request The current {@link FtpRequest} * @return The action for the container to take - * @throws FtpException - * @throws IOException + * @throws FtpException If a FTP error occurred + * @throws IOException If an IO error occurred */ - public FtpletResult onDeleteStart(FtpSession session, FtpRequest request) - throws FtpException, IOException { + public FtpletResult onDeleteStart(FtpSession session, FtpRequest request) throws FtpException, IOException { return null; } /** * Override this method to handle deletions after completion + * * @param session The current {@link FtpSession} * @param request The current {@link FtpRequest} * @return The action for the container to take - * @throws FtpException - * @throws IOException + * @throws FtpException If a FTP error occurred + * @throws IOException If an IO error occurred */ - public FtpletResult onDeleteEnd(FtpSession session, FtpRequest request) - throws FtpException, IOException { + public FtpletResult onDeleteEnd(FtpSession session, FtpRequest request) throws FtpException, IOException { return null; } /** * Override this method to intercept uploads + * * @param session The current {@link FtpSession} * @param request The current {@link FtpRequest} * @return The action for the container to take - * @throws FtpException - * @throws IOException + * @throws FtpException If a FTP error occurred + * @throws IOException If an IO error occurred */ - public FtpletResult onUploadStart(FtpSession session, FtpRequest request) - throws FtpException, IOException { + public FtpletResult onUploadStart(FtpSession session, FtpRequest request) throws FtpException, IOException { return null; } /** * Override this method to handle uploads after completion + * * @param session The current {@link FtpSession} * @param request The current {@link FtpRequest} * @return The action for the container to take - * @throws FtpException - * @throws IOException + * @throws FtpException If a FTP error occurred + * @throws IOException If an IO error occurred */ - public FtpletResult onUploadEnd(FtpSession session, FtpRequest request) - throws FtpException, IOException { + public FtpletResult onUploadEnd(FtpSession session, FtpRequest request) throws FtpException, IOException { return null; } /** * Override this method to intercept downloads + * * @param session The current {@link FtpSession} * @param request The current {@link FtpRequest} * @return The action for the container to take - * @throws FtpException - * @throws IOException + * @throws FtpException If a FTP error occurred + * @throws IOException If an IO error occurred */ - public FtpletResult onDownloadStart(FtpSession session, FtpRequest request) - throws FtpException, IOException { + public FtpletResult onDownloadStart(FtpSession session, FtpRequest request) throws FtpException, IOException { return null; } /** * Override this method to handle downloads after completion + * * @param session The current {@link FtpSession} * @param request The current {@link FtpRequest} * @return The action for the container to take - * @throws FtpException - * @throws IOException + * @throws FtpException If a FTP error occurred + * @throws IOException If an IO error occurred */ - public FtpletResult onDownloadEnd(FtpSession session, FtpRequest request) - throws FtpException, IOException { + public FtpletResult onDownloadEnd(FtpSession session, FtpRequest request) throws FtpException, IOException { return null; } /** * Override this method to intercept deletion of directories + * * @param session The current {@link FtpSession} * @param request The current {@link FtpRequest} * @return The action for the container to take - * @throws FtpException - * @throws IOException + * @throws FtpException If a FTP error occurred + * @throws IOException If an IO error occurred */ - public FtpletResult onRmdirStart(FtpSession session, FtpRequest request) - throws FtpException, IOException { + public FtpletResult onRmdirStart(FtpSession session, FtpRequest request) throws FtpException, IOException { return null; } /** * Override this method to handle deletion of directories after completion + * * @param session The current {@link FtpSession} * @param request The current {@link FtpRequest} * @return The action for the container to take - * @throws FtpException - * @throws IOException + * @throws FtpException If a FTP error occurred + * @throws IOException If an IO error occurred */ - public FtpletResult onRmdirEnd(FtpSession session, FtpRequest request) - throws FtpException, IOException { + public FtpletResult onRmdirEnd(FtpSession session, FtpRequest request) throws FtpException, IOException { return null; } /** * Override this method to intercept creation of directories + * * @param session The current {@link FtpSession} * @param request The current {@link FtpRequest} * @return The action for the container to take - * @throws FtpException - * @throws IOException + * @throws FtpException If a FTP error occurred + * @throws IOException If an IO error occurred */ - public FtpletResult onMkdirStart(FtpSession session, FtpRequest request) - throws FtpException, IOException { + public FtpletResult onMkdirStart(FtpSession session, FtpRequest request) throws FtpException, IOException { return null; } /** * Override this method to handle creation of directories after completion + * * @param session The current {@link FtpSession} * @param request The current {@link FtpRequest} * @return The action for the container to take - * @throws FtpException - * @throws IOException + * @throws FtpException If a FTP error occurred + * @throws IOException If an IO error occurred */ - public FtpletResult onMkdirEnd(FtpSession session, FtpRequest request) - throws FtpException, IOException { + public FtpletResult onMkdirEnd(FtpSession session, FtpRequest request) throws FtpException, IOException { return null; } /** * Override this method to intercept file appends + * * @param session The current {@link FtpSession} * @param request The current {@link FtpRequest} * @return The action for the container to take - * @throws FtpException - * @throws IOException + * @throws FtpException If a FTP error occurred + * @throws IOException If an IO error occurred */ - public FtpletResult onAppendStart(FtpSession session, FtpRequest request) - throws FtpException, IOException { + public FtpletResult onAppendStart(FtpSession session, FtpRequest request) throws FtpException, IOException { return null; } /** * Override this method to intercept file appends after completion + * * @param session The current {@link FtpSession} * @param request The current {@link FtpRequest} * @return The action for the container to take - * @throws FtpException - * @throws IOException + * @throws FtpException If a FTP error occurred + * @throws IOException If an IO error occurred */ - public FtpletResult onAppendEnd(FtpSession session, FtpRequest request) - throws FtpException, IOException { + public FtpletResult onAppendEnd(FtpSession session, FtpRequest request) throws FtpException, IOException { return null; } /** * Override this method to intercept unique uploads + * * @param session The current {@link FtpSession} * @param request The current {@link FtpRequest} * @return The action for the container to take - * @throws FtpException - * @throws IOException + * @throws FtpException If a FTP error occurred + * @throws IOException If an IO error occurred */ - public FtpletResult onUploadUniqueStart(FtpSession session, - FtpRequest request) throws FtpException, IOException { + public FtpletResult onUploadUniqueStart(FtpSession session, FtpRequest request) throws FtpException, IOException { return null; } /** * Override this method to handle unique uploads after completion + * * @param session The current {@link FtpSession} * @param request The current {@link FtpRequest} * @return The action for the container to take - * @throws FtpException - * @throws IOException + * @throws FtpException If a FTP error occurred + * @throws IOException If an IO error occurred */ - public FtpletResult onUploadUniqueEnd(FtpSession session, FtpRequest request) - throws FtpException, IOException { + public FtpletResult onUploadUniqueEnd(FtpSession session, FtpRequest request) throws FtpException, IOException { return null; } /** * Override this method to intercept renames + * * @param session The current {@link FtpSession} * @param request The current {@link FtpRequest} * @return The action for the container to take - * @throws FtpException - * @throws IOException + * @throws FtpException If a FTP error occurred + * @throws IOException If an IO error occurred */ - public FtpletResult onRenameStart(FtpSession session, FtpRequest request) - throws FtpException, IOException { + public FtpletResult onRenameStart(FtpSession session, FtpRequest request) throws FtpException, IOException { return null; } /** * Override this method to handle renames after completion + * * @param session The current {@link FtpSession} * @param request The current {@link FtpRequest} * @return The action for the container to take - * @throws FtpException - * @throws IOException + * @throws FtpException If a FTP error occurred + * @throws IOException If an IO error occurred */ - public FtpletResult onRenameEnd(FtpSession session, FtpRequest request) - throws FtpException, IOException { + public FtpletResult onRenameEnd(FtpSession session, FtpRequest request) throws FtpException, IOException { return null; } /** * Override this method to intercept SITE commands + * * @param session The current {@link FtpSession} * @param request The current {@link FtpRequest} * @return The action for the container to take - * @throws FtpException - * @throws IOException + * @throws FtpException If a FTP error occurred + * @throws IOException If an IO error occurred */ - public FtpletResult onSite(FtpSession session, FtpRequest request) - throws FtpException, IOException { + public FtpletResult onSite(FtpSession session, FtpRequest request) throws FtpException, IOException { return null; } } diff --git a/ftplet-api/src/main/java/org/apache/ftpserver/ftplet/FileSystemFactory.java b/ftplet-api/src/main/java/org/apache/ftpserver/ftplet/FileSystemFactory.java index 314df4c2..3142876d 100644 --- a/ftplet-api/src/main/java/org/apache/ftpserver/ftplet/FileSystemFactory.java +++ b/ftplet-api/src/main/java/org/apache/ftpserver/ftplet/FileSystemFactory.java @@ -25,12 +25,12 @@ package org.apache.ftpserver.ftplet; * @author <a href="http://mina.apache.org">Apache MINA Project</a> */ public interface FileSystemFactory { - /** * Create user specific file system view. + * * @param user The user for which the file system should be created * @return The current {@link FileSystemView} for the provided user - * @throws FtpException + * @throws FtpException If a FTP error is thrown while creating the File System view */ FileSystemView createFileSystemView(User user) throws FtpException; } diff --git a/ftplet-api/src/main/java/org/apache/ftpserver/ftplet/FileSystemView.java b/ftplet-api/src/main/java/org/apache/ftpserver/ftplet/FileSystemView.java index 3796dfde..1a3e705a 100644 --- a/ftplet-api/src/main/java/org/apache/ftpserver/ftplet/FileSystemView.java +++ b/ftplet-api/src/main/java/org/apache/ftpserver/ftplet/FileSystemView.java @@ -25,41 +25,45 @@ package org.apache.ftpserver.ftplet; * @author <a href="http://mina.apache.org">Apache MINA Project</a> */ public interface FileSystemView { - /** * Get the user home directory. + * * @return The {@link FtpFile} for the users home directory - * @throws FtpException + * @throws FtpException When the Home Directory can't be retrieved */ FtpFile getHomeDirectory() throws FtpException; /** * Get user current directory. + * * @return The {@link FtpFile} for the users current directory - * @throws FtpException + * @throws FtpException When the working Directory can't be retrieved */ FtpFile getWorkingDirectory() throws FtpException; /** * Change directory. + * * @param dir The path of the directory to set as the current directory for the user * @return true if successful - * @throws FtpException + * @throws FtpException When the change to Home Directory can't be done */ boolean changeWorkingDirectory(String dir) throws FtpException; /** * Get file object. + * * @param file The path to the file to get * @return The {@link FtpFile} for the provided path - * @throws FtpException + * @throws FtpException When the file can't be retrieved */ FtpFile getFile(String file) throws FtpException; /** * Does the file system support random file access? + * * @return true if the file supports random access - * @throws FtpException + * @throws FtpException When random file access isn't supported */ boolean isRandomAccessible() throws FtpException;
