diff -r ed84c8bdd87b -r 5d7d1adf387f src/org/sonews/daemon/command/ListCommand.java --- a/src/org/sonews/daemon/command/ListCommand.java Sun Aug 29 17:28:58 2010 +0200 +++ b/src/org/sonews/daemon/command/ListCommand.java Tue Jun 07 11:55:22 2011 +0200 @@ -37,117 +37,93 @@ public class ListCommand implements Command { - @Override - public String[] getSupportedCommandStrings() - { - return new String[]{"LIST"}; - } + @Override + public String[] getSupportedCommandStrings() + { + return new String[] {"LIST"}; + } - @Override - public boolean hasFinished() - { - return true; - } + @Override + public boolean hasFinished() + { + return true; + } - @Override - public String impliedCapability() - { - return null; - } + @Override + public String impliedCapability() + { + return null; + } - @Override - public boolean isStateful() - { - return false; - } - - @Override - public void processLine(NNTPConnection conn, final String line, byte[] raw) - throws IOException, StorageBackendException - { - final String[] command = line.split(" "); - - if(command.length >= 2) - { - if(command[1].equalsIgnoreCase("OVERVIEW.FMT")) - { - conn.println("215 information follows"); - conn.println("Subject:\nFrom:\nDate:\nMessage-ID:\nReferences:\nBytes:\nLines:\nXref"); - conn.println("."); - } - else if(command[1].equalsIgnoreCase("NEWSGROUPS")) - { - conn.println("215 information follows"); - final List list = Channel.getAll(); - for (Channel g : list) - { - conn.println(g.getName() + "\t" + "-"); - } - conn.println("."); - } - else if(command[1].equalsIgnoreCase("SUBSCRIPTIONS")) - { - conn.println("215 information follows"); - conn.println("."); - } - else if(command[1].equalsIgnoreCase("EXTENSIONS")) - { - conn.println("202 Supported NNTP extensions."); - conn.println("LISTGROUP"); - conn.println("XDAEMON"); - conn.println("XPAT"); - conn.println("."); - } - else if(command[1].equalsIgnoreCase("ACTIVE")) - { - String pattern = command.length == 2 - ? null : command[2].replace("*", "\\w*"); - printGroupInfo(conn, pattern); - } - else - { - conn.println("500 unknown argument to LIST command"); - } - } - else - { - printGroupInfo(conn, null); - } - } + @Override + public boolean isStateful() + { + return false; + } - private void printGroupInfo(NNTPConnection conn, String pattern) - throws IOException, StorageBackendException - { - final List groups = Channel.getAll(); - if(groups != null) - { - conn.println("215 list of newsgroups follows"); - for(Channel g : groups) - { - try - { - Matcher matcher = pattern == null ? - null : Pattern.compile(pattern).matcher(g.getName()); - if(!g.isDeleted() && - (matcher == null || matcher.find())) - { - String writeable = g.isWriteable() ? " y" : " n"; - // Indeed first the higher article number then the lower - conn.println(g.getName() + " " + g.getLastArticleNumber() + " " - + g.getFirstArticleNumber() + writeable); - } - } - catch(PatternSyntaxException ex) - { - Log.get().info(ex.toString()); - } - } - conn.println("."); - } - else - { - conn.println("500 server backend malfunction"); - } - } + @Override + public void processLine(NNTPConnection conn, final String line, byte[] raw) + throws IOException, StorageBackendException + { + final String[] command = line.split(" "); + if (command.length >= 2) { + if (command[1].equalsIgnoreCase("OVERVIEW.FMT")) { + conn.println("215 information follows"); + conn.println("Subject:\nFrom:\nDate:\nMessage-ID:\nReferences:\nBytes:\nLines:\nXref"); + conn.println("."); + } else if (command[1].equalsIgnoreCase("NEWSGROUPS")) { + conn.println("215 information follows"); + final List list = Channel.getAll(); + for (Channel g : list) { + conn.println(g.getName() + "\t" + "-"); + } + conn.println("."); + } else if (command[1].equalsIgnoreCase("SUBSCRIPTIONS")) { + conn.println("215 information follows"); + conn.println("."); + } else if (command[1].equalsIgnoreCase("EXTENSIONS")) { + conn.println("202 Supported NNTP extensions."); + conn.println("LISTGROUP"); + conn.println("XDAEMON"); + conn.println("XPAT"); + conn.println("."); + } else if (command[1].equalsIgnoreCase("ACTIVE")) { + String pattern = command.length == 2 + ? null : command[2].replace("*", "\\w*"); + printGroupInfo(conn, pattern); + } else { + conn.println("500 unknown argument to LIST command"); + } + } else { + printGroupInfo(conn, null); + } + } + + private void printGroupInfo(NNTPConnection conn, String pattern) + throws IOException, StorageBackendException + { + final List groups = Channel.getAll(); + if (groups != null) { + conn.println("215 list of newsgroups follows"); + for (Channel g : groups) { + try { + Matcher matcher = pattern == null + ? null : Pattern.compile(pattern).matcher(g.getName()); + if (!g.isDeleted() + && (matcher == null || matcher.find())) { + String writeable = g.isWriteable() ? " y" : " n"; + // Indeed first the higher article number then the lower + conn.println(g.getName() + " " + g.getLastArticleNumber() + " " + + g.getFirstArticleNumber() + writeable); + } + } catch (PatternSyntaxException ex) { + Log.get().info(ex.toString()); + } + } + conn.println("."); + } else { + conn.println("500 server backend malfunction"); + } + } }