1.1 --- a/org/sonews/daemon/command/OverCommand.java Wed Jul 01 10:48:22 2009 +0200
1.2 +++ b/org/sonews/daemon/command/OverCommand.java Wed Jul 22 14:04:05 2009 +0200
1.3 @@ -19,13 +19,13 @@
1.4 package org.sonews.daemon.command;
1.5
1.6 import java.io.IOException;
1.7 -import java.sql.SQLException;
1.8 import java.util.List;
1.9 import org.sonews.util.Log;
1.10 import org.sonews.daemon.NNTPConnection;
1.11 -import org.sonews.daemon.storage.Article;
1.12 -import org.sonews.daemon.storage.ArticleHead;
1.13 -import org.sonews.daemon.storage.Headers;
1.14 +import org.sonews.storage.Article;
1.15 +import org.sonews.storage.ArticleHead;
1.16 +import org.sonews.storage.Headers;
1.17 +import org.sonews.storage.StorageBackendException;
1.18 import org.sonews.util.Pair;
1.19
1.20 /**
1.21 @@ -106,14 +106,15 @@
1.22 * @author Christian Lins
1.23 * @since sonews/0.5.0
1.24 */
1.25 -public class OverCommand extends AbstractCommand
1.26 +public class OverCommand implements Command
1.27 {
1.28
1.29 - public static final int MAX_LINES_PER_DBREQUEST = 100;
1.30 -
1.31 - public OverCommand(final NNTPConnection conn)
1.32 + public static final int MAX_LINES_PER_DBREQUEST = 200;
1.33 +
1.34 + @Override
1.35 + public String[] getSupportedCommandStrings()
1.36 {
1.37 - super(conn);
1.38 + return new String[]{"OVER", "XOVER"};
1.39 }
1.40
1.41 @Override
1.42 @@ -123,12 +124,18 @@
1.43 }
1.44
1.45 @Override
1.46 - public void processLine(final String line)
1.47 - throws IOException, SQLException
1.48 + public boolean isStateful()
1.49 {
1.50 - if(getCurrentGroup() == null)
1.51 + return false;
1.52 + }
1.53 +
1.54 + @Override
1.55 + public void processLine(NNTPConnection conn, final String line, byte[] raw)
1.56 + throws IOException, StorageBackendException
1.57 + {
1.58 + if(conn.getCurrentChannel() == null)
1.59 {
1.60 - printStatus(412, "No news group current selected");
1.61 + conn.println("412 no newsgroup selected");
1.62 }
1.63 else
1.64 {
1.65 @@ -138,20 +145,20 @@
1.66 // the currently selected article(s)
1.67 if(command.length == 1)
1.68 {
1.69 - final Article art = getCurrentArticle();
1.70 + final Article art = conn.getCurrentArticle();
1.71 if(art == null)
1.72 {
1.73 - printStatus(420, "No article(s) selected");
1.74 + conn.println("420 no article(s) selected");
1.75 return;
1.76 }
1.77
1.78 - println(buildOverview(art, -1));
1.79 + conn.println(buildOverview(art, -1));
1.80 }
1.81 // otherwise print information about the specified range
1.82 else
1.83 {
1.84 - int artStart;
1.85 - int artEnd = getCurrentGroup().getLastArticleNumber();
1.86 + long artStart;
1.87 + long artEnd = conn.getCurrentChannel().getLastArticleNumber();
1.88 String[] nums = command[1].split("-");
1.89 if(nums.length >= 1)
1.90 {
1.91 @@ -167,7 +174,7 @@
1.92 }
1.93 else
1.94 {
1.95 - artStart = getCurrentGroup().getFirstArticleNumber();
1.96 + artStart = conn.getCurrentChannel().getFirstArticleNumber();
1.97 }
1.98
1.99 if(nums.length >=2)
1.100 @@ -186,41 +193,41 @@
1.101 {
1.102 if(command[0].equalsIgnoreCase("OVER"))
1.103 {
1.104 - printStatus(423, "No articles in that range");
1.105 + conn.println("423 no articles in that range");
1.106 }
1.107 else
1.108 {
1.109 - printStatus(224, "(empty) overview information follows:");
1.110 - println(".");
1.111 + conn.println("224 (empty) overview information follows:");
1.112 + conn.println(".");
1.113 }
1.114 }
1.115 else
1.116 {
1.117 - for(int n = artStart; n <= artEnd; n += MAX_LINES_PER_DBREQUEST)
1.118 + for(long n = artStart; n <= artEnd; n += MAX_LINES_PER_DBREQUEST)
1.119 {
1.120 - int nEnd = Math.min(n + MAX_LINES_PER_DBREQUEST - 1, artEnd);
1.121 - List<Pair<Long, ArticleHead>> articleHeads = getCurrentGroup()
1.122 + long nEnd = Math.min(n + MAX_LINES_PER_DBREQUEST - 1, artEnd);
1.123 + List<Pair<Long, ArticleHead>> articleHeads = conn.getCurrentChannel()
1.124 .getArticleHeads(n, nEnd);
1.125 if(articleHeads.isEmpty() && n == artStart
1.126 && command[0].equalsIgnoreCase("OVER"))
1.127 {
1.128 // This reply is only valid for OVER, not for XOVER command
1.129 - printStatus(423, "No articles in that range");
1.130 + conn.println("423 no articles in that range");
1.131 return;
1.132 }
1.133 else if(n == artStart)
1.134 {
1.135 // XOVER replies this although there is no data available
1.136 - printStatus(224, "Overview information follows");
1.137 + conn.println("224 overview information follows");
1.138 }
1.139
1.140 for(Pair<Long, ArticleHead> article : articleHeads)
1.141 {
1.142 String overview = buildOverview(article.getB(), article.getA());
1.143 - println(overview);
1.144 + conn.println(overview);
1.145 }
1.146 } // for
1.147 - println(".");
1.148 + conn.println(".");
1.149 }
1.150 }
1.151 }