trunk/com/so/news/command/NextCommand.java
author chris <chris@marvin>
Tue Jan 20 10:21:03 2009 +0100 (2009-01-20)
changeset 0 f907866f0e4b
permissions -rw-r--r--
Initial import.
chris@0
     1
/*
chris@0
     2
 *   StarOffice News Server
chris@0
     3
 *   see AUTHORS for the list of contributors
chris@0
     4
 *
chris@0
     5
 *   This program is free software: you can redistribute it and/or modify
chris@0
     6
 *   it under the terms of the GNU General Public License as published by
chris@0
     7
 *   the Free Software Foundation, either version 3 of the License, or
chris@0
     8
 *   (at your option) any later version.
chris@0
     9
 *
chris@0
    10
 *   This program is distributed in the hope that it will be useful,
chris@0
    11
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
chris@0
    12
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
chris@0
    13
 *   GNU General Public License for more details.
chris@0
    14
 *
chris@0
    15
 *   You should have received a copy of the GNU General Public License
chris@0
    16
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
chris@0
    17
 */
chris@0
    18
chris@0
    19
package com.so.news.command;
chris@0
    20
chris@0
    21
import java.io.IOException;
chris@0
    22
import com.so.news.NNTPConnection;
chris@0
    23
import com.so.news.storage.Article;
chris@0
    24
import com.so.news.storage.Group;
chris@0
    25
chris@0
    26
/**
chris@0
    27
 * Class handling the NEXT and LAST command.
chris@0
    28
 * @author Christian Lins
chris@0
    29
 * @author Dennis Schwerdel
chris@0
    30
 */
chris@0
    31
public class NextCommand extends Command
chris@0
    32
{
chris@0
    33
  public NextCommand(NNTPConnection conn)
chris@0
    34
  {
chris@0
    35
    super(conn);
chris@0
    36
  }
chris@0
    37
chris@0
    38
  public boolean process(String[] command) throws IOException
chris@0
    39
  {
chris@0
    40
    String commandName = command[0];
chris@0
    41
    if (!(commandName.equalsIgnoreCase("NEXT") || commandName
chris@0
    42
        .equalsIgnoreCase("LAST")))
chris@0
    43
      return false;
chris@0
    44
    // untested, RFC977 complient
chris@0
    45
    Article currA = getCurrentArticle();
chris@0
    46
    Group currG = getCurrentGroup();
chris@0
    47
    if (currA == null)
chris@0
    48
    {
chris@0
    49
      printStatus(420, "no current article has been selected");
chris@0
    50
      return true;
chris@0
    51
    }
chris@0
    52
    if (currG == null)
chris@0
    53
    {
chris@0
    54
      printStatus(412, "no newsgroup selected");
chris@0
    55
      return true;
chris@0
    56
    }
chris@0
    57
    Article article;
chris@0
    58
    if (commandName.equalsIgnoreCase("NEXT"))
chris@0
    59
    {
chris@0
    60
      article = currA.nextArticleInGroup();
chris@0
    61
      if (article == null)
chris@0
    62
      {
chris@0
    63
        printStatus(421, "no next article in this group");
chris@0
    64
        return true;
chris@0
    65
      }
chris@0
    66
    }
chris@0
    67
    else
chris@0
    68
    {
chris@0
    69
      article = currA.prevArticleInGroup();
chris@0
    70
      if (article == null)
chris@0
    71
      {
chris@0
    72
        printStatus(422, "no previous article in this group");
chris@0
    73
        return true;
chris@0
    74
      }
chris@0
    75
    }
chris@0
    76
    setCurrentArticle(article);
chris@0
    77
    printStatus(223, article.getNumberInGroup() + " " + article.getMessageID()
chris@0
    78
        + " article retrieved - request text separately");
chris@0
    79
    return true;
chris@0
    80
  }
chris@0
    81
chris@0
    82
}