chris@0: /*
chris@0: * StarOffice News Server
chris@0: * see AUTHORS for the list of contributors
chris@0: *
chris@0: * This program is free software: you can redistribute it and/or modify
chris@0: * it under the terms of the GNU General Public License as published by
chris@0: * the Free Software Foundation, either version 3 of the License, or
chris@0: * (at your option) any later version.
chris@0: *
chris@0: * This program is distributed in the hope that it will be useful,
chris@0: * but WITHOUT ANY WARRANTY; without even the implied warranty of
chris@0: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
chris@0: * GNU General Public License for more details.
chris@0: *
chris@0: * You should have received a copy of the GNU General Public License
chris@0: * along with this program. If not, see .
chris@0: */
chris@0:
chris@0: package com.so.news.command;
chris@0:
chris@0: import java.util.List;
chris@0: import com.so.news.NNTPConnection;
chris@0: import com.so.news.storage.Article;
chris@0: import com.so.news.storage.Group;
chris@0:
chris@0: /**
chris@0: * Class handling the LISTGROUP command.
chris@0: * @author Christian Lins
chris@0: * @author Dennis Schwerdel
chris@0: */
chris@0: public class ListGroupCommand extends Command
chris@0: {
chris@0: public ListGroupCommand(NNTPConnection conn)
chris@0: {
chris@0: super(conn);
chris@0: }
chris@0:
chris@0: public boolean process(String[] command)
chris@0: throws Exception
chris@0: {
chris@0: String commandName = command[0];
chris@0: if (!commandName.equalsIgnoreCase("LISTGROUP"))
chris@0: return false;
chris@0: // untested, RFC977 complient
chris@0: Group group = null;
chris@0: if (command.length >= 2)
chris@0: {
chris@0: group = Group.getByName(command[1]);
chris@0: }
chris@0: else
chris@0: {
chris@0: group = getCurrentGroup();
chris@0: }
chris@0: if (group == null)
chris@0: {
chris@0: printStatus(412, "Not currently in newsgroup");
chris@0: return true;
chris@0: }
chris@0: List list = group.getAllArticles();
chris@0: printStatus(211, "list of article numbers follow"); // argh, bad english in
chris@0: // RFC
chris@0: for (Article a : list)
chris@0: {
chris@0: printTextLine("" + a.getNumberInGroup());
chris@0: }
chris@0: println(".");
chris@0: flush();
chris@0: return true;
chris@0: }
chris@0:
chris@0: }