KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > drftpd > master > FtpRequest


1 /*
2  * This file is part of DrFTPD, Distributed FTP Daemon.
3  *
4  * DrFTPD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * DrFTPD is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with DrFTPD; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18 package net.sf.drftpd.master;
19
20 /**
21  * Ftp command request class. We can access command, line and argument using
22  * <code>{CMD}, {ARG}</code> within ftp status file. This represents
23  * single Ftp request.
24  *
25  * @author <a HREF="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
26  * @version $Id: FtpRequest.java,v 1.7 2004/02/10 00:03:06 mog Exp $
27  */

28 public class FtpRequest {
29
30     private String JavaDoc line = null;
31     private String JavaDoc command = null;
32     private String JavaDoc argument = null;
33
34     /**
35      * Constructor.
36      *
37      * @param commandLine ftp input command line.
38      */

39     public FtpRequest(String JavaDoc commandLine) {
40         line = commandLine.trim();
41         parse();
42     }
43
44     /**
45      * Parse the ftp command line.
46      */

47     private void parse() {
48         int spInd = line.indexOf(' ');
49
50         if (spInd != -1) {
51             command = line.substring(0, spInd).toUpperCase();
52             argument = line.substring(spInd + 1);
53             if (command.equals("SITE")) {
54                 spInd = line.indexOf(' ', spInd+1);
55                 if(spInd != -1) {
56                     command = line.substring(0, spInd).toUpperCase();
57                     argument = line.substring(spInd + 1);
58                 } else {
59                     command = line.toUpperCase();
60                     argument = null;
61                 }
62             }
63         } else {
64             command = line.toUpperCase();
65             argument = null;
66         }
67
68 // if ((command.length() > 0) && (command.charAt(0) == 'X')) {
69
// command = command.substring(1);
70
// }
71
}
72
73     /**
74      * Get the ftp command.
75      */

76     public String JavaDoc getCommand() {
77         return command;
78     }
79
80     /**
81      * Get ftp input argument.
82      */

83     public String JavaDoc getArgument() {
84         if(argument == null) throw new IllegalStateException JavaDoc();
85         return argument;
86     }
87
88     /**
89      * Get the ftp request line.
90      */

91     public String JavaDoc getCommandLine() {
92         return line;
93     }
94
95     /**
96      * Has argument.
97      */

98     public boolean hasArgument() {
99         return argument != null;
100     }
101
102 }
103
Popular Tags