org/sonews/daemon/command/StatCommand.java
changeset 3 2fdc9cc89502
parent 1 6fceb66e1ad7
child 20 6ae5e4f8329b
     1.1 --- a/org/sonews/daemon/command/StatCommand.java	Wed Jul 01 10:48:22 2009 +0200
     1.2 +++ b/org/sonews/daemon/command/StatCommand.java	Wed Jul 22 14:04:05 2009 +0200
     1.3 @@ -19,21 +19,22 @@
     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.storage.StorageBackendException;
    1.12  
    1.13  /**
    1.14   * Implementation of the STAT command.
    1.15   * @author Christian Lins
    1.16   * @since sonews/0.5.0
    1.17   */
    1.18 -public class StatCommand extends AbstractCommand
    1.19 +public class StatCommand implements Command
    1.20  {
    1.21  
    1.22 -  public StatCommand(final NNTPConnection conn)
    1.23 +  @Override
    1.24 +  public String[] getSupportedCommandStrings()
    1.25    {
    1.26 -    super(conn);
    1.27 +    return new String[]{"STAT"};
    1.28    }
    1.29  
    1.30    @Override
    1.31 @@ -42,20 +43,26 @@
    1.32      return true;
    1.33    }
    1.34  
    1.35 +  @Override
    1.36 +  public boolean isStateful()
    1.37 +  {
    1.38 +    return false;
    1.39 +  }
    1.40 +
    1.41    // TODO: Method has various exit points => Refactor!
    1.42    @Override
    1.43 -  public void processLine(final String line)
    1.44 -    throws IOException, SQLException
    1.45 +  public void processLine(NNTPConnection conn, final String line, byte[] raw)
    1.46 +    throws IOException, StorageBackendException
    1.47    {
    1.48      final String[] command = line.split(" ");
    1.49  
    1.50      Article article = null;
    1.51      if(command.length == 1)
    1.52      {
    1.53 -      article = getCurrentArticle();
    1.54 +      article = conn.getCurrentArticle();
    1.55        if(article == null)
    1.56        {
    1.57 -        printStatus(420, "no current article has been selected");
    1.58 +        conn.println("420 no current article has been selected");
    1.59          return;
    1.60        }
    1.61      }
    1.62 @@ -65,7 +72,7 @@
    1.63        article = Article.getByMessageID(command[1]);
    1.64        if (article == null)
    1.65        {
    1.66 -        printStatus(430, "no such article found");
    1.67 +        conn.println("430 no such article found");
    1.68          return;
    1.69        }
    1.70      }
    1.71 @@ -75,26 +82,27 @@
    1.72        try
    1.73        {
    1.74          long aid = Long.parseLong(command[1]);
    1.75 -        article = Article.getByArticleNumber(aid, getCurrentGroup());
    1.76 +        article = conn.getCurrentChannel().getArticle(aid);
    1.77        }
    1.78        catch(NumberFormatException ex)
    1.79        {
    1.80          ex.printStackTrace();
    1.81        }
    1.82 -      catch(SQLException ex)
    1.83 +      catch(StorageBackendException ex)
    1.84        {
    1.85          ex.printStackTrace();
    1.86        }
    1.87        if (article == null)
    1.88        {
    1.89 -        printStatus(423, "no such article number in this group");
    1.90 +        conn.println("423 no such article number in this group");
    1.91          return;
    1.92        }
    1.93 -      setCurrentArticle(article);
    1.94 +      conn.setCurrentArticle(article);
    1.95      }
    1.96      
    1.97 -    printStatus(223, article.getIndexInGroup(getCurrentGroup()) + " " + article.getMessageID()
    1.98 -          + " article retrieved - request text separately");
    1.99 +    conn.println("223 " + conn.getCurrentChannel().getIndexOf(article) + " "
   1.100 +      + article.getMessageID()
   1.101 +      + " article retrieved - request text separately");
   1.102    }
   1.103    
   1.104  }