KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > filesys > ftp > FTPCommand


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.filesys.ftp;
18
19 /**
20  * FTP Command Types Class
21  *
22  * @author GKSpencer
23  */

24 public class FTPCommand
25 {
26
27     // Command ids
28

29     public final static int User = 0;
30     public final static int Pass = 1;
31     public final static int Acct = 2;
32     public final static int Cwd = 3;
33     public final static int Cdup = 4;
34     public final static int Smnt = 5;
35     public final static int Rein = 6;
36     public final static int Quit = 7;
37     public final static int Port = 8;
38     public final static int Pasv = 9;
39     public final static int Type = 10;
40     public final static int Stru = 11;
41     public final static int Mode = 12;
42     public final static int Retr = 13;
43     public final static int Stor = 14;
44     public final static int Stou = 15;
45     public final static int Appe = 16;
46     public final static int Allo = 17;
47     public final static int Rest = 18;
48     public final static int Rnfr = 19;
49     public final static int Rnto = 20;
50     public final static int Abor = 21;
51     public final static int Dele = 22;
52     public final static int Rmd = 23;
53     public final static int Mkd = 24;
54     public final static int Pwd = 25;
55     public final static int List = 26;
56     public final static int Nlst = 27;
57     public final static int Site = 28;
58     public final static int Syst = 29;
59     public final static int Stat = 30;
60     public final static int Help = 31;
61     public final static int Noop = 32;
62     public final static int Mdtm = 33;
63     public final static int Size = 34;
64     public final static int Opts = 35;
65     public final static int Feat = 36;
66     public final static int XPwd = 37;
67     public final static int XMkd = 38;
68     public final static int XRmd = 39;
69     public final static int XCup = 40;
70     public final static int XCwd = 41;
71
72     public final static int MaxId = 41;
73
74     public final static int InvalidCmd = -1;
75
76     // Command name strings
77

78     private static final String JavaDoc[] _cmds = { "USER", "PASS", "ACCT", "CWD", "CDUP", "SMNT", "REIN", "QUIT", "PORT",
79             "PASV", "TYPE", "STRU", "MODE", "RETR", "STOR", "STOU", "APPE", "ALLO", "REST", "RNFR", "RNTO", "ABOR",
80             "DELE", "RMD", "MKD", "PWD", "LIST", "NLST", "SITE", "SYST", "STAT", "HELP", "NOOP", "MDTM", "SIZE",
81             "OPTS", "FEAT", "XPWD", "XMKD", "XRMD", "XCUP", "XCWD" };
82
83     /**
84      * Convert an FTP command to an id
85      *
86      * @param cmd String
87      * @return int
88      */

89     public final static int getCommandId(String JavaDoc cmd)
90     {
91
92         // Check if the command is valid
93

94         if (cmd == null)
95             return InvalidCmd;
96
97         // Convert to a command id
98

99         for (int i = 0; i <= MaxId; i++)
100             if (_cmds[i].equalsIgnoreCase(cmd))
101                 return i;
102
103         // Command not found
104

105         return InvalidCmd;
106     }
107
108     /**
109      * Return the FTP command name for the specified id
110      *
111      * @param id int
112      * @return String
113      */

114     public final static String JavaDoc getCommandName(int id)
115     {
116         if (id < 0 || id > MaxId)
117             return null;
118         return _cmds[id];
119     }
120 }
121
Popular Tags