#544 fixed.
1.1 --- a/org/sonews/daemon/command/ListCommand.java Thu Aug 20 21:31:03 2009 +0200
1.2 +++ b/org/sonews/daemon/command/ListCommand.java Thu Aug 20 22:18:45 2009 +0200
1.3 @@ -20,9 +20,13 @@
1.4
1.5 import java.io.IOException;
1.6 import java.util.List;
1.7 +import java.util.regex.Matcher;
1.8 +import java.util.regex.Pattern;
1.9 +import java.util.regex.PatternSyntaxException;
1.10 import org.sonews.daemon.NNTPConnection;
1.11 import org.sonews.storage.Channel;
1.12 import org.sonews.storage.StorageBackendException;
1.13 +import org.sonews.util.Log;
1.14
1.15 /**
1.16 * Class handling the LIST command.
1.17 @@ -90,8 +94,9 @@
1.18 }
1.19 else if(command[1].equalsIgnoreCase("ACTIVE"))
1.20 {
1.21 - // TODO: Implement wildcards for LIST ACTIVE
1.22 - printGroupInfo(conn);
1.23 + String pattern = command.length == 2
1.24 + ? null : command[2].replace("*", "\\w*");
1.25 + printGroupInfo(conn, pattern);
1.26 }
1.27 else
1.28 {
1.29 @@ -100,31 +105,42 @@
1.30 }
1.31 else
1.32 {
1.33 - printGroupInfo(conn);
1.34 + printGroupInfo(conn, null);
1.35 }
1.36 }
1.37
1.38 - private void printGroupInfo(NNTPConnection conn)
1.39 + private void printGroupInfo(NNTPConnection conn, String pattern)
1.40 throws IOException, StorageBackendException
1.41 {
1.42 final List<Channel> groups = Channel.getAll();
1.43 - if (groups != null)
1.44 + if(groups != null)
1.45 {
1.46 conn.println("215 list of newsgroups follows");
1.47 - for (Channel g : groups)
1.48 + for(Channel g : groups)
1.49 {
1.50 - if (!g.isDeleted())
1.51 + try
1.52 {
1.53 - String writeable = g.isWriteable() ? " y" : " n";
1.54 - // Indeed first the higher article number then the lower
1.55 - conn.println(g.getName() + " " + g.getLastArticleNumber() + " " + g.getFirstArticleNumber() + writeable);
1.56 + Matcher matcher = pattern == null ?
1.57 + null : Pattern.compile(pattern).matcher(g.getName());
1.58 + if(!g.isDeleted() &&
1.59 + (matcher == null || matcher.find()))
1.60 + {
1.61 + String writeable = g.isWriteable() ? " y" : " n";
1.62 + // Indeed first the higher article number then the lower
1.63 + conn.println(g.getName() + " " + g.getLastArticleNumber() + " "
1.64 + + g.getFirstArticleNumber() + writeable);
1.65 + }
1.66 + }
1.67 + catch(PatternSyntaxException ex)
1.68 + {
1.69 + Log.get().info(ex.toString());
1.70 }
1.71 }
1.72 conn.println(".");
1.73 }
1.74 else
1.75 {
1.76 - conn.println("500 server database malfunction");
1.77 + conn.println("500 server backend malfunction");
1.78 }
1.79 }
1.80