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.io.IOException;
22 import java.text.SimpleDateFormat;
23 import java.util.Locale;
25 import com.so.news.Debug;
26 import com.so.news.NNTPConnection;
27 import com.so.news.storage.Article;
30 * Class handling the ARTICLE command.
31 * @author Christian Lins
32 * @author Dennis Schwerdel
34 public class ArticleCommand extends Command
36 public ArticleCommand(NNTPConnection connection)
41 public boolean process(String[] command) throws IOException
43 String commandName = command[0];
45 // untested, RFC977 compliant
46 Article article = null;
47 if (command.length <= 1)
49 article = getCurrentArticle();
52 printStatus(420, "no current article has been selected");
56 else if (command[1].matches(NNTPConnection.MESSAGE_ID_PATTERN))
59 article = Article.getByMessageID(command[1]);
62 printStatus(430, "no such article found");
71 int num = Integer.parseInt(command[1]);
72 article = Article.getByNumberInGroup(connection.getCurrentGroup(), num);
76 ex.printStackTrace(Debug.getInstance().getStream());
77 System.err.println(ex.getLocalizedMessage());
81 printStatus(423, "no such article number in this group");
84 setCurrentArticle(article);
87 if (commandName.equalsIgnoreCase("ARTICLE"))
89 printStatus(220, article.getNumberInGroup() + " " + article.getMessageID()
90 + " article retrieved - head and body follow");
91 Map<String, String> header = article.getHeader();
92 for(Map.Entry<String, String> entry : header.entrySet())
94 if(entry.getKey().equals("Date"))
96 SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z", Locale.US);
97 printTextPart("Date: " + sdf.format(article.getDate()));
100 printTextPart(entry.getKey() + ": " + entry.getValue());
103 printText(article.getBody());
105 else if (commandName.equalsIgnoreCase("HEAD"))
107 printStatus(500, "No longer supported! Use XOVER instead.");
110 else if (commandName.equalsIgnoreCase("BODY"))
112 printStatus(222, article.getNumberInGroup() + " " + article.getMessageID()
114 printText(article.getBody());
116 else if (commandName.equalsIgnoreCase("STAT"))
118 printStatus(223, article.getNumberInGroup() + " " + article.getMessageID()
119 + " article retrieved - request text separately");