You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by do...@apache.org on 2002/05/20 12:20:19 UTC
cvs commit: jakarta-avalon-apps/xcommander/src/java/org/apache/avalon/xcommander/saxhandlers CommandElementHandler.java
donaldp 02/05/20 03:20:19
Modified: ftpserver/src/java/org/apache/avalon/ftpserver
BaseFtpConnection.java FtpConnection.java
FtpStatus.java FtpUser.java SiteCommandHandler.java
ftpserver/src/java/org/apache/avalon/ftpserver/gui
ConfigTableModel.java FtpAboutPanel.java
FtpAdmin.java FtpAdminFrame.java
FtpConnectionTableModel.java FtpFileTableModel.java
FtpSpyContainerPanel.java FtpStatisticsPanel.java
FtpTree.java FtpUserPanel.java
ftpserver/src/java/org/apache/avalon/ftpserver/ip
FileIpRestrictor.java
ftpserver/src/java/org/apache/avalon/ftpserver/usermanager
LdapUserManager.java PropertiesUserManager.java
ftpserver/src/java/org/apache/avalon/ftpserver/util
DateUtils.java IoUtils.java StringUtils.java
VirtualDirectory.java
xcommander/src/java/org/apache/avalon/xcommander
XCommanderHandler.java
xcommander/src/java/org/apache/avalon/xcommander/saxhandlers
CommandElementHandler.java
Log:
final static --> static final to cpomply with JLS recomendations.
Revision Changes Path
1.3 +30 -30 jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/BaseFtpConnection.java
Index: BaseFtpConnection.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/BaseFtpConnection.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- BaseFtpConnection.java 1 Apr 2002 17:27:30 -0000 1.2
+++ BaseFtpConnection.java 20 May 2002 10:20:17 -0000 1.3
@@ -26,7 +26,7 @@
/**
- * This is a generic ftp connection handler. It delegates
+ * This is a generic ftp connection handler. It delegates
* the request to appropriate methods in subclasses.
*
* @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
@@ -34,8 +34,8 @@
public
class BaseFtpConnection implements ConnectionHandler, StreamConnectorObserver {
- protected final static Class[] METHOD_INPUT_SIG = new Class[] {FtpRequest.class, FtpWriter.class};
-
+ protected static final Class[] METHOD_INPUT_SIG = new Class[] {FtpRequest.class, FtpWriter.class};
+
protected FtpConfig mConfig = null;
protected FtpStatus mFtpStatus = null;
protected FtpDataConnection mDataConnection = null;
@@ -53,7 +53,7 @@
public BaseFtpConnection(FtpConfig ftpConfig) {
mConfig = ftpConfig;
mFtpStatus = mConfig.getStatus();
- mUser = new FtpUser();
+ mUser = new FtpUser();
}
@@ -61,46 +61,46 @@
* Server one FTP connection.
*/
public void handleConnection(final Socket socket) {
-
+
InetAddress clientAddress = socket.getInetAddress();
mConfig.getLogger().info("Handling new request from " + clientAddress.getHostAddress());
mControlSocket = socket;
mDataConnection = new FtpDataConnection(mConfig);
mUser.setClientAddress(clientAddress);
mConfig.getConnectionService().newConnection(this);
-
+
BufferedReader in = null;
try {
- in = new BufferedReader(new InputStreamReader(mControlSocket.getInputStream()));
- mWriter = new FtpWriter(mControlSocket, mConfig);
-
+ in = new BufferedReader(new InputStreamReader(mControlSocket.getInputStream()));
+ mWriter = new FtpWriter(mControlSocket, mConfig);
+
// permission check
if( !mConfig.getIpRestrictor().hasPermission(mControlSocket.getInetAddress()) ) {
mWriter.write(mFtpStatus.getResponse(530, null, mUser, null));
return;
}
mWriter.write(mFtpStatus.getResponse(220, null, mUser, null));
-
+
do {
notifyObserver();
String commandLine = in.readLine();
-
+
// test command line
if(commandLine == null) {
break;
}
-
+
spyRequest(commandLine);
if(commandLine.equals("")) {
continue;
}
-
+
FtpRequest request = new FtpRequest(commandLine);
if(!hasPermission(request)) {
mWriter.write(mFtpStatus.getResponse(530, request, mUser, null));
break;
}
-
+
// execute command
service(request, mWriter);
}
@@ -151,14 +151,14 @@
}
}
}
-
+
/**
* Check permission - default implementation - does nothing.
*/
protected boolean hasPermission(FtpRequest request) {
return true;
}
-
+
/**
* User logout and stop this thread.
*/
@@ -177,18 +177,18 @@
mControlSocket = null;
}
if (mUser.hasLoggedIn()) {
- mUser.logout();
+ mUser.logout();
}
mObserver = null;
}
-
+
/**
* Is the connection closed?
*/
public boolean isClosed() {
return mbStopRequest;
}
-
+
/**
* Monitor the user request.
*/
@@ -209,21 +209,21 @@
mConfig.getMessageQueue().add(msg);
}
}
-
+
/**
* Get user object
*/
public FtpUser getUser() {
return mUser;
}
-
+
/**
* Get connection spy object
*/
public SpyConnectionInterface getSpyObject() {
return mSpy;
}
-
+
/**
* Set spy object
*/
@@ -231,7 +231,7 @@
mWriter.setSpyObject(spy);
mSpy = spy;
}
-
+
/**
* Get observer
*/
@@ -251,7 +251,7 @@
*/
public void notifyObserver() {
mUser.hitUser();
- final FtpUser thisUser = mUser;
+ final FtpUser thisUser = mUser;
final FtpConnectionObserver obsr = mObserver;
if (obsr != null) {
@@ -263,27 +263,27 @@
mConfig.getMessageQueue().add(msg);
}
}
-
+
/**
* This method tracks data transfer.
*/
public void dataTransferred(int sz) {
notifyObserver();
}
-
+
/**
* Get config object
*/
public FtpConfig getConfig() {
return mConfig;
}
-
+
/**
* Get status object
*/
public FtpStatus getStatus() {
return mFtpStatus;
- }
-
+ }
+
}
-
+
1.13 +241 -241 jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/FtpConnection.java
Index: FtpConnection.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/FtpConnection.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- FtpConnection.java 26 Apr 2002 14:27:06 -0000 1.12
+++ FtpConnection.java 20 May 2002 10:20:17 -0000 1.13
@@ -1,4 +1,4 @@
-// $Id: FtpConnection.java,v 1.12 2002/04/26 14:27:06 rana_b Exp $
+// $Id: FtpConnection.java,v 1.13 2002/05/20 10:20:17 donaldp Exp $
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
@@ -42,7 +42,7 @@
public
class FtpConnection extends BaseFtpConnection {
- private final static SimpleDateFormat DATE_FMT = new SimpleDateFormat("yyyyMMddHHmmss.SSS");
+ private static final SimpleDateFormat DATE_FMT = new SimpleDateFormat("yyyyMMddHHmmss.SSS");
// command state specific temporary variables
private boolean mbReset = false;
@@ -60,32 +60,32 @@
public FtpConnection(FtpConfig cfg) {
super(cfg);
}
-
+
/**
* Check the user permission to execute this command.
*/
protected boolean hasPermission(FtpRequest request) {
String cmd = request.getCommand();
- return mUser.hasLoggedIn() ||
- cmd.equals("USER") ||
+ return mUser.hasLoggedIn() ||
+ cmd.equals("USER") ||
cmd.equals("PASS") ||
cmd.equals("HELP");
}
-
+
/**
* Reset temporary state variables.
*/
private void resetState() {
mbRenFr = false;
mstRenFr = null;
-
+
mbReset = false;
mlSkipLen = 0;
-
+
mbUser = false;
mbPass = false;
}
-
+
////////////////////////////////////////////////////////////
///////////////// all the FTP handlers /////////////////
////////////////////////////////////////////////////////////
@@ -97,19 +97,19 @@
* No action is to be taken if the previous command
* has been completed (including data transfer). The control
* connection is not to be closed by the server, but the data
- * connection must be closed.
- * Current implementation does not do anything. As here data
- * transfers are not multi-threaded.
+ * connection must be closed.
+ * Current implementation does not do anything. As here data
+ * transfers are not multi-threaded.
*/
public void doABOR(FtpRequest request, FtpWriter out) throws IOException {
-
+
// reset state variables
resetState();
mDataConnection.reset();
out.write(mFtpStatus.getResponse(226, request, mUser, null));
}
-
-
+
+
/**
* <code>APPE <SP> <pathname> <CRLF></code><br>
*
@@ -121,29 +121,29 @@
* pathname shall be created at the server site.
*/
public void doAPPE(FtpRequest request, FtpWriter out) throws IOException {
-
+
// reset state variables
resetState();
-
+
// argument check
if(!request.hasArgument()) {
out.write(mFtpStatus.getResponse(501, request, mUser, null));
- return;
+ return;
}
-
+
// get filenames
String fileName = request.getArgument();
fileName = mUser.getVirtualDirectory().getAbsoluteName(fileName);
String physicalName = mUser.getVirtualDirectory().getPhysicalName(fileName);
File requestedFile = new File(physicalName);
String args[] = {fileName};
-
+
// check permission
if(!mUser.getVirtualDirectory().hasWritePermission(physicalName, true)) {
out.write(mFtpStatus.getResponse(450, request, mUser, args));
return;
}
-
+
// now transfer file data
out.write(mFtpStatus.getResponse(150, request, mUser, args));
InputStream is = null;
@@ -154,24 +154,24 @@
out.write(mFtpStatus.getResponse(550, request, mUser, args));
return;
}
-
+
is = dataSoc.getInputStream();
RandomAccessFile raf = new RandomAccessFile(requestedFile, "rw");
raf.seek(raf.length());
os = mUser.getOutputStream( new FileOutputStream(raf.getFD()) );
-
+
StreamConnector msc = new StreamConnector(is, os);
msc.setMaxTransferRate(mUser.getMaxUploadRate());
msc.setObserver(this);
msc.connect();
-
+
if(msc.hasException()) {
out.write(mFtpStatus.getResponse(451, request, mUser, args));
}
else {
mConfig.getStatistics().setUpload(requestedFile, mUser, msc.getTransferredSize());
}
-
+
out.write(mFtpStatus.getResponse(226, request, mUser, args));
}
catch(IOException ex) {
@@ -180,11 +180,11 @@
finally {
IoUtils.close(is);
IoUtils.close(os);
- mDataConnection.reset();
+ mDataConnection.reset();
}
}
-
-
+
+
/**
* <code>CDUP <CRLF></code><br>
*
@@ -192,13 +192,13 @@
* simplify the implementation of programs for transferring
* directory trees between operating systems having different
* syntaxes for naming the parent directory. The reply codes
- * shall be identical to the reply codes of CWD.
+ * shall be identical to the reply codes of CWD.
*/
public void doCDUP(FtpRequest request, FtpWriter out) throws IOException {
-
+
// reset state variables
resetState();
-
+
// change directory
if (mUser.getVirtualDirectory().changeDirectory("..")) {
String args[] = {mUser.getVirtualDirectory().getCurrentDirectory()};
@@ -208,8 +208,8 @@
out.write(mFtpStatus.getResponse(431, request, mUser, null));
}
}
-
-
+
+
/**
* <code>CWD <SP> <pathname> <CRLF></code><br>
*
@@ -220,16 +220,16 @@
* pathname specifying a directory.
*/
public void doCWD(FtpRequest request, FtpWriter out) throws IOException {
-
+
// reset state variables
resetState();
-
+
// get new directory name
String dirName = "/";
if (request.hasArgument()) {
dirName = request.getArgument();
- }
-
+ }
+
// change directory
if (mUser.getVirtualDirectory().changeDirectory(dirName)) {
String args[] = {mUser.getVirtualDirectory().getCurrentDirectory()};
@@ -239,8 +239,8 @@
out.write(mFtpStatus.getResponse(431, request, mUser, null));
}
}
-
-
+
+
/**
* <code>DELE <SP> <pathname> <CRLF></code><br>
*
@@ -248,40 +248,40 @@
* deleted at the server site.
*/
public void doDELE(FtpRequest request, FtpWriter out) throws IOException {
-
+
// reset state variables
- resetState();
-
+ resetState();
+
// argument check
if(!request.hasArgument()) {
out.write(mFtpStatus.getResponse(501, request, mUser, null));
- return;
- }
-
+ return;
+ }
+
// get filenames
String fileName = request.getArgument();
fileName = mUser.getVirtualDirectory().getAbsoluteName(fileName);
String physicalName = mUser.getVirtualDirectory().getPhysicalName(fileName);
File requestedFile = new File(physicalName);
String[] args = {fileName};
-
+
// check permission
if(!mUser.getVirtualDirectory().hasWritePermission(physicalName, true)) {
out.write(mFtpStatus.getResponse(450, request, mUser, args));
return;
}
-
+
// now delete
if(requestedFile.delete()) {
- out.write(mFtpStatus.getResponse(250, request, mUser, args));
- mConfig.getStatistics().setDelete(requestedFile, mUser);
+ out.write(mFtpStatus.getResponse(250, request, mUser, args));
+ mConfig.getStatistics().setDelete(requestedFile, mUser);
}
else {
out.write(mFtpStatus.getResponse(450, request, mUser, args));
}
}
-
-
+
+
/**
* <code>HELP [<SP> <string>] <CRLF></code><br>
*
@@ -292,22 +292,22 @@
* information as a response.
*/
public void doHELP(FtpRequest request, FtpWriter out) throws IOException {
-
+
// print global help
if(!request.hasArgument()) {
out.write(mFtpStatus.getResponse(214, null, mUser, null));
return;
}
-
+
// print command specific help
String ftpCmd = request.getArgument().toUpperCase();
String args[] = null;
FtpRequest tempRequest = new FtpRequest(ftpCmd);
out.write(mFtpStatus.getResponse(214, tempRequest, mUser, args));
return;
- }
-
-
+ }
+
+
/**
* <code>LIST [<SP> <pathname>] <CRLF></code><br>
*
@@ -321,10 +321,10 @@
* connection
*/
public void doLIST(FtpRequest request, FtpWriter out) throws IOException {
-
+
// reset state variables
resetState();
-
+
out.write(mFtpStatus.getResponse(150, request, mUser, null));
Writer os = null;
try {
@@ -333,9 +333,9 @@
out.write(mFtpStatus.getResponse(550, request, mUser, null));
return;
}
-
+
os = new OutputStreamWriter(dataSoc.getOutputStream());
-
+
if (!mUser.getVirtualDirectory().printList(request.getArgument(), os)) {
out.write(mFtpStatus.getResponse(501, request, mUser, null));
}
@@ -352,24 +352,24 @@
mDataConnection.reset();
}
}
-
-
+
+
/**
* <code>MDTM <SP> <pathname> <CRLF></code><br>
- *
+ *
* Returns the date and time of when a file was modified.
*/
public void doMDTM(FtpRequest request, FtpWriter out) throws IOException {
-
+
// argument check
if(!request.hasArgument()) {
out.write(mFtpStatus.getResponse(501, request, mUser, null));
- return;
+ return;
}
-
+
// reset state variables
resetState();
-
+
// get filenames
String fileName = request.getArgument();
fileName = mUser.getVirtualDirectory().getAbsoluteName(fileName);
@@ -384,9 +384,9 @@
else {
out.write(mFtpStatus.getResponse(550, request, mUser, null));
}
- }
-
-
+ }
+
+
/**
* <code>MKD <SP> <pathname> <CRLF></code><br>
*
@@ -396,38 +396,38 @@
* the pathname is relative).
*/
public void doMKD(FtpRequest request, FtpWriter out) throws IOException {
-
+
// reset state variables
- resetState();
-
+ resetState();
+
// argument check
if(!request.hasArgument()) {
out.write(mFtpStatus.getResponse(501, request, mUser, null));
- return;
+ return;
}
-
+
// get filenames
String fileName = request.getArgument();
fileName = mUser.getVirtualDirectory().getAbsoluteName(fileName);
String physicalName = mUser.getVirtualDirectory().getPhysicalName(fileName);
String args[] = {fileName};
-
+
// check permission
if(!mUser.getVirtualDirectory().hasCreatePermission(physicalName, true)) {
out.write(mFtpStatus.getResponse(450, request, mUser, args));
return;
}
-
+
// now create directory
if(new File(physicalName).mkdirs()) {
- out.write(mFtpStatus.getResponse(250, request, mUser, args));
+ out.write(mFtpStatus.getResponse(250, request, mUser, args));
}
else {
out.write(mFtpStatus.getResponse(450, request, mUser, args));
}
}
-
+
/**
* <code>MODE <SP> <mode-code> <CRLF></code><br>
*
@@ -436,16 +436,16 @@
* Transmission Modes.
*/
public void doMODE(FtpRequest request, FtpWriter out) throws IOException {
-
+
// reset state variables
resetState();
-
+
// argument check
if(!request.hasArgument()) {
out.write(mFtpStatus.getResponse(501, request, mUser, null));
- return;
+ return;
}
-
+
if (mUser.setMode(request.getArgument().charAt(0))) {
out.write(mFtpStatus.getResponse(200, request, mUser, null));
}
@@ -453,8 +453,8 @@
out.write(mFtpStatus.getResponse(504, request, mUser, null));
}
}
-
-
+
+
/**
* <code>NLST [<SP> <pathname>] <CRLF></code><br>
*
@@ -466,10 +466,10 @@
* information.
*/
public void doNLST(FtpRequest request, FtpWriter out) throws IOException {
-
+
// reset state variables
resetState();
-
+
out.write(mFtpStatus.getResponse(150, request, mUser, null));
Writer os = null;
try {
@@ -478,9 +478,9 @@
out.write(mFtpStatus.getResponse(550, request, mUser, null));
return;
}
-
+
os = new OutputStreamWriter(dataSoc.getOutputStream());
-
+
if (!mUser.getVirtualDirectory().printNList(request.getArgument(), os)) {
out.write(mFtpStatus.getResponse(501, request, mUser, null));
}
@@ -497,8 +497,8 @@
mDataConnection.reset();
}
}
-
-
+
+
/**
* <code>NOOP <CRLF></code><br>
*
@@ -507,14 +507,14 @@
* server send an OK reply.
*/
public void doNOOP(FtpRequest request, FtpWriter out) throws IOException {
-
+
// reset state variables
resetState();
-
+
out.write(mFtpStatus.getResponse(200, request, mUser, null));
- }
-
-
+ }
+
+
/**
* <code>PASS <SP> <password> <CRLF></code><br>
*
@@ -531,11 +531,11 @@
return;
}
resetState();
- mbPass = true;
-
+ mbPass = true;
+
// set user password and login
String pass = request.hasArgument() ? request.getArgument() : "";
- mUser.setPassword(pass);
+ mUser.setPassword(pass);
// login failure - close connection
String args[] = {mUser.getName()};
@@ -550,8 +550,8 @@
}
}
}
-
-
+
+
/**
* <code>PASV <CRLF></code><br>
*
@@ -562,29 +562,29 @@
* host and port address this server is listening on.
*/
public void doPASV(FtpRequest request, FtpWriter out) throws IOException {
-
+
if (!mDataConnection.setPasvCommand()) {
out.write(mFtpStatus.getResponse(550, request, mUser, null));
- return;
+ return;
}
-
+
InetAddress servAddr = mDataConnection.getInetAddress();
if(servAddr == null) {
servAddr = mConfig.getSelfAddress();
- }
+ }
int servPort = mDataConnection.getPort();
-
+
String addrStr = servAddr.getHostAddress().replace( '.', ',' ) + ',' + (servPort>>8) + ',' + (servPort&0xFF);
String[] args = {addrStr};
-
+
out.write(mFtpStatus.getResponse(227, request, mUser, args));
if (!mDataConnection.listenPasvConnection()) {
out.write(mFtpStatus.getResponse(425, request, mUser, args));
}
}
-
-
+
+
/**
* <code>PORT <SP> <host-port> <CRLF></code><br>
*
@@ -600,21 +600,21 @@
* by commas. A port command would be:
*
* PORT h1,h2,h3,h4,p1,p2
- *
+ *
* where h1 is the high order 8 bits of the internet host address.
*/
public void doPORT(FtpRequest request, FtpWriter out) throws IOException {
-
+
// reset state variables
resetState();
-
+
InetAddress clientAddr = null;
int clientPort = 0;
-
+
// argument check
if(!request.hasArgument()) {
out.write(mFtpStatus.getResponse(501, request, mUser, null));
- return;
+ return;
}
StringTokenizer st = new StringTokenizer(request.getArgument(), ",");
@@ -622,7 +622,7 @@
out.write(mFtpStatus.getResponse(510, request, mUser, null));
return;
}
-
+
// get data server
String dataSrvName = st.nextToken() + '.' + st.nextToken() + '.' +
st.nextToken() + '.' + st.nextToken();
@@ -633,22 +633,22 @@
out.write(mFtpStatus.getResponse(553, request, mUser, null));
return;
}
-
+
// get data server port
try {
int hi = Integer.parseInt(st.nextToken());
int lo = Integer.parseInt(st.nextToken());
- clientPort = (hi << 8) | lo;
+ clientPort = (hi << 8) | lo;
}
catch(NumberFormatException ex) {
- out.write(mFtpStatus.getResponse(552, request, mUser, null));
- return;
+ out.write(mFtpStatus.getResponse(552, request, mUser, null));
+ return;
}
mDataConnection.setPortCommand(clientAddr, clientPort);
out.write(mFtpStatus.getResponse(200, request, mUser, null));
}
-
-
+
+
/**
* <code>PWD <CRLF></code><br>
*
@@ -656,14 +656,14 @@
* directory to be returned in the reply.
*/
public void doPWD(FtpRequest request, FtpWriter out) throws IOException {
-
+
// reset state variables
resetState();
String args[] = {mUser.getVirtualDirectory().getCurrentDirectory()};
out.write(mFtpStatus.getResponse(257, request, mUser, args));
}
-
-
+
+
/**
* <code>QUIT <CRLF></code><br>
*
@@ -671,10 +671,10 @@
* in progress, the server closes the control connection.
*/
public void doQUIT(FtpRequest request, FtpWriter out) throws IOException {
-
+
// reset state variables
resetState();
-
+
// and exit
out.write(mFtpStatus.getResponse(221, request, mUser, null));
ConnectionService conService = mConfig.getConnectionService();
@@ -682,8 +682,8 @@
conService.closeConnection(mUser.getSessionId());
}
}
-
-
+
+
/**
* <code>REST <SP> <marker> <CRLF></code><br>
*
@@ -695,22 +695,22 @@
* file transfer to resume.
*/
public void doREST(FtpRequest request, FtpWriter out) throws IOException {
-
+
// argument check
if(!request.hasArgument()) {
out.write(mFtpStatus.getResponse(501, request, mUser, null));
- return;
+ return;
}
-
+
// set state variables
resetState();
mlSkipLen = 0;
String skipNum = request.getArgument();
- try {
+ try {
mlSkipLen = Long.parseLong(skipNum);
}
catch(NumberFormatException ex) {
- out.write(mFtpStatus.getResponse(501, request, mUser, null));
+ out.write(mFtpStatus.getResponse(501, request, mUser, null));
return;
}
if(mlSkipLen < 0) {
@@ -720,9 +720,9 @@
}
mbReset = true;
out.write(mFtpStatus.getResponse(350, request, mUser, null));
- }
-
-
+ }
+
+
/**
* <code>RETR <SP> <pathname> <CRLF></code><br>
*
@@ -732,30 +732,30 @@
* contents of the file at the server site shall be unaffected.
*/
public void doRETR(FtpRequest request, FtpWriter out) throws IOException {
-
+
// set state variables
long skipLen = (mbReset) ? mlSkipLen : 0;
resetState();
-
+
// argument check
if(!request.hasArgument()) {
out.write(mFtpStatus.getResponse(501, request, mUser, null));
- return;
+ return;
}
-
+
// get filenames
String fileName = request.getArgument();
fileName = mUser.getVirtualDirectory().getAbsoluteName(fileName);
String physicalName = mUser.getVirtualDirectory().getPhysicalName(fileName);
File requestedFile = new File(physicalName);
String args[] = {fileName};
-
+
// check permission
if(!mUser.getVirtualDirectory().hasReadPermission(physicalName, true)) {
out.write(mFtpStatus.getResponse(550, request, mUser, args));
return;
}
-
+
// now transfer file data
out.write(mFtpStatus.getResponse(150, request, mUser, null));
InputStream is = null;
@@ -766,18 +766,18 @@
out.write(mFtpStatus.getResponse(550, request, mUser, args));
return;
}
-
+
os = mUser.getOutputStream(dataSoc.getOutputStream());
-
+
RandomAccessFile raf = new RandomAccessFile(requestedFile, "r");
raf.seek(skipLen);
- is = new FileInputStream(raf.getFD());
-
+ is = new FileInputStream(raf.getFD());
+
StreamConnector msc = new StreamConnector(is, os);
msc.setMaxTransferRate(mUser.getMaxDownloadRate());
msc.setObserver(this);
msc.connect();
-
+
if(msc.hasException()) {
out.write(mFtpStatus.getResponse(451, request, mUser, args));
return;
@@ -785,7 +785,7 @@
else {
mConfig.getStatistics().setDownload(requestedFile, mUser, msc.getTransferredSize());
}
-
+
out.write(mFtpStatus.getResponse(226, request, mUser, null));
}
catch(IOException ex) {
@@ -797,8 +797,8 @@
mDataConnection.reset();
}
}
-
-
+
+
/**
* <code>RMD <SP> <pathname> <CRLF></code><br>
*
@@ -808,39 +808,39 @@
* the pathname is relative).
*/
public void doRMD(FtpRequest request, FtpWriter out) throws IOException {
-
+
// reset state variables
- resetState();
-
+ resetState();
+
// argument check
if(!request.hasArgument()) {
out.write(mFtpStatus.getResponse(501, request, mUser, null));
- return;
+ return;
}
-
+
// get file names
String fileName = request.getArgument();
fileName = mUser.getVirtualDirectory().getAbsoluteName(fileName);
String physicalName = mUser.getVirtualDirectory().getPhysicalName(fileName);
File requestedFile = new File(physicalName);
String args[] = {fileName};
-
+
// check permission
if(!mUser.getVirtualDirectory().hasWritePermission(physicalName, true)) {
out.write(mFtpStatus.getResponse(450, request, mUser, args));
return;
}
-
+
// now delete
if(requestedFile.delete()) {
- out.write(mFtpStatus.getResponse(250, request, mUser, args));
+ out.write(mFtpStatus.getResponse(250, request, mUser, args));
}
else {
out.write(mFtpStatus.getResponse(450, request, mUser, args));
}
}
-
-
+
+
/**
* <code>RNFR <SP> <pathname> <CRLF></code><br>
*
@@ -849,29 +849,29 @@
* a "rename to" command specifying the new file pathname.
*/
public void doRNFR(FtpRequest request, FtpWriter out) throws IOException {
-
+
// reset state variable
resetState();
-
+
// argument check
if(!request.hasArgument()) {
out.write(mFtpStatus.getResponse(501, request, mUser, null));
- return;
+ return;
}
-
+
// set state variable
mbRenFr = true;
-
+
// get filenames
String fileName = request.getArgument();
fileName = mUser.getVirtualDirectory().getAbsoluteName(fileName);
mstRenFr = mUser.getVirtualDirectory().getPhysicalName(fileName);
String args[] = {fileName};
-
+
out.write(mFtpStatus.getResponse(350, request, mUser, args));
}
-
-
+
+
/**
* <code>RNTO <SP> <pathname> <CRLF></code><br>
*
@@ -881,21 +881,21 @@
* renamed.
*/
public void doRNTO(FtpRequest request, FtpWriter out) throws IOException {
-
+
// argument check
if(!request.hasArgument()) {
- resetState();
+ resetState();
out.write(mFtpStatus.getResponse(501, request, mUser, null));
- return;
+ return;
}
-
+
// set state variables
if((!mbRenFr) || (mstRenFr == null)) {
resetState();
out.write(mFtpStatus.getResponse(100, request, mUser, null));
return;
}
-
+
// get filenames
String fromFileStr = mUser.getVirtualDirectory().getVirtualName(mstRenFr);
String toFileStr = request.getArgument();
@@ -904,15 +904,15 @@
File fromFile = new File(mstRenFr);
File toFile = new File(physicalToFileStr);
String args[] = {fromFileStr, toFileStr};
-
+
resetState();
-
+
// check permission
if(!mUser.getVirtualDirectory().hasCreatePermission(physicalToFileStr, true)) {
out.write(mFtpStatus.getResponse(553, request, mUser, null));
return;
}
-
+
// now rename
if(fromFile.renameTo(toFile)) {
out.write(mFtpStatus.getResponse(250, request, mUser, args));
@@ -920,9 +920,9 @@
else {
out.write(mFtpStatus.getResponse(553, request, mUser, args));
}
- }
-
-
+ }
+
+
/**
* <code>SITE <SP> <string> <CRLF></code><br>
*
@@ -935,41 +935,41 @@
SiteCommandHandler siteCmd = new SiteCommandHandler( mConfig, mUser );
out.write( siteCmd.getResponse(request) );
}
-
-
+
+
/**
* <code>SIZE <SP> <pathname> <CRLF></code><br>
*
* Returns the size of the file in bytes.
*/
public void doSIZE(FtpRequest request, FtpWriter out) throws IOException {
-
+
// argument check
if(!request.hasArgument()) {
out.write(mFtpStatus.getResponse(501, request, mUser, null));
- return;
+ return;
}
-
+
// reset state variables
resetState();
-
+
// get filenames
String fileName = request.getArgument();
fileName = mUser.getVirtualDirectory().getAbsoluteName(fileName);
String physicalName = mUser.getVirtualDirectory().getPhysicalName(fileName);
File reqFile = new File(physicalName);
-
+
// print file size
if(reqFile.exists()) {
- String args[] = {String.valueOf(reqFile.length())};
+ String args[] = {String.valueOf(reqFile.length())};
out.write(mFtpStatus.getResponse(213, request, mUser, args));
}
else {
out.write(mFtpStatus.getResponse(550, request, mUser, null));
}
- }
-
-
+ }
+
+
/**
* <code>STAT [<SP> <pathname>] <CRLF></code><br>
*
@@ -982,11 +982,11 @@
mControlSocket.getInetAddress().getHostAddress(),
mUser.getName()
};
-
- out.write(mFtpStatus.getResponse(211, request, mUser, args));
- }
-
-
+
+ out.write(mFtpStatus.getResponse(211, request, mUser, args));
+ }
+
+
/**
* <code>STOR <SP> <pathname> <CRLF></code><br>
*
@@ -999,29 +999,29 @@
* pathname does not already exist.
*/
public void doSTOR(FtpRequest request, FtpWriter out) throws IOException {
-
+
// set state variables
long skipLen = (mbReset) ? mlSkipLen : 0;
resetState();
-
+
// argument check
if(!request.hasArgument()) {
out.write(mFtpStatus.getResponse(501, request, mUser, null));
- return;
+ return;
}
-
+
// get filenames
String fileName = request.getArgument();
fileName = mUser.getVirtualDirectory().getAbsoluteName(fileName);
String physicalName = mUser.getVirtualDirectory().getPhysicalName(fileName);
File requestedFile = new File(physicalName);
-
+
// get permission
if(!mUser.getVirtualDirectory().hasCreatePermission(physicalName, true)) {
out.write(mFtpStatus.getResponse(550, request, mUser, null));
return;
}
-
+
// now transfer file data
out.write(mFtpStatus.getResponse(150, request, mUser, null));
InputStream is = null;
@@ -1032,18 +1032,18 @@
out.write(mFtpStatus.getResponse(550, request, mUser, null));
return;
}
-
+
is = dataSoc.getInputStream();
-
+
RandomAccessFile raf = new RandomAccessFile(requestedFile, "rw");
raf.seek(skipLen);
os = mUser.getOutputStream( new FileOutputStream(raf.getFD()) );
-
+
StreamConnector msc = new StreamConnector(is, os);
msc.setMaxTransferRate(mUser.getMaxUploadRate());
msc.setObserver(this);
msc.connect();
-
+
if(msc.hasException()) {
out.write(mFtpStatus.getResponse(451, request, mUser, null));
return;
@@ -1051,7 +1051,7 @@
else {
mConfig.getStatistics().setUpload(requestedFile, mUser, msc.getTransferredSize());
}
-
+
out.write(mFtpStatus.getResponse(226, request, mUser, null));
}
catch(IOException ex) {
@@ -1063,8 +1063,8 @@
mDataConnection.reset();
}
}
-
-
+
+
/**
* <code>STOU <CRLF></code><br>
*
@@ -1074,10 +1074,10 @@
* must include the name generated.
*/
public void doSTOU(FtpRequest request, FtpWriter out) throws IOException {
-
+
// reset state variables
resetState();
-
+
// get filenames
String fileName = mUser.getVirtualDirectory().getAbsoluteName("ftp.dat");
String physicalName = mUser.getVirtualDirectory().getPhysicalName(fileName);
@@ -1085,13 +1085,13 @@
requestedFile = IoUtils.getUniqueFile(requestedFile);
fileName = mUser.getVirtualDirectory().getVirtualName(requestedFile.getAbsolutePath());
String args[] = {fileName};
-
+
// check permission
if(!mUser.getVirtualDirectory().hasCreatePermission(fileName, false)) {
out.write(mFtpStatus.getResponse(550, request, mUser, null));
return;
}
-
+
// now transfer file data
out.write(mFtpStatus.getResponse(150, request, mUser, null));
InputStream is = null;
@@ -1103,15 +1103,15 @@
return;
}
-
+
is = dataSoc.getInputStream();
os = mUser.getOutputStream( new FileOutputStream(requestedFile) );
-
+
StreamConnector msc = new StreamConnector(is, os);
msc.setMaxTransferRate(mUser.getMaxUploadRate());
msc.setObserver(this);
msc.connect();
-
+
if(msc.hasException()) {
out.write(mFtpStatus.getResponse(451, request, mUser, null));
return;
@@ -1119,7 +1119,7 @@
else {
mConfig.getStatistics().setUpload(requestedFile, mUser, msc.getTransferredSize());
}
-
+
out.write(mFtpStatus.getResponse(226, request, mUser, null));
mDataConnection.reset();
out.write(mFtpStatus.getResponse(250, request, mUser, args));
@@ -1130,11 +1130,11 @@
finally {
IoUtils.close(is);
IoUtils.close(os);
- mDataConnection.reset();
+ mDataConnection.reset();
}
}
-
-
+
+
/**
* <code>STRU <SP> <structure-code> <CRLF></code><br>
*
@@ -1142,16 +1142,16 @@
* file structure.
*/
public void doSTRU(FtpRequest request, FtpWriter out) throws IOException {
-
+
// reset state variables
resetState();
-
+
// argument check
if(!request.hasArgument()) {
out.write(mFtpStatus.getResponse(501, request, mUser, null));
- return;
+ return;
}
-
+
if (mUser.setStructure(request.getArgument().charAt(0))) {
out.write(mFtpStatus.getResponse(200, request, mUser, null));
}
@@ -1159,40 +1159,40 @@
out.write(mFtpStatus.getResponse(504, request, mUser, null));
}
}
-
-
+
+
/**
- * <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.
*/
public void doSYST(FtpRequest request, FtpWriter out) throws IOException {
-
+
// reset state variables
resetState();
-
+
String args[] = {mConfig.getSystemName()};
out.write(mFtpStatus.getResponse(215, request, mUser, args));
}
-
-
+
+
/**
* <code>TYPE <SP> <type-code> <CRLF></code><br>
*
* The argument specifies the representation type.
*/
public void doTYPE(FtpRequest request, FtpWriter out) throws IOException {
-
+
// reset state variables
resetState();
-
+
// get type from argument
char type = 'A';
if (request.hasArgument()){
type = request.getArgument().charAt(0);
}
-
+
// set it
if (mUser.setType(type)) {
out.write(mFtpStatus.getResponse(200, request, mUser, null));
@@ -1201,8 +1201,8 @@
out.write(mFtpStatus.getResponse(504, request, mUser, null));
}
}
-
-
+
+
/**
* <code>USER <SP> <username> <CRLF></code><br>
*
@@ -1213,16 +1213,16 @@
* the control connections are made.
*/
public void doUSER(FtpRequest request, FtpWriter out) throws IOException {
-
+
// set state variables
resetState();
-
+
// argument check
if(!request.hasArgument()) {
out.write(mFtpStatus.getResponse(501, request, mUser, null));
- return;
- }
-
+ return;
+ }
+
// check user login status
mbUser = true;
if(mUser.hasLoggedIn()) {
@@ -1238,7 +1238,7 @@
// set user name and send appropriate message
mUser.setName(request.getArgument());
if(mUser.getIsAnonymous()) {
- if(mConfig.isAnonymousLoginAllowed()) {
+ if(mConfig.isAnonymousLoginAllowed()) {
FtpRequest anoRequest = new FtpRequest(mUser.getName());
out.write(mFtpStatus.getResponse(331, anoRequest, mUser, null));
}
1.6 +37 -37 jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/FtpStatus.java
Index: FtpStatus.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/FtpStatus.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- FtpStatus.java 26 Apr 2002 14:35:17 -0000 1.5
+++ FtpStatus.java 20 May 2002 10:20:17 -0000 1.6
@@ -1,4 +1,4 @@
-// $Id: FtpStatus.java,v 1.5 2002/04/26 14:35:17 rana_b Exp $
+// $Id: FtpStatus.java,v 1.6 2002/05/20 10:20:17 donaldp Exp $
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
@@ -20,20 +20,20 @@
* file from the classpath. It generates the descriptive ftp status for
* astatus code. The actual response depends on the status code, the ftp
* command and the passed argument list.
- *
+ *
* @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
*/
public
class FtpStatus extends Properties {
-
- private final static String RESOURCE = "org/apache/avalon/ftpserver/FtpStatus.properties";
- private final static String PREFIX = "FtpServer.status.";
- private final static String EMPTY = "";
- private final static String CRLF = "\r\n";
-
- private final static String CMD = "CMD";
- private final static String ARG = "ARG";
-
+
+ private static final String RESOURCE = "org/apache/avalon/ftpserver/FtpStatus.properties";
+ private static final String PREFIX = "FtpServer.status.";
+ private static final String EMPTY = "";
+ private static final String CRLF = "\r\n";
+
+ private static final String CMD = "CMD";
+ private static final String ARG = "ARG";
+
/**
* Load status propeties file from the classpath.
*/
@@ -42,30 +42,30 @@
load(pis);
pis.close();
}
-
+
/**
* Process ftp response new line character.
*/
public String processNewLine(String msg, int status) {
-
+
// no newline
if(msg.indexOf('\n') == -1) {
return status + " " + msg + CRLF;
}
-
+
StringBuffer sw = new StringBuffer(256);
-
+
try {
BufferedReader sr = new BufferedReader(new StringReader(msg));
-
+
sw.append(String.valueOf(status));
sw.append('-');
-
+
String line = sr.readLine();
for(;;) {
- String nextLine = sr.readLine();
-
+ String nextLine = sr.readLine();
+
if(nextLine != null) {
sw.append(line);
sw.append(CRLF);
@@ -83,23 +83,23 @@
}
catch(IOException ex) {
}
-
+
return sw.toString();
}
-
-
+
+
/**
* Get ftp message from the properties file and replace the variables.
*/
private String getMessage(int status, FtpRequest cmdLine, String[] args) {
-
+
// make the key from the passed parameters
String key = PREFIX + status;
String keyc = key;
if(cmdLine != null) {
keyc = keyc + '.' + cmdLine.getCommand();
}
-
+
// get status property
String str = getProperty(keyc);
if(str == null) {
@@ -108,26 +108,26 @@
if(str == null) {
str = EMPTY;
}
-
+
// replace variables
int startIndex = 0;
int openIndex = str.indexOf('{', startIndex);
int closeIndex = str.indexOf('}', startIndex);
-
+
if( (openIndex == -1) || (closeIndex == -1) || (openIndex > closeIndex) ) {
return str;
}
-
+
StringBuffer sb = new StringBuffer();
sb.append(str.substring(startIndex, openIndex));
while(true) {
String intStr = str.substring(openIndex+1, closeIndex);
sb.append(getParam(cmdLine, args, intStr));
-
+
startIndex = closeIndex + 1;
openIndex = str.indexOf('{', startIndex);
closeIndex = str.indexOf('}', startIndex);
-
+
if( (openIndex == -1) || (closeIndex == -1) || (openIndex > closeIndex) ) {
sb.append(str.substring(startIndex));
break;
@@ -136,13 +136,13 @@
}
return sb.toString();
}
-
-
+
+
/**
- * Get variable value.
+ * Get variable value.
*/
private String getParam(FtpRequest cmdLine, String[] elms, String intStr) {
-
+
// command line param
if(cmdLine != null) {
if(intStr.equals(CMD)) {
@@ -152,12 +152,12 @@
return cmdLine.getArgument();
}
}
-
+
// list param
if(elms == null) {
return EMPTY;
}
-
+
int index = 0;
try {
index = Integer.parseInt(intStr);
@@ -170,8 +170,8 @@
}
return elms[index];
}
-
-
+
+
/**
* Get ftp response.
* @param status ftp status code.
1.12 +11 -11 jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/FtpUser.java
Index: FtpUser.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/FtpUser.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- FtpUser.java 7 Apr 2002 17:11:21 -0000 1.11
+++ FtpUser.java 20 May 2002 10:20:17 -0000 1.12
@@ -5,7 +5,7 @@
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE file.
*/
-
+
package org.apache.avalon.ftpserver;
import java.io.OutputStream;
@@ -25,19 +25,19 @@
*/
public
class FtpUser extends User implements Serializable {
-
- public final static String ANONYMOUS = "anonymous";
-
+
+ public static final String ANONYMOUS = "anonymous";
+
private char mcDataType = 'A';
private char mcStructure = 'F';
private char mcMode = 'S';
-
+
/**
* Constructor - does nothing.
*/
public FtpUser() {
}
-
+
/**
* Get the user data type.
*/
@@ -64,8 +64,8 @@
*/
public char getStructure() {
return mcStructure;
- }
-
+ }
+
/**
* Set the file structure. Supported structure type is F (file).
* @return true if success
@@ -79,14 +79,14 @@
return true;
}
-
+
/**
* Get the transfer mode.
*/
public char getMode() {
return mcMode;
}
-
+
/**
* Set the transfer type. Supported transfer type is S (stream).
* @return true if success
@@ -111,7 +111,7 @@
}
return os;
}
-
+
/**
* Is an anonymous user?
*/
1.4 +57 -57 jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/SiteCommandHandler.java
Index: SiteCommandHandler.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/SiteCommandHandler.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- SiteCommandHandler.java 16 Apr 2002 03:51:31 -0000 1.3
+++ SiteCommandHandler.java 20 May 2002 10:20:17 -0000 1.4
@@ -9,7 +9,7 @@
package org.apache.avalon.ftpserver;
import java.util.Date;
-import java.util.List;
+import java.util.List;
import java.util.Collection;
import java.util.Iterator;
import java.util.StringTokenizer;
@@ -28,14 +28,14 @@
*/
public
class SiteCommandHandler {
-
- protected final static SimpleDateFormat DATE_FMT = new SimpleDateFormat("MM/dd HH:mm:ss");
- protected final static Class[] INPUT_SIG = new Class[] {String[].class, FtpRequest.class};
-
+
+ protected static final SimpleDateFormat DATE_FMT = new SimpleDateFormat("MM/dd HH:mm:ss");
+ protected static final Class[] INPUT_SIG = new Class[] {String[].class, FtpRequest.class};
+
private FtpConfig mConfig;
private FtpUser mUser;
-
-
+
+
/**
* Constructor - set the configuration object
*/
@@ -43,14 +43,14 @@
mConfig = cfg;
mUser = user;
}
-
-
+
+
/**
* Handle site.
*/
public String getResponse(FtpRequest request) {
String argArray[] = parseArg(request.getArgument());
-
+
String response = "";
if (hasPermission(argArray)) {
if ((argArray != null) && (argArray.length != 0)) {
@@ -71,11 +71,11 @@
else {
response = mConfig.getStatus().getResponse(530, request, mUser, null);
}
-
+
return response;
}
-
-
+
+
/**
* Parse all the tokens.
*/
@@ -83,19 +83,19 @@
if (arg == null) {
return null;
}
-
+
StringTokenizer st = new StringTokenizer(arg, " ");
- String[] args = new String[st.countTokens()];
+ String[] args = new String[st.countTokens()];
for(int i=0; i<args.length; i++) {
args[i] = st.nextToken();
}
-
+
return args;
}
-
-
+
+
/**
- * Has permission.
+ * Has permission.
*/
private boolean hasPermission(String args[]) {
UserManagerInterface userManager = mConfig.getUserManager();
@@ -105,10 +105,10 @@
}
return ( (args.length > 0) && "HELP".equalsIgnoreCase(args[0]) );
}
-
-
- ////////////////////////////////////////////////////////////////////////////
- //////////////////////// All site command handlers ////////////////////////
+
+
+ ////////////////////////////////////////////////////////////////////////////
+ //////////////////////// All site command handlers ////////////////////////
/**
* Add banned IP
*/
@@ -116,7 +116,7 @@
if (args.length != 2) {
return mConfig.getStatus().getResponse(501, cmd, mUser, null);
}
-
+
String response = "";
try {
IpRestrictorInterface ipRestrictor = mConfig.getIpRestrictor();
@@ -129,7 +129,7 @@
response = mConfig.getStatus().getResponse(451, cmd, mUser, null);
}
return response;
- }
+ }
/**
@@ -139,7 +139,7 @@
if (args.length != 2) {
return mConfig.getStatus().getResponse(501, cmd, mUser, null);
}
-
+
String response = "";
try {
User user = new User();
@@ -159,9 +159,9 @@
response = mConfig.getStatus().getResponse(451, cmd, mUser, null);
}
return response;
- }
+ }
+
-
/**
* Add banned IP
*/
@@ -169,7 +169,7 @@
if (args.length != 2) {
return mConfig.getStatus().getResponse(501, cmd, mUser, null);
}
-
+
String response = "";
try {
IpRestrictorInterface ipRestrictor = mConfig.getIpRestrictor();
@@ -182,9 +182,9 @@
response = mConfig.getStatus().getResponse(451, cmd, mUser, null);
}
return response;
- }
-
-
+ }
+
+
/**
* Delete user from repository.
*/
@@ -192,7 +192,7 @@
if (args.length != 2) {
return mConfig.getStatus().getResponse(501, cmd, mUser, null);
}
-
+
String response = "";
try {
mConfig.getUserManager().delete(args[1]);
@@ -203,8 +203,8 @@
response = mConfig.getStatus().getResponse(451, cmd, mUser, null);
}
return response;
- }
-
+ }
+
/**
* Describe user.
*/
@@ -212,7 +212,7 @@
if (args.length != 2) {
return mConfig.getStatus().getResponse(501, cmd, mUser, null);
}
-
+
StringBuffer sb = new StringBuffer();
sb.append('\n');
User user = mConfig.getUserManager().getUserByName(args[1]);
@@ -228,9 +228,9 @@
}
sb.append('\n');
return mConfig.getStatus().processNewLine(sb.toString(), 200);
- }
-
-
+ }
+
+
/**
* Display site help.
*/
@@ -250,8 +250,8 @@
sb.append("WHO : display all connected users").append('\n');
sb.append('\n');
return mConfig.getStatus().processNewLine(sb.toString(), 200);
- }
-
+ }
+
/**
* Disconnect ftp connections
*/
@@ -269,8 +269,8 @@
}
return mConfig.getStatus().getResponse(200, cmd, mUser, null);
}
-
-
+
+
/**
* List all banned IPs.
*/
@@ -283,8 +283,8 @@
sb.append('\n');
return mConfig.getStatus().processNewLine(sb.toString(), 200);
}
-
-
+
+
/**
* List all the users.
*/
@@ -298,8 +298,8 @@
sb.append('\n');
return mConfig.getStatus().processNewLine(sb.toString(), 200);
}
-
-
+
+
/**
* Delete user from repository.
*/
@@ -307,12 +307,12 @@
if (args.length != 4) {
return mConfig.getStatus().getResponse(501, cmd, mUser, null);
}
-
+
boolean bSuccess = true;
try {
User user = mConfig.getUserManager().getUserByName(args[1]);
if (user != null) {
-
+
if ( "password".equals(args[2]) ) {
user.setPassword(args[3]);
}
@@ -337,7 +337,7 @@
else {
bSuccess = false;
}
-
+
if (bSuccess) {
mConfig.getUserManager().save(user);
}
@@ -350,7 +350,7 @@
mConfig.getLogger().warn("SiteCommandHandler.doSETATTR()", ex);
bSuccess = false;
}
-
+
String response = "";
if (bSuccess) {
response = mConfig.getStatus().getResponse(200, cmd, mUser, null);
@@ -358,18 +358,18 @@
else {
response = mConfig.getStatus().getResponse(451, cmd, mUser, null);
}
-
+
return response;
}
-
-
+
+
/**
* Display all connected users.
*/
public String doWHO(String[] args, FtpRequest cmd) {
StringBuffer sb = new StringBuffer();
List allUsers = mConfig.getConnectionService().getAllUsers();
-
+
sb.append('\n');
for(Iterator userIt = allUsers.iterator(); userIt.hasNext(); ) {
FtpUser user = (FtpUser)userIt.next();
@@ -385,5 +385,5 @@
sb.append('\n');
return mConfig.getStatus().processNewLine(sb.toString(), 200);
}
-
-}
+
+}
1.8 +39 -39 jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/ConfigTableModel.java
Index: ConfigTableModel.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/ConfigTableModel.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- ConfigTableModel.java 8 Mar 2002 06:27:30 -0000 1.7
+++ ConfigTableModel.java 20 May 2002 10:20:17 -0000 1.8
@@ -20,19 +20,19 @@
*/
public
class ConfigTableModel extends AbstractTableModel {
-
- private final static String[] COL_NAMES = {"Name", "Value"};
-
+
+ private static final String[] COL_NAMES = {"Name", "Value"};
+
private FtpConfigInterface mConfig;
private CommonHandler mCommonHandler;
-
+
/**
* All properties key.
*/
- private Vector mTableKeys = new Vector();
+ private Vector mTableKeys = new Vector();
private Vector mTableVals = new Vector();
-
-
+
+
/**
* Create this <code>TableModel</code>.
*/
@@ -41,79 +41,79 @@
mCommonHandler = commonHandler;
initializeTable();
}
-
+
/**
* Initialize table - populate vector.
*/
private void initializeTable() throws RemoteException {
mTableKeys.clear();
mTableVals.clear();
-
+
if(mConfig != null) {
mTableKeys.add("Server Address");
mTableVals.add(mConfig.getAddressString());
-
+
mTableKeys.add("Server Port");
mTableVals.add(String.valueOf(mConfig.getServerPort()));
mTableKeys.add("Anonymous Login Supported");
mTableVals.add(String.valueOf(mConfig.isAnonymousLoginAllowed()));
-
+
mTableKeys.add("Maximum Connections");
mTableVals.add(String.valueOf(mConfig.getMaxConnections()));
-
+
mTableKeys.add("Maximum Anonymous Connections");
mTableVals.add(String.valueOf(mConfig.getMaxAnonymousLogins()));
-
+
mTableKeys.add("Scheduler Interval (sec)");
mTableVals.add(String.valueOf(mConfig.getSchedulerInterval()));
-
+
mTableKeys.add("Default Idle Time (sec)");
mTableVals.add(String.valueOf(mConfig.getDefaultIdleTime()));
-
+
mTableKeys.add("Default Root Directory");
mTableVals.add(String.valueOf(mConfig.getDefaultRoot()));
-
+
mTableKeys.add("Remote Admin Port");
mTableVals.add(String.valueOf(mConfig.getRemoteAdminPort()));
-
+
mTableKeys.add("Remote Admin Allowed");
- mTableVals.add(String.valueOf(mConfig.isRemoteAdminAllowed()));
-
+ mTableVals.add(String.valueOf(mConfig.isRemoteAdminAllowed()));
+
mTableKeys.add("Base Directory");
- mTableVals.add(mConfig.getBaseDirectory());
+ mTableVals.add(mConfig.getBaseDirectory());
}
- }
-
-
+ }
+
+
/**
* Get column class - always string.
*/
public Class getColumnClass(int index) {
return String.class;
}
-
+
/**
* Get column count.
*/
public int getColumnCount() {
return COL_NAMES.length;
- }
-
+ }
+
/**
* Get column name.
*/
public String getColumnName(int index) {
return COL_NAMES[index];
- }
-
+ }
+
/**
* Get row count.
*/
public int getRowCount() {
return mTableKeys.size();
- }
-
+ }
+
/**
* Get value at.
*/
@@ -122,23 +122,23 @@
return mTableKeys.get(row);
}
else {
- return mTableVals.get(row);
+ return mTableVals.get(row);
}
- }
-
+ }
+
/**
* Is cell editable - currently true.
*/
public boolean isCellEditable(int row, int col) {
return true;
- }
-
+ }
+
/**
* Set value at - does not set value - dummy metod.
*/
public void setValueAt(Object val, int row, int col) {
- }
-
+ }
+
/**
* Clear table model.
*/
@@ -147,5 +147,5 @@
mTableVals.clear();
mConfig = null;
fireTableDataChanged();
- }
-}
+ }
+}
1.3 +13 -13 jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/FtpAboutPanel.java
Index: FtpAboutPanel.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/FtpAboutPanel.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- FtpAboutPanel.java 31 Mar 2002 16:52:43 -0000 1.2
+++ FtpAboutPanel.java 20 May 2002 10:20:17 -0000 1.3
@@ -34,10 +34,10 @@
*/
public
class FtpAboutPanel extends PluginPanel implements HyperlinkListener {
-
- public final static String ABOUT_PAGE = "org/apache/avalon/ftpserver/gui/about.html";
+
+ public static final String ABOUT_PAGE = "org/apache/avalon/ftpserver/gui/about.html";
private JEditorPane mjEditorPane = null;
-
+
/**
* Constructor.
*/
@@ -45,8 +45,8 @@
super(commonHandler, tree);
initComponents();
}
-
-
+
+
/**
* Initialize GUI components.
*/
@@ -57,12 +57,12 @@
mjEditorPane.setContentType("text/html");
goHome();
mjEditorPane.addHyperlinkListener(this);
-
+
JScrollPane editorScrollPane = new JScrollPane(mjEditorPane);
editorScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
editorScrollPane.setPreferredSize(new Dimension(480, 340));
add(editorScrollPane, BorderLayout.CENTER);
-
+
JPanel bottomPane = new JPanel();
bottomPane.setLayout(new FlowLayout(FlowLayout.CENTER));
JButton homeButton = new JButton("Home");
@@ -74,7 +74,7 @@
bottomPane.add(homeButton);
add(bottomPane, BorderLayout.SOUTH);
}
-
+
/**
* Handle user mouse click.
*/
@@ -86,7 +86,7 @@
HTMLFrameHyperlinkEvent evt = (HTMLFrameHyperlinkEvent)e;
HTMLDocument doc = (HTMLDocument)pane.getDocument();
doc.processHTMLFrameHyperlinkEvent(evt);
- }
+ }
else {
pane.setPage(e.getURL());
}
@@ -94,8 +94,8 @@
}
catch(Throwable th) {
}
- }
-
+ }
+
/**
* Display about page
*/
@@ -113,6 +113,6 @@
finally {
IoUtils.close(is);
}
- }
-
+ }
+
}
1.11 +74 -74 jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/FtpAdmin.java
Index: FtpAdmin.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/FtpAdmin.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- FtpAdmin.java 31 Mar 2002 16:52:43 -0000 1.10
+++ FtpAdmin.java 20 May 2002 10:20:17 -0000 1.11
@@ -32,25 +32,25 @@
*/
public
class FtpAdmin extends JFrame implements CommonHandler {
-
- private final static ImageIcon ICON_IMG = GuiUtils.createImageIcon("org/apache/avalon/ftpserver/gui/login.gif");
-
+
+ private static final ImageIcon ICON_IMG = GuiUtils.createImageIcon("org/apache/avalon/ftpserver/gui/login.gif");
+
private String mstSessionId = null;
- private JTextField mjHostTxt = null;
+ private JTextField mjHostTxt = null;
private JTextField mjPortTxt = null;
private JTextField mjAdminTxt = null;
private JPasswordField mjPasswordTxt = null;
-
+
private FtpAdminFrame mAdminFrame = null;
-
+
private RemoteHandlerInterface mRemote = null;
private FtpConfigInterface mConfig = null;
private FtpStatisticsInterface mStat = null;
- private ConnectionServiceInterface mConService = null;
+ private ConnectionServiceInterface mConService = null;
private IpRestrictorInterface mIpRestrictor = null;
private UserManagerInterface mUserManager = null;
-
-
+
+
/**
* Consructor - initialize components and display
* the login dialog box.
@@ -63,14 +63,14 @@
GuiUtils.setLocation(this);
show();
}
-
+
/**
* Iniialize all the swing components.
*/
public void initComponents() {
GridBagConstraints gc;
getContentPane().setLayout(new GridBagLayout());
-
+
// Host name
JLabel jHostLab = new JLabel("Host");
jHostLab.setHorizontalAlignment(JLabel.RIGHT);
@@ -82,7 +82,7 @@
gc.anchor = GridBagConstraints.EAST;
gc.insets = new Insets(0, 0, 5, 10);
getContentPane().add(jHostLab, gc);
-
+
mjHostTxt = new JTextField("localhost");
mjHostTxt.setColumns(15);
gc = new GridBagConstraints();
@@ -91,7 +91,7 @@
gc.gridwidth = 2;
gc.anchor = GridBagConstraints.WEST;
getContentPane().add(mjHostTxt, gc);
-
+
// Port number
JLabel jPortLab = new JLabel("Port");
jPortLab.setHorizontalAlignment(JLabel.RIGHT);
@@ -103,7 +103,7 @@
gc.anchor = GridBagConstraints.EAST;
gc.insets = new Insets(0, 0, 5, 10);
getContentPane().add(jPortLab, gc);
-
+
mjPortTxt = new JTextField(String.valueOf(Registry.REGISTRY_PORT));
mjPortTxt.setColumns(5);
gc = new GridBagConstraints();
@@ -124,7 +124,7 @@
gc.anchor = GridBagConstraints.EAST;
gc.insets = new Insets(0, 0, 5, 10);
getContentPane().add(jAdminLab, gc);
-
+
mjAdminTxt = new JTextField();
mjAdminTxt.setColumns(15);
gc = new GridBagConstraints();
@@ -145,7 +145,7 @@
gc.anchor = GridBagConstraints.EAST;
gc.insets = new Insets(0, 0, 5, 10);
getContentPane().add(jPasswordLab, gc);
-
+
mjPasswordTxt = new JPasswordField();
mjPasswordTxt.setColumns(15);
gc = new GridBagConstraints();
@@ -154,48 +154,48 @@
gc.gridwidth = 2;
gc.anchor = GridBagConstraints.WEST;
getContentPane().add(mjPasswordTxt, gc);
-
+
// button panel
JPanel btnPane = new JPanel();
btnPane.setLayout(new FlowLayout(FlowLayout.CENTER));
-
+
JButton jLoginBtn = new JButton("Login");
jLoginBtn.setSelected(true);
jLoginBtn.setDefaultCapable(true);
btnPane.add(jLoginBtn);
-
+
JButton jCancelBtn = new JButton("Cancel");
btnPane.add(jCancelBtn);
-
+
gc = new GridBagConstraints();
gc.gridx = 0;
gc.gridy = 4;
gc.gridwidth = 3;
getContentPane().add(btnPane, gc);
-
-
+
+
// event listeners
jLoginBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
login();
}
});
-
+
jCancelBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
terminate();
}
});
-
+
// set login icon
if (ICON_IMG != null) {
setIconImage(ICON_IMG.getImage());
}
}
-
+
/*
* Handle window closing event.
- */
+ */
protected void processWindowEvent(WindowEvent e) {
int id = e.getID();
if (id == WindowEvent.WINDOW_CLOSING) {
@@ -203,10 +203,10 @@
}
else {
super.processWindowEvent(e);
- }
+ }
}
-
-
+
+
/**
* Login and get remote object
*/
@@ -215,37 +215,37 @@
String host = mjHostTxt.getText();
String port = mjPortTxt.getText();
String login = mjAdminTxt.getText();
- String password = new String(mjPasswordTxt.getPassword());
-
+ String password = new String(mjPasswordTxt.getPassword());
+
mjHostTxt.setText("localhost");
mjPortTxt.setText(String.valueOf(Registry.REGISTRY_PORT));
mjAdminTxt.setText("");
mjPasswordTxt.setText("");
-
+
String url = "rmi://" + host + ":" + port + "/" + RemoteHandlerInterface.BIND_NAME;
mRemote = (RemoteHandlerInterface)Naming.lookup(url);
- mstSessionId = mRemote.login(login, password);
-
+ mstSessionId = mRemote.login(login, password);
+
mConfig = mRemote.getConfigInterface(mstSessionId);
mStat = mConfig.getStatistics();
mConService = mConfig.getConnectionService();
mIpRestrictor = mConfig.getIpRestrictor();
mUserManager = mConfig.getUserManager();
-
+
if (mAdminFrame != null) {
mAdminFrame.close();
mAdminFrame = null;
}
mAdminFrame = new FtpAdminFrame(this);
-
- setVisible(false);
+
+ setVisible(false);
mAdminFrame.show();
}
catch(Exception ex) {
handleException(ex);
}
}
-
+
/**
* Handle exception
*/
@@ -257,7 +257,7 @@
setVisible(true);
}
}
-
+
/**
* Terminate application
*/
@@ -266,62 +266,62 @@
dispose();
System.exit(0);
}
-
-
+
+
/**
* Get admin session id
*/
public String getSessionId() {
return mstSessionId;
- }
-
-
+ }
+
+
/**
* Get server interface
*/
public RemoteHandlerInterface getRemoteHandler() {
return mRemote;
- }
-
-
+ }
+
+
/**
* Get ftp server configuration
*/
public FtpConfigInterface getConfig() {
return mConfig;
- }
-
+ }
+
/**
* Get statistics interface
*/
public FtpStatisticsInterface getStatistics() {
return mStat;
- }
-
+ }
+
/**
* Get connection service
- */
+ */
public ConnectionServiceInterface getConnectionService() {
return mConService;
}
-
+
/**
* Get IP restrictor
- */
+ */
public IpRestrictorInterface getIpRestrictor() {
return mIpRestrictor;
- }
-
+ }
+
/**
* Get user manager
- */
+ */
public UserManagerInterface getUserManager() {
return mUserManager;
}
-
+
/**
* Get user object from the session id
- */
+ */
public FtpUser getUser(String sessionId) {
try {
return mConService.getUser(sessionId);
@@ -330,40 +330,40 @@
handleException(ex);
}
return null;
- }
+ }
/**
* Logout admin user
- */
+ */
private void logout() {
if (mAdminFrame != null) {
mAdminFrame.close();
mAdminFrame = null;
}
if (mRemote != null) {
- try {
- mRemote.logout(mstSessionId);
- }
+ try {
+ mRemote.logout(mstSessionId);
+ }
catch(Exception ex) {
}
mRemote = null;
}
- mstSessionId = null;
- }
-
-
+ mstSessionId = null;
+ }
+
+
/**
* Get top component of this application
- */
+ */
public Component getTopComponent() {
Component topComp = this;
if (mAdminFrame != null) {
topComp = mAdminFrame;
}
-
+
return topComp;
- }
-
+ }
+
////////////////////////////////////////////////////////////////////////
/////////////////////// Program Starting Point ///////////////////////
////////////////////////////////////////////////////////////////////////
@@ -373,5 +373,5 @@
public static void main(String args[]) {
new FtpAdmin();
}
-
-}
\ No newline at end of file
+
+}
\ No newline at end of file
1.12 +28 -28 jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/FtpAdminFrame.java
Index: FtpAdminFrame.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/FtpAdminFrame.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- FtpAdminFrame.java 31 Mar 2002 16:52:43 -0000 1.11
+++ FtpAdminFrame.java 20 May 2002 10:20:17 -0000 1.12
@@ -19,60 +19,60 @@
/**
- * Ftp server admin user interface.
+ * Ftp server admin user interface.
*
* @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
*/
-public
+public
class FtpAdminFrame extends JFrame implements TreeSelectionListener {
-
- private final static ImageIcon ICON_IMG = GuiUtils.createImageIcon("org/apache/avalon/ftpserver/gui/server.gif");
-
- private JTabbedPane mjTabPane;
-
+
+ private static final ImageIcon ICON_IMG = GuiUtils.createImageIcon("org/apache/avalon/ftpserver/gui/server.gif");
+
+ private JTabbedPane mjTabPane;
+
private FtpTree mjFtpTree = null;
private JPanel mjFtpPane = null;
-
+
private CommonHandler mCommonHandler = null;
-
- /**
- * Creates new form MyServerFrame
+
+ /**
+ * Creates new form MyServerFrame
*/
- public FtpAdminFrame(CommonHandler commonHandler) throws RemoteException {
+ public FtpAdminFrame(CommonHandler commonHandler) throws RemoteException {
mCommonHandler = commonHandler;
- initComponents();
+ initComponents();
}
- /**
+ /**
* This method is called from within the constructor to
* initialize the form.
*/
- private void initComponents() throws RemoteException {
+ private void initComponents() throws RemoteException {
mjTabPane = new JTabbedPane();
-
+
// top level
JSplitPane jSplitPane = new JSplitPane();
jSplitPane.setDividerSize(2);
-
+
// left pane
mjFtpTree = new FtpTree(mCommonHandler);
mjFtpTree.addTreeSelectionListener(this);
- JScrollPane custPane = new JScrollPane(mjFtpTree,
+ JScrollPane custPane = new JScrollPane(mjFtpTree,
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
jSplitPane.setLeftComponent(custPane);
-
+
// right pane
mjFtpPane = new JPanel();
jSplitPane.setRightComponent(mjFtpPane);
-
+
mjFtpPane.add(mjFtpTree.getRootPanel());
-
- jSplitPane.setDividerLocation(100);
+
+ jSplitPane.setDividerLocation(100);
mjTabPane.addTab(RemoteHandlerInterface.DISPLAY_NAME, jSplitPane);
-
+
getContentPane().add(mjTabPane, BorderLayout.CENTER);
-
+
pack();
setTitle("Ftp Server");
if (ICON_IMG != null) {
@@ -84,7 +84,7 @@
/*
* Handle window closing event.
- */
+ */
protected void processWindowEvent(WindowEvent e) {
int id = e.getID();
if (id == WindowEvent.WINDOW_CLOSING) {
@@ -92,10 +92,10 @@
return;
}
mCommonHandler.terminate();
- }
+ }
else {
super.processWindowEvent(e);
- }
+ }
}
/**
@@ -107,7 +107,7 @@
GuiUtils.showNewPanel(mjFtpPane, dispPane);
}
}
-
+
/**
* Release resources
*/
1.6 +49 -49 jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/FtpConnectionTableModel.java
Index: FtpConnectionTableModel.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/FtpConnectionTableModel.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- FtpConnectionTableModel.java 31 Mar 2002 16:52:43 -0000 1.5
+++ FtpConnectionTableModel.java 20 May 2002 10:20:17 -0000 1.6
@@ -30,30 +30,30 @@
* @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>.
*/
public
-class FtpConnectionTableModel extends AbstractTableModel
+class FtpConnectionTableModel extends AbstractTableModel
implements FtpConnectionObserver {
-
- private final static SimpleDateFormat DATE_FMT = new SimpleDateFormat("MM/dd HH:mm:ss");
-
- private final static String[] COL_NAMES = {"User",
- "Login Time",
- "Last Access Time",
+
+ private static final SimpleDateFormat DATE_FMT = new SimpleDateFormat("MM/dd HH:mm:ss");
+
+ private static final String[] COL_NAMES = {"User",
+ "Login Time",
+ "Last Access Time",
"Client"};
private List mConnectedUserList;
-
+
private ConnectionServiceInterface mConService;
private CommonHandler mCommonHandler;
private FtpConnectionObserverAdapter mObserver;
-
-
+
+
/**
* Constructor - initialize user list
*/
public FtpConnectionTableModel(CommonHandler commonHandler) {
mCommonHandler = commonHandler;
mConService = mCommonHandler.getConnectionService();
- mConnectedUserList = new Vector();
- try {
+ mConnectedUserList = new Vector();
+ try {
mObserver = new FtpConnectionObserverAdapter(mConService, this);
reload();
}
@@ -61,7 +61,7 @@
commonHandler.handleException(ex);
}
}
-
+
/**
* Get user
*/
@@ -74,61 +74,61 @@
}
return user;
}
-
-
+
+
/**
* Get column class - always string
*/
public Class getColumnClass(int index) {
return String.class;
}
-
+
/**
* Get column count.
*/
public int getColumnCount() {
return COL_NAMES.length;
}
-
+
/**
* Get column name.
*/
public String getColumnName(int index) {
return COL_NAMES[index];
- }
-
+ }
+
/**
* Get row count.
*/
public int getRowCount() {
return mConnectedUserList.size();
}
-
+
/**
* Is cell editable - currently false.
*/
public boolean isCellEditable(int row, int col) {
return true;
}
-
+
/**
* Set value at - dummy method
*/
public void setValueAt(Object val, int row, int col) {
}
-
+
/**
* Get value at.
*/
public Object getValueAt(int row, int col) {
-
+
// error check
- String retVal = "";
+ String retVal = "";
FtpUser thisUser = getUser(row);
if (thisUser == null) {
return retVal;
}
-
+
switch(col) {
case 0:
retVal = thisUser.getName();
@@ -136,32 +136,32 @@
retVal = "";
}
break;
-
+
case 1:
long loginTime = thisUser.getLoginTime();
if (loginTime > 0) {
retVal = DATE_FMT.format(new Date(loginTime));
}
break;
-
+
case 2:
long accessTime = thisUser.getLastAccessTime();
if (accessTime > 0) {
retVal = DATE_FMT.format(new Date(accessTime));
}
break;
-
+
case 3:
InetAddress remoteHost = thisUser.getClientAddress();
if(remoteHost != null) {
retVal = remoteHost.getHostAddress();
}
- break;
+ break;
}
return retVal;
}
-
-
+
+
/////////////////////////// Observer Methods ///////////////////////////
/**
* Add a new user
@@ -170,7 +170,7 @@
if (thisUser == null) {
return;
}
-
+
int sz = -1;
synchronized(mConnectedUserList) {
mConnectedUserList.add(thisUser);
@@ -180,9 +180,9 @@
if (sz != -1) {
fireTableRowsInserted(sz, sz);
}
- }
-
-
+ }
+
+
/**
* Close .
*/
@@ -190,7 +190,7 @@
if (user == null) {
return;
}
-
+
int index = -1;
synchronized(mConnectedUserList) {
index = mConnectedUserList.indexOf(user);
@@ -198,12 +198,12 @@
mConnectedUserList.remove(index);
}
}
-
+
if (index != -1) {
fireTableRowsDeleted(index, index);
}
}
-
+
/**
* Existing connected user update notification.
*/
@@ -211,7 +211,7 @@
if (user == null) {
return;
}
-
+
int index = -1;
synchronized(mConnectedUserList) {
index = mConnectedUserList.indexOf(user);
@@ -219,13 +219,13 @@
mConnectedUserList.set(index, user);
}
}
-
+
if (index != -1) {
fireTableRowsUpdated(index, index);
}
- }
-
-
+ }
+
+
/**
* Reload table model
*/
@@ -235,16 +235,16 @@
mConnectedUserList.addAll(mConService.getAllUsers());
}
fireTableDataChanged();
- }
-
-
+ }
+
+
/**
* Close the resource
*/
public void close() {
mObserver.close();
mConnectedUserList.clear();
- }
-
-}
+ }
+
+}
1.3 +32 -32 jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/FtpFileTableModel.java
Index: FtpFileTableModel.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/FtpFileTableModel.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- FtpFileTableModel.java 10 Mar 2002 06:10:36 -0000 1.2
+++ FtpFileTableModel.java 20 May 2002 10:20:17 -0000 1.3
@@ -16,21 +16,21 @@
/**
* This table model tracks user file related activities.
- *
+ *
* @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>.
*/
public
class FtpFileTableModel extends AbstractTableModel {
-
- private final static int MAX_SIZE = 1000;
- private final static SimpleDateFormat DATE_FMT = new SimpleDateFormat("MM/dd HH:mm:ss");
- private final static String[] COL_NAMES = {"File",
- "User",
- "Time"};
+
+ private static final int MAX_SIZE = 1000;
+ private static final SimpleDateFormat DATE_FMT = new SimpleDateFormat("MM/dd HH:mm:ss");
+ private static final String[] COL_NAMES = {"File",
+ "User",
+ "Time"};
private Vector mEntryList = new Vector();
-
-
+
+
/**
* Reload the model.
*/
@@ -38,53 +38,53 @@
mEntryList.clear();
fireTableDataChanged();
}
-
+
/**
* Get column class - always string
*/
public Class getColumnClass(int index) {
return String.class;
}
-
+
/**
* Get column count.
*/
public int getColumnCount() {
return COL_NAMES.length;
}
-
+
/**
* Get column name.
*/
public String getColumnName(int index) {
return COL_NAMES[index];
- }
-
+ }
+
/**
* Get row count.
*/
public int getRowCount() {
return mEntryList.size();
}
-
+
/**
* Is cell editable - currently false.
*/
public boolean isCellEditable(int row, int col) {
return true;
}
-
+
/**
* Set value at - dummy method
*/
public void setValueAt(Object val, int row, int col) {
}
-
+
/**
* Get value at.
*/
public Object getValueAt(int row, int col) {
-
+
String retVal = "";
TableEntry entry = null;
try {
@@ -95,23 +95,23 @@
if (entry == null) {
return retVal;
}
-
+
switch(col) {
case 0:
retVal = entry.fileName;
break;
-
+
case 1:
retVal = entry.userName;
break;
-
+
case 2:
retVal = entry.date;
- break;
+ break;
}
return retVal;
}
-
+
/**
* Find column index.
*/
@@ -125,37 +125,37 @@
}
return index;
}
-
+
/**
* Add a new user
*/
public void newEntry(String file, FtpUser user) {
-
+
TableEntry entry = new TableEntry();
entry.fileName = file;
entry.userName = user.getName();
entry.date = DATE_FMT.format(new Date());
-
+
int sz = mEntryList.size();
if ( (MAX_SIZE > 0) && (sz >= MAX_SIZE) ) {
reset();
sz = 0;
}
-
+
synchronized(mEntryList) {
mEntryList.add(entry);
++sz;
}
fireTableRowsInserted(sz, sz);
- }
-
+ }
+
/**
* Remove all entries
*/
public void close() {
mEntryList.clear();
}
-
+
//////////////////////////////////////////////////////////
///////////////////////list entry ///////////////////////
public class TableEntry {
@@ -163,5 +163,5 @@
String userName;
String date;
}
-
-}
+
+}
1.3 +32 -32 jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/FtpSpyContainerPanel.java
Index: FtpSpyContainerPanel.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/FtpSpyContainerPanel.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- FtpSpyContainerPanel.java 7 Apr 2002 17:09:30 -0000 1.2
+++ FtpSpyContainerPanel.java 20 May 2002 10:20:17 -0000 1.3
@@ -19,22 +19,22 @@
/**
* This panel holds all connection spy panels.
- *
+ *
* @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
*/
public
class FtpSpyContainerPanel extends PluginPanel {
-
- public final static String SPY_PAGE = "org/apache/avalon/ftpserver/gui/spy.html";
-
+
+ public static final String SPY_PAGE = "org/apache/avalon/ftpserver/gui/spy.html";
+
private JTabbedPane mjTabbedPane = null;
-
+
private JButton mjClearButton = null;
private JButton mjCloseButton = null;
private JButton mjDisconnectButton = null;
private JScrollPane mjAboutPane = null;
-
-
+
+
/**
* Constructor - create empty tabbed frame
*/
@@ -42,7 +42,7 @@
super(commonHandler, tree);
initComponents();
}
-
+
/**
* Initialize all components
*/
@@ -51,10 +51,10 @@
mjTabbedPane = new JTabbedPane();
mjTabbedPane.setPreferredSize(new Dimension(470, 340));
add(mjTabbedPane, BorderLayout.CENTER);
-
+
JPanel bottomPane = new JPanel();
bottomPane.setLayout(new FlowLayout(FlowLayout.CENTER));
-
+
mjClearButton = new JButton("Clear");
bottomPane.add(mjClearButton);
mjClearButton.addActionListener(new ActionListener() {
@@ -62,7 +62,7 @@
clearLog();
}
});
-
+
mjCloseButton = new JButton("Close");
bottomPane.add(mjCloseButton);
mjCloseButton.addActionListener(new ActionListener() {
@@ -70,7 +70,7 @@
closePane();
}
});
-
+
mjDisconnectButton = new JButton("Disconnect");
bottomPane.add(mjDisconnectButton);
mjDisconnectButton.addActionListener(new ActionListener() {
@@ -79,8 +79,8 @@
}
});
add(bottomPane, BorderLayout.SOUTH);
-
- // initialize component to be displayed if
+
+ // initialize component to be displayed if
// there is no currently monitored connection
JEditorPane editorPane = new JEditorPane();
editorPane.setEditable(false);
@@ -97,14 +97,14 @@
finally {
IoUtils.close(is);
}
- mjAboutPane = new JScrollPane(editorPane,
+ mjAboutPane = new JScrollPane(editorPane,
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
- mjTabbedPane.addTab("Spy", mjAboutPane);
-
+ mjTabbedPane.addTab("Spy", mjAboutPane);
+
}
-
-
+
+
/**
* Clear user log
*/
@@ -114,10 +114,10 @@
((SpyPanel)selComp).clearLog();
}
}
-
+
/**
* Close connection spy panel.
- */
+ */
private void closePane() {
Component selComp = mjTabbedPane.getSelectedComponent();
if ( (selComp != null) && (selComp != mjAboutPane) ) {
@@ -128,7 +128,7 @@
}
}
}
-
+
/**
* Disconnected user connection
*/
@@ -141,14 +141,14 @@
}
}
}
-
+
/**
* Monitor connection
*/
public void monitorConnection(FtpUser user) {
String userName = getName(user);
- String userSession = user.getSessionId();
-
+ String userSession = user.getSessionId();
+
// don't add another tab if already being monitored
int tabCount = mjTabbedPane.getTabCount();
for(int i=tabCount; --i>=0; ) {
@@ -162,7 +162,7 @@
}
}
}
-
+
// add new tab
try {
SpyPanel spyPane = new SpyPanel(getCommonHandler(), user);
@@ -173,8 +173,8 @@
catch(Exception ex) {
getCommonHandler().handleException(ex);
}
- }
-
+ }
+
/**
* Get name
*/
@@ -187,11 +187,11 @@
}
}
return name;
- }
-
+ }
+
/**
* Stop all spying
- */
+ */
public void close() {
int tabCount = mjTabbedPane.getTabCount();
for(int i=tabCount; --i>=0; ) {
@@ -202,5 +202,5 @@
}
}
}
-
+
}
1.10 +83 -83 jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/FtpStatisticsPanel.java
Index: FtpStatisticsPanel.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/FtpStatisticsPanel.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- FtpStatisticsPanel.java 31 Mar 2002 16:52:43 -0000 1.9
+++ FtpStatisticsPanel.java 20 May 2002 10:20:17 -0000 1.10
@@ -23,55 +23,55 @@
/**
* Ftp server global statistics panel. It listenes to the global
* statistics changes.
- *
+ *
* @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
*/
public
-class FtpStatisticsPanel extends PluginPanel
- implements FtpStatisticsListener, FtpFileListener {
+class FtpStatisticsPanel extends PluginPanel
+ implements FtpStatisticsListener, FtpFileListener {
+
+ private static final SimpleDateFormat DATE_FMT = new SimpleDateFormat("MM/dd HH:mm:ss");
- private final static SimpleDateFormat DATE_FMT = new SimpleDateFormat("MM/dd HH:mm:ss");
-
private JTextField mjStartTimeTxt;
-
+
private JTextField mjUploadNbrTxt;
private JTextField mjDownloadNbrTxt;
private JTextField mjDeleteNbrTxt;
-
+
private JTextField mjUploadBytesTxt;
private JTextField mjDownloadBytesTxt;
-
+
private JTextField mjLoginNbrTxt;
private JTextField mjAnonLoginNbrTxt;
private JTextField mjConNbrTxt;
-
+
private JTextField mjTotalLoginNbrTxt;
private JTextField mjTotalAnonLoginNbrTxt;
private JTextField mjTotalConNbrTxt;
-
+
private FtpFileTableModel mUploadModel;
private FtpFileTableModel mDownloadModel;
private FtpFileTableModel mDeleteModel;
-
- private FtpStatisticsInterface mStat;
-
+
+ private FtpStatisticsInterface mStat;
+
private FtpFileListenerAdapter mFileListener;
private FtpStatisticsListenerAdapter mListener;
-
- /**
- * Creates new panel to display ftp global statistics.
+
+ /**
+ * Creates new panel to display ftp global statistics.
*/
public FtpStatisticsPanel(CommonHandler commonHandler, JTree tree) {
super(commonHandler, tree);
mStat = commonHandler.getStatistics();
-
+
mUploadModel = new FtpFileTableModel();
mDownloadModel = new FtpFileTableModel();
mDeleteModel = new FtpFileTableModel();
initComponents();
-
+
try {
- mFileListener = new FtpFileListenerAdapter(mStat, this);
+ mFileListener = new FtpFileListenerAdapter(mStat, this);
mListener = new FtpStatisticsListenerAdapter(mStat, this);
reload();
mjStartTimeTxt.setText(DATE_FMT.format(mStat.getStartTime()));
@@ -81,17 +81,17 @@
}
}
- /**
+ /**
* This method is called from within the constructor to
* initialize the panel.
*/
private void initComponents() {
setLayout(new BorderLayout());
-
+
JPanel topPane = new JPanel();
GridBagConstraints gc;
topPane.setLayout(new GridBagLayout());
-
+
// start time
JLabel jStartTimeLab = new JLabel("Start Time");
jStartTimeLab.setHorizontalAlignment(JLabel.RIGHT);
@@ -103,7 +103,7 @@
gc.anchor = GridBagConstraints.EAST;
gc.insets = new Insets(15, 0, 0, 5);
topPane.add(jStartTimeLab, gc);
-
+
mjStartTimeTxt = new JTextField();
mjStartTimeTxt.setColumns(15);
mjStartTimeTxt.setEditable(false);
@@ -114,7 +114,7 @@
gc.anchor = GridBagConstraints.WEST;
gc.insets = new Insets(15, 0, 0, 5);
topPane.add(mjStartTimeTxt, gc);
-
+
// number of uploads
JLabel jUploadNbrLab = new JLabel("Number of uploads");
jUploadNbrLab.setHorizontalAlignment(JLabel.RIGHT);
@@ -125,8 +125,8 @@
gc.gridwidth = 1;
gc.anchor = GridBagConstraints.EAST;
gc.insets = new Insets(5, 0, 0, 5);
- topPane.add(jUploadNbrLab, gc);
-
+ topPane.add(jUploadNbrLab, gc);
+
mjUploadNbrTxt = new JTextField();
mjUploadNbrTxt.setColumns(6);
mjUploadNbrTxt.setEditable(false);
@@ -137,7 +137,7 @@
gc.anchor = GridBagConstraints.WEST;
gc.insets = new Insets(5, 0, 0, 5);
topPane.add(mjUploadNbrTxt, gc);
-
+
// number of downloads
JLabel jDownloadNbrLab = new JLabel("Number of downloads");
jDownloadNbrLab.setHorizontalAlignment(JLabel.RIGHT);
@@ -149,7 +149,7 @@
gc.anchor = GridBagConstraints.EAST;
gc.insets = new Insets(5, 0, 0, 5);
topPane.add(jDownloadNbrLab, gc);
-
+
mjDownloadNbrTxt = new JTextField();
mjDownloadNbrTxt.setColumns(6);
mjDownloadNbrTxt.setEditable(false);
@@ -160,7 +160,7 @@
gc.anchor = GridBagConstraints.WEST;
gc.insets = new Insets(5, 0, 0, 5);
topPane.add(mjDownloadNbrTxt, gc);
-
+
// number of downloads
JLabel jDeleteNbrLab = new JLabel("Number of deletes");
jDeleteNbrLab.setHorizontalAlignment(JLabel.RIGHT);
@@ -172,7 +172,7 @@
gc.anchor = GridBagConstraints.EAST;
gc.insets = new Insets(5, 0, 0, 5);
topPane.add(jDeleteNbrLab, gc);
-
+
mjDeleteNbrTxt = new JTextField();
mjDeleteNbrTxt.setColumns(6);
mjDeleteNbrTxt.setEditable(false);
@@ -182,8 +182,8 @@
gc.gridwidth = 2;
gc.anchor = GridBagConstraints.WEST;
gc.insets = new Insets(5, 0, 0, 5);
- topPane.add(mjDeleteNbrTxt, gc);
-
+ topPane.add(mjDeleteNbrTxt, gc);
+
// number of uploaded bytes
JLabel jUploadBytesLab = new JLabel("Uploaded bytes");
jUploadBytesLab.setHorizontalAlignment(JLabel.RIGHT);
@@ -195,7 +195,7 @@
gc.anchor = GridBagConstraints.EAST;
gc.insets = new Insets(5, 0, 0, 5);
topPane.add(jUploadBytesLab, gc);
-
+
mjUploadBytesTxt = new JTextField();
mjUploadBytesTxt.setColumns(15);
mjUploadBytesTxt.setEditable(false);
@@ -206,7 +206,7 @@
gc.anchor = GridBagConstraints.WEST;
gc.insets = new Insets(5, 0, 0, 5);
topPane.add(mjUploadBytesTxt, gc);
-
+
// number of uploaded bytes
JLabel jDownloadBytesLab = new JLabel("Downloaded bytes");
jDownloadBytesLab.setHorizontalAlignment(JLabel.RIGHT);
@@ -218,10 +218,10 @@
gc.anchor = GridBagConstraints.EAST;
gc.insets = new Insets(5, 0, 0, 5);
topPane.add(jDownloadBytesLab, gc);
-
+
mjDownloadBytesTxt = new JTextField();
mjDownloadBytesTxt.setColumns(15);
- mjDownloadBytesTxt.setEditable(false);
+ mjDownloadBytesTxt.setEditable(false);
gc = new GridBagConstraints();
gc.gridx = 1;
gc.gridy = 5;
@@ -229,7 +229,7 @@
gc.anchor = GridBagConstraints.WEST;
gc.insets = new Insets(5, 0, 0, 5);
topPane.add(mjDownloadBytesTxt, gc);
-
+
// number of current logins
JLabel jLoginNbrLab = new JLabel("Current logins");
jLoginNbrLab.setHorizontalAlignment(JLabel.RIGHT);
@@ -241,7 +241,7 @@
gc.anchor = GridBagConstraints.EAST;
gc.insets = new Insets(5, 0, 0, 5);
topPane.add(jLoginNbrLab, gc);
-
+
mjLoginNbrTxt = new JTextField();
mjLoginNbrTxt.setColumns(6);
mjLoginNbrTxt.setEditable(false);
@@ -252,7 +252,7 @@
gc.anchor = GridBagConstraints.WEST;
gc.insets = new Insets(5, 0, 0, 5);
topPane.add(mjLoginNbrTxt, gc);
-
+
// number of total logins
JLabel jTotalLoginNbrLab = new JLabel("Total logins");
jTotalLoginNbrLab.setHorizontalAlignment(JLabel.RIGHT);
@@ -264,7 +264,7 @@
gc.anchor = GridBagConstraints.EAST;
gc.insets = new Insets(5, 0, 0, 5);
topPane.add(jTotalLoginNbrLab, gc);
-
+
mjTotalLoginNbrTxt = new JTextField();
mjTotalLoginNbrTxt.setColumns(6);
mjTotalLoginNbrTxt.setEditable(false);
@@ -275,7 +275,7 @@
gc.anchor = GridBagConstraints.WEST;
gc.insets = new Insets(5, 0, 0, 5);
topPane.add(mjTotalLoginNbrTxt, gc);
-
+
// number of current anonymous logins
JLabel jAnonLoginNbrLab = new JLabel("Current anonymous logins");
jAnonLoginNbrLab.setHorizontalAlignment(JLabel.RIGHT);
@@ -287,7 +287,7 @@
gc.anchor = GridBagConstraints.EAST;
gc.insets = new Insets(5, 0, 0, 5);
topPane.add(jAnonLoginNbrLab, gc);
-
+
mjAnonLoginNbrTxt = new JTextField();
mjAnonLoginNbrTxt.setColumns(6);
mjAnonLoginNbrTxt.setEditable(false);
@@ -297,8 +297,8 @@
gc.gridwidth = 2;
gc.anchor = GridBagConstraints.WEST;
gc.insets = new Insets(5, 0, 0, 5);
- topPane.add(mjAnonLoginNbrTxt, gc);
-
+ topPane.add(mjAnonLoginNbrTxt, gc);
+
// number of total anonymous logins
JLabel jTotalAnonLoginNbrLab = new JLabel("Total anonymous logins");
jTotalAnonLoginNbrLab.setHorizontalAlignment(JLabel.RIGHT);
@@ -310,7 +310,7 @@
gc.anchor = GridBagConstraints.EAST;
gc.insets = new Insets(5, 0, 0, 5);
topPane.add(jTotalAnonLoginNbrLab, gc);
-
+
mjTotalAnonLoginNbrTxt = new JTextField();
mjTotalAnonLoginNbrTxt.setColumns(6);
mjTotalAnonLoginNbrTxt.setEditable(false);
@@ -321,7 +321,7 @@
gc.anchor = GridBagConstraints.WEST;
gc.insets = new Insets(5, 0, 0, 5);
topPane.add(mjTotalAnonLoginNbrTxt, gc);
-
+
// number of current connections
JLabel jConNbrLab = new JLabel("Current connections");
jConNbrLab.setHorizontalAlignment(JLabel.RIGHT);
@@ -333,7 +333,7 @@
gc.anchor = GridBagConstraints.EAST;
gc.insets = new Insets(5, 0, 0, 5);
topPane.add(jConNbrLab, gc);
-
+
mjConNbrTxt = new JTextField();
mjConNbrTxt.setColumns(6);
mjConNbrTxt.setEditable(false);
@@ -343,8 +343,8 @@
gc.gridwidth = 2;
gc.anchor = GridBagConstraints.WEST;
gc.insets = new Insets(5, 0, 0, 5);
- topPane.add(mjConNbrTxt, gc);
-
+ topPane.add(mjConNbrTxt, gc);
+
// number of current connections
JLabel jTotalConNbrLab = new JLabel("Total connections");
jTotalConNbrLab.setHorizontalAlignment(JLabel.RIGHT);
@@ -356,7 +356,7 @@
gc.anchor = GridBagConstraints.EAST;
gc.insets = new Insets(5, 0, 0, 5);
topPane.add(jTotalConNbrLab, gc);
-
+
mjTotalConNbrTxt = new JTextField();
mjTotalConNbrTxt.setColumns(6);
mjTotalConNbrTxt.setEditable(false);
@@ -366,10 +366,10 @@
gc.gridwidth = 2;
gc.anchor = GridBagConstraints.WEST;
gc.insets = new Insets(5, 0, 0, 5);
- topPane.add(mjTotalConNbrTxt, gc);
-
- add(topPane, BorderLayout.CENTER);
-
+ topPane.add(mjTotalConNbrTxt, gc);
+
+ add(topPane, BorderLayout.CENTER);
+
JPanel bottomPane = new JPanel();
bottomPane.setLayout(new FlowLayout(FlowLayout.CENTER));
JButton jReloadButton = new JButton("Reload");
@@ -379,36 +379,36 @@
}
});
bottomPane.add(jReloadButton);
-
+
add(bottomPane, BorderLayout.SOUTH);
}
-
+
/**
* Get upload file table model.
*/
public FtpFileTableModel getUploadModel() {
return mUploadModel;
}
-
+
/**
* Get download file table model.
*/
public FtpFileTableModel getDownloadModel() {
return mDownloadModel;
}
-
+
/**
* Get delete file table model.
*/
public FtpFileTableModel getDeleteModel() {
return mDeleteModel;
}
-
+
/**
* Upload notification.
*/
public void notifyUpload() {
- try {
+ try {
mjUploadNbrTxt.setText(String.valueOf(mStat.getFileUploadNbr()));
mjUploadBytesTxt.setText(String.valueOf(mStat.getFileUploadSize()));
}
@@ -416,7 +416,7 @@
getCommonHandler().handleException(ex);
}
}
-
+
/**
* Download notification.
*/
@@ -429,8 +429,8 @@
getCommonHandler().handleException(ex);
}
}
-
-
+
+
/**
* Delete notification.
*/
@@ -442,7 +442,7 @@
getCommonHandler().handleException(ex);
}
}
-
+
/**
* User login notification.
*/
@@ -457,17 +457,17 @@
getCommonHandler().handleException(ex);
}
}
-
+
/**
* User logout notification.
*/
public void notifyLogout() {
notifyLogin();
- }
-
+ }
+
/**
* Notify open/close connection
- */
+ */
public void notifyConnection() {
try {
mjConNbrTxt.setText(String.valueOf(mStat.getConnectionNbr()));
@@ -476,39 +476,39 @@
catch(Exception ex) {
getCommonHandler().handleException(ex);
}
- }
-
+ }
+
/**
* Notify file upload
- */
+ */
public void notifyUpload(final String fl, final String sessId) {
FtpUser user = getCommonHandler().getUser(sessId);
if (user != null) {
mUploadModel.newEntry(fl, user);
}
- }
-
+ }
+
/**
* Notify file download
- */
+ */
public void notifyDownload(final String fl, final String sessId) {
FtpUser user = getCommonHandler().getUser(sessId);
if (user != null) {
mDownloadModel.newEntry(fl, user);
}
}
-
+
/**
* Notify file delete
- */
+ */
public void notifyDelete(final String fl, final String sessId) {
FtpUser user = getCommonHandler().getUser(sessId);
if (user != null) {
mDeleteModel.newEntry(fl, user);
}
}
-
-
+
+
/**
* Load all the global statistics parameters
*/
@@ -519,14 +519,14 @@
notifyLogin();
notifyConnection();
}
-
-
+
+
/**
* Close it.
*/
public void close() {
mListener.close();
- mFileListener.close();
- }
-
+ mFileListener.close();
+ }
+
}
1.2 +27 -27 jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/FtpTree.java
Index: FtpTree.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/FtpTree.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- FtpTree.java 31 Mar 2002 16:52:43 -0000 1.1
+++ FtpTree.java 20 May 2002 10:20:17 -0000 1.2
@@ -47,8 +47,8 @@
public
class FtpTree extends JTree implements TreeModel {
-
- public final static String[] CHILDREN = {
+
+ public static final String[] CHILDREN = {
"User",
"IP",
"Connection",
@@ -57,15 +57,15 @@
"Upload",
"Download",
"Delete",
- "About"
- };
-
+ "About"
+ };
+
private Vector mListenrList;
-
+
private FtpRootPanel mRootPanel;
private PluginPanel[] mPluginPanels;
private CommonHandler mCommonHandler;
-
+
/**
* create this tree model
*/
@@ -73,26 +73,26 @@
mCommonHandler = commonHandler;
mListenrList = new Vector();
setModel(this);
-
+
setSelectionPath(new TreePath(RemoteHandlerInterface.DISPLAY_NAME));
putClientProperty("JTree.lineStyle", "Angled");
-
+
DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
renderer.setLeafIcon(null);
renderer.setOpenIcon(null);
renderer.setClosedIcon(null);
setCellRenderer(renderer);
-
+
initPlugins();
mRootPanel = new FtpRootPanel(mCommonHandler, this);
}
-
+
/**
* Initialize all plugin panels
*/
private void initPlugins() {
mPluginPanels = new PluginPanel[CHILDREN.length];
-
+
mPluginPanels[0] = new FtpUserPanel(mCommonHandler, this);
mPluginPanels[1] = new FtpIpPanel(mCommonHandler, this);
mPluginPanels[2] = new FtpConnectionPanel(mCommonHandler, this);
@@ -103,7 +103,7 @@
mPluginPanels[7] = new FtpFilePanel(mCommonHandler, this, ((FtpStatisticsPanel)mPluginPanels[4]).getDeleteModel(), "Deleted Files");
mPluginPanels[8] = new FtpAboutPanel(mCommonHandler, this);
}
-
+
/**
* get root object
@@ -112,12 +112,12 @@
return RemoteHandlerInterface.DISPLAY_NAME;
}
- /**
+ /**
* get child object
*/
public Object getChild(Object parent, int index) {
return CHILDREN[index];
- }
+ }
/**
* get child count
@@ -169,14 +169,14 @@
public void removeTreeModelListener(TreeModelListener l) {
mListenrList.remove(l);
}
-
+
/**
* Get root panel.
*/
public FtpRootPanel getRootPanel() {
return mRootPanel;
}
-
+
/**
* Get plugin panel.
*/
@@ -190,14 +190,14 @@
}
return panel;
}
-
-
+
+
/**
* Get the selected panel.
- */
+ */
public JPanel getSelectedPanel() {
Object node = getSelectionPath().getLastPathComponent();
-
+
JPanel dispPane = null;
if(getRoot().equals(node)) {
dispPane = mRootPanel;
@@ -208,10 +208,10 @@
dispPane = mRootPanel;
}
}
-
+
return dispPane;
- }
-
+ }
+
/**
* Close all panels
*/
@@ -219,13 +219,13 @@
if (mRootPanel != null) {
mRootPanel.close();
}
-
+
for(int i=mPluginPanels.length; --i>=0; ) {
PluginPanel panel = mPluginPanels[i];
if (panel != null) {
panel.close();
}
}
- }
-
+ }
+
}
1.13 +85 -85 jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/FtpUserPanel.java
Index: FtpUserPanel.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/FtpUserPanel.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- FtpUserPanel.java 1 Apr 2002 17:25:11 -0000 1.12
+++ FtpUserPanel.java 20 May 2002 10:20:17 -0000 1.13
@@ -30,70 +30,70 @@
/**
* Ftp server user admin panel. You can create, update,
* delete user using this panel.
- *
+ *
* @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
*/
-public
-class FtpUserPanel extends PluginPanel
- implements ActionListener {
-
- private final static Random PASS_GEN = new Random(System.currentTimeMillis());
-
- private final static Object[] BYTE_RATES = {
+public
+class FtpUserPanel extends PluginPanel
+ implements ActionListener {
+
+ private static final Random PASS_GEN = new Random(System.currentTimeMillis());
+
+ private static final Object[] BYTE_RATES = {
"No limit",
new Integer(1200),
new Integer(2400),
new Integer(4800),
new Integer(9600),
new Integer(14400),
- new Integer(28800),
+ new Integer(28800),
new Integer(57600),
- new Integer(115200)
- };
-
- private final static Object[] IDLE_SECONDS = {
+ new Integer(115200)
+ };
+
+ private static final Object[] IDLE_SECONDS = {
"No limit",
new Integer(60),
new Integer(300),
new Integer(900),
new Integer(1800),
- new Integer(3600)
+ new Integer(3600)
};
-
+
private UserManagerInterface mUserManager;
-
+
private JComboBox mjUserLst;
private JTextField mjNameTxt;
-
+
private JPasswordField mjPasswordTxt;
private JPasswordField mjRetypePasswordTxt;
private JCheckBox mjPasswordChkBox;
-
+
private JTextField mjDirectoryTxt;
private JCheckBox mjEnabledChkBox;
private JCheckBox mjWriteChkBox;
private JComboBox mjIdleLst;
private JComboBox mjUploadLst;
private JComboBox mjDownloadLst;
-
- /**
- * Creates new panel.
+
+ /**
+ * Creates new panel.
*/
public FtpUserPanel(CommonHandler commonHandler, JTree tree) {
super(commonHandler, tree);
mUserManager = commonHandler.getUserManager();
initComponents();
- refresh();
+ refresh();
}
- /**
+ /**
* This method is called from within the constructor to
* initialize the form.
*/
private void initComponents() {
GridBagConstraints gc;
setLayout(new GridBagLayout());
-
+
// user list
mjUserLst = new JComboBox();
mjUserLst.addActionListener(this);
@@ -103,7 +103,7 @@
gc.gridwidth = 3;
gc.insets = new Insets(10, 0, 10, 10);
add(mjUserLst, gc);
-
+
// user name
JLabel jNameLab = new JLabel("Name");
jNameLab.setHorizontalAlignment(JLabel.RIGHT);
@@ -115,7 +115,7 @@
gc.insets = new Insets(5, 0, 0, 10);
gc.anchor = GridBagConstraints.EAST;
add(jNameLab, gc);
-
+
mjNameTxt = new JTextField();
mjNameTxt.setColumns(12);
gc = new GridBagConstraints();
@@ -125,7 +125,7 @@
gc.insets = new Insets(5, 0, 0, 10);
gc.anchor = GridBagConstraints.WEST;
add(mjNameTxt, gc);
-
+
// password
JLabel jPasswordLab = new JLabel("Password");
jPasswordLab.setHorizontalAlignment(JLabel.RIGHT);
@@ -136,8 +136,8 @@
gc.gridwidth = 1;
gc.insets = new Insets(5, 0, 0, 10);
gc.anchor = GridBagConstraints.EAST;
- add(jPasswordLab, gc);
-
+ add(jPasswordLab, gc);
+
mjPasswordTxt = new JPasswordField();
mjPasswordTxt.setColumns(12);
gc = new GridBagConstraints();
@@ -161,7 +161,7 @@
gc.insets = new Insets(5, 0, 0, 10);
gc.anchor = GridBagConstraints.WEST;
add(jGeneratePassBtn, gc);
-
+
// retype password
JLabel jRetypePasswordLab = new JLabel("Retype Password");
jRetypePasswordLab.setHorizontalAlignment(JLabel.RIGHT);
@@ -173,7 +173,7 @@
gc.insets = new Insets(5, 0, 0, 10);
gc.anchor = GridBagConstraints.EAST;
add(jRetypePasswordLab, gc);
-
+
mjRetypePasswordTxt = new JPasswordField();
mjRetypePasswordTxt.setColumns(12);
gc = new GridBagConstraints();
@@ -183,7 +183,7 @@
gc.insets = new Insets(5, 0, 0, 10);
gc.anchor = GridBagConstraints.WEST;
add(mjRetypePasswordTxt, gc);
-
+
// set password
JLabel jSetPasswordLab = new JLabel("Set Password");
jSetPasswordLab.setHorizontalAlignment(JLabel.RIGHT);
@@ -195,7 +195,7 @@
gc.insets = new Insets(5, 0, 0, 10);
gc.anchor = GridBagConstraints.EAST;
add(jSetPasswordLab, gc);
-
+
mjPasswordChkBox = new JCheckBox();
mjPasswordChkBox.setHorizontalTextPosition(SwingConstants.LEFT);
gc = new GridBagConstraints();
@@ -217,17 +217,17 @@
gc.anchor = GridBagConstraints.EAST;
gc.insets = new Insets(5, 0, 0, 10);
add(jDirectoryLab, gc);
-
+
mjDirectoryTxt = new JTextField();
- mjDirectoryTxt.setColumns(12);
+ mjDirectoryTxt.setColumns(12);
gc = new GridBagConstraints();
gc.gridx = 1;
gc.gridy = 5;
gc.gridwidth = 1;
gc.anchor = GridBagConstraints.WEST;
gc.insets = new Insets(5, 0, 0, 10);
- add(mjDirectoryTxt, gc);
-
+ add(mjDirectoryTxt, gc);
+
// enable/disable
JLabel jEnabledLab = new JLabel("Enabled");
jEnabledLab.setHorizontalAlignment(JLabel.RIGHT);
@@ -248,7 +248,7 @@
gc.insets = new Insets(5, 0, 0, 10);
gc.anchor = GridBagConstraints.WEST;
add(mjEnabledChkBox, gc);
-
+
// write permission
JLabel jWritePermLab = new JLabel("Write Permission");
jWritePermLab.setHorizontalAlignment(JLabel.RIGHT);
@@ -260,7 +260,7 @@
gc.insets = new Insets(5, 0, 0, 10);
gc.anchor = GridBagConstraints.EAST;
add(jWritePermLab, gc);
-
+
mjWriteChkBox = new JCheckBox();
gc = new GridBagConstraints();
gc.gridx = 1;
@@ -269,7 +269,7 @@
gc.insets = new Insets(5, 0, 0, 10);
gc.anchor = GridBagConstraints.WEST;
add(mjWriteChkBox, gc);
-
+
// idle time
JLabel jIdleLab = new JLabel("Max. Idle Time (seconds)");
jIdleLab.setHorizontalAlignment(JLabel.RIGHT);
@@ -281,7 +281,7 @@
gc.insets = new Insets(5, 0, 0, 10);
gc.anchor = GridBagConstraints.EAST;
add(jIdleLab, gc);
-
+
mjIdleLst = new JComboBox(IDLE_SECONDS);
mjIdleLst.setEditable(true);
gc = new GridBagConstraints();
@@ -291,10 +291,10 @@
gc.insets = new Insets(5, 0, 0, 10);
gc.anchor = GridBagConstraints.WEST;
add(mjIdleLst, gc);
-
+
JPanel btnPane = new JPanel();
btnPane.setLayout(new FlowLayout(FlowLayout.CENTER));
-
+
// user upload limit
JLabel jUploadLab = new JLabel("Max. Upload (bytes/sec)");
jUploadLab.setHorizontalAlignment(JLabel.RIGHT);
@@ -306,7 +306,7 @@
gc.insets = new Insets(5, 0, 0, 10);
gc.anchor = GridBagConstraints.EAST;
add(jUploadLab, gc);
-
+
mjUploadLst = new JComboBox(BYTE_RATES);
mjUploadLst.setEditable(true);
gc = new GridBagConstraints();
@@ -316,7 +316,7 @@
gc.insets = new Insets(5, 0, 0, 10);
gc.anchor = GridBagConstraints.WEST;
add(mjUploadLst, gc);
-
+
// user download limit
JLabel jDownloadLab = new JLabel("Max. Download (bytes/sec)");
jDownloadLab.setHorizontalAlignment(JLabel.RIGHT);
@@ -328,7 +328,7 @@
gc.insets = new Insets(5, 0, 0, 10);
gc.anchor = GridBagConstraints.EAST;
add(jDownloadLab, gc);
-
+
mjDownloadLst = new JComboBox(BYTE_RATES);
mjDownloadLst.setEditable(true);
gc = new GridBagConstraints();
@@ -338,7 +338,7 @@
gc.insets = new Insets(5, 0, 0, 10);
gc.anchor = GridBagConstraints.WEST;
add(mjDownloadLst, gc);
-
+
// save user
JButton jSaveBtn = new JButton("Save");
jSaveBtn.addActionListener(new ActionListener() {
@@ -347,7 +347,7 @@
}
});
btnPane.add(jSaveBtn);
-
+
// delete user
JButton jDeleteBtn = new JButton("Delete");
jDeleteBtn.addActionListener(new ActionListener() {
@@ -356,7 +356,7 @@
}
});
btnPane.add(jDeleteBtn);
-
+
// reload user data
JButton jReloadBtn = new JButton("Reload");
jReloadBtn.addActionListener(new ActionListener() {
@@ -365,28 +365,28 @@
}
});
btnPane.add(jReloadBtn);
-
+
gc = new GridBagConstraints();
gc.gridx = 0;
gc.gridy = 11;
gc.gridwidth = 3;
gc.insets = new Insets(5, 0, 0, 10);
- add(btnPane, gc);
+ add(btnPane, gc);
}
-
-
+
+
/**
* Save the user object
*/
private void save() {
-
+
// check user name field
String userName = mjNameTxt.getText().trim();
if(userName.equals("")) {
GuiUtils.showErrorMessage(getCommonHandler().getTopComponent(), "Please enter an user name");
return;
}
-
+
try {
FtpUser user = new FtpUser();
user.setName(userName);
@@ -405,8 +405,8 @@
getCommonHandler().handleException(ex);
}
}
-
-
+
+
/**
* Save the user object
*/
@@ -415,7 +415,7 @@
if(selVal == null) {
return;
}
-
+
String userName = selVal.toString();
boolean bConf = GuiUtils.getConfirmation(getCommonHandler().getTopComponent(), "Do you really want to delete user " + userName + "?");
if(!bConf) {
@@ -429,7 +429,7 @@
getCommonHandler().handleException(ex);
}
}
-
+
/**
* Initialize user list.
*/
@@ -446,10 +446,10 @@
}
}
-
-
+
+
/**
- * List selection changed.
+ * List selection changed.
*/
public void actionPerformed(ActionEvent e) {
Object selVal = mjUserLst.getSelectedItem();
@@ -463,8 +463,8 @@
catch(Exception ex) {
getCommonHandler().handleException(ex);
}
- }
-
+ }
+
/**
* Populate user data fields.
*/
@@ -480,7 +480,7 @@
setByteRateCombo(mjUploadLst, user.getMaxUploadRate());
setByteRateCombo(mjDownloadLst, user.getMaxDownloadRate());
}
-
+
/**
* Generate random password.
*/
@@ -489,17 +489,17 @@
for(int i=0; i<8; i++) {
int charType = PASS_GEN.nextInt(3);
switch (charType) {
-
+
// number
case 0:
sb.append( (char)('0' + PASS_GEN.nextInt(10)) );
break;
-
- // uppercase character
- case 1:
+
+ // uppercase character
+ case 1:
sb.append( (char)('A' + PASS_GEN.nextInt(26)) );
break;
-
+
// lowercase character
case 2:
sb.append( (char)('a' + PASS_GEN.nextInt(26)) );
@@ -512,32 +512,32 @@
mjRetypePasswordTxt.setText(password);
mjPasswordChkBox.setSelected(true);
}
-
-
+
+
/**
* Set password if necessary.
*/
private boolean setPassword(FtpUser usr) {
-
+
try {
String userName = usr.getName();
boolean bNewUser = !mUserManager.doesExist(userName);
boolean bPassSet = mjPasswordChkBox.isSelected();
String password = new String(mjPasswordTxt.getPassword());
- String repassword = new String(mjRetypePasswordTxt.getPassword());
-
+ String repassword = new String(mjRetypePasswordTxt.getPassword());
+
// new user
if( bNewUser && (!bPassSet) && (!usr.getIsAnonymous()) ) {
GuiUtils.showErrorMessage(getCommonHandler().getTopComponent(), "New user - password required");
return false;
}
-
- // password set
+
+ // password set
if( bPassSet && (!password.equals(repassword)) && (!usr.getIsAnonymous()) ) {
GuiUtils.showErrorMessage(getCommonHandler().getTopComponent(), "Password entries are not equal");
return false;
}
-
+
// set password if necessary
if(bPassSet && (!usr.getIsAnonymous())) {
usr.setPassword(password);
@@ -551,8 +551,8 @@
getCommonHandler().handleException(ex);
}
return false;
- }
-
+ }
+
/**
* Get max bytes/sec.
*/
@@ -567,10 +567,10 @@
GuiUtils.showErrorMessage(getCommonHandler().getTopComponent(), ex.getMessage());
}
}
-
+
return rate;
}
-
+
/**
* Get max idle time in sec.
*/
@@ -585,10 +585,10 @@
GuiUtils.showErrorMessage(getCommonHandler().getTopComponent(), ex.getMessage());
}
}
-
+
return sec;
}
-
+
/**
* Set byte transfer rate combo.
*/
@@ -599,7 +599,7 @@
}
combo.setSelectedItem(selItem);
}
-
+
/**
* Set idle time combo.
*/
1.3 +23 -23 jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/ip/FileIpRestrictor.java
Index: FileIpRestrictor.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/ip/FileIpRestrictor.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- FileIpRestrictor.java 7 Apr 2002 17:03:35 -0000 1.2
+++ FileIpRestrictor.java 20 May 2002 10:20:18 -0000 1.3
@@ -28,23 +28,23 @@
/**
* This class provides IP restriction functionality.
- *
+ *
* @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
*/
-public
+public
class FileIpRestrictor extends AbstractIpRestrictor {
-
- private final static String LINE_SEP = System.getProperty("line.separator", "\n");
-
+
+ private static final String LINE_SEP = System.getProperty("line.separator", "\n");
+
private File mIpFile = null;
- private Vector mAllEntries = new Vector();
-
+ private Vector mAllEntries = new Vector();
+
/**
* Default constructor.
*/
public FileIpRestrictor() {
}
-
+
/**
* Set application context.
*/
@@ -61,7 +61,7 @@
}
getLogger().info("IP restrictor file = " + mIpFile);
}
-
+
/**
* Read the list from the file.
@@ -86,14 +86,14 @@
IoUtils.close(br);
}
}
-
+
/**
* Get IP resrictor file object.
*/
public File getFile() {
return mIpFile;
}
-
+
/**
* Save this IP restriction list.
*/
@@ -111,12 +111,12 @@
IoUtils.close(fw);
}
}
-
+
/**
* Check IP permission. Compare it with all the entries in the list.
*/
- public boolean hasPermission(InetAddress addr) {
- boolean bMatch = false;
+ public boolean hasPermission(InetAddress addr) {
+ boolean bMatch = false;
Object[] entries = mAllEntries.toArray();
for(int i=entries.length; --i>=0; ) {
RegularExpr regExp = new RegularExpr(entries[i].toString());
@@ -143,26 +143,26 @@
return;
}
mAllEntries.add(entry);
- }
-
+ }
+
/**
* Remove entry
- */
+ */
public void removeEntry(String entry) {
mAllEntries.remove(entry);
- }
-
+ }
+
/**
* Get all entries
*/
public Collection getAllEntries() {
return (Collection)mAllEntries.clone();
}
-
+
/**
* Remove all entries
*/
public void clear() {
- mAllEntries.clear();
- }
-}
+ mAllEntries.clear();
+ }
+}
1.7 +74 -74 jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/usermanager/LdapUserManager.java
Index: LdapUserManager.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/usermanager/LdapUserManager.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- LdapUserManager.java 10 Mar 2002 06:09:36 -0000 1.6
+++ LdapUserManager.java 20 May 2002 10:20:18 -0000 1.7
@@ -32,28 +32,28 @@
* Ldap based user manager class. Tested using Netscape Directory Server 4.1.
* The LDAP requires the password to be nonempty for simple authentication. So
* instead of using empty string password (""), we will be using single space (" ").
- *
+ *
* @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
*/
public
class LdapUserManager extends AbstractUserManager {
-
-
+
+
// LDAP attributes
- private final static String LOGIN = "memberuid";
- private final static String UID = "uid";
- private final static String CN = "cn";
- private final static String SN = "sn";
- private final static String PASSWORD = "userpassword";
- private final static String OBJ_CLASS = "objectclass";
- private final static String ENABLE = "enableflag";
- private final static String ROOT_DIR = "homedirectory";
- private final static String WRITE_PERM = "writepermission";
- private final static String IDLE_TIME = "idletime";
- private final static String UP_RATE = "uploadrate";
- private final static String DOWN_RATE = "downloadrate";
-
- private final static String[] ALL_ATTRS = {
+ private static final String LOGIN = "memberuid";
+ private static final String UID = "uid";
+ private static final String CN = "cn";
+ private static final String SN = "sn";
+ private static final String PASSWORD = "userpassword";
+ private static final String OBJ_CLASS = "objectclass";
+ private static final String ENABLE = "enableflag";
+ private static final String ROOT_DIR = "homedirectory";
+ private static final String WRITE_PERM = "writepermission";
+ private static final String IDLE_TIME = "idletime";
+ private static final String UP_RATE = "uploadrate";
+ private static final String DOWN_RATE = "downloadrate";
+
+ private static final String[] ALL_ATTRS = {
CN,
LOGIN,
ENABLE,
@@ -63,29 +63,29 @@
UP_RATE,
DOWN_RATE
};
-
- private final static Attribute OBJCLASS_ATTR = new BasicAttribute(OBJ_CLASS, true);
-
-
+
+ private static final Attribute OBJCLASS_ATTR = new BasicAttribute(OBJ_CLASS, true);
+
+
// Currently we are using only one connection.
- // This will be replaced by LDAP connection pool.
+ // This will be replaced by LDAP connection pool.
private DirContext mAdminContext;
private Properties mAdminEnv;
private String mstLdapRoot;
-
+
/**
* Default constructor
*/
public LdapUserManager() {
}
-
-
+
+
/**
* Instantiate <code>UserManager</code> implementation.
* Open LDAP connection.
*/
- public void configure(Configuration conf) throws ConfigurationException {
- super.configure(conf);
+ public void configure(Configuration conf) throws ConfigurationException {
+ super.configure(conf);
// get ldap parameters
String url = conf.getChild("url").getValue();
@@ -93,15 +93,15 @@
String admin = conf.getChild("admin").getValue();
String password = conf.getChild("password").getValue();
String auth = conf.getChild("authentication").getValue();
-
+
try {
mAdminEnv = new Properties();
mAdminEnv.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
mAdminEnv.setProperty(Context.PROVIDER_URL, url);
- mAdminEnv.setProperty(Context.SECURITY_AUTHENTICATION, auth);
- mAdminEnv.setProperty(Context.SECURITY_PRINCIPAL, admin);
- mAdminEnv.setProperty(Context.SECURITY_CREDENTIALS, password);
-
+ mAdminEnv.setProperty(Context.SECURITY_AUTHENTICATION, auth);
+ mAdminEnv.setProperty(Context.SECURITY_PRINCIPAL, admin);
+ mAdminEnv.setProperty(Context.SECURITY_CREDENTIALS, password);
+
mAdminContext = new InitialDirContext(mAdminEnv);
mstLdapRoot = ldapRoot;
getLogger().info("LDAP user manager opened.");
@@ -111,8 +111,8 @@
throw new ConfigurationException(ex.getMessage(), ex);
}
}
-
-
+
+
/**
* Get common name
*/
@@ -121,7 +121,7 @@
matchAttrs.put(new BasicAttribute(LOGIN, login));
matchAttrs.put(OBJCLASS_ATTR);
NamingEnumeration answers = mAdminContext.search("ou=people," + mstLdapRoot, matchAttrs, ALL_ATTRS);
-
+
String cn = null;
if (answers.hasMore()) {
SearchResult sr = (SearchResult)answers.next();
@@ -130,14 +130,14 @@
answers.close();
return cn;
}
-
-
+
+
/**
* Get all user names
*/
public synchronized List getAllUserNames() {
ArrayList allUsers = new ArrayList();
-
+
try {
Attributes matchAttrs = new BasicAttributes(true);
matchAttrs.put(OBJCLASS_ATTR);
@@ -151,18 +151,18 @@
catch(NamingException ex) {
getLogger().error(ex.getMessage(), ex);
}
-
+
Collections.sort(allUsers);
return allUsers;
- }
-
-
+ }
+
+
/**
* Get user object.
*/
public synchronized User getUserByName(String name) {
User user = null;
-
+
try {
Attributes matchAttrs = new BasicAttributes(true);
matchAttrs.put(new BasicAttribute(LOGIN, name));
@@ -171,12 +171,12 @@
if (answers.hasMore()) {
SearchResult sr = (SearchResult)answers.next();
Attributes attrs = sr.getAttributes();
-
+
user = new User();
user.setName(attrs.get(LOGIN).get().toString());
user.getVirtualDirectory().setRootDirectory(new File(attrs.get(ROOT_DIR).get().toString()));
user.setEnabled(Boolean.TRUE.toString().equals(attrs.get(ENABLE).get().toString()));
- user.getVirtualDirectory().setWritePermission(Boolean.TRUE.toString().equals(attrs.get(WRITE_PERM).get().toString()));
+ user.getVirtualDirectory().setWritePermission(Boolean.TRUE.toString().equals(attrs.get(WRITE_PERM).get().toString()));
user.setMaxIdleTime( Integer.parseInt(attrs.get(IDLE_TIME).get().toString()) );
user.setMaxUploadRate( Integer.parseInt(attrs.get(UP_RATE).get().toString()) );
user.setMaxDownloadRate( Integer.parseInt(attrs.get(DOWN_RATE).get().toString()) );
@@ -187,16 +187,16 @@
getLogger().error(ex.getMessage(), ex);
user = null;
}
-
+
return user;
}
-
-
+
+
/**
* User authentication.
*/
public boolean authenticate(String name, String password) {
-
+
// empty password string is not allowed
if (password == null) {
password = " ";
@@ -204,25 +204,25 @@
if (password.equals("")) {
password = " ";
}
-
+
try {
String cn = getCommonName(name);
if (cn != null) {
Properties userProp = (Properties)mAdminEnv.clone();
String dn = CN + '=' + cn + ",ou=people," + mstLdapRoot;
- userProp.setProperty(Context.SECURITY_PRINCIPAL, dn);
+ userProp.setProperty(Context.SECURITY_PRINCIPAL, dn);
userProp.setProperty(Context.SECURITY_CREDENTIALS, password);
DirContext userContext = new InitialDirContext(userProp);
- userContext.close();
+ userContext.close();
return true;
}
}
- catch(NamingException ex) {
+ catch(NamingException ex) {
}
return false;
}
-
-
+
+
/**
* Save user
*/
@@ -234,13 +234,13 @@
add(user);
}
}
-
-
+
+
/**
* Add a new user
*/
private synchronized void add(User user) throws NamingException {
-
+
// empty password is not allowed
if (user.getPassword() == null) {
user.setPassword(" ");
@@ -248,10 +248,10 @@
if (user.getPassword().equals("")) {
user.setPassword(" ");
}
-
+
String cn = user.getName() + "-" + System.currentTimeMillis();
String path = CN + '=' + cn + ",ou=people," + mstLdapRoot;
-
+
Attributes attrs = new BasicAttributes(true);
attrs.put(new BasicAttribute(LOGIN, user.getName()));
attrs.put(new BasicAttribute(UID, user.getName()));
@@ -265,11 +265,11 @@
attrs.put(new BasicAttribute(IDLE_TIME, String.valueOf(user.getMaxIdleTime())));
attrs.put(new BasicAttribute(UP_RATE, String.valueOf(user.getMaxUploadRate())));
attrs.put(new BasicAttribute(DOWN_RATE, String.valueOf(user.getMaxDownloadRate())));
-
+
mAdminContext.bind(path, null, attrs);
}
-
-
+
+
/**
* Update an existing user
*/
@@ -277,7 +277,7 @@
String cn = getCommonName(user.getName());
String dn = CN + '=' + cn + ",ou=people," + mstLdapRoot;
ArrayList mods = new ArrayList();
-
+
if (user.getPassword() != null) {
if (user.getPassword().equals("")) {
user.setPassword(" ");
@@ -290,16 +290,16 @@
mods.add(new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute(IDLE_TIME, String.valueOf(user.getMaxIdleTime()))));
mods.add(new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute(UP_RATE, String.valueOf(user.getMaxUploadRate()))));
mods.add(new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute(DOWN_RATE, String.valueOf(user.getMaxDownloadRate()))));
-
-
+
+
ModificationItem modArr[] = new ModificationItem[mods.size()];
for(int i=0; i<modArr.length; i++) {
modArr[i] = (ModificationItem)mods.get(i);
}
mAdminContext.modifyAttributes(dn, modArr);
}
-
-
+
+
/**
* User existance check
*/
@@ -313,8 +313,8 @@
}
return cn != null;
}
-
-
+
+
/**
* Delete user
*/
@@ -325,8 +325,8 @@
mAdminContext.unbind(dn);
}
}
-
-
+
+
/**
* Close user manager
*/
@@ -341,7 +341,7 @@
mAdminContext = null;
}
}
-
+
// static block
static {
OBJCLASS_ATTR.add("top");
@@ -350,5 +350,5 @@
OBJCLASS_ATTR.add("inetOrgPerson");
OBJCLASS_ATTR.add("ftpUsers");
}
-}
+}
1.7 +33 -33 jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/usermanager/PropertiesUserManager.java
Index: PropertiesUserManager.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/usermanager/PropertiesUserManager.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- PropertiesUserManager.java 10 Mar 2002 06:09:36 -0000 1.6
+++ PropertiesUserManager.java 20 May 2002 10:20:18 -0000 1.7
@@ -32,21 +32,21 @@
* Properties file based <code>UserManager</code>
* implementation. We use <code>user.properties</code> file
* to store user data.
- *
+ *
* @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
*/
public
class PropertiesUserManager extends AbstractUserManager {
- private final static String PREFIX = "FtpServer.user.";
- private final static String USER_PROP = "user.properties";
+ private static final String PREFIX = "FtpServer.user.";
+ private static final String USER_PROP = "user.properties";
private BaseProperties mUserData;
private File mUserDataFile;
private boolean mbEncrypt;
-
+
private long mlLastModified;
-
+
/**
* Instantiate user manager - default constructor.
*
@@ -70,9 +70,9 @@
catch(IOException ex) {
getLogger().error(ex.getMessage(), ex);
throw new ContextException(ex.getMessage());
- }
+ }
}
-
+
/**
* Set configuration
*/
@@ -80,7 +80,7 @@
super.configure(conf);
mbEncrypt = conf.getChild("encrypt").getValueAsBoolean(false);
}
-
+
/**
* Save user data. Store the properties.
@@ -92,7 +92,7 @@
throw new NullPointerException("User name is null.");
}
String thisPrefix = PREFIX + usr.getName() + '.';
-
+
// set other properties
mUserData.setProperty(thisPrefix+"password", getPassword(usr));
mUserData.setProperty(thisPrefix+"home", usr.getVirtualDirectory().getRootDirectory());
@@ -101,7 +101,7 @@
mUserData.setProperty(thisPrefix+"idle", usr.getMaxIdleTime());
mUserData.setProperty(thisPrefix+"upload", usr.getMaxUploadRate());
mUserData.setProperty(thisPrefix+"download", usr.getMaxDownloadRate());
-
+
// save user data
FileOutputStream fos = null;
try {
@@ -113,14 +113,14 @@
IoUtils.close(fos);
}
}
-
+
/**
* Delete an user. Removes all this user entries from the properties.
* After removing the corresponding from the properties, save the data.
*/
public synchronized void delete(String usrName) throws IOException {
-
+
// remove entries from properties
String thisPrefix = PREFIX + usrName + '.';
Enumeration propNames = mUserData.propertyNames();
@@ -135,10 +135,10 @@
while (remKeysIt.hasNext()) {
mUserData.remove(remKeysIt.next().toString());
}
-
+
// save user data
FileOutputStream fos = null;
- try {
+ try {
fos = new FileOutputStream(mUserDataFile);
mUserData.store(fos, "Generated file - don't edit (please)");
mlLastModified = mUserDataFile.lastModified();
@@ -147,16 +147,16 @@
IoUtils.close(fos);
}
}
-
-
+
+
/**
* Get user password. Returns the encrypted value.
* If the password value is not null
- * password = new password
- * else
+ * password = new password
+ * else
* if user does exist
* password = old password
- * else
+ * else
* password = ""
*/
private String getPassword(User usr) {
@@ -170,15 +170,15 @@
String key = PREFIX + usr.getName() + ".password";
password = mUserData.getProperty(key, "");
}
-
+
if (password == null) {
password = "";
}
-
+
return password;
- }
-
-
+ }
+
+
/**
* Get all user names.
*/
@@ -196,7 +196,7 @@
ulst.add(name);
}
}
-
+
Collections.sort(ulst);
return ulst;
}
@@ -206,11 +206,11 @@
* Load user data.
*/
public synchronized User getUserByName(String userName) {
-
+
if (!doesExist(userName)) {
return null;
}
-
+
String baseKey = PREFIX + userName + '.';
User user = new User();
user.setName(userName);
@@ -222,8 +222,8 @@
user.setMaxDownloadRate(mUserData.getInteger(baseKey + "download", 0));
return user;
}
-
-
+
+
/**
* User existance check
*/
@@ -231,8 +231,8 @@
String key = PREFIX + name + ".home";
return mUserData.containsKey(key);
}
-
-
+
+
/**
* User authenticate method
*/
@@ -243,7 +243,7 @@
}
return password.equals(passVal);
}
-
+
/**
* Reload the user data if necessary
*/
@@ -257,7 +257,7 @@
getLogger().info("File modified - loading " + mUserDataFile.getAbsolutePath());
}
}
-
+
/**
* Close the user manager - remove existing entries.
*/
1.2 +22 -22 jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/util/DateUtils.java
Index: DateUtils.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/util/DateUtils.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DateUtils.java 6 Mar 2002 13:42:57 -0000 1.1
+++ DateUtils.java 20 May 2002 10:20:18 -0000 1.2
@@ -12,13 +12,13 @@
/**
* This is a timezone conversion utility class.
- *
+ *
* @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
*/
public class DateUtils {
-
- private final static String[] MONTHS = {
+
+ private static final String[] MONTHS = {
"Jan",
"Feb",
"Mar",
@@ -32,10 +32,10 @@
"Nov",
"Dec"
};
-
- private final static DateFormat AFTER_SIX = new SimpleDateFormat(" yyyy");
- private final static DateFormat BEFORE_SIX = new SimpleDateFormat("HH:mm");
-
+
+ private static final DateFormat AFTER_SIX = new SimpleDateFormat(" yyyy");
+ private static final DateFormat BEFORE_SIX = new SimpleDateFormat("HH:mm");
+
/**
* Get unix style date string
*/
@@ -44,26 +44,26 @@
if (dateTime < 0) {
return "------------";
}
-
+
Calendar cal = new GregorianCalendar();
cal.setTime(date);
String firstPart = MONTHS[cal.get(Calendar.MONTH)] + ' ';
-
+
String dateStr = String.valueOf(cal.get(Calendar.DATE));
if (dateStr.length() == 1) {
dateStr = " " + dateStr;
}
firstPart += dateStr + ' ';
-
+
long nowTime = System.currentTimeMillis();
if ( Math.abs(nowTime - dateTime) > 183L * 24L * 60L * 60L * 1000L) {
return firstPart + AFTER_SIX.format(date);
- }
+ }
else {
return firstPart + BEFORE_SIX.format(date);
}
}
-
+
/**
* Get the timezone specific string.
*/
@@ -84,14 +84,14 @@
/**
* Get date object.
*/
- public static Date getDate(String str, DateFormat df, TimeZone from)
+ public static Date getDate(String str, DateFormat df, TimeZone from)
throws java.text.ParseException {
df.setTimeZone(from);
return df.parse(str);
}
-
+
/**
- * Get date difference => d1 - d2.
+ * Get date difference => d1 - d2.
*/
public static String getDifference(Date d1, Date d2) {
Calendar calendar = new GregorianCalendar();
@@ -100,17 +100,17 @@
int day2 = calendar.get(Calendar.DAY_OF_YEAR);
int hour2 = calendar.get(Calendar.HOUR_OF_DAY);
int min2 = calendar.get(Calendar.MINUTE);
-
+
calendar.setTime(d1);
int year1 = calendar.get(Calendar.YEAR);
int day1 = calendar.get(Calendar.DAY_OF_YEAR);
int hour1 = calendar.get(Calendar.HOUR_OF_DAY);
int min1 = calendar.get(Calendar.MINUTE);
-
+
int leftDays = (day1-day2)+(year1-year2)*365;
int leftHours = hour1-hour2;
int leftMins = min1 - min2;
-
+
if(leftMins < 0) {
leftMins += 60;
--leftHours;
@@ -119,7 +119,7 @@
leftHours += 24;
--leftDays;
}
-
+
String interval = "";
if(leftDays > 0) {
interval = leftDays + " Days";
@@ -134,7 +134,7 @@
interval = "";
}
return interval;
- }
-
-
+ }
+
+
}
1.3 +18 -18 jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/util/IoUtils.java
Index: IoUtils.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/util/IoUtils.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- IoUtils.java 6 Mar 2002 13:42:57 -0000 1.2
+++ IoUtils.java 20 May 2002 10:20:18 -0000 1.3
@@ -13,20 +13,20 @@
/**
* IO utility methods.
- *
+ *
* @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
*/
public
class IoUtils {
-
+
/**
* Random number generator to make unique file name
*/
- private final static Random RANDOM_GEN = new Random(System.currentTimeMillis());
-
-
+ private static final Random RANDOM_GEN = new Random(System.currentTimeMillis());
+
+
/**
- * Get a <code>BufferedInputStream</code>.
+ * Get a <code>BufferedInputStream</code>.
*/
public static BufferedInputStream getBufferedInputStream(InputStream in) {
BufferedInputStream bin = null;
@@ -38,9 +38,9 @@
}
return bin;
}
-
+
/**
- * Get a <code>BufferedOutputStream</code>.
+ * Get a <code>BufferedOutputStream</code>.
*/
public static BufferedOutputStream getBufferedOutputStream(OutputStream out) {
BufferedOutputStream bout = null;
@@ -52,7 +52,7 @@
}
return bout;
}
-
+
/**
* Get <code>BufferedReader</code>.
*/
@@ -66,7 +66,7 @@
}
return br;
}
-
+
/**
* Get <code>BufferedWriter</code>.
*/
@@ -94,8 +94,8 @@
}
return newFile;
}
-
-
+
+
/**
* No exception <code>InputStream</code> close method.
*/
@@ -103,8 +103,8 @@
if(is != null) {
try { is.close(); } catch(Exception ex) {}
}
- }
-
+ }
+
/**
* No exception <code>OutputStream</code> close method.
*/
@@ -113,7 +113,7 @@
try { os.close(); } catch(Exception ex) {}
}
}
-
+
/**
* No exception <code>java.io.Reader</code> close method.
*/
@@ -122,7 +122,7 @@
try { rd.close(); } catch(Exception ex) {}
}
}
-
+
/**
* No exception <code>java.io.Writer</code> close method.
*/
@@ -131,7 +131,7 @@
try { wr.close(); } catch(Exception ex) {}
}
}
-
+
/**
* Get exception stack trace.
*/
@@ -149,5 +149,5 @@
e.printStackTrace();
}
return result;
- }
+ }
}
1.3 +23 -23 jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/util/StringUtils.java
Index: StringUtils.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/util/StringUtils.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- StringUtils.java 26 Apr 2002 14:30:11 -0000 1.2
+++ StringUtils.java 20 May 2002 10:20:18 -0000 1.3
@@ -1,4 +1,4 @@
-// $Id: StringUtils.java,v 1.2 2002/04/26 14:30:11 rana_b Exp $
+// $Id: StringUtils.java,v 1.3 2002/05/20 10:20:18 donaldp Exp $
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
@@ -20,14 +20,14 @@
/**
* String utility methods.
- *
+ *
* @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
*/
public
class StringUtils {
- private final static char SEPARATOR = '\n';
+ private static final char SEPARATOR = '\n';
/**
* This is a string replacement method.
@@ -52,12 +52,12 @@
*
* @param source the HTML code to be processes
* @param bReplaceNl if true '\n' will be replaced by <br>
- * @param bReplaceTag if true '<' will be replaced by < and
+ * @param bReplaceTag if true '<' will be replaced by < and
* '>' will be replaced by >
- * @param bReplaceQuote if true '\"' will be replaced by "
+ * @param bReplaceQuote if true '\"' will be replaced by "
*/
- public static String formatHtml(String source,
- boolean bReplaceNl,
+ public static String formatHtml(String source,
+ boolean bReplaceNl,
boolean bReplaceTag,
boolean bReplaceQuote) {
@@ -86,7 +86,7 @@
if (bReplaceTag) sb.append("<br>");
else sb.append("<br>");
} else {
- sb.append(c);
+ sb.append(c);
}
break;
@@ -103,35 +103,35 @@
}
}
return sb.toString();
- }
-
+ }
+
/**
* Pad string object
*/
- public static String pad(String src,
- char padChar,
- boolean rightPad,
+ public static String pad(String src,
+ char padChar,
+ boolean rightPad,
int totalLength) {
-
+
int srcLength = src.length();
if (srcLength >= totalLength) {
return src;
}
-
+
int padLength = totalLength - srcLength;
StringBuffer sb = new StringBuffer(padLength);
for(int i=0; i<padLength; ++i) {
sb.append(padChar);
}
-
+
if (rightPad) {
return src + sb.toString();
}
else {
return sb.toString() + src;
}
- }
-
+ }
+
/**
* Get hex string from byte array
*/
@@ -145,8 +145,8 @@
sb.append(digit);
}
return sb.toString().toUpperCase();
- }
-
+ }
+
/**
* Get byte array from hex string
*/
@@ -159,6 +159,6 @@
buff[i] = (byte)Integer.parseInt(digit, 16);
}
return buff;
- }
-
-}
+ }
+
+}
1.6 +78 -78 jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/util/VirtualDirectory.java
Index: VirtualDirectory.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/util/VirtualDirectory.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- VirtualDirectory.java 7 Apr 2002 17:04:55 -0000 1.5
+++ VirtualDirectory.java 20 May 2002 10:20:18 -0000 1.6
@@ -22,29 +22,29 @@
*/
public
class VirtualDirectory implements Serializable {
-
- private final static String NEWLINE = "\r\n";
- private final static String DELIM = " ";
-
+
+ private static final String NEWLINE = "\r\n";
+ private static final String DELIM = " ";
+
private String mstRoot = "/";
private String mstCurrDir = "/";
-
+
private boolean mbWritePerm = false;
-
-
+
+
/**
* Default constructor does nothing
*/
public VirtualDirectory() {
}
-
+
/**
* Set write permission.
*/
public void setWritePermission(boolean perm) {
mbWritePerm = perm;
}
-
+
/**
* Set root directory. Root directory string will always
* end with '/'.
@@ -55,53 +55,53 @@
root = new File("/");
}
mstRoot = normalizeSeparateChar(root.getAbsolutePath());
-
+
// if not ends with '/' - add one
if(mstRoot.charAt(mstRoot.length()-1) != '/') {
mstRoot = mstRoot + '/';
}
mstCurrDir = "/";
}
-
+
/**
* Set root directory.
*/
public void setRootDirectory(String root) throws IOException {
//File rootFile = new File(root).getCanonicalFile();
//setRootDirectory(rootFile);
-
+
mstRoot = normalizeSeparateChar(root);
-
+
// if not ends with '/' - add one
if(mstRoot.charAt(mstRoot.length()-1) != '/') {
mstRoot = mstRoot + '/';
}
mstCurrDir = "/";
}
-
+
/**
* Get write permission in this system
*/
public boolean getWritePermission() {
return mbWritePerm;
}
-
+
/**
* Get current working directory.
*/
public String getCurrentDirectory() {
return mstCurrDir;
}
-
-
+
+
/**
* Get root directory.
*/
public String getRootDirectory() {
return mstRoot;
}
-
-
+
+
/**
* Get physical name (wrt the machine root).
*/
@@ -109,31 +109,31 @@
virtualName = normalizeSeparateChar(virtualName);
return replaceDots(virtualName);
}
-
-
+
+
/**
- * Get virtual name (wrt the virtual root).
- * The return value will never end with '/' unless it is '/'.
+ * Get virtual name (wrt the virtual root).
+ * The return value will never end with '/' unless it is '/'.
*/
public String getAbsoluteName(String virtualName) {
virtualName = normalizeSeparateChar(virtualName);
String physicalName = replaceDots(virtualName);
-
+
String absoluteName = physicalName.substring(mstRoot.length()-1).trim();
return removeLastSlash(absoluteName);
}
-
-
+
+
/**
* Get virtual name (wrt the virtual root). The virtual
- * name will never end with '/' unless it is '/'.
+ * name will never end with '/' unless it is '/'.
*/
public String getVirtualName(String physicalName) {
physicalName = normalizeSeparateChar(physicalName);
if (!physicalName.startsWith(mstRoot)) {
return null;
}
-
+
String virtualName = physicalName.substring(mstRoot.length()-1).trim();
return removeLastSlash(virtualName);
}
@@ -146,23 +146,23 @@
* @return true if success
*/
public boolean changeDirectory(String virtualDir) {
-
+
String physcialDir = getPhysicalName(virtualDir);
if (physcialDir.equals("")) {
physcialDir = "/";
}
-
+
File dirFl = new File(physcialDir);
if (dirFl.exists() && dirFl.isDirectory()) {
mstCurrDir = physcialDir.substring(mstRoot.length() - 1).trim();
mstCurrDir = removeLastSlash(mstCurrDir);
return true;
}
-
+
return false;
}
-
+
/**
* Check read permission.
*/
@@ -180,8 +180,8 @@
return new File(fileName).canRead();
}
-
-
+
+
/**
* Chech file write/delete permission.
*/
@@ -191,7 +191,7 @@
if(!mbWritePerm) {
return false;
}
-
+
// if virtual name - get the physical name
if(bPhysical) {
fileName = normalizeSeparateChar(fileName);
@@ -212,12 +212,12 @@
* Check file create permission.
*/
public boolean hasCreatePermission(String fileName, boolean bPhysical) {
-
+
// no write permission
if(!mbWritePerm) {
return false;
}
-
+
// if virtual name - get the physical name
if(bPhysical) {
fileName = normalizeSeparateChar(fileName);
@@ -225,11 +225,11 @@
else {
fileName = getPhysicalName(fileName);
}
-
+
return fileName.startsWith(mstRoot);
}
-
-
+
+
/**
* Print file list. Detail listing.
* <pre>
@@ -261,11 +261,11 @@
}
options = optionsSb.toString();
}
-
+
// check options
boolean bAll = options.indexOf('a') != -1;
- boolean bDetail = options.indexOf('l') != -1;
-
+ boolean bDetail = options.indexOf('l') != -1;
+
// check pattern
lsDirName = getPhysicalName(lsDirName);
int slashIndex = lsDirName.lastIndexOf('/');
@@ -273,7 +273,7 @@
pattern = lsDirName.substring(slashIndex+1);
lsDirName = lsDirName.substring(0, slashIndex+1);
}
-
+
// check directory
File lstDirObj = new File(lsDirName);
if(!lstDirObj.exists()) {
@@ -282,7 +282,7 @@
if(!lstDirObj.isDirectory()) {
return false;
}
-
+
// now print
File flLst[];
if ( (pattern == null) || pattern.equals("*") || pattern.equals("") ) {
@@ -291,7 +291,7 @@
else {
flLst = lstDirObj.listFiles(new FileRegularFilter(pattern));
}
-
+
if(flLst != null) {
for(int i=0; i<flLst.length; i++) {
if ( (!bAll) && flLst[i].isHidden() ) {
@@ -303,8 +303,8 @@
}
return true;
}
-
-
+
+
/**
* Print file list.
* <pre>
@@ -314,7 +314,7 @@
* @return true if success
*/
public boolean printNList(String argument, Writer out) throws IOException {
-
+
String lsDirName = "./";
String options = "";
String pattern = "*";
@@ -367,7 +367,7 @@
else {
flLst = lstDirObj.listFiles(new FileRegularFilter(pattern));
}
-
+
// print file list
if (flLst != null) {
for(int i=0; i<flLst.length; i++) {
@@ -385,7 +385,7 @@
}
return true;
}
-
+
/**
* Get file owner.
*/
@@ -400,8 +400,8 @@
private String getGroup(File fl) {
return "group";
}
-
-
+
+
/**
* Get link count
*/
@@ -413,8 +413,8 @@
return String.valueOf(1);
}
}
-
-
+
+
/**
* Get size
*/
@@ -456,8 +456,8 @@
return flName.substring(lastIndex + 1);
}
}
-
-
+
+
/**
* Get permission string.
*/
@@ -470,14 +470,14 @@
else {
sb.append('-');
}
-
+
if (fl.canRead()) {
sb.append('r');
}
else {
sb.append('-');
}
-
+
if (mbWritePerm && fl.canWrite()) {
sb.append('w');
}
@@ -487,8 +487,8 @@
sb.append("-------");
return sb.toString();
}
-
-
+
+
/**
* Normalize separate characher. Separate character should be '/' always.
*/
@@ -497,14 +497,14 @@
pathName = pathName.replace('\\', '/');
return pathName;
}
-
-
+
+
/**
* Replace dots. Returns physical name.
* @param inArg the virtaul name
*/
private String replaceDots(String inArg) {
-
+
// get the starting directory
String resArg;
if(inArg.charAt(0) != '/') {
@@ -512,14 +512,14 @@
}
else {
resArg = mstRoot;
- }
-
- // strip last '/'
+ }
+
+ // strip last '/'
if(resArg.charAt(resArg.length() -1) == '/') {
resArg = resArg.substring(0, resArg.length()-1);
}
-
- // replace ., ~ and ..
+
+ // replace ., ~ and ..
StringTokenizer st = new StringTokenizer(inArg, "/");
while(st.hasMoreTokens()) {
@@ -540,30 +540,30 @@
}
continue;
}
-
+
// ~ => home directory (in this case /)
if (tok.equals("~")) {
resArg = mstRoot.substring(0, mstRoot.length()-1).trim();
continue;
}
-
+
resArg = resArg + '/' + tok;
}
-
+
// add last slash if necessary
if( !inArg.equals("") && (inArg.charAt(inArg.length()-1)=='/') ) {
resArg = resArg + '/';
}
-
+
// final check
if (resArg.length() < mstRoot.length()) {
resArg = mstRoot;
}
-
+
return resArg;
}
-
-
+
+
/**
* Get each directory line.
*/
@@ -584,7 +584,7 @@
out.write(DELIM);
out.write(getName(fl));
}
-
+
/**
* If the string is not '/', remove last slash.
*/
@@ -594,5 +594,5 @@
}
return str;
}
-
+
}
1.4 +2 -2 jakarta-avalon-apps/xcommander/src/java/org/apache/avalon/xcommander/XCommanderHandler.java
Index: XCommanderHandler.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-apps/xcommander/src/java/org/apache/avalon/xcommander/XCommanderHandler.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- XCommanderHandler.java 14 May 2002 11:02:55 -0000 1.3
+++ XCommanderHandler.java 20 May 2002 10:20:18 -0000 1.4
@@ -33,8 +33,8 @@
extends AbstractLogEnabled
implements Initializable, ConnectionHandler, CommandHandler
{
- protected final static String DEFAULT_PARSER = "org.apache.xerces.parsers.SAXParser";
- protected final static String PARSER =
+ protected static final String DEFAULT_PARSER = "org.apache.xerces.parsers.SAXParser";
+ protected static final String PARSER =
System.getProperty( "org.xml.sax.parser", DEFAULT_PARSER );
protected XMLReader m_parser;
protected XCommanderServer m_parent;
1.3 +1 -1 jakarta-avalon-apps/xcommander/src/java/org/apache/avalon/xcommander/saxhandlers/CommandElementHandler.java
Index: CommandElementHandler.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-apps/xcommander/src/java/org/apache/avalon/xcommander/saxhandlers/CommandElementHandler.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- CommandElementHandler.java 14 May 2002 11:02:55 -0000 1.2
+++ CommandElementHandler.java 20 May 2002 10:20:18 -0000 1.3
@@ -26,7 +26,7 @@
extends AbstractElementHandler
{
/** This is the method we try to call if none is specified */
- public final static String DEFAULT_METHODNAME = "toString";
+ public static final String DEFAULT_METHODNAME = "toString";
private String type;
private String identifier;
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>