You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by ng...@apache.org on 2008/08/17 21:52:49 UTC
svn commit: r686637 [5/16] - in /mina/ftpserver/trunk:
core/src/main/java/org/apache/ftpserver/
core/src/main/java/org/apache/ftpserver/command/
core/src/main/java/org/apache/ftpserver/config/spring/
core/src/main/java/org/apache/ftpserver/filesystem/ ...
Modified: mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/SITE_WHO.java
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/SITE_WHO.java?rev=686637&r1=686636&r2=686637&view=diff
==============================================================================
--- mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/SITE_WHO.java (original)
+++ mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/SITE_WHO.java Sun Aug 17 12:52:42 2008
@@ -15,7 +15,7 @@
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
- */
+ */
package org.apache.ftpserver.command;
@@ -37,58 +37,67 @@
import org.apache.ftpserver.util.StringUtils;
import org.apache.mina.core.session.IoSession;
-
/**
* Sends the list of all the connected users.
+ *
+ * @author The Apache MINA Project (dev@mina.apache.org)
+ * @version $Rev$, $Date$
*/
-public
-class SITE_WHO extends AbstractCommand {
-
+public class SITE_WHO extends AbstractCommand {
+
/**
* Execute command.
*/
public void execute(final FtpIoSession session,
- final FtpServerContext context,
- final FtpRequest request) throws IOException, FtpException {
-
+ final FtpServerContext context, final FtpRequest request)
+ throws IOException, FtpException {
+
// reset state variables
session.resetState();
-
+
// only administrator can execute this
- UserManager userManager = context.getUserManager();
+ UserManager userManager = context.getUserManager();
boolean isAdmin = userManager.isAdmin(session.getUser().getName());
- if(!isAdmin) {
- session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_530_NOT_LOGGED_IN, "SITE", null));
+ if (!isAdmin) {
+ session.write(FtpReplyUtil.translate(session, request, context,
+ FtpReply.REPLY_530_NOT_LOGGED_IN, "SITE", null));
return;
}
-
+
// print all the connected user information
StringBuffer sb = new StringBuffer();
- Map<Long,IoSession> sessions = session.getService().getManagedSessions();
-
+ Map<Long, IoSession> sessions = session.getService()
+ .getManagedSessions();
+
sb.append('\n');
Iterator<IoSession> sessionIterator = sessions.values().iterator();
-
- while(sessionIterator.hasNext()) {
- FtpIoSession managedSession = new FtpIoSession(sessionIterator.next(), context);
- if(!managedSession.isLoggedIn()) {
+ while (sessionIterator.hasNext()) {
+ FtpIoSession managedSession = new FtpIoSession(sessionIterator
+ .next(), context);
+
+ if (!managedSession.isLoggedIn()) {
continue;
}
-
+
User tmpUsr = managedSession.getUser();
- sb.append( StringUtils.pad(tmpUsr.getName(), ' ', true, 16) );
-
- if(managedSession.getRemoteAddress() instanceof InetSocketAddress) {
- sb.append( StringUtils.pad(((InetSocketAddress)managedSession.getRemoteAddress()).getAddress().getHostAddress(), ' ', true, 16) );
+ sb.append(StringUtils.pad(tmpUsr.getName(), ' ', true, 16));
+
+ if (managedSession.getRemoteAddress() instanceof InetSocketAddress) {
+ sb.append(StringUtils.pad(((InetSocketAddress) managedSession
+ .getRemoteAddress()).getAddress().getHostAddress(),
+ ' ', true, 16));
}
- sb.append( StringUtils.pad(DateUtils.getISO8601Date(managedSession.getLoginTime().getTime()), ' ', true, 20) );
- sb.append( StringUtils.pad(DateUtils.getISO8601Date(managedSession.getLastAccessTime().getTime()), ' ', true, 20) );
+ sb.append(StringUtils.pad(DateUtils.getISO8601Date(managedSession
+ .getLoginTime().getTime()), ' ', true, 20));
+ sb.append(StringUtils.pad(DateUtils.getISO8601Date(managedSession
+ .getLastAccessTime().getTime()), ' ', true, 20));
sb.append('\n');
}
sb.append('\n');
- session.write(new DefaultFtpReply(FtpReply.REPLY_200_COMMAND_OKAY, sb.toString()));
+ session.write(new DefaultFtpReply(FtpReply.REPLY_200_COMMAND_OKAY, sb
+ .toString()));
}
}
Modified: mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/SITE_ZONE.java
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/SITE_ZONE.java?rev=686637&r1=686636&r2=686637&view=diff
==============================================================================
--- mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/SITE_ZONE.java (original)
+++ mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/SITE_ZONE.java Sun Aug 17 12:52:42 2008
@@ -15,7 +15,7 @@
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
- */
+ */
package org.apache.ftpserver.command;
@@ -32,24 +32,28 @@
/**
* Displays the FTP server timezone in RFC 822 format.
+ *
+ * @author The Apache MINA Project (dev@mina.apache.org)
+ * @version $Rev$, $Date$
*/
-public
-class SITE_ZONE extends AbstractCommand {
+public class SITE_ZONE extends AbstractCommand {
- private final static SimpleDateFormat TIMEZONE_FMT = new SimpleDateFormat("Z");
+ private final static SimpleDateFormat TIMEZONE_FMT = new SimpleDateFormat(
+ "Z");
/**
* Execute command.
*/
public void execute(final FtpIoSession session,
- final FtpServerContext context,
- final FtpRequest request) throws IOException, FtpException {
-
+ final FtpServerContext context, final FtpRequest request)
+ throws IOException, FtpException {
+
// reset state variables
session.resetState();
-
+
// send timezone data
String timezone = TIMEZONE_FMT.format(new Date());
- session.write(new DefaultFtpReply(FtpReply.REPLY_200_COMMAND_OKAY, timezone));
+ session.write(new DefaultFtpReply(FtpReply.REPLY_200_COMMAND_OKAY,
+ timezone));
}
}
Modified: mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/SIZE.java
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/SIZE.java?rev=686637&r1=686636&r2=686637&view=diff
==============================================================================
--- mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/SIZE.java (original)
+++ mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/SIZE.java Sun Aug 17 12:52:42 2008
@@ -15,7 +15,7 @@
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
- */
+ */
package org.apache.ftpserver.command;
@@ -33,56 +33,64 @@
/**
* <code>SIZE <SP> <pathname> <CRLF></code><br>
- *
+ *
* Returns the size of the file in bytes.
+ *
+ * @author The Apache MINA Project (dev@mina.apache.org)
+ * @version $Rev$, $Date$
*/
-public
-class SIZE extends AbstractCommand {
-
+public class SIZE extends AbstractCommand {
+
private final Logger LOG = LoggerFactory.getLogger(SIZE.class);
-
+
/**
* Execute command.
*/
public void execute(final FtpIoSession session,
- final FtpServerContext context,
- final FtpRequest request) throws IOException, FtpException {
-
+ final FtpServerContext context, final FtpRequest request)
+ throws IOException, FtpException {
+
// reset state variables
session.resetState();
-
+
// argument check
String fileName = request.getArgument();
- if(fileName == null) {
- session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_501_SYNTAX_ERROR_IN_PARAMETERS_OR_ARGUMENTS, "SIZE", null));
- return;
+ if (fileName == null) {
+ session.write(FtpReplyUtil.translate(session, request, context,
+ FtpReply.REPLY_501_SYNTAX_ERROR_IN_PARAMETERS_OR_ARGUMENTS,
+ "SIZE", null));
+ return;
}
-
+
// get file object
FileObject file = null;
try {
file = session.getFileSystemView().getFileObject(fileName);
- }
- catch(Exception ex) {
+ } catch (Exception ex) {
LOG.debug("Exception getting file object", ex);
}
- if(file == null) {
- session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_550_REQUESTED_ACTION_NOT_TAKEN, "SIZE.missing", fileName));
+ if (file == null) {
+ session.write(FtpReplyUtil.translate(session, request, context,
+ FtpReply.REPLY_550_REQUESTED_ACTION_NOT_TAKEN,
+ "SIZE.missing", fileName));
return;
}
-
+
// print file size
fileName = file.getFullName();
- if(!file.doesExist()) {
- session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_550_REQUESTED_ACTION_NOT_TAKEN, "SIZE.missing", fileName));
- }
- else if(!file.isFile()) {
- session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_550_REQUESTED_ACTION_NOT_TAKEN, "SIZE.invalid", fileName));
- }
- else {
- String fileLen = String.valueOf(file.getSize());
- session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_213_FILE_STATUS, "SIZE", fileLen));
+ if (!file.doesExist()) {
+ session.write(FtpReplyUtil.translate(session, request, context,
+ FtpReply.REPLY_550_REQUESTED_ACTION_NOT_TAKEN,
+ "SIZE.missing", fileName));
+ } else if (!file.isFile()) {
+ session.write(FtpReplyUtil.translate(session, request, context,
+ FtpReply.REPLY_550_REQUESTED_ACTION_NOT_TAKEN,
+ "SIZE.invalid", fileName));
+ } else {
+ String fileLen = String.valueOf(file.getSize());
+ session.write(FtpReplyUtil.translate(session, request, context,
+ FtpReply.REPLY_213_FILE_STATUS, "SIZE", fileLen));
}
- }
+ }
}
Modified: mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/STAT.java
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/STAT.java?rev=686637&r1=686636&r2=686637&view=diff
==============================================================================
--- mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/STAT.java (original)
+++ mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/STAT.java Sun Aug 17 12:52:42 2008
@@ -15,7 +15,7 @@
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
- */
+ */
package org.apache.ftpserver.command;
@@ -29,25 +29,28 @@
/**
* <code>STAT [<SP> <pathname>] <CRLF></code><br>
+ *
+ * This command shall cause a status response to be sent over the control
+ * connection in the form of a reply.
*
- * This command shall cause a status response to be sent over
- * the control connection in the form of a reply.
+ * @author The Apache MINA Project (dev@mina.apache.org)
+ * @version $Rev$, $Date$
*/
-public
-class STAT extends AbstractCommand {
+public class STAT extends AbstractCommand {
/**
* Execute command
*/
- public void execute(final FtpIoSession session,
- final FtpServerContext context,
- final FtpRequest request) throws IOException {
-
+ public void execute(final FtpIoSession session,
+ final FtpServerContext context, final FtpRequest request)
+ throws IOException {
+
// reset state variables
session.resetState();
-
+
// write the status info
- session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_211_SYSTEM_STATUS_REPLY, "STAT", null));
+ session.write(FtpReplyUtil.translate(session, request, context,
+ FtpReply.REPLY_211_SYSTEM_STATUS_REPLY, "STAT", null));
}
-
+
}
Modified: mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/STOR.java
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/STOR.java?rev=686637&r1=686636&r2=686637&view=diff
==============================================================================
--- mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/STOR.java (original)
+++ mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/STOR.java Sun Aug 17 12:52:42 2008
@@ -15,7 +15,7 @@
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
- */
+ */
package org.apache.ftpserver.command;
@@ -42,117 +42,144 @@
/**
* <code>STOR <SP> <pathname> <CRLF></code><br>
+ *
+ * This command causes the server-DTP to accept the data transferred via the
+ * data connection and to store the data as a file at the server site. If the
+ * file specified in the pathname exists at the server site, then its contents
+ * shall be replaced by the data being transferred. A new file is created at the
+ * server site if the file specified in the pathname does not already exist.
*
- * This command causes the server-DTP to accept the data
- * transferred via the data connection and to store the data as
- * a file at the server site. If the file specified in the
- * pathname exists at the server site, then its contents shall
- * be replaced by the data being transferred. A new file is
- * created at the server site if the file specified in the
- * pathname does not already exist.
+ * @author The Apache MINA Project (dev@mina.apache.org)
+ * @version $Rev$, $Date$
*/
-public
-class STOR extends AbstractCommand {
-
+public class STOR extends AbstractCommand {
+
private final Logger LOG = LoggerFactory.getLogger(STOR.class);
/**
* Execute command.
*/
- public void execute(final FtpIoSession session,
- final FtpServerContext context,
- final FtpRequest request) throws IOException, FtpException {
-
+ public void execute(final FtpIoSession session,
+ final FtpServerContext context, final FtpRequest request)
+ throws IOException, FtpException {
+
try {
-
+
// get state variable
long skipLen = session.getFileOffset();
-
+
// argument check
String fileName = request.getArgument();
- if(fileName == null) {
- session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_501_SYNTAX_ERROR_IN_PARAMETERS_OR_ARGUMENTS, "STOR", null));
- return;
+ if (fileName == null) {
+ session
+ .write(FtpReplyUtil
+ .translate(
+ session,
+ request,
+ context,
+ FtpReply.REPLY_501_SYNTAX_ERROR_IN_PARAMETERS_OR_ARGUMENTS,
+ "STOR", null));
+ return;
}
- // 24-10-2007 - added check if PORT or PASV is issued, see https://issues.apache.org/jira/browse/FTPSERVER-110
+ // 24-10-2007 - added check if PORT or PASV is issued, see
+ // https://issues.apache.org/jira/browse/FTPSERVER-110
DataConnectionFactory connFactory = session.getDataConnection();
if (connFactory instanceof IODataConnectionFactory) {
- InetAddress address = ((IODataConnectionFactory)connFactory).getInetAddress();
+ InetAddress address = ((IODataConnectionFactory) connFactory)
+ .getInetAddress();
if (address == null) {
- session.write(new DefaultFtpReply(FtpReply.REPLY_503_BAD_SEQUENCE_OF_COMMANDS, "PORT or PASV must be issued first"));
+ session.write(new DefaultFtpReply(
+ FtpReply.REPLY_503_BAD_SEQUENCE_OF_COMMANDS,
+ "PORT or PASV must be issued first"));
return;
}
}
-
+
// get filename
FileObject file = null;
try {
file = session.getFileSystemView().getFileObject(fileName);
- }
- catch(Exception ex) {
+ } catch (Exception ex) {
LOG.debug("Exception getting file object", ex);
}
- if(file == null) {
- session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_550_REQUESTED_ACTION_NOT_TAKEN, "STOR.invalid", fileName));
+ if (file == null) {
+ session.write(FtpReplyUtil.translate(session, request, context,
+ FtpReply.REPLY_550_REQUESTED_ACTION_NOT_TAKEN,
+ "STOR.invalid", fileName));
return;
}
fileName = file.getFullName();
-
+
// get permission
- if( !file.hasWritePermission() ) {
- session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_550_REQUESTED_ACTION_NOT_TAKEN, "STOR.permission", fileName));
+ if (!file.hasWritePermission()) {
+ session.write(FtpReplyUtil.translate(session, request, context,
+ FtpReply.REPLY_550_REQUESTED_ACTION_NOT_TAKEN,
+ "STOR.permission", fileName));
return;
}
-
+
// get data connection
- session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_150_FILE_STATUS_OKAY, "STOR", fileName)).awaitUninterruptibly(10000);
-
+ session.write(
+ FtpReplyUtil.translate(session, request, context,
+ FtpReply.REPLY_150_FILE_STATUS_OKAY, "STOR",
+ fileName)).awaitUninterruptibly(10000);
+
DataConnection dataConnection;
try {
dataConnection = session.getDataConnection().openConnection();
} catch (Exception e) {
LOG.debug("Exception getting the input data stream", e);
- session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_425_CANT_OPEN_DATA_CONNECTION, "STOR", fileName));
+ session.write(FtpReplyUtil.translate(session, request, context,
+ FtpReply.REPLY_425_CANT_OPEN_DATA_CONNECTION, "STOR",
+ fileName));
return;
}
-
+
// transfer data
boolean failure = false;
OutputStream outStream = null;
try {
outStream = file.createOutputStream(skipLen);
long transSz = dataConnection.transferFromClient(outStream);
-
+
// log message
String userName = session.getUser().getName();
LOG.info("File upload : " + userName + " - " + fileName);
-
+
// notify the statistics component
- ServerFtpStatistics ftpStat = (ServerFtpStatistics)context.getFtpStatistics();
+ ServerFtpStatistics ftpStat = (ServerFtpStatistics) context
+ .getFtpStatistics();
ftpStat.setUpload(session, file, transSz);
- }
- catch(SocketException ex) {
+ } catch (SocketException ex) {
LOG.debug("Socket exception during data transfer", ex);
failure = true;
- session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_426_CONNECTION_CLOSED_TRANSFER_ABORTED, "STOR", fileName));
- }
- catch(IOException ex) {
+ session.write(FtpReplyUtil.translate(session, request, context,
+ FtpReply.REPLY_426_CONNECTION_CLOSED_TRANSFER_ABORTED,
+ "STOR", fileName));
+ } catch (IOException ex) {
LOG.debug("IOException during data transfer", ex);
failure = true;
- session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_551_REQUESTED_ACTION_ABORTED_PAGE_TYPE_UNKNOWN, "STOR", fileName));
- }
- finally {
+ session
+ .write(FtpReplyUtil
+ .translate(
+ session,
+ request,
+ context,
+ FtpReply.REPLY_551_REQUESTED_ACTION_ABORTED_PAGE_TYPE_UNKNOWN,
+ "STOR", fileName));
+ } finally {
IoUtils.close(outStream);
}
-
+
// if data transfer ok - send transfer complete message
- if(!failure) {
- session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_226_CLOSING_DATA_CONNECTION, "STOR", fileName));
-
+ if (!failure) {
+ session.write(FtpReplyUtil.translate(session, request, context,
+ FtpReply.REPLY_226_CLOSING_DATA_CONNECTION, "STOR",
+ fileName));
+
}
- }
- finally {
+ } finally {
session.resetState();
session.getDataConnection().closeDataConnection();
}
Modified: mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/STOU.java
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/STOU.java?rev=686637&r1=686636&r2=686637&view=diff
==============================================================================
--- mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/STOU.java (original)
+++ mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/STOU.java Sun Aug 17 12:52:42 2008
@@ -15,7 +15,7 @@
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
- */
+ */
package org.apache.ftpserver.command;
@@ -43,145 +43,169 @@
/**
* <code>STOU <CRLF></code><br>
+ *
+ * This command behaves like STOR except that the resultant file is to be
+ * created in the current directory under a name unique to that directory. The
+ * 150 Transfer Started response must include the name generated, See RFC1123
+ * section 4.1.2.9
*
- * This command behaves like STOR except that the resultant
- * file is to be created in the current directory under a name
- * unique to that directory. The 150 Transfer Started response
- * must include the name generated, See RFC1123 section 4.1.2.9
+ * @author The Apache MINA Project (dev@mina.apache.org)
+ * @version $Rev$, $Date$
*/
-public
-class STOU extends AbstractCommand {
+public class STOU extends AbstractCommand {
private final Logger LOG = LoggerFactory.getLogger(STOU.class);
/**
* Execute command.
*/
- public void execute(final FtpIoSession session,
- final FtpServerContext context,
- final FtpRequest request) throws IOException, FtpException {
-
+ public void execute(final FtpIoSession session,
+ final FtpServerContext context, final FtpRequest request)
+ throws IOException, FtpException {
+
try {
- // 24-10-2007 - added check if PORT or PASV is issued, see https://issues.apache.org/jira/browse/FTPSERVER-110
+ // 24-10-2007 - added check if PORT or PASV is issued, see
+ // https://issues.apache.org/jira/browse/FTPSERVER-110
DataConnectionFactory connFactory = session.getDataConnection();
if (connFactory instanceof IODataConnectionFactory) {
- InetAddress address = ((IODataConnectionFactory)connFactory).getInetAddress();
+ InetAddress address = ((IODataConnectionFactory) connFactory)
+ .getInetAddress();
if (address == null) {
- session.write(new DefaultFtpReply(FtpReply.REPLY_503_BAD_SEQUENCE_OF_COMMANDS, "PORT or PASV must be issued first"));
+ session.write(new DefaultFtpReply(
+ FtpReply.REPLY_503_BAD_SEQUENCE_OF_COMMANDS,
+ "PORT or PASV must be issued first"));
return;
}
}
-
+
// reset state variables
session.resetState();
-
+
String pathName = request.getArgument();
-
+
// get filenames
FileObject file = null;
try {
- String filePrefix;
- if(pathName == null) {
- filePrefix = "ftp.dat";
- } else {
- FileObject dir = session.getFileSystemView().getFileObject(pathName);
- if(dir.isDirectory()) {
- filePrefix = pathName + "/ftp.dat";
- } else {
- filePrefix = pathName;
- }
- }
-
+ String filePrefix;
+ if (pathName == null) {
+ filePrefix = "ftp.dat";
+ } else {
+ FileObject dir = session.getFileSystemView().getFileObject(
+ pathName);
+ if (dir.isDirectory()) {
+ filePrefix = pathName + "/ftp.dat";
+ } else {
+ filePrefix = pathName;
+ }
+ }
+
file = session.getFileSystemView().getFileObject(filePrefix);
- if(file != null) {
+ if (file != null) {
file = getUniqueFile(session, file);
}
- }
- catch(Exception ex) {
+ } catch (Exception ex) {
LOG.debug("Exception getting file object", ex);
}
-
- if(file == null) {
- session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_550_REQUESTED_ACTION_NOT_TAKEN, "STOU", null));
+
+ if (file == null) {
+ session.write(FtpReplyUtil.translate(session, request, context,
+ FtpReply.REPLY_550_REQUESTED_ACTION_NOT_TAKEN, "STOU",
+ null));
return;
}
String fileName = file.getFullName();
-
+
// check permission
- if(!file.hasWritePermission()) {
- session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_550_REQUESTED_ACTION_NOT_TAKEN, "STOU.permission", fileName));
+ if (!file.hasWritePermission()) {
+ session.write(FtpReplyUtil.translate(session, request, context,
+ FtpReply.REPLY_550_REQUESTED_ACTION_NOT_TAKEN,
+ "STOU.permission", fileName));
return;
}
-
+
// get data connection
- session.write(new DefaultFtpReply(FtpReply.REPLY_150_FILE_STATUS_OKAY, "FILE: " + fileName));
+ session.write(new DefaultFtpReply(
+ FtpReply.REPLY_150_FILE_STATUS_OKAY, "FILE: " + fileName));
// get data from client
boolean failure = false;
OutputStream os = null;
-
+
DataConnection dataConnection;
try {
dataConnection = session.getDataConnection().openConnection();
} catch (Exception e) {
LOG.debug("Exception getting the input data stream", e);
- session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_425_CANT_OPEN_DATA_CONNECTION, "STOU", fileName));
+ session.write(FtpReplyUtil.translate(session, request, context,
+ FtpReply.REPLY_425_CANT_OPEN_DATA_CONNECTION, "STOU",
+ fileName));
return;
}
-
+
try {
-
+
// open streams
os = file.createOutputStream(0L);
// transfer data
long transSz = dataConnection.transferFromClient(os);
-
+
// log message
String userName = session.getUser().getName();
LOG.info("File upload : " + userName + " - " + fileName);
-
+
// notify the statistics component
- ServerFtpStatistics ftpStat = (ServerFtpStatistics)context.getFtpStatistics();
- if(ftpStat != null) {
+ ServerFtpStatistics ftpStat = (ServerFtpStatistics) context
+ .getFtpStatistics();
+ if (ftpStat != null) {
ftpStat.setUpload(session, file, transSz);
}
- }
- catch(SocketException ex) {
+ } catch (SocketException ex) {
LOG.debug("Socket exception during data transfer", ex);
failure = true;
- session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_426_CONNECTION_CLOSED_TRANSFER_ABORTED, "STOU", fileName));
- }
- catch(IOException ex) {
+ session.write(FtpReplyUtil.translate(session, request, context,
+ FtpReply.REPLY_426_CONNECTION_CLOSED_TRANSFER_ABORTED,
+ "STOU", fileName));
+ } catch (IOException ex) {
LOG.debug("IOException during data transfer", ex);
failure = true;
- session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_551_REQUESTED_ACTION_ABORTED_PAGE_TYPE_UNKNOWN, "STOU", fileName));
- }
- finally {
+ session
+ .write(FtpReplyUtil
+ .translate(
+ session,
+ request,
+ context,
+ FtpReply.REPLY_551_REQUESTED_ACTION_ABORTED_PAGE_TYPE_UNKNOWN,
+ "STOU", fileName));
+ } finally {
IoUtils.close(os);
}
-
+
// if data transfer ok - send transfer complete message
- if(!failure) {
- session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_226_CLOSING_DATA_CONNECTION, "STOU", fileName));
-
+ if (!failure) {
+ session.write(FtpReplyUtil.translate(session, request, context,
+ FtpReply.REPLY_226_CLOSING_DATA_CONNECTION, "STOU",
+ fileName));
+
}
} finally {
session.getDataConnection().closeDataConnection();
}
-
+
}
/**
* Get unique file object.
*/
- protected FileObject getUniqueFile(FtpIoSession session, FileObject oldFile) throws FtpException {
+ protected FileObject getUniqueFile(FtpIoSession session, FileObject oldFile)
+ throws FtpException {
FileObject newFile = oldFile;
FileSystemView fsView = session.getFileSystemView();
String fileName = newFile.getFullName();
- while( newFile.doesExist() ) {
- newFile = fsView.getFileObject(fileName + '.' + System.currentTimeMillis());
- if(newFile == null) {
+ while (newFile.doesExist()) {
+ newFile = fsView.getFileObject(fileName + '.'
+ + System.currentTimeMillis());
+ if (newFile == null) {
break;
}
}
Modified: mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/STRU.java
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/STRU.java?rev=686637&r1=686636&r2=686637&view=diff
==============================================================================
--- mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/STRU.java (original)
+++ mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/STRU.java Sun Aug 17 12:52:42 2008
@@ -15,7 +15,7 @@
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
- */
+ */
package org.apache.ftpserver.command;
@@ -32,40 +32,52 @@
/**
* <code>STRU <SP> <structure-code> <CRLF></code><br>
+ *
+ * The argument is a single Telnet character code specifying file structure.
*
- * The argument is a single Telnet character code specifying
- * file structure.
+ * @author The Apache MINA Project (dev@mina.apache.org)
+ * @version $Rev$, $Date$
*/
-public
-class STRU extends AbstractCommand {
-
+public class STRU extends AbstractCommand {
+
private final Logger LOG = LoggerFactory.getLogger(STRU.class);
-
+
/**
* Execute command
*/
- public void execute(final FtpIoSession session,
- final FtpServerContext context,
- final FtpRequest request) throws IOException {
-
+ public void execute(final FtpIoSession session,
+ final FtpServerContext context, final FtpRequest request)
+ throws IOException {
+
// reset state variables
session.resetState();
-
+
// argument check
- if(!request.hasArgument()) {
- session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_501_SYNTAX_ERROR_IN_PARAMETERS_OR_ARGUMENTS, "STRU", null));
- return;
+ if (!request.hasArgument()) {
+ session.write(FtpReplyUtil.translate(session, request, context,
+ FtpReply.REPLY_501_SYNTAX_ERROR_IN_PARAMETERS_OR_ARGUMENTS,
+ "STRU", null));
+ return;
}
-
+
// set structure
char stru = request.getArgument().charAt(0);
- try {
+ try {
session.setStructure(Structure.parseArgument(stru));
- session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_200_COMMAND_OKAY, "STRU", null));
- }
- catch(IllegalArgumentException e) {
- LOG.debug("Illegal structure argument: " + request.getArgument(), e);
- session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_504_COMMAND_NOT_IMPLEMENTED_FOR_THAT_PARAMETER, "STRU", null));
+ session.write(FtpReplyUtil.translate(session, request, context,
+ FtpReply.REPLY_200_COMMAND_OKAY, "STRU", null));
+ } catch (IllegalArgumentException e) {
+ LOG
+ .debug("Illegal structure argument: "
+ + request.getArgument(), e);
+ session
+ .write(FtpReplyUtil
+ .translate(
+ session,
+ request,
+ context,
+ FtpReply.REPLY_504_COMMAND_NOT_IMPLEMENTED_FOR_THAT_PARAMETER,
+ "STRU", null));
}
}
Modified: mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/SYST.java
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/SYST.java?rev=686637&r1=686636&r2=686637&view=diff
==============================================================================
--- mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/SYST.java (original)
+++ mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/SYST.java Sun Aug 17 12:52:42 2008
@@ -15,7 +15,7 @@
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
- */
+ */
package org.apache.ftpserver.command;
@@ -28,36 +28,36 @@
import org.apache.ftpserver.util.FtpReplyUtil;
/**
- * <code>SYST <CRLF></code><br>
+ * <code>SYST <CRLF></code><br>
+ *
+ * This command is used to find out the type of operating system at the server.
*
- * This command is used to find out the type of operating
- * system at the server.
+ * @author The Apache MINA Project (dev@mina.apache.org)
+ * @version $Rev$, $Date$
*/
-public
-class SYST extends AbstractCommand {
-
-
+public class SYST extends AbstractCommand {
+
/**
* Execute command
*/
public void execute(final FtpIoSession session,
- final FtpServerContext context,
- final FtpRequest request) throws IOException {
-
+ final FtpServerContext context, final FtpRequest request)
+ throws IOException {
+
// reset state variables
session.resetState();
-
- // get server system info
+
+ // get server system info
String systemName = System.getProperty("os.name");
- if(systemName == null) {
+ if (systemName == null) {
systemName = "UNKNOWN";
- }
- else {
+ } else {
systemName = systemName.toUpperCase();
systemName = systemName.replace(' ', '-');
}
// print server system info
- session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_215_NAME_SYSTEM_TYPE, "SYST", systemName));
+ session.write(FtpReplyUtil.translate(session, request, context,
+ FtpReply.REPLY_215_NAME_SYSTEM_TYPE, "SYST", systemName));
}
}
Modified: mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/TYPE.java
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/TYPE.java?rev=686637&r1=686636&r2=686637&view=diff
==============================================================================
--- mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/TYPE.java (original)
+++ mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/TYPE.java Sun Aug 17 12:52:42 2008
@@ -15,7 +15,7 @@
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
- */
+ */
package org.apache.ftpserver.command;
@@ -32,39 +32,48 @@
/**
* <code>TYPE <SP> <type-code> <CRLF></code><br>
- *
+ *
* The argument specifies the representation type.
+ *
+ * @author The Apache MINA Project (dev@mina.apache.org)
+ * @version $Rev$, $Date$
*/
-public
-class TYPE extends AbstractCommand {
-
+public class TYPE extends AbstractCommand {
+
private final Logger LOG = LoggerFactory.getLogger(TYPE.class);
-
+
/**
* Execute command
*/
public void execute(final FtpIoSession session,
- final FtpServerContext context,
- final FtpRequest request) throws IOException {
-
+ final FtpServerContext context, final FtpRequest request)
+ throws IOException {
+
// reset state variables
session.resetState();
-
+
// get type from argument
char type = 'A';
- if (request.hasArgument()){
+ if (request.hasArgument()) {
type = request.getArgument().charAt(0);
}
-
+
// set type
try {
session.setDataType(DataType.parseArgument(type));
- session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_200_COMMAND_OKAY, "TYPE", null));
- }
- catch(IllegalArgumentException e) {
+ session.write(FtpReplyUtil.translate(session, request, context,
+ FtpReply.REPLY_200_COMMAND_OKAY, "TYPE", null));
+ } catch (IllegalArgumentException e) {
LOG.debug("Illegal type argument: " + request.getArgument(), e);
- session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_504_COMMAND_NOT_IMPLEMENTED_FOR_THAT_PARAMETER, "TYPE", null));
+ session
+ .write(FtpReplyUtil
+ .translate(
+ session,
+ request,
+ context,
+ FtpReply.REPLY_504_COMMAND_NOT_IMPLEMENTED_FOR_THAT_PARAMETER,
+ "TYPE", null));
}
}
-
+
}
Modified: mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/USER.java
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/USER.java?rev=686637&r1=686636&r2=686637&view=diff
==============================================================================
--- mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/USER.java (original)
+++ mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/USER.java Sun Aug 17 12:52:42 2008
@@ -15,7 +15,7 @@
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
- */
+ */
package org.apache.ftpserver.command;
@@ -37,109 +37,149 @@
/**
* <code>USER <SP> <username> <CRLF></code><br>
+ *
+ * The argument field is a Telnet string identifying the user. The user
+ * identification is that which is required by the server for access to its file
+ * system. This command will normally be the first command transmitted by the
+ * user after the control connections are made.
*
- * The argument field is a Telnet string identifying the user.
- * The user identification is that which is required by the
- * server for access to its file system. This command will
- * normally be the first command transmitted by the user after
- * the control connections are made.
+ * @author The Apache MINA Project (dev@mina.apache.org)
+ * @version $Rev$, $Date$
*/
-public
-class USER extends AbstractCommand {
-
+public class USER extends AbstractCommand {
+
/**
* Execute command.
*/
- public void execute(final FtpIoSession session,
- final FtpServerContext context,
- final FtpRequest request) throws IOException, FtpException {
-
+ public void execute(final FtpIoSession session,
+ final FtpServerContext context, final FtpRequest request)
+ throws IOException, FtpException {
+
boolean success = false;
- ServerFtpStatistics stat = (ServerFtpStatistics)context.getFtpStatistics();
+ ServerFtpStatistics stat = (ServerFtpStatistics) context
+ .getFtpStatistics();
try {
-
+
// reset state variables
session.resetState();
-
+
// argument check
String userName = request.getArgument();
- if(userName == null) {
- session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_501_SYNTAX_ERROR_IN_PARAMETERS_OR_ARGUMENTS, "USER", null));
- return;
+ if (userName == null) {
+ session
+ .write(FtpReplyUtil
+ .translate(
+ session,
+ request,
+ context,
+ FtpReply.REPLY_501_SYNTAX_ERROR_IN_PARAMETERS_OR_ARGUMENTS,
+ "USER", null));
+ return;
}
-
+
// Add to the MDC logging
MdcInjectionFilter.setProperty(session, "userName", userName);
-
+
// already logged-in
- BaseUser user = (BaseUser)session.getUser();
- if(session.isLoggedIn()) {
- if( userName.equals(user.getName()) ) {
- session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_230_USER_LOGGED_IN, "USER", null));
+ BaseUser user = (BaseUser) session.getUser();
+ if (session.isLoggedIn()) {
+ if (userName.equals(user.getName())) {
+ session.write(FtpReplyUtil.translate(session, request,
+ context, FtpReply.REPLY_230_USER_LOGGED_IN, "USER",
+ null));
success = true;
- }
- else {
- session.write(FtpReplyUtil.translate(session, request, context, 530, "USER.invalid", null));
+ } else {
+ session.write(FtpReplyUtil.translate(session, request,
+ context, 530, "USER.invalid", null));
}
return;
}
-
+
// anonymous login is not enabled
boolean anonymous = userName.equals("anonymous");
- if( anonymous && (!context.getConnectionConfig().isAnonymousLoginEnabled()) ) {
- session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_530_NOT_LOGGED_IN, "USER.anonymous", null));
+ if (anonymous
+ && (!context.getConnectionConfig()
+ .isAnonymousLoginEnabled())) {
+ session.write(FtpReplyUtil.translate(session, request, context,
+ FtpReply.REPLY_530_NOT_LOGGED_IN, "USER.anonymous",
+ null));
return;
}
-
+
// anonymous login limit check
int currAnonLogin = stat.getCurrentAnonymousLoginNumber();
- int maxAnonLogin = context.getConnectionConfig().getMaxAnonymousLogins();
- if( anonymous && (currAnonLogin >= maxAnonLogin) ) {
- session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_421_SERVICE_NOT_AVAILABLE_CLOSING_CONTROL_CONNECTION, "USER.anonymous", null));
+ int maxAnonLogin = context.getConnectionConfig()
+ .getMaxAnonymousLogins();
+ if (anonymous && (currAnonLogin >= maxAnonLogin)) {
+ session
+ .write(FtpReplyUtil
+ .translate(
+ session,
+ request,
+ context,
+ FtpReply.REPLY_421_SERVICE_NOT_AVAILABLE_CLOSING_CONTROL_CONNECTION,
+ "USER.anonymous", null));
return;
}
-
+
// login limit check
int currLogin = stat.getCurrentLoginNumber();
int maxLogin = context.getConnectionConfig().getMaxLogins();
- if(maxLogin != 0 && currLogin >= maxLogin) {
- session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_421_SERVICE_NOT_AVAILABLE_CLOSING_CONTROL_CONNECTION, "USER.login", null));
+ if (maxLogin != 0 && currLogin >= maxLogin) {
+ session
+ .write(FtpReplyUtil
+ .translate(
+ session,
+ request,
+ context,
+ FtpReply.REPLY_421_SERVICE_NOT_AVAILABLE_CLOSING_CONTROL_CONNECTION,
+ "USER.login", null));
return;
}
-
+
User configUser = context.getUserManager().getUserByName(userName);
- if(configUser != null){
- //user login limit check
-
- InetAddress address = null;
- if(session.getRemoteAddress() instanceof InetSocketAddress) {
- address = ((InetSocketAddress)session.getRemoteAddress()).getAddress();
- }
-
- ConcurrentLoginRequest loginRequest = new ConcurrentLoginRequest(
+ if (configUser != null) {
+ // user login limit check
+
+ InetAddress address = null;
+ if (session.getRemoteAddress() instanceof InetSocketAddress) {
+ address = ((InetSocketAddress) session.getRemoteAddress())
+ .getAddress();
+ }
+
+ ConcurrentLoginRequest loginRequest = new ConcurrentLoginRequest(
stat.getCurrentUserLoginNumber(configUser) + 1,
stat.getCurrentUserLoginNumber(configUser, address) + 1);
-
- if(configUser.authorize(loginRequest) == null) {
- session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_421_SERVICE_NOT_AVAILABLE_CLOSING_CONTROL_CONNECTION, "USER.login", null));
+
+ if (configUser.authorize(loginRequest) == null) {
+ session
+ .write(FtpReplyUtil
+ .translate(
+ session,
+ request,
+ context,
+ FtpReply.REPLY_421_SERVICE_NOT_AVAILABLE_CLOSING_CONTROL_CONNECTION,
+ "USER.login", null));
return;
}
}
-
+
// finally set the user name
success = true;
session.setUserArgument(userName);
- if(anonymous) {
- session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_331_USER_NAME_OKAY_NEED_PASSWORD, "USER.anonymous", userName));
+ if (anonymous) {
+ session.write(FtpReplyUtil.translate(session, request, context,
+ FtpReply.REPLY_331_USER_NAME_OKAY_NEED_PASSWORD,
+ "USER.anonymous", userName));
+ } else {
+ session.write(FtpReplyUtil.translate(session, request, context,
+ FtpReply.REPLY_331_USER_NAME_OKAY_NEED_PASSWORD,
+ "USER", userName));
}
- else {
- session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_331_USER_NAME_OKAY_NEED_PASSWORD, "USER", userName));
- }
- }
- finally {
+ } finally {
// if not ok - close connection
- if(!success) {
+ if (!success) {
session.closeOnFlush().awaitUninterruptibly(10000);
}
}
Modified: mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/config/spring/CommandFactoryBeanDefinitionParser.java
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/config/spring/CommandFactoryBeanDefinitionParser.java?rev=686637&r1=686636&r2=686637&view=diff
==============================================================================
--- mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/config/spring/CommandFactoryBeanDefinitionParser.java (original)
+++ mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/config/spring/CommandFactoryBeanDefinitionParser.java Sun Aug 17 12:52:42 2008
@@ -15,7 +15,7 @@
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
- */
+ */
package org.apache.ftpserver.config.spring;
@@ -31,11 +31,14 @@
import org.w3c.dom.Element;
/**
- * Parses the FtpServer "commands" element into a Spring
- * bean graph
+ * Parses the FtpServer "commands" element into a Spring bean graph
+ *
+ * @author The Apache MINA Project (dev@mina.apache.org)
+ * @version $Rev$, $Date$
*/
-public class CommandFactoryBeanDefinitionParser extends AbstractSingleBeanDefinitionParser {
-
+public class CommandFactoryBeanDefinitionParser extends
+ AbstractSingleBeanDefinitionParser {
+
/**
* {@inheritDoc}
*/
@@ -48,21 +51,25 @@
* {@inheritDoc}
*/
@Override
- protected void doParse(final Element element, final ParserContext parserContext, final BeanDefinitionBuilder builder) {
+ protected void doParse(final Element element,
+ final ParserContext parserContext,
+ final BeanDefinitionBuilder builder) {
ManagedMap commands = new ManagedMap();
-
+
List<Element> childs = SpringUtil.getChildElements(element);
- for(Element commandElm : childs) {
+ for (Element commandElm : childs) {
String name = commandElm.getAttribute("name");
- Object bean = SpringUtil.parseSpringChildElement(commandElm, parserContext, builder);
+ Object bean = SpringUtil.parseSpringChildElement(commandElm,
+ parserContext, builder);
commands.put(name, bean);
}
-
+
builder.addPropertyValue("commandMap", commands);
-
- if(StringUtils.hasText(element.getAttribute("use-default"))) {
- builder.addPropertyValue("useDefaultCommands", Boolean.parseBoolean(element.getAttribute("use-default")));
+
+ if (StringUtils.hasText(element.getAttribute("use-default"))) {
+ builder.addPropertyValue("useDefaultCommands", Boolean
+ .parseBoolean(element.getAttribute("use-default")));
}
}
}
Modified: mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/config/spring/FileSystemBeanDefinitionParser.java
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/config/spring/FileSystemBeanDefinitionParser.java?rev=686637&r1=686636&r2=686637&view=diff
==============================================================================
--- mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/config/spring/FileSystemBeanDefinitionParser.java (original)
+++ mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/config/spring/FileSystemBeanDefinitionParser.java Sun Aug 17 12:52:42 2008
@@ -15,7 +15,7 @@
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
- */
+ */
package org.apache.ftpserver.config.spring;
@@ -28,16 +28,20 @@
import org.w3c.dom.Element;
/**
- * Parses the FtpServer "native-filesystem" element into a Spring
- * bean graph
+ * Parses the FtpServer "native-filesystem" element into a Spring bean graph
+ *
+ * @author The Apache MINA Project (dev@mina.apache.org)
+ * @version $Rev$, $Date$
*/
-public class FileSystemBeanDefinitionParser extends AbstractSingleBeanDefinitionParser {
-
+public class FileSystemBeanDefinitionParser extends
+ AbstractSingleBeanDefinitionParser {
+
/**
* {@inheritDoc}
*/
@Override
- protected Class<? extends FileSystemManager> getBeanClass(final Element element) {
+ protected Class<? extends FileSystemManager> getBeanClass(
+ final Element element) {
return NativeFileSystemManager.class;
}
@@ -45,12 +49,16 @@
* {@inheritDoc}
*/
@Override
- protected void doParse(final Element element, final ParserContext parserContext, final BeanDefinitionBuilder builder) {
- if(StringUtils.hasText(element.getAttribute("case-insensitive"))) {
- builder.addPropertyValue("caseInsensitive", Boolean.parseBoolean(element.getAttribute("case-insensitive")));
+ protected void doParse(final Element element,
+ final ParserContext parserContext,
+ final BeanDefinitionBuilder builder) {
+ if (StringUtils.hasText(element.getAttribute("case-insensitive"))) {
+ builder.addPropertyValue("caseInsensitive", Boolean
+ .parseBoolean(element.getAttribute("case-insensitive")));
}
- if(StringUtils.hasText(element.getAttribute("create-home"))) {
- builder.addPropertyValue("create-home", Boolean.parseBoolean(element.getAttribute("create-home")));
+ if (StringUtils.hasText(element.getAttribute("create-home"))) {
+ builder.addPropertyValue("create-home", Boolean
+ .parseBoolean(element.getAttribute("create-home")));
}
}
}
Modified: mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/config/spring/FtpServerNamespaceHandler.java
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/config/spring/FtpServerNamespaceHandler.java?rev=686637&r1=686636&r2=686637&view=diff
==============================================================================
--- mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/config/spring/FtpServerNamespaceHandler.java (original)
+++ mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/config/spring/FtpServerNamespaceHandler.java Sun Aug 17 12:52:42 2008
@@ -15,7 +15,7 @@
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
- */
+ */
package org.apache.ftpserver.config.spring;
@@ -23,6 +23,9 @@
/**
* Registration point for FtpServer bean defintion parsers
+ *
+ * @author The Apache MINA Project (dev@mina.apache.org)
+ * @version $Rev$, $Date$
*/
public class FtpServerNamespaceHandler extends NamespaceHandlerSupport {
@@ -31,19 +34,23 @@
*/
public static final String FTPSERVER_NS = "http://mina.apache.org/ftpserver/spring/v1";
-
/**
- * Register the necessary element names with the appropriate
- * bean definition parser
+ * Register the necessary element names with the appropriate bean definition
+ * parser
*/
public FtpServerNamespaceHandler() {
- registerBeanDefinitionParser("server", new ServerBeanDefinitionParser());
- registerBeanDefinitionParser("nio-listener", new ListenerBeanDefinitionParser());
- registerBeanDefinitionParser("file-user-manager", new UserManagerBeanDefinitionParser());
- registerBeanDefinitionParser("db-user-manager", new UserManagerBeanDefinitionParser());
- registerBeanDefinitionParser("native-filesystem", new FileSystemBeanDefinitionParser());
- registerBeanDefinitionParser("commands", new CommandFactoryBeanDefinitionParser());
-
+ registerBeanDefinitionParser("server", new ServerBeanDefinitionParser());
+ registerBeanDefinitionParser("nio-listener",
+ new ListenerBeanDefinitionParser());
+ registerBeanDefinitionParser("file-user-manager",
+ new UserManagerBeanDefinitionParser());
+ registerBeanDefinitionParser("db-user-manager",
+ new UserManagerBeanDefinitionParser());
+ registerBeanDefinitionParser("native-filesystem",
+ new FileSystemBeanDefinitionParser());
+ registerBeanDefinitionParser("commands",
+ new CommandFactoryBeanDefinitionParser());
+
}
/**
Modified: mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/config/spring/ListenerBeanDefinitionParser.java
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/config/spring/ListenerBeanDefinitionParser.java?rev=686637&r1=686636&r2=686637&view=diff
==============================================================================
--- mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/config/spring/ListenerBeanDefinitionParser.java (original)
+++ mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/config/spring/ListenerBeanDefinitionParser.java Sun Aug 17 12:52:42 2008
@@ -15,7 +15,7 @@
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
- */
+ */
package org.apache.ftpserver.config.spring;
@@ -41,14 +41,17 @@
import org.w3c.dom.Element;
/**
- * Parses the FtpServer "nio-listener" element into a Spring
- * bean graph
+ * Parses the FtpServer "nio-listener" element into a Spring bean graph
+ *
+ * @author The Apache MINA Project (dev@mina.apache.org)
+ * @version $Rev$, $Date$
*/
-public class ListenerBeanDefinitionParser extends AbstractSingleBeanDefinitionParser {
+public class ListenerBeanDefinitionParser extends
+ AbstractSingleBeanDefinitionParser {
- private final Logger LOG = LoggerFactory.getLogger(ListenerBeanDefinitionParser.class);
+ private final Logger LOG = LoggerFactory
+ .getLogger(ListenerBeanDefinitionParser.class);
-
/**
* {@inheritDoc}
*/
@@ -58,216 +61,249 @@
}
/**
- * Parse CIDR notations into MINA {@link Subnet}s.
- * TODO: move to Mina
+ * Parse CIDR notations into MINA {@link Subnet}s. TODO: move to Mina
*/
private Subnet parseSubnet(final String subnet) {
- if(subnet == null) {
+ if (subnet == null) {
throw new NullPointerException("subnet can not be null");
}
-
+
String[] tokens = subnet.split("/");
String ipString;
String maskString;
- if(tokens.length == 2) {
+ if (tokens.length == 2) {
ipString = tokens[0];
maskString = tokens[1];
- } else if(tokens.length == 1) {
+ } else if (tokens.length == 1) {
ipString = tokens[0];
maskString = "32";
} else {
- throw new IllegalArgumentException("Illegal subnet format: " + subnet);
+ throw new IllegalArgumentException("Illegal subnet format: "
+ + subnet);
}
InetAddress address;
try {
address = InetAddress.getByName(ipString);
} catch (UnknownHostException e) {
- throw new IllegalArgumentException("Illegal IP address in subnet: " + subnet);
+ throw new IllegalArgumentException("Illegal IP address in subnet: "
+ + subnet);
}
-
+
int mask = Integer.parseInt(maskString);
- if(mask < 0 || mask > 32) {
+ if (mask < 0 || mask > 32) {
throw new IllegalArgumentException("Mask must be in the range 0-32");
}
-
+
return new Subnet(address, mask);
}
-
+
/**
* {@inheritDoc}
*/
@Override
- protected void doParse(final Element element, final ParserContext parserContext, final BeanDefinitionBuilder builder) {
- if(StringUtils.hasText(element.getAttribute("port"))) {
- builder.addPropertyValue("port", Integer.parseInt(element.getAttribute("port")));
+ protected void doParse(final Element element,
+ final ParserContext parserContext,
+ final BeanDefinitionBuilder builder) {
+ if (StringUtils.hasText(element.getAttribute("port"))) {
+ builder.addPropertyValue("port", Integer.parseInt(element
+ .getAttribute("port")));
}
-
+
SslConfiguration ssl = parseSsl(element);
- if(ssl != null) {
+ if (ssl != null) {
builder.addPropertyValue("sslConfiguration", ssl);
}
-
- Element dataConElm = SpringUtil.getChildElement(element, FtpServerNamespaceHandler.FTPSERVER_NS, "data-connection");
+
+ Element dataConElm = SpringUtil.getChildElement(element,
+ FtpServerNamespaceHandler.FTPSERVER_NS, "data-connection");
DataConnectionConfiguration dc = parseDataConnection(dataConElm, ssl);
builder.addPropertyValue("dataConnectionConfiguration", dc);
-
- Element blacklistElm = SpringUtil.getChildElement(element, FtpServerNamespaceHandler.FTPSERVER_NS, "blacklist");
- if(blacklistElm != null && StringUtils.hasText(blacklistElm.getTextContent())) {
+
+ Element blacklistElm = SpringUtil.getChildElement(element,
+ FtpServerNamespaceHandler.FTPSERVER_NS, "blacklist");
+ if (blacklistElm != null
+ && StringUtils.hasText(blacklistElm.getTextContent())) {
String[] blocks = blacklistElm.getTextContent().split("[\\s,]+");
List<Subnet> subnets = new ArrayList<Subnet>();
-
- for(String block : blocks) {
+
+ for (String block : blocks) {
subnets.add(parseSubnet(block));
}
-
+
builder.addPropertyValue("blockedSubnets", subnets);
}
-
- if(StringUtils.hasText(element.getAttribute("idle-timeout"))) {
- builder.addPropertyValue("idleTimeout", SpringUtil.parseInt(element, "idle-timeout", 300));
- }
- if(StringUtils.hasText(element.getAttribute("port"))) {
- builder.addPropertyValue("port", SpringUtil.parseInt(element, "port", 21));
- }
- InetAddress localAddress = SpringUtil.parseInetAddress(element, "local-address");
- if(localAddress != null) {
+
+ if (StringUtils.hasText(element.getAttribute("idle-timeout"))) {
+ builder.addPropertyValue("idleTimeout", SpringUtil.parseInt(
+ element, "idle-timeout", 300));
+ }
+ if (StringUtils.hasText(element.getAttribute("port"))) {
+ builder.addPropertyValue("port", SpringUtil.parseInt(element,
+ "port", 21));
+ }
+ InetAddress localAddress = SpringUtil.parseInetAddress(element,
+ "local-address");
+ if (localAddress != null) {
builder.addPropertyValue("serverAddress", localAddress);
}
- builder.addPropertyValue("implicitSsl", SpringUtil.parseBoolean(element, "implicit-ssl", false));
+ builder.addPropertyValue("implicitSsl", SpringUtil.parseBoolean(
+ element, "implicit-ssl", false));
}
-
-
+
private SslConfiguration parseSsl(final Element parent) {
- Element sslElm = SpringUtil.getChildElement(parent, FtpServerNamespaceHandler.FTPSERVER_NS, "ssl");
-
- if(sslElm != null) {
+ Element sslElm = SpringUtil.getChildElement(parent,
+ FtpServerNamespaceHandler.FTPSERVER_NS, "ssl");
+
+ if (sslElm != null) {
DefaultSslConfiguration ssl = new DefaultSslConfiguration();
-
- Element keyStoreElm = SpringUtil.getChildElement(sslElm, FtpServerNamespaceHandler.FTPSERVER_NS, "keystore");
- if(keyStoreElm != null) {
+
+ Element keyStoreElm = SpringUtil.getChildElement(sslElm,
+ FtpServerNamespaceHandler.FTPSERVER_NS, "keystore");
+ if (keyStoreElm != null) {
ssl.setKeystoreFile(SpringUtil.parseFile(keyStoreElm, "file"));
- ssl.setKeystorePassword(SpringUtil.parseString(keyStoreElm, "password"));
-
+ ssl.setKeystorePassword(SpringUtil.parseString(keyStoreElm,
+ "password"));
+
String type = SpringUtil.parseString(keyStoreElm, "type");
- if(type != null) {
+ if (type != null) {
ssl.setKeystoreType(type);
}
- String keyAlias = SpringUtil.parseString(keyStoreElm, "key-alias");
- if(keyAlias != null) {
+ String keyAlias = SpringUtil.parseString(keyStoreElm,
+ "key-alias");
+ if (keyAlias != null) {
ssl.setKeyAlias(keyAlias);
}
-
- String keyPassword = SpringUtil.parseString(keyStoreElm, "key-password");
- if(keyPassword != null) {
+
+ String keyPassword = SpringUtil.parseString(keyStoreElm,
+ "key-password");
+ if (keyPassword != null) {
ssl.setKeyPassword(keyPassword);
}
-
- String algorithm = SpringUtil.parseString(keyStoreElm, "algorithm");
- if(algorithm != null) {
+
+ String algorithm = SpringUtil.parseString(keyStoreElm,
+ "algorithm");
+ if (algorithm != null) {
ssl.setKeystoreAlgorithm(algorithm);
}
}
-
- Element trustStoreElm = SpringUtil.getChildElement(sslElm, FtpServerNamespaceHandler.FTPSERVER_NS, "truststore");
- if(trustStoreElm != null) {
- ssl.setTruststoreFile(SpringUtil.parseFile(trustStoreElm, "file"));
- ssl.setTruststorePassword(SpringUtil.parseString(trustStoreElm, "password"));
-
+
+ Element trustStoreElm = SpringUtil.getChildElement(sslElm,
+ FtpServerNamespaceHandler.FTPSERVER_NS, "truststore");
+ if (trustStoreElm != null) {
+ ssl.setTruststoreFile(SpringUtil.parseFile(trustStoreElm,
+ "file"));
+ ssl.setTruststorePassword(SpringUtil.parseString(trustStoreElm,
+ "password"));
+
String type = SpringUtil.parseString(trustStoreElm, "type");
- if(type != null) {
+ if (type != null) {
ssl.setTruststoreType(type);
}
-
- String algorithm = SpringUtil.parseString(trustStoreElm, "algorithm");
- if(algorithm != null) {
+
+ String algorithm = SpringUtil.parseString(trustStoreElm,
+ "algorithm");
+ if (algorithm != null) {
ssl.setTruststoreAlgorithm(algorithm);
}
}
-
- String clientAuthStr = SpringUtil.parseString(sslElm, "client-authentication");
- if(clientAuthStr != null) {
+
+ String clientAuthStr = SpringUtil.parseString(sslElm,
+ "client-authentication");
+ if (clientAuthStr != null) {
ssl.setClientAuthentication(clientAuthStr);
- }
-
- String enabledCiphersuites = SpringUtil.parseString(sslElm, "enabled-ciphersuites");
- if(enabledCiphersuites != null) {
+ }
+
+ String enabledCiphersuites = SpringUtil.parseString(sslElm,
+ "enabled-ciphersuites");
+ if (enabledCiphersuites != null) {
ssl.setEnabledCipherSuites(enabledCiphersuites.split(" "));
- }
+ }
String protocol = SpringUtil.parseString(sslElm, "protocol");
- if(protocol != null) {
+ if (protocol != null) {
ssl.setSslProtocol(protocol);
- }
+ }
-
return ssl;
} else {
return null;
}
-
-
+
}
-
- private DataConnectionConfiguration parseDataConnection(final Element element, final SslConfiguration listenerSslConfiguration) {
+
+ private DataConnectionConfiguration parseDataConnection(
+ final Element element,
+ final SslConfiguration listenerSslConfiguration) {
DefaultDataConnectionConfiguration dc = new DefaultDataConnectionConfiguration();
-
- if(element != null) {
+
+ if (element != null) {
// data con config element available
SslConfiguration ssl = parseSsl(element);
- if(ssl != null) {
+ if (ssl != null) {
LOG.debug("SSL configuration found for the data connection");
dc.setSslConfiguration(ssl);
} else {
// go look for the parent element SSL config
// find the listener element
- if(listenerSslConfiguration != null) {
- LOG.debug("SSL configuration found for the listener, falling back for that for the data connection");
+ if (listenerSslConfiguration != null) {
+ LOG
+ .debug("SSL configuration found for the listener, falling back for that for the data connection");
dc.setSslConfiguration(listenerSslConfiguration);
}
}
-
- Element activeElm = SpringUtil.getChildElement(element, FtpServerNamespaceHandler.FTPSERVER_NS, "active");
- if(activeElm != null) {
+
+ Element activeElm = SpringUtil.getChildElement(element,
+ FtpServerNamespaceHandler.FTPSERVER_NS, "active");
+ if (activeElm != null) {
Active active = new Active();
- active.setEnable(SpringUtil.parseBoolean(activeElm, "enabled", true));
- active.setIpCheck(SpringUtil.parseBoolean(activeElm, "ip-check", false));
- active.setLocalPort(SpringUtil.parseInt(activeElm, "local-port", 0));
-
- InetAddress localAddress = SpringUtil.parseInetAddress(activeElm, "local-address");
- if(localAddress != null) {
+ active.setEnable(SpringUtil.parseBoolean(activeElm, "enabled",
+ true));
+ active.setIpCheck(SpringUtil.parseBoolean(activeElm,
+ "ip-check", false));
+ active.setLocalPort(SpringUtil.parseInt(activeElm,
+ "local-port", 0));
+
+ InetAddress localAddress = SpringUtil.parseInetAddress(
+ activeElm, "local-address");
+ if (localAddress != null) {
active.setLocalAddress(localAddress);
}
-
+
dc.setActive(active);
}
-
- Element passiveElm = SpringUtil.getChildElement(element, FtpServerNamespaceHandler.FTPSERVER_NS, "passive");
- if(passiveElm != null) {
+
+ Element passiveElm = SpringUtil.getChildElement(element,
+ FtpServerNamespaceHandler.FTPSERVER_NS, "passive");
+ if (passiveElm != null) {
Passive passive = new Passive();
-
- InetAddress address = SpringUtil.parseInetAddress(passiveElm, "address");
- if(address != null) {
+
+ InetAddress address = SpringUtil.parseInetAddress(passiveElm,
+ "address");
+ if (address != null) {
passive.setAddress(address);
}
-
- InetAddress externalAddress = SpringUtil.parseInetAddress(passiveElm, "external-address");
- if(externalAddress != null) {
+
+ InetAddress externalAddress = SpringUtil.parseInetAddress(
+ passiveElm, "external-address");
+ if (externalAddress != null) {
passive.setExternalAddress(externalAddress);
}
-
+
String ports = SpringUtil.parseString(passiveElm, "ports");
- if(ports != null) {
+ if (ports != null) {
passive.setPorts(ports);
}
dc.setPassive(passive);
}
} else {
- // no data conn config element, do we still have SSL config from the parent?
- if(listenerSslConfiguration != null) {
- LOG.debug("SSL configuration found for the listener, falling back for that for the data connection");
+ // no data conn config element, do we still have SSL config from the
+ // parent?
+ if (listenerSslConfiguration != null) {
+ LOG
+ .debug("SSL configuration found for the listener, falling back for that for the data connection");
dc.setSslConfiguration(listenerSslConfiguration);
}
@@ -276,5 +312,4 @@
return dc;
}
-
}
Modified: mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/config/spring/ServerBeanDefinitionParser.java
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/config/spring/ServerBeanDefinitionParser.java?rev=686637&r1=686636&r2=686637&view=diff
==============================================================================
--- mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/config/spring/ServerBeanDefinitionParser.java (original)
+++ mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/config/spring/ServerBeanDefinitionParser.java Sun Aug 17 12:52:42 2008
@@ -15,7 +15,7 @@
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
- */
+ */
package org.apache.ftpserver.config.spring;
@@ -36,11 +36,13 @@
import org.w3c.dom.Element;
/**
- * Parses the FtpServer "server" element into a Spring
- * bean graph
+ * Parses the FtpServer "server" element into a Spring bean graph
+ *
+ * @author The Apache MINA Project (dev@mina.apache.org)
+ * @version $Rev$, $Date$
*/
-public class ServerBeanDefinitionParser extends AbstractSingleBeanDefinitionParser {
-
+public class ServerBeanDefinitionParser extends
+ AbstractSingleBeanDefinitionParser {
/**
* {@inheritDoc}
@@ -53,61 +55,80 @@
* {@inheritDoc}
*/
@Override
- protected void doParse(final Element element, final ParserContext parserContext, final BeanDefinitionBuilder builder) {
+ protected void doParse(final Element element,
+ final ParserContext parserContext,
+ final BeanDefinitionBuilder builder) {
List<Element> childs = SpringUtil.getChildElements(element);
- for(Element childElm : childs) {
+ for (Element childElm : childs) {
String childName = childElm.getLocalName();
-
- if("listeners".equals(childName)) {
+
+ if ("listeners".equals(childName)) {
Map listeners = parseListeners(childElm, parserContext, builder);
-
- if(listeners.size() > 0) {
+
+ if (listeners.size() > 0) {
builder.addPropertyValue("listeners", listeners);
}
- } else if("ftplets".equals(childName)) {
+ } else if ("ftplets".equals(childName)) {
Map ftplets = parseFtplets(childElm, parserContext, builder);
builder.addPropertyValue("ftplets", ftplets);
- } else if("file-user-manager".equals(childName) ||
- "db-user-manager".equals(childName)) {
- Object userManager = parserContext.getDelegate().parseCustomElement(childElm, builder.getBeanDefinition());
+ } else if ("file-user-manager".equals(childName)
+ || "db-user-manager".equals(childName)) {
+ Object userManager = parserContext.getDelegate()
+ .parseCustomElement(childElm,
+ builder.getBeanDefinition());
builder.addPropertyValue("userManager", userManager);
- } else if("user-manager".equals(childName)) {
- builder.addPropertyValue("userManager", SpringUtil.parseSpringChildElement(childElm, parserContext, builder));
- } else if("native-filesystem".equals(childName)) {
- Object fileSystem = parserContext.getDelegate().parseCustomElement(childElm, builder.getBeanDefinition());
+ } else if ("user-manager".equals(childName)) {
+ builder.addPropertyValue("userManager", SpringUtil
+ .parseSpringChildElement(childElm, parserContext,
+ builder));
+ } else if ("native-filesystem".equals(childName)) {
+ Object fileSystem = parserContext.getDelegate()
+ .parseCustomElement(childElm,
+ builder.getBeanDefinition());
builder.addPropertyValue("fileSystem", fileSystem);
- } else if("filesystem".equals(childName)) {
- builder.addPropertyValue("fileSystem", SpringUtil.parseSpringChildElement(childElm, parserContext, builder));
- } else if("commands".equals(childName)) {
- Object commandFactory = parserContext.getDelegate().parseCustomElement(childElm, builder.getBeanDefinition());
+ } else if ("filesystem".equals(childName)) {
+ builder.addPropertyValue("fileSystem", SpringUtil
+ .parseSpringChildElement(childElm, parserContext,
+ builder));
+ } else if ("commands".equals(childName)) {
+ Object commandFactory = parserContext.getDelegate()
+ .parseCustomElement(childElm,
+ builder.getBeanDefinition());
builder.addPropertyValue("commandFactory", commandFactory);
- } else if("messages".equals(childName)) {
- MessageResource mr = parseMessageResource(childElm, parserContext, builder);
+ } else if ("messages".equals(childName)) {
+ MessageResource mr = parseMessageResource(childElm,
+ parserContext, builder);
builder.addPropertyValue("messageResource", mr);
} else {
- throw new FtpServerConfigurationException("Unknown configuration name: " + childName);
+ throw new FtpServerConfigurationException(
+ "Unknown configuration name: " + childName);
}
}
// Configure login limits
DefaultConnectionConfig connectionConfig = new DefaultConnectionConfig();
- if(StringUtils.hasText(element.getAttribute("max-logins"))) {
- connectionConfig.setMaxLogins(SpringUtil.parseInt(element, "max-logins"));
- }
- if(StringUtils.hasText(element.getAttribute("max-anon-logins"))) {
- connectionConfig.setMaxAnonymousLogins(SpringUtil.parseInt(element, "max-anon-logins"));
+ if (StringUtils.hasText(element.getAttribute("max-logins"))) {
+ connectionConfig.setMaxLogins(SpringUtil.parseInt(element,
+ "max-logins"));
+ }
+ if (StringUtils.hasText(element.getAttribute("max-anon-logins"))) {
+ connectionConfig.setMaxAnonymousLogins(SpringUtil.parseInt(element,
+ "max-anon-logins"));
+ }
+ if (StringUtils.hasText(element.getAttribute("anon-enabled"))) {
+ connectionConfig.setAnonymousLoginEnabled(SpringUtil.parseBoolean(
+ element, "anon-enabled", true));
+ }
+ if (StringUtils.hasText(element.getAttribute("max-login-failures"))) {
+ connectionConfig.setMaxLoginFailures(SpringUtil.parseInt(element,
+ "max-login-failures"));
+ }
+ if (StringUtils.hasText(element.getAttribute("login-failure-delay"))) {
+ connectionConfig.setLoginFailureDelay(SpringUtil.parseInt(element,
+ "login-failure-delay"));
}
- if(StringUtils.hasText(element.getAttribute("anon-enabled"))) {
- connectionConfig.setAnonymousLoginEnabled(SpringUtil.parseBoolean(element, "anon-enabled", true));
- }
- if(StringUtils.hasText(element.getAttribute("max-login-failures"))) {
- connectionConfig.setMaxLoginFailures(SpringUtil.parseInt(element, "max-login-failures"));
- }
- if(StringUtils.hasText(element.getAttribute("login-failure-delay"))) {
- connectionConfig.setLoginFailureDelay(SpringUtil.parseInt(element, "login-failure-delay"));
- }
-
+
builder.addPropertyValue("connectionConfig", connectionConfig);
}
@@ -115,22 +136,24 @@
/**
* Parse the "messages" element
*/
- private MessageResource parseMessageResource(final Element childElm, final ParserContext parserContext,
+ private MessageResource parseMessageResource(final Element childElm,
+ final ParserContext parserContext,
final BeanDefinitionBuilder builder) {
-
+
MessageResourceImpl mr = new MessageResourceImpl();
-
- if(StringUtils.hasText(childElm.getAttribute("languages"))) {
+
+ if (StringUtils.hasText(childElm.getAttribute("languages"))) {
String langString = childElm.getAttribute("languages");
-
+
String[] languages = langString.split("[\\s,]+");
-
+
mr.setLanguages(languages);
}
-
- if(StringUtils.hasText(childElm.getAttribute("directory"))) {
- mr.setCustomMessageDirectory(new File(childElm.getAttribute("directory")));
-
+
+ if (StringUtils.hasText(childElm.getAttribute("directory"))) {
+ mr.setCustomMessageDirectory(new File(childElm
+ .getAttribute("directory")));
+
}
return mr;
@@ -139,16 +162,20 @@
/**
* Parse the "ftplets" element
*/
- private Map parseFtplets(final Element childElm, final ParserContext parserContext, final BeanDefinitionBuilder builder) {
+ private Map parseFtplets(final Element childElm,
+ final ParserContext parserContext,
+ final BeanDefinitionBuilder builder) {
ManagedMap ftplets = new ManagedMap();
List<Element> childs = SpringUtil.getChildElements(childElm);
- for(Element ftpletElm : childs) {
- ftplets.put(ftpletElm.getAttribute("name"),
- SpringUtil.parseSpringChildElement(ftpletElm, parserContext, builder));
+ for (Element ftpletElm : childs) {
+ ftplets
+ .put(ftpletElm.getAttribute("name"), SpringUtil
+ .parseSpringChildElement(ftpletElm, parserContext,
+ builder));
}
-
+
return ftplets;
}
@@ -156,27 +183,32 @@
* Parse listeners elements
*/
@SuppressWarnings("unchecked")
- private Map parseListeners(final Element listenersElm, final ParserContext parserContext, final BeanDefinitionBuilder builder) {
+ private Map parseListeners(final Element listenersElm,
+ final ParserContext parserContext,
+ final BeanDefinitionBuilder builder) {
ManagedMap listeners = new ManagedMap();
List<Element> childs = SpringUtil.getChildElements(listenersElm);
- for(Element listenerElm : childs) {
+ for (Element listenerElm : childs) {
Object listener = null;
String ln = listenerElm.getLocalName();
- if("nio-listener".equals(ln)) {
- listener = parserContext.getDelegate().parseCustomElement(listenerElm, builder.getBeanDefinition());
+ if ("nio-listener".equals(ln)) {
+ listener = parserContext.getDelegate().parseCustomElement(
+ listenerElm, builder.getBeanDefinition());
} else if ("listener".equals(ln)) {
- listener = SpringUtil.parseSpringChildElement(listenerElm, parserContext, builder);
+ listener = SpringUtil.parseSpringChildElement(listenerElm,
+ parserContext, builder);
} else {
- throw new FtpServerConfigurationException("Unknown listener element " + ln);
+ throw new FtpServerConfigurationException(
+ "Unknown listener element " + ln);
}
-
+
String name = listenerElm.getAttribute("name");
listeners.put(name, listener);
}
-
+
return listeners;
}
}