org/sonews/daemon/command/NextPrevCommand.java
changeset 19 91dc9acb03ed
parent 1 6fceb66e1ad7
child 20 6ae5e4f8329b
     1.1 --- a/org/sonews/daemon/command/NextPrevCommand.java	Fri Jun 26 16:48:50 2009 +0200
     1.2 +++ b/org/sonews/daemon/command/NextPrevCommand.java	Fri Aug 21 17:40:54 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.NNTPConnection;
     1.9 -import org.sonews.daemon.storage.Article;
    1.10 -import org.sonews.daemon.storage.Group;
    1.11 +import org.sonews.storage.Article;
    1.12 +import org.sonews.storage.Channel;
    1.13 +import org.sonews.storage.StorageBackendException;
    1.14  
    1.15  /**
    1.16   * Class handling the NEXT and LAST command.
    1.17 @@ -30,12 +30,13 @@
    1.18   * @author Dennis Schwerdel
    1.19   * @since n3tpd/0.1
    1.20   */
    1.21 -public class NextPrevCommand extends AbstractCommand
    1.22 +public class NextPrevCommand implements Command
    1.23  {
    1.24  
    1.25 -  public NextPrevCommand(final NNTPConnection conn)
    1.26 +  @Override
    1.27 +  public String[] getSupportedCommandStrings()
    1.28    {
    1.29 -    super(conn);
    1.30 +    return new String[]{"NEXT", "PREV"};
    1.31    }
    1.32  
    1.33    @Override
    1.34 @@ -45,21 +46,27 @@
    1.35    }
    1.36  
    1.37    @Override
    1.38 -  public void processLine(final String line)
    1.39 -    throws IOException, SQLException
    1.40 +  public boolean isStateful()
    1.41    {
    1.42 -    final Article currA = getCurrentArticle();
    1.43 -    final Group   currG = getCurrentGroup();
    1.44 +    return false;
    1.45 +  }
    1.46 +
    1.47 +  @Override
    1.48 +  public void processLine(NNTPConnection conn, final String line, byte[] raw)
    1.49 +    throws IOException, StorageBackendException
    1.50 +  {
    1.51 +    final Article currA = conn.getCurrentArticle();
    1.52 +    final Channel currG = conn.getCurrentChannel();
    1.53      
    1.54      if (currA == null)
    1.55      {
    1.56 -      printStatus(420, "no current article has been selected");
    1.57 +      conn.println("420 no current article has been selected");
    1.58        return;
    1.59      }
    1.60      
    1.61      if (currG == null)
    1.62      {
    1.63 -      printStatus(412, "no newsgroup selected");
    1.64 +      conn.println("412 no newsgroup selected");
    1.65        return;
    1.66      }
    1.67      
    1.68 @@ -67,33 +74,36 @@
    1.69  
    1.70      if(command[0].equalsIgnoreCase("NEXT"))
    1.71      {
    1.72 -      selectNewArticle(currA, currG, 1);
    1.73 +      selectNewArticle(conn, currA, currG, 1);
    1.74      }
    1.75      else if(command[0].equalsIgnoreCase("PREV"))
    1.76      {
    1.77 -      selectNewArticle(currA, currG, -1);
    1.78 +      selectNewArticle(conn, currA, currG, -1);
    1.79      }
    1.80      else
    1.81      {
    1.82 -      printStatus(500, "internal server error");
    1.83 +      conn.println("500 internal server error");
    1.84      }
    1.85    }
    1.86    
    1.87 -  private void selectNewArticle(Article article, Group grp, final int delta)
    1.88 -    throws IOException, SQLException
    1.89 +  private void selectNewArticle(NNTPConnection conn, Article article, Channel grp,
    1.90 +    final int delta)
    1.91 +    throws IOException, StorageBackendException
    1.92    {
    1.93      assert article != null;
    1.94  
    1.95 -    article = Article.getByArticleNumber(article.getIndexInGroup(grp) + delta, grp);
    1.96 +    article = grp.getArticle(grp.getIndexOf(article) + delta);
    1.97  
    1.98      if(article == null)
    1.99      {
   1.100 -      printStatus(421, "no next article in this group");
   1.101 +      conn.println("421 no next article in this group");
   1.102      }
   1.103      else
   1.104      {
   1.105 -      setCurrentArticle(article);
   1.106 -      printStatus(223, article.getIndexInGroup(getCurrentGroup()) + " " + article.getMessageID() + " article retrieved - request text separately");
   1.107 +      conn.setCurrentArticle(article);
   1.108 +      conn.println("223 " + conn.getCurrentChannel().getIndexOf(article)
   1.109 +                    + " " + article.getMessageID()
   1.110 +                    + " article retrieved - request text separately");
   1.111      }
   1.112    }
   1.113