Revision 51:9d2e96814e6c
b/java/gssclient/src/gssclient/cli/GSSClient.java | ||
---|---|---|
41 | 41 |
UserInfo userInfo = UserInfo.getInstance(); |
42 | 42 |
userInfo.fillFromUserInfoFile(); |
43 | 43 |
|
44 |
GSSCmdFactory factory = GSSCmdFactoryImpl.getInstance();
|
|
44 |
GSSCmdFactory factory = GSSCmdFactory.getInstance(); |
|
45 | 45 |
if (factory == null) { |
46 | 46 |
System.err.println("Command not found"); |
47 | 47 |
return; |
b/java/gssclient/src/gssclient/cli/GSSCmdFactory.java | ||
---|---|---|
1 | 1 |
package gssclient.cli; |
2 | 2 |
|
3 |
import java.io.File; |
|
4 |
import java.io.FileFilter; |
|
5 |
import java.util.Date; |
|
6 |
|
|
7 |
import org.apache.commons.io.filefilter.WildcardFileFilter; |
|
8 |
|
|
3 | 9 |
import gssclient.UserInfo; |
10 |
import gssclient.commands.CompositeCmd; |
|
4 | 11 |
import gssclient.commands.GSSCmd; |
12 |
import gssclient.commands.GetFileCmd; |
|
13 |
import gssclient.commands.ListPropertiesCmd; |
|
14 |
import gssclient.commands.MkDirCmd; |
|
15 |
import gssclient.commands.PutFileCmd; |
|
5 | 16 |
|
6 |
public interface GSSCmdFactory { |
|
7 |
public GSSCmd getGSSCmdInstance(String args[], UserInfo userInfo); |
|
17 |
public class GSSCmdFactory { |
|
18 |
|
|
19 |
private static GSSCmdFactory INSTANCE = new GSSCmdFactory(); |
|
20 |
|
|
21 |
private GSSCmdFactory() { } |
|
22 |
|
|
23 |
public static GSSCmdFactory getInstance() { |
|
24 |
return INSTANCE; |
|
25 |
} |
|
26 |
|
|
27 |
public GSSCmd getGSSCmdInstance(String args[], UserInfo userInfo) { |
|
28 |
Command cmd = Command.fromString(args[0]); |
|
29 |
GSSCmd gssCommand = null; |
|
30 |
switch (cmd) { |
|
31 |
case GET_FILE: |
|
32 |
gssCommand = createGetFileCmd(userInfo, new Date(), args); |
|
33 |
break; |
|
34 |
case PUT_FILE: |
|
35 |
gssCommand = createPutFileCmd(userInfo, new Date(), args); |
|
36 |
break; |
|
37 |
case MKDIR: |
|
38 |
gssCommand = createMkDirCmd(userInfo, new Date(), args); |
|
39 |
break; |
|
40 |
case LIST: |
|
41 |
gssCommand = createListPropertiesCmd(userInfo, new Date(), args); |
|
42 |
break; |
|
43 |
} |
|
44 |
return gssCommand; |
|
45 |
} |
|
46 |
|
|
47 |
private GSSCmd createGetFileCmd(UserInfo userInfo, Date date, |
|
48 |
String args[]) { |
|
49 |
return new GetFileCmd(userInfo, date, args[1], args[2]); |
|
50 |
} |
|
51 |
|
|
52 |
private GSSCmd createPutFileCmd(UserInfo userInfo, Date date, |
|
53 |
String args[]) { |
|
54 |
CompositeCmd cmd = new CompositeCmd(); |
|
55 |
/* First argument is the command name; last argument the |
|
56 |
* the destination directory. |
|
57 |
*/ |
|
58 |
for (int i = 1; i < args.length - 1; i++) { |
|
59 |
File file = new File(args[i]); |
|
60 |
if (file.isFile()) { |
|
61 |
cmd.add(new PutFileCmd(userInfo, new Date(), |
|
62 |
args[args.length - 1], args[i])); |
|
63 |
} else { |
|
64 |
String name = file.getName(); |
|
65 |
if (name == null) |
|
66 |
continue; |
|
67 |
File dir = file.getParentFile(); |
|
68 |
if (dir == null) |
|
69 |
continue; |
|
70 |
FileFilter filter = new WildcardFileFilter(name); |
|
71 |
File[] filteredFiles = dir.listFiles(filter); |
|
72 |
if (filteredFiles == null) |
|
73 |
continue; |
|
74 |
for (File filteredFile : filteredFiles) { |
|
75 |
cmd.add(new PutFileCmd(userInfo, new Date(), |
|
76 |
args[args.length - 1], |
|
77 |
filteredFile.getAbsolutePath())); |
|
78 |
} |
|
79 |
} |
|
80 |
} |
|
81 |
if (cmd.isEmpty()) { |
|
82 |
return null; |
|
83 |
} else { |
|
84 |
return cmd; |
|
85 |
} |
|
86 |
} |
|
87 |
|
|
88 |
private GSSCmd createMkDirCmd(UserInfo userInfo, Date date, |
|
89 |
String args[]) { |
|
90 |
return new MkDirCmd(userInfo, new Date(), args[1], null); |
|
91 |
} |
|
92 |
|
|
93 |
private GSSCmd createListPropertiesCmd(UserInfo userInfo, Date date, |
|
94 |
String args[]) { |
|
95 |
return new ListPropertiesCmd(userInfo, new Date(), args[1], null); |
|
96 |
} |
|
8 | 97 |
} |
/dev/null | ||
---|---|---|
1 |
package gssclient.cli; |
|
2 |
|
|
3 |
import gssclient.UserInfo; |
|
4 |
import gssclient.commands.GSSCmd; |
|
5 |
|
|
6 |
import java.util.HashMap; |
|
7 |
import java.util.Map; |
|
8 |
|
|
9 |
public class GSSCmdFactoryImpl implements GSSCmdFactory { |
|
10 |
|
|
11 |
private static final String GET_FILE = "get"; |
|
12 |
private static final String PUT_FILE = "put"; |
|
13 |
private static final String MKDIR = "mkdir"; |
|
14 |
private static final String LIST = "ls"; |
|
15 |
|
|
16 |
private static final Map<String, GSSCmdFactory> COMMANDS |
|
17 |
= new HashMap<String, GSSCmdFactory>(); |
|
18 |
|
|
19 |
static { |
|
20 |
COMMANDS.put(GET_FILE, GetFileCmdFactory.getInstance()); |
|
21 |
COMMANDS.put(PUT_FILE, PutFileCmdFactory.getInstance()); |
|
22 |
COMMANDS.put(MKDIR, MkDirCmdFactory.getInstance()); |
|
23 |
COMMANDS.put(LIST, ListPropertiesCmdFactory.getInstance()); |
|
24 |
} |
|
25 |
|
|
26 |
private static GSSCmdFactory INSTANCE = new GSSCmdFactoryImpl(); |
|
27 |
|
|
28 |
private GSSCmdFactoryImpl() { } |
|
29 |
|
|
30 |
public static GSSCmdFactory getInstance() { |
|
31 |
return INSTANCE; |
|
32 |
} |
|
33 |
|
|
34 |
public GSSCmd getGSSCmdInstance(String args[], UserInfo userInfo) { |
|
35 |
GSSCmdFactory factory = COMMANDS.get(args[0]); |
|
36 |
if (factory != null) { |
|
37 |
return factory.getGSSCmdInstance(args, userInfo); |
|
38 |
} else { |
|
39 |
return null; |
|
40 |
} |
|
41 |
} |
|
42 |
} |
/dev/null | ||
---|---|---|
1 |
package gssclient.cli; |
|
2 |
|
|
3 |
import gssclient.UserInfo; |
|
4 |
import gssclient.commands.GSSCmd; |
|
5 |
import gssclient.commands.GetFileCmd; |
|
6 |
|
|
7 |
import java.util.Date; |
|
8 |
|
|
9 |
/** |
|
10 |
* Class for creating GetFileCmd objects. |
|
11 |
*/ |
|
12 |
public class GetFileCmdFactory implements GSSCmdFactory { |
|
13 |
|
|
14 |
private static final GetFileCmdFactory INSTANCE = |
|
15 |
new GetFileCmdFactory(); |
|
16 |
|
|
17 |
private GetFileCmdFactory() { } |
|
18 |
|
|
19 |
public static GetFileCmdFactory getInstance() { |
|
20 |
return INSTANCE; |
|
21 |
} |
|
22 |
|
|
23 |
public GSSCmd getGSSCmdInstance(String[] args, UserInfo userInfo) { |
|
24 |
GetFileCmd cmd = new GetFileCmd(userInfo, new Date(), |
|
25 |
args[1], args[2]); |
|
26 |
return cmd; |
|
27 |
} |
|
28 |
} |
|
29 |
|
/dev/null | ||
---|---|---|
1 |
package gssclient.cli; |
|
2 |
|
|
3 |
import gssclient.UserInfo; |
|
4 |
import gssclient.commands.GSSCmd; |
|
5 |
import gssclient.commands.ListPropertiesCmd; |
|
6 |
|
|
7 |
import java.util.Date; |
|
8 |
|
|
9 |
/** |
|
10 |
* Class for creating ListPropertiesCmd objects. |
|
11 |
*/ |
|
12 |
public class ListPropertiesCmdFactory implements GSSCmdFactory { |
|
13 |
|
|
14 |
private static final ListPropertiesCmdFactory INSTANCE = |
|
15 |
new ListPropertiesCmdFactory(); |
|
16 |
|
|
17 |
private ListPropertiesCmdFactory() { } |
|
18 |
|
|
19 |
public static ListPropertiesCmdFactory getInstance() { |
|
20 |
return INSTANCE; |
|
21 |
} |
|
22 |
|
|
23 |
public GSSCmd getGSSCmdInstance(String[] args, UserInfo userInfo) { |
|
24 |
ListPropertiesCmd cmd = new ListPropertiesCmd(userInfo, |
|
25 |
new Date(), args[1], null); |
|
26 |
return cmd; |
|
27 |
} |
|
28 |
} |
/dev/null | ||
---|---|---|
1 |
package gssclient.cli; |
|
2 |
|
|
3 |
import gssclient.UserInfo; |
|
4 |
import gssclient.commands.GSSCmd; |
|
5 |
import gssclient.commands.MkDirCmd; |
|
6 |
|
|
7 |
import java.util.Date; |
|
8 |
|
|
9 |
/** |
|
10 |
* Class for creating MkDirCmd objects. |
|
11 |
*/ |
|
12 |
public class MkDirCmdFactory implements GSSCmdFactory { |
|
13 |
|
|
14 |
private static final MkDirCmdFactory INSTANCE = |
|
15 |
new MkDirCmdFactory(); |
|
16 |
|
|
17 |
private MkDirCmdFactory() { } |
|
18 |
|
|
19 |
public static MkDirCmdFactory getInstance() { |
|
20 |
return INSTANCE; |
|
21 |
} |
|
22 |
|
|
23 |
public GSSCmd getGSSCmdInstance(String[] args, UserInfo userInfo) { |
|
24 |
MkDirCmd cmd = new MkDirCmd(userInfo, new Date(), |
|
25 |
args[1], null); |
|
26 |
return cmd; |
|
27 |
} |
|
28 |
} |
/dev/null | ||
---|---|---|
1 |
package gssclient.cli; |
|
2 |
|
|
3 |
import gssclient.UserInfo; |
|
4 |
import gssclient.commands.CompositeCmd; |
|
5 |
import gssclient.commands.GSSCmd; |
|
6 |
import gssclient.commands.PutFileCmd; |
|
7 |
|
|
8 |
import java.io.File; |
|
9 |
import java.io.FileFilter; |
|
10 |
import java.util.Date; |
|
11 |
|
|
12 |
import org.apache.commons.io.filefilter.WildcardFileFilter; |
|
13 |
|
|
14 |
/** |
|
15 |
* Class for creating PutFileCmd objects. |
|
16 |
*/ |
|
17 |
public class PutFileCmdFactory implements GSSCmdFactory { |
|
18 |
private static final PutFileCmdFactory INSTANCE = |
|
19 |
new PutFileCmdFactory(); |
|
20 |
|
|
21 |
private PutFileCmdFactory() { } |
|
22 |
|
|
23 |
public static PutFileCmdFactory getInstance() { |
|
24 |
return INSTANCE; |
|
25 |
} |
|
26 |
|
|
27 |
public GSSCmd getGSSCmdInstance(String[] args, UserInfo userInfo) { |
|
28 |
|
|
29 |
CompositeCmd cmd = new CompositeCmd(); |
|
30 |
/* First argument is the command name; last argument the |
|
31 |
* the destination directory. |
|
32 |
*/ |
|
33 |
for (int i = 1; i < args.length - 1; i++) { |
|
34 |
File file = new File(args[i]); |
|
35 |
if (file.isFile()) { |
|
36 |
cmd.add(new PutFileCmd(userInfo, new Date(), |
|
37 |
args[args.length - 1], args[i])); |
|
38 |
} else { |
|
39 |
String name = file.getName(); |
|
40 |
if (name == null) |
|
41 |
continue; |
|
42 |
File dir = file.getParentFile(); |
|
43 |
if (dir == null) |
|
44 |
continue; |
|
45 |
FileFilter filter = new WildcardFileFilter(name); |
|
46 |
File[] filteredFiles = dir.listFiles(filter); |
|
47 |
if (filteredFiles == null) |
|
48 |
continue; |
|
49 |
for (File filteredFile : filteredFiles) { |
|
50 |
cmd.add(new PutFileCmd(userInfo, new Date(), |
|
51 |
args[args.length - 1], |
|
52 |
filteredFile.getAbsolutePath())); |
|
53 |
} |
|
54 |
} |
|
55 |
} |
|
56 |
if (cmd.isEmpty()) { |
|
57 |
return null; |
|
58 |
} else { |
|
59 |
return cmd; |
|
60 |
} |
|
61 |
} |
|
62 |
} |
b/java/gssclient/src/gssclient/httpmethods/HttpMethodFactory.java | ||
---|---|---|
154 | 154 |
} |
155 | 155 |
|
156 | 156 |
/** |
157 |
* Generates an HTTP method given the arguments. This is an instance of |
|
158 |
* the strategy pattern. Subclasses need to fill in the |
|
159 |
* generateSpecificMethod, while this method does any general scaffolding |
|
160 |
* operations. |
|
157 |
* Generates an HTTP method given the arguments. |
|
161 | 158 |
* |
162 | 159 |
* @param method the HTTP method. |
163 | 160 |
* @param scheme The URI scheme (e.g., HTTP or HTTPS). |
b/java/gssclient/src/gssclient/httpmethods/StatusCode.java | ||
---|---|---|
70 | 70 |
this.description = description; |
71 | 71 |
} |
72 | 72 |
|
73 |
// Implementing a fromString method on an enum type, |
|
74 |
// taken from Joshua Bloch's "Effective Java", 2nd edition. |
|
73 |
// Taken from Joshua Bloch's "Effective Java", 2nd edition. |
|
75 | 74 |
private static final Map<Integer, StatusCode> intToEnum = |
76 | 75 |
new HashMap<Integer, StatusCode>(); |
77 | 76 |
static { // Initialize map from constant name to enum constant |
78 | 77 |
for (StatusCode sc : values()) |
79 | 78 |
intToEnum.put(sc.code(), sc); |
80 | 79 |
} |
80 |
|
|
81 | 81 |
// Returns StatusCode for integer, or null if integer is invalid |
82 | 82 |
public static StatusCode fromInt(int sc) { |
83 | 83 |
return intToEnum.get(sc); |
Also available in: Unified diff