Hooray... sonews/0.5.0 final
HG: Enter commit message. Lines beginning with 'HG:' are removed.
HG: Remove all lines to abort the collapse operation.
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 org.sonews.daemon.command;
21 import java.io.IOException;
22 import java.sql.SQLException;
23 import org.sonews.daemon.storage.Article;
24 import org.sonews.daemon.NNTPConnection;
25 import org.sonews.daemon.storage.Group;
28 * Class handling the ARTICLE, BODY and HEAD commands.
29 * @author Christian Lins
30 * @author Dennis Schwerdel
33 public class ArticleCommand extends AbstractCommand
36 public ArticleCommand(final NNTPConnection connection)
42 public boolean hasFinished()
47 // TODO: Refactor this method to reduce its complexity!
49 public void processLine(final String line)
52 final String[] command = line.split(" ");
54 Article article = null;
56 if (command.length == 1)
58 article = getCurrentArticle();
61 printStatus(420, "no current article has been selected");
65 else if (command[1].matches(NNTPConnection.MESSAGE_ID_PATTERN))
68 article = Article.getByMessageID(command[1]);
71 printStatus(430, "no such article found");
80 Group currentGroup = connection.getCurrentGroup();
81 if(currentGroup == null)
83 printStatus(400, "no group selected");
87 artIndex = Long.parseLong(command[1]);
88 article = Article.getByArticleNumber(artIndex, currentGroup);
90 catch(NumberFormatException ex)
94 catch(SQLException ex)
101 printStatus(423, "no such article number in this group");
104 setCurrentArticle(article);
107 if(command[0].equalsIgnoreCase("ARTICLE"))
109 printStatus(220, artIndex + " " + article.getMessageID()
110 + " article retrieved - head and body follow");
112 println(article.getHeaderSource());
115 println(article.getBody(), article.getBodyCharset());
118 else if(command[0].equalsIgnoreCase("BODY"))
120 printStatus(222, artIndex + " " + article.getMessageID() + " body");
121 println(article.getBody(), article.getBodyCharset());
126 * HEAD: This command is mandatory.
135 * First form (message-id specified)
136 * 221 0|n message-id Headers follow (multi-line)
137 * 430 No article with that message-id
139 * Second form (article number specified)
140 * 221 n message-id Headers follow (multi-line)
141 * 412 No newsgroup selected
142 * 423 No article with that number
144 * Third form (current article number used)
145 * 221 n message-id Headers follow (multi-line)
146 * 412 No newsgroup selected
147 * 420 Current article number is invalid
150 * number Requested article number
151 * n Returned article number
152 * message-id Article message-id
154 else if(command[0].equalsIgnoreCase("HEAD"))
156 printStatus(221, artIndex + " " + article.getMessageID()
157 + " Headers follow (multi-line)");
159 println(article.getHeaderSource());