1.1 --- a/org/sonews/daemon/command/ArticleCommand.java Wed Jul 01 10:48:22 2009 +0200
1.2 +++ b/org/sonews/daemon/command/ArticleCommand.java Wed Jul 22 14:04:05 2009 +0200
1.3 @@ -19,10 +19,10 @@
1.4 package org.sonews.daemon.command;
1.5
1.6 import java.io.IOException;
1.7 -import java.sql.SQLException;
1.8 -import org.sonews.daemon.storage.Article;
1.9 +import org.sonews.storage.Article;
1.10 import org.sonews.daemon.NNTPConnection;
1.11 -import org.sonews.daemon.storage.Group;
1.12 +import org.sonews.storage.Channel;
1.13 +import org.sonews.storage.StorageBackendException;
1.14
1.15 /**
1.16 * Class handling the ARTICLE, BODY and HEAD commands.
1.17 @@ -30,12 +30,13 @@
1.18 * @author Dennis Schwerdel
1.19 * @since n3tpd/0.1
1.20 */
1.21 -public class ArticleCommand extends AbstractCommand
1.22 +public class ArticleCommand implements Command
1.23 {
1.24 -
1.25 - public ArticleCommand(final NNTPConnection connection)
1.26 +
1.27 + @Override
1.28 + public String[] getSupportedCommandStrings()
1.29 {
1.30 - super(connection);
1.31 + return new String[] {"ARTICLE", "BODY", "HEAD"};
1.32 }
1.33
1.34 @Override
1.35 @@ -44,9 +45,15 @@
1.36 return true;
1.37 }
1.38
1.39 + @Override
1.40 + public boolean isStateful()
1.41 + {
1.42 + return false;
1.43 + }
1.44 +
1.45 // TODO: Refactor this method to reduce its complexity!
1.46 @Override
1.47 - public void processLine(final String line)
1.48 + public void processLine(NNTPConnection conn, final String line, byte[] raw)
1.49 throws IOException
1.50 {
1.51 final String[] command = line.split(" ");
1.52 @@ -55,10 +62,10 @@
1.53 long artIndex = -1;
1.54 if (command.length == 1)
1.55 {
1.56 - article = getCurrentArticle();
1.57 + article = conn.getCurrentArticle();
1.58 if (article == null)
1.59 {
1.60 - printStatus(420, "no current article has been selected");
1.61 + conn.println("420 no current article has been selected");
1.62 return;
1.63 }
1.64 }
1.65 @@ -68,7 +75,7 @@
1.66 article = Article.getByMessageID(command[1]);
1.67 if (article == null)
1.68 {
1.69 - printStatus(430, "no such article found");
1.70 + conn.println("430 no such article found");
1.71 return;
1.72 }
1.73 }
1.74 @@ -77,49 +84,47 @@
1.75 // Message Number
1.76 try
1.77 {
1.78 - Group currentGroup = connection.getCurrentGroup();
1.79 + Channel currentGroup = conn.getCurrentChannel();
1.80 if(currentGroup == null)
1.81 {
1.82 - printStatus(400, "no group selected");
1.83 + conn.println("400 no group selected");
1.84 return;
1.85 }
1.86
1.87 artIndex = Long.parseLong(command[1]);
1.88 - article = Article.getByArticleNumber(artIndex, currentGroup);
1.89 + article = currentGroup.getArticle(artIndex);
1.90 }
1.91 catch(NumberFormatException ex)
1.92 {
1.93 ex.printStackTrace();
1.94 }
1.95 - catch(SQLException ex)
1.96 + catch(StorageBackendException ex)
1.97 {
1.98 ex.printStackTrace();
1.99 }
1.100
1.101 if (article == null)
1.102 {
1.103 - printStatus(423, "no such article number in this group");
1.104 + conn.println("423 no such article number in this group");
1.105 return;
1.106 }
1.107 - setCurrentArticle(article);
1.108 + conn.setCurrentArticle(article);
1.109 }
1.110
1.111 if(command[0].equalsIgnoreCase("ARTICLE"))
1.112 {
1.113 - printStatus(220, artIndex + " " + article.getMessageID()
1.114 + conn.println("220 " + artIndex + " " + article.getMessageID()
1.115 + " article retrieved - head and body follow");
1.116 -
1.117 - println(article.getHeaderSource());
1.118 -
1.119 - println("");
1.120 - println(article.getBody(), article.getBodyCharset());
1.121 - println(".");
1.122 + conn.println(article.getHeaderSource());
1.123 + conn.println("");
1.124 + conn.println(article.getBody());
1.125 + conn.println(".");
1.126 }
1.127 else if(command[0].equalsIgnoreCase("BODY"))
1.128 {
1.129 - printStatus(222, artIndex + " " + article.getMessageID() + " body");
1.130 - println(article.getBody(), article.getBodyCharset());
1.131 - println(".");
1.132 + conn.println("222 " + artIndex + " " + article.getMessageID() + " body");
1.133 + conn.println(article.getBody());
1.134 + conn.println(".");
1.135 }
1.136
1.137 /*
1.138 @@ -153,11 +158,10 @@
1.139 */
1.140 else if(command[0].equalsIgnoreCase("HEAD"))
1.141 {
1.142 - printStatus(221, artIndex + " " + article.getMessageID()
1.143 + conn.println("221 " + artIndex + " " + article.getMessageID()
1.144 + " Headers follow (multi-line)");
1.145 -
1.146 - println(article.getHeaderSource());
1.147 - println(".");
1.148 + conn.println(article.getHeaderSource());
1.149 + conn.println(".");
1.150 }
1.151 }
1.152