Initial import.
2 * StarOffice News Server
3 * see AUTHORS for the list of contributors
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 package com.so.news.command;
21 import java.text.SimpleDateFormat;
22 import java.util.Locale;
24 import com.so.news.Debug;
25 import com.so.news.NNTPConnection;
26 import com.so.news.storage.Article;
29 * Class handling the OVER/XOVER command.
31 * Description of the XOVER command:
35 * The XOVER command returns information from the overview
36 * database for the article(s) specified.
38 * The optional range argument may be any of the following:
40 * an article number followed by a dash to indicate
42 * an article number followed by a dash followed by
43 * another article number
45 * If no argument is specified, then information from the
46 * current article is displayed. Successful responses start
47 * with a 224 response followed by the overview information
48 * for all matched messages. Once the output is complete, a
49 * period is sent on a line by itself. If no argument is
50 * specified, the information for the current article is
51 * returned. A news group must have been selected earlier,
52 * else a 412 error response is returned. If no articles are
53 * in the range specified, a 420 error response is returned
54 * by the server. A 502 response will be returned if the
55 * client only has permission to transfer articles.
57 * Each line of output will be formatted with the article number,
58 * followed by each of the headers in the overview database or the
59 * article itself (when the data is not available in the overview
60 * database) for that article separated by a tab character. The
61 * sequence of fields must be in this order: subject, author,
62 * date, message-id, references, byte count, and line count. Other
63 * optional fields may follow line count. Other optional fields may
64 * follow line count. These fields are specified by examining the
65 * response to the LIST OVERVIEW.FMT command. Where no data exists,
66 * a null field must be provided (i.e. the output will have two tab
67 * characters adjacent to each other). Servers should not output
68 * fields for articles that have been removed since the XOVER database
71 * The LIST OVERVIEW.FMT command should be implemented if XOVER
72 * is implemented. A client can use LIST OVERVIEW.FMT to determine
73 * what optional fields and in which order all fields will be
74 * supplied by the XOVER command.
76 * Note that any tab and end-of-line characters in any header
77 * data that is returned will be converted to a space character.
81 * 224 Overview information follows
82 * 412 No news group current selected
83 * 420 No article(s) selected
86 * @author Christian Lins
88 public class OverCommand extends Command
90 public OverCommand(NNTPConnection conn)
95 public boolean process(String[] command)
98 if(getCurrentGroup() == null)
100 printStatus(412, "No news group current selected");
104 // If no parameter was specified, show information about
105 // the currently selected article(s)
106 if(command.length == 1)
108 Article art = getCurrentArticle();
111 printStatus(420, "No article(s) selected");
115 String o = buildOverview(art, -1);
118 // otherwise print information about the specified range
123 String[] nums = command[1].split("-");
128 artStart = Integer.parseInt(nums[0]);
132 artStart = Integer.parseInt(command[1]);
136 artEnd = Integer.parseInt(nums[1]);
138 catch(Exception e) {}
141 printStatus(224, "Overview information follows");
142 for(int n = artStart; n <= artEnd; n++)
144 Article art = Article.getByNumberInGroup(getCurrentGroup(), n);
147 Debug.getInstance().log("Article (gid=" + getCurrentGroup() + ", art=" + n + " is null!");
151 printTextPart(buildOverview(art, n) + NEWLINE);
161 private String buildOverview(Article art, int nr)
163 SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z", Locale.US);
164 StringBuilder overview = new StringBuilder();
166 overview.append('\t');
167 overview.append(art.getHeader().get("Subject"));
168 overview.append('\t');
169 overview.append(art.getHeader().get("From"));
170 overview.append('\t');
171 overview.append(sdf.format(art.getDate()));
172 overview.append('\t');
173 overview.append(art.getHeader().get("Message-ID"));
174 overview.append('\t');
175 overview.append(art.getHeader().get("References"));
176 overview.append('\t');
177 overview.append(art.getHeader().get("Bytes"));
178 overview.append('\t');
179 overview.append(art.getHeader().get("Lines"));
181 return overview.toString();