# HG changeset patch # User cli # Date 1250799525 -7200 # Node ID 4ae6ada7ea231e86216d0448c2e492b316cd7d96 # Parent 5a4a41cfc0a3e74802f4ae690bb99e796d949902 #544 fixed. diff -r 5a4a41cfc0a3 -r 4ae6ada7ea23 org/sonews/daemon/command/ListCommand.java --- a/org/sonews/daemon/command/ListCommand.java Thu Aug 20 21:31:03 2009 +0200 +++ b/org/sonews/daemon/command/ListCommand.java Thu Aug 20 22:18:45 2009 +0200 @@ -20,9 +20,13 @@ import java.io.IOException; import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; import org.sonews.daemon.NNTPConnection; import org.sonews.storage.Channel; import org.sonews.storage.StorageBackendException; +import org.sonews.util.Log; /** * Class handling the LIST command. @@ -90,8 +94,9 @@ } else if(command[1].equalsIgnoreCase("ACTIVE")) { - // TODO: Implement wildcards for LIST ACTIVE - printGroupInfo(conn); + String pattern = command.length == 2 + ? null : command[2].replace("*", "\\w*"); + printGroupInfo(conn, pattern); } else { @@ -100,31 +105,42 @@ } else { - printGroupInfo(conn); + printGroupInfo(conn, null); } } - private void printGroupInfo(NNTPConnection conn) + private void printGroupInfo(NNTPConnection conn, String pattern) throws IOException, StorageBackendException { final List groups = Channel.getAll(); - if (groups != null) + if(groups != null) { conn.println("215 list of newsgroups follows"); - for (Channel g : groups) + for(Channel g : groups) { - if (!g.isDeleted()) + try { - String writeable = g.isWriteable() ? " y" : " n"; - // Indeed first the higher article number then the lower - conn.println(g.getName() + " " + g.getLastArticleNumber() + " " + g.getFirstArticleNumber() + writeable); + 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 database malfunction"); + conn.println("500 server backend malfunction"); } }