1.1 --- a/src/org/sonews/daemon/command/NextPrevCommand.java Sun Aug 29 17:28:58 2010 +0200
1.2 +++ b/src/org/sonews/daemon/command/NextPrevCommand.java Tue Jun 07 11:55:22 2011 +0200
1.3 @@ -33,84 +33,73 @@
1.4 public class NextPrevCommand implements Command
1.5 {
1.6
1.7 - @Override
1.8 - public String[] getSupportedCommandStrings()
1.9 - {
1.10 - return new String[]{"NEXT", "PREV"};
1.11 - }
1.12 + @Override
1.13 + public String[] getSupportedCommandStrings()
1.14 + {
1.15 + return new String[] {"NEXT", "PREV"};
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 - @Override
1.52 - public void processLine(NNTPConnection conn, final String line, byte[] raw)
1.53 - throws IOException, StorageBackendException
1.54 - {
1.55 - final Article currA = conn.getCurrentArticle();
1.56 - final Channel currG = conn.getCurrentChannel();
1.57 -
1.58 - if (currA == null)
1.59 - {
1.60 - conn.println("420 no current article has been selected");
1.61 - return;
1.62 - }
1.63 -
1.64 - if (currG == null)
1.65 - {
1.66 - conn.println("412 no newsgroup selected");
1.67 - return;
1.68 - }
1.69 -
1.70 - final String[] command = line.split(" ");
1.71 + @Override
1.72 + public void processLine(NNTPConnection conn, final String line, byte[] raw)
1.73 + throws IOException, StorageBackendException
1.74 + {
1.75 + final Article currA = conn.getCurrentArticle();
1.76 + final Channel currG = conn.getCurrentChannel();
1.77
1.78 - if(command[0].equalsIgnoreCase("NEXT"))
1.79 - {
1.80 - selectNewArticle(conn, currA, currG, 1);
1.81 - }
1.82 - else if(command[0].equalsIgnoreCase("PREV"))
1.83 - {
1.84 - selectNewArticle(conn, currA, currG, -1);
1.85 - }
1.86 - else
1.87 - {
1.88 - conn.println("500 internal server error");
1.89 - }
1.90 - }
1.91 -
1.92 - private void selectNewArticle(NNTPConnection conn, Article article, Channel grp,
1.93 - final int delta)
1.94 - throws IOException, StorageBackendException
1.95 - {
1.96 - assert article != null;
1.97 + if (currA == null) {
1.98 + conn.println("420 no current article has been selected");
1.99 + return;
1.100 + }
1.101
1.102 - article = grp.getArticle(grp.getIndexOf(article) + delta);
1.103 + if (currG == null) {
1.104 + conn.println("412 no newsgroup selected");
1.105 + return;
1.106 + }
1.107
1.108 - if(article == null)
1.109 - {
1.110 - conn.println("421 no next article in this group");
1.111 - }
1.112 - else
1.113 - {
1.114 - conn.setCurrentArticle(article);
1.115 - conn.println("223 " + conn.getCurrentChannel().getIndexOf(article)
1.116 - + " " + article.getMessageID()
1.117 - + " article retrieved - request text separately");
1.118 - }
1.119 - }
1.120 + final String[] command = line.split(" ");
1.121
1.122 + if (command[0].equalsIgnoreCase("NEXT")) {
1.123 + selectNewArticle(conn, currA, currG, 1);
1.124 + } else if (command[0].equalsIgnoreCase("PREV")) {
1.125 + selectNewArticle(conn, currA, currG, -1);
1.126 + } else {
1.127 + conn.println("500 internal server error");
1.128 + }
1.129 + }
1.130 +
1.131 + private void selectNewArticle(NNTPConnection conn, Article article, Channel grp,
1.132 + final int delta)
1.133 + throws IOException, StorageBackendException
1.134 + {
1.135 + assert article != null;
1.136 +
1.137 + article = grp.getArticle(grp.getIndexOf(article) + delta);
1.138 +
1.139 + if (article == null) {
1.140 + conn.println("421 no next article in this group");
1.141 + } else {
1.142 + conn.setCurrentArticle(article);
1.143 + conn.println("223 " + conn.getCurrentChannel().getIndexOf(article)
1.144 + + " " + article.getMessageID()
1.145 + + " article retrieved - request text separately");
1.146 + }
1.147 + }
1.148 }