src/org/sonews/daemon/command/StatCommand.java
changeset 44 5d7d1adf387f
parent 35 ed84c8bdd87b
child 48 b78e77619152
     1.1 --- a/src/org/sonews/daemon/command/StatCommand.java	Sun Aug 29 17:28:58 2010 +0200
     1.2 +++ b/src/org/sonews/daemon/command/StatCommand.java	Tue Jun 07 11:55:22 2011 +0200
     1.3 @@ -31,84 +31,70 @@
     1.4  public class StatCommand implements Command
     1.5  {
     1.6  
     1.7 -  @Override
     1.8 -  public String[] getSupportedCommandStrings()
     1.9 -  {
    1.10 -    return new String[]{"STAT"};
    1.11 -  }
    1.12 +	@Override
    1.13 +	public String[] getSupportedCommandStrings()
    1.14 +	{
    1.15 +		return new String[] {"STAT"};
    1.16 +	}
    1.17  
    1.18 -  @Override
    1.19 -  public boolean hasFinished()
    1.20 -  {
    1.21 -    return true;
    1.22 -  }
    1.23 +	@Override
    1.24 +	public boolean hasFinished()
    1.25 +	{
    1.26 +		return true;
    1.27 +	}
    1.28  
    1.29 -  @Override
    1.30 -  public String impliedCapability()
    1.31 -  {
    1.32 -    return null;
    1.33 -  }
    1.34 +	@Override
    1.35 +	public String impliedCapability()
    1.36 +	{
    1.37 +		return null;
    1.38 +	}
    1.39  
    1.40 -  @Override
    1.41 -  public boolean isStateful()
    1.42 -  {
    1.43 -    return false;
    1.44 -  }
    1.45 +	@Override
    1.46 +	public boolean isStateful()
    1.47 +	{
    1.48 +		return false;
    1.49 +	}
    1.50  
    1.51 -  // TODO: Method has various exit points => Refactor!
    1.52 -  @Override
    1.53 -  public void processLine(NNTPConnection conn, final String line, byte[] raw)
    1.54 -    throws IOException, StorageBackendException
    1.55 -  {
    1.56 -    final String[] command = line.split(" ");
    1.57 +	// TODO: Method has various exit points => Refactor!
    1.58 +	@Override
    1.59 +	public void processLine(NNTPConnection conn, final String line, byte[] raw)
    1.60 +		throws IOException, StorageBackendException
    1.61 +	{
    1.62 +		final String[] command = line.split(" ");
    1.63  
    1.64 -    Article article = null;
    1.65 -    if(command.length == 1)
    1.66 -    {
    1.67 -      article = conn.getCurrentArticle();
    1.68 -      if(article == null)
    1.69 -      {
    1.70 -        conn.println("420 no current article has been selected");
    1.71 -        return;
    1.72 -      }
    1.73 -    }
    1.74 -    else if(command[1].matches(NNTPConnection.MESSAGE_ID_PATTERN))
    1.75 -    {
    1.76 -      // Message-ID
    1.77 -      article = Article.getByMessageID(command[1]);
    1.78 -      if (article == null)
    1.79 -      {
    1.80 -        conn.println("430 no such article found");
    1.81 -        return;
    1.82 -      }
    1.83 -    }
    1.84 -    else
    1.85 -    {
    1.86 -      // Message Number
    1.87 -      try
    1.88 -      {
    1.89 -        long aid = Long.parseLong(command[1]);
    1.90 -        article = conn.getCurrentChannel().getArticle(aid);
    1.91 -      }
    1.92 -      catch(NumberFormatException ex)
    1.93 -      {
    1.94 -        ex.printStackTrace();
    1.95 -      }
    1.96 -      catch(StorageBackendException ex)
    1.97 -      {
    1.98 -        ex.printStackTrace();
    1.99 -      }
   1.100 -      if (article == null)
   1.101 -      {
   1.102 -        conn.println("423 no such article number in this group");
   1.103 -        return;
   1.104 -      }
   1.105 -      conn.setCurrentArticle(article);
   1.106 -    }
   1.107 -    
   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 +		Article article = null;
   1.114 +		if (command.length == 1) {
   1.115 +			article = conn.getCurrentArticle();
   1.116 +			if (article == null) {
   1.117 +				conn.println("420 no current article has been selected");
   1.118 +				return;
   1.119 +			}
   1.120 +		} else if (command[1].matches(NNTPConnection.MESSAGE_ID_PATTERN)) {
   1.121 +			// Message-ID
   1.122 +			article = Article.getByMessageID(command[1]);
   1.123 +			if (article == null) {
   1.124 +				conn.println("430 no such article found");
   1.125 +				return;
   1.126 +			}
   1.127 +		} else {
   1.128 +			// Message Number
   1.129 +			try {
   1.130 +				long aid = Long.parseLong(command[1]);
   1.131 +				article = conn.getCurrentChannel().getArticle(aid);
   1.132 +			} catch (NumberFormatException ex) {
   1.133 +				ex.printStackTrace();
   1.134 +			} catch (StorageBackendException ex) {
   1.135 +				ex.printStackTrace();
   1.136 +			}
   1.137 +			if (article == null) {
   1.138 +				conn.println("423 no such article number in this group");
   1.139 +				return;
   1.140 +			}
   1.141 +			conn.setCurrentArticle(article);
   1.142 +		}
   1.143 +
   1.144 +		conn.println("223 " + conn.getCurrentChannel().getIndexOf(article) + " "
   1.145 +			+ article.getMessageID()
   1.146 +			+ " article retrieved - request text separately");
   1.147 +	}
   1.148  }