org/sonews/daemon/command/ListCommand.java
changeset 1 6fceb66e1ad7
child 3 2fdc9cc89502
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/org/sonews/daemon/command/ListCommand.java	Fri Jun 26 16:48:50 2009 +0200
     1.3 @@ -0,0 +1,109 @@
     1.4 +/*
     1.5 + *   SONEWS News Server
     1.6 + *   see AUTHORS for the list of contributors
     1.7 + *
     1.8 + *   This program is free software: you can redistribute it and/or modify
     1.9 + *   it under the terms of the GNU General Public License as published by
    1.10 + *   the Free Software Foundation, either version 3 of the License, or
    1.11 + *   (at your option) any later version.
    1.12 + *
    1.13 + *   This program is distributed in the hope that it will be useful,
    1.14 + *   but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.15 + *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.16 + *   GNU General Public License for more details.
    1.17 + *
    1.18 + *   You should have received a copy of the GNU General Public License
    1.19 + *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
    1.20 + */
    1.21 +
    1.22 +package org.sonews.daemon.command;
    1.23 +
    1.24 +import java.io.IOException;
    1.25 +import java.sql.SQLException;
    1.26 +import java.util.List;
    1.27 +import org.sonews.daemon.NNTPConnection;
    1.28 +import org.sonews.daemon.storage.Group;
    1.29 +
    1.30 +/**
    1.31 + * Class handling the LIST command.
    1.32 + * @author Christian Lins
    1.33 + * @author Dennis Schwerdel
    1.34 + * @since n3tpd/0.1
    1.35 + */
    1.36 +public class ListCommand extends AbstractCommand
    1.37 +{
    1.38 +
    1.39 +  public ListCommand(final NNTPConnection conn)
    1.40 +  {
    1.41 +    super(conn);
    1.42 +  }
    1.43 +
    1.44 +  @Override
    1.45 +  public boolean hasFinished()
    1.46 +  {
    1.47 +    return true;
    1.48 +  }
    1.49 +  
    1.50 +  @Override
    1.51 +  public void processLine(final String line)
    1.52 +    throws IOException, SQLException
    1.53 +  {
    1.54 +    final String[] command = line.split(" ");
    1.55 +    
    1.56 +    if (command.length >= 2)
    1.57 +    {
    1.58 +      if (command[1].equalsIgnoreCase("OVERVIEW.FMT"))
    1.59 +      {
    1.60 +        printStatus(215, "information follows");
    1.61 +        println("Subject:\nFrom:\nDate:\nMessage-ID:\nReferences:\nBytes:\nLines:\nXref");
    1.62 +        println(".");
    1.63 +      }
    1.64 +      else if (command[1].equalsIgnoreCase("NEWSGROUPS"))
    1.65 +      {
    1.66 +        printStatus(215, "information follows");
    1.67 +        final List<Group> list = Group.getAll();
    1.68 +        for (Group g : list)
    1.69 +        {
    1.70 +          println(g.getName() + "\t" + "-");
    1.71 +        }
    1.72 +        println(".");
    1.73 +      }
    1.74 +      else if (command[1].equalsIgnoreCase("SUBSCRIPTIONS"))
    1.75 +      {
    1.76 +        printStatus(215, "information follows");
    1.77 +        println(".");
    1.78 +      }
    1.79 +      else if (command[1].equalsIgnoreCase("EXTENSIONS"))
    1.80 +      {
    1.81 +        printStatus(202, "Supported NNTP extensions.");
    1.82 +        println("LISTGROUP");
    1.83 +        println(".");
    1.84 + 
    1.85 +      }
    1.86 +      else
    1.87 +      {
    1.88 +        printStatus(500, "unknown argument to LIST command");
    1.89 +      }
    1.90 +    }
    1.91 +    else
    1.92 +    {
    1.93 +      final List<Group> groups = Group.getAll();
    1.94 +      if(groups != null)
    1.95 +      {
    1.96 +        printStatus(215, "list of newsgroups follows");
    1.97 +        for (Group g : groups)
    1.98 +        {
    1.99 +          // Indeed first the higher article number then the lower
   1.100 +          println(g.getName() + " " + g.getLastArticleNumber() + " "
   1.101 +              + g.getFirstArticleNumber() + " y");
   1.102 +        }
   1.103 +        println(".");
   1.104 +      }
   1.105 +      else
   1.106 +      {
   1.107 +        printStatus(500, "server database malfunction");
   1.108 +      }
   1.109 +    }
   1.110 +  }
   1.111 +
   1.112 +}