trunk/com/so/news/command/ListCommand.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.
     1 /*
     2  *   StarOffice News Server
     3  *   see AUTHORS for the list of contributors
     4  *
     5  *   This program is free software: you can redistribute it and/or modify
     6  *   it under the terms of the GNU General Public License as published by
     7  *   the Free Software Foundation, either version 3 of the License, or
     8  *   (at your option) any later version.
     9  *
    10  *   This program is distributed in the hope that it will be useful,
    11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13  *   GNU General Public License for more details.
    14  *
    15  *   You should have received a copy of the GNU General Public License
    16  *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
    17  */
    18 
    19 package com.so.news.command;
    20 
    21 import java.io.IOException;
    22 import java.util.ArrayList;
    23 import com.so.news.NNTPConnection;
    24 import com.so.news.storage.Group;
    25 
    26 /**
    27  * Class handling the LIST command.
    28  * @author Christian Lins
    29  * @author Dennis Schwerdel
    30  */
    31 public class ListCommand extends Command
    32 {
    33   public ListCommand(NNTPConnection conn)
    34   {
    35     super(conn);
    36   }
    37 
    38   public boolean process(String[] command) 
    39     throws Exception
    40   {
    41     if (command.length >= 2)
    42     {
    43       if (command[1].equalsIgnoreCase("OVERVIEW.FMT"))
    44       {
    45         printStatus(215, "information follows");
    46         printText("Subject:\nFrom:\nDate:\nMessage-ID:\nReferences:\nBytes:\nLines:");
    47         return true;
    48       }
    49       if (command[1].equalsIgnoreCase("NEWSGROUPS"))
    50       {
    51         printStatus(215, "information follows");
    52         ArrayList<Group> list = Group.getAll();
    53         for (Group g : list)
    54         {
    55           printTextLine(g.getName() + "\t" + "-");
    56         }
    57         println(".");
    58         flush();
    59         return true;
    60       }
    61       if (command[1].equalsIgnoreCase("SUBSCRIPTIONS"))
    62       {
    63         printStatus(215, "information follows");
    64         println(".");
    65         flush();
    66         return true;
    67       }
    68       if (command[1].equalsIgnoreCase("EXTENSIONS"))
    69       {
    70         printStatus(202, "Supported NNTP extensions.");
    71         printTextLine("LISTGROUP");
    72         println(".");
    73         flush();
    74         return true;
    75       }
    76       return false;
    77     }
    78     printStatus(215, "list of newsgroups follows");
    79     for (Group g : Group.getAll())
    80     {
    81       //if(g.getEstimatedArticleCount() <= 0)
    82       //  continue;
    83       
    84       printTextLine(g.getName() + " " + g.getLastArticle() + " "
    85           + g.getFirstArticle() + " y");
    86     }
    87     println(".");
    88     flush();
    89     return true;
    90   }
    91 
    92 }