src/org/sonews/daemon/command/GroupCommand.java
author František Kučera <franta-hg@frantovo.cz>
Thu Jul 05 13:19:19 2012 +0200 (2012-07-05)
changeset 119 f5b57e221e38
parent 37 74139325d305
permissions -rwxr-xr-x
mezery, tabulátory
chris@1
     1
/*
chris@1
     2
 *   SONEWS News Server
chris@1
     3
 *   see AUTHORS for the list of contributors
chris@1
     4
 *
chris@1
     5
 *   This program is free software: you can redistribute it and/or modify
chris@1
     6
 *   it under the terms of the GNU General Public License as published by
chris@1
     7
 *   the Free Software Foundation, either version 3 of the License, or
chris@1
     8
 *   (at your option) any later version.
chris@1
     9
 *
chris@1
    10
 *   This program is distributed in the hope that it will be useful,
chris@1
    11
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
chris@1
    12
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
chris@1
    13
 *   GNU General Public License for more details.
chris@1
    14
 *
chris@1
    15
 *   You should have received a copy of the GNU General Public License
chris@1
    16
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
chris@1
    17
 */
chris@1
    18
chris@1
    19
package org.sonews.daemon.command;
chris@1
    20
chris@1
    21
import java.io.IOException;
chris@1
    22
import org.sonews.daemon.NNTPConnection;
cli@48
    23
import org.sonews.storage.Group;
chris@3
    24
import org.sonews.storage.StorageBackendException;
cli@48
    25
import org.sonews.storage.StorageManager;
chris@1
    26
chris@1
    27
/**
chris@1
    28
 * Class handling the GROUP command.
chris@1
    29
 * <pre>
chris@1
    30
 *  Syntax
chris@1
    31
 *    GROUP group
chris@1
    32
 *
chris@1
    33
 *  Responses
chris@1
    34
 *    211 number low high group     Group successfully selected
chris@1
    35
 *    411                           No such newsgroup
chris@1
    36
 *
chris@1
    37
 *  Parameters
chris@1
    38
 *    group     Name of newsgroup
chris@1
    39
 *    number    Estimated number of articles in the group
chris@1
    40
 *    low       Reported low water mark
chris@1
    41
 *    high      Reported high water mark
chris@1
    42
 * </pre>
chris@1
    43
 * (from RFC 3977)
chris@1
    44
 * 
chris@1
    45
 * @author Christian Lins
chris@1
    46
 * @author Dennis Schwerdel
chris@1
    47
 * @since n3tpd/0.1
chris@1
    48
 */
chris@3
    49
public class GroupCommand implements Command
chris@1
    50
{
chris@1
    51
cli@37
    52
	@Override
cli@37
    53
	public String[] getSupportedCommandStrings()
cli@37
    54
	{
cli@37
    55
		return new String[] {"GROUP"};
cli@37
    56
	}
chris@1
    57
cli@37
    58
	@Override
cli@37
    59
	public boolean hasFinished()
cli@37
    60
	{
cli@37
    61
		return true;
cli@37
    62
	}
chris@3
    63
cli@37
    64
	@Override
cli@37
    65
	public String impliedCapability()
cli@37
    66
	{
cli@37
    67
		return null;
cli@37
    68
	}
cli@20
    69
cli@37
    70
	@Override
cli@37
    71
	public boolean isStateful()
cli@37
    72
	{
cli@37
    73
		return true;
cli@37
    74
	}
chris@1
    75
cli@37
    76
	@Override
cli@37
    77
	public void processLine(NNTPConnection conn, final String line, byte[] raw)
cli@37
    78
		throws IOException, StorageBackendException
cli@37
    79
	{
cli@37
    80
		final String[] command = line.split(" ");
chris@1
    81
cli@48
    82
		Group group;
cli@37
    83
		if (command.length >= 2) {
cli@48
    84
			group = StorageManager.current().getGroup(command[1]);
cli@37
    85
			if (group == null || group.isDeleted()) {
cli@37
    86
				conn.println("411 no such news group");
cli@37
    87
			} else {
cli@37
    88
				conn.setCurrentGroup(group);
cli@37
    89
				conn.println("211 " + group.getPostingsCount() + " " + group.getFirstArticleNumber()
cli@37
    90
					+ " " + group.getLastArticleNumber() + " " + group.getName() + " group selected");
cli@37
    91
			}
cli@37
    92
		} else {
cli@37
    93
			conn.println("500 no group name given");
cli@37
    94
		}
cli@37
    95
	}
chris@1
    96
}