01: package pygmy.nntp;
02:
03: import pygmy.core.Request;
04:
05: import java.io.IOException;
06: import java.io.InputStream;
07: import java.util.StringTokenizer;
08: import java.util.Properties;
09: import java.net.Socket;
10:
11: public class NntpRequest extends Request {
12: NntpInputStream stream;
13: String command;
14: String[] parameters;
15:
16: public NntpRequest(Socket connection, Properties serverConfig,
17: InputStream stream) throws IOException {
18: super (connection, serverConfig);
19: this .stream = new NntpInputStream(stream);
20: }
21:
22: public String nextCommand() throws IOException {
23: String line = stream.readline();
24:
25: StringTokenizer tokenizer = new StringTokenizer(line, " \t");
26: command = tokenizer.nextToken();
27: parameters = new String[tokenizer.countTokens()];
28: for (int i = 0; i < parameters.length; i++) {
29: parameters[i] = tokenizer.nextToken();
30: }
31:
32: return command;
33: }
34:
35: public String getCommand() {
36: return command;
37: }
38:
39: public String getParameter(int index) {
40: if (index < 0 || index >= parameterLength()) {
41: return null;
42: } else {
43: return parameters[index];
44: }
45: }
46:
47: public NntpInputStream getInput() {
48: return stream;
49: }
50:
51: public boolean isDone() {
52: return (command != null && command.equalsIgnoreCase("quit"));
53: }
54:
55: public String getCurrentNewsgroup()
56: throws NoCurrentNewsgroupException {
57: String group = getProperty("newsgroup", null);
58: if (group == null)
59: throw new NoCurrentNewsgroupException();
60: return group;
61: }
62:
63: public String getCurrentArticle() throws NoCurrentArticleException {
64: String group = getProperty("currentArticle", null);
65: if (group == null)
66: throw new NoCurrentArticleException();
67: return group;
68: }
69:
70: public void setCurrentNewsgroup(String newsgroup) {
71: putProperty("newsgroup", newsgroup);
72: }
73:
74: public void setCurrentArticle(String articlePointer) {
75: putProperty("currentArticle", articlePointer);
76: }
77:
78: public int parameterLength() {
79: return parameters.length;
80: }
81: }
|