KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > freecs > commands > CmdListBan


1 /**
2  * Copyright (C) 2003 Manfred Andres
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17  *
18  * Created on 28.09.2003
19  */

20
21 package freecs.commands;
22 import java.util.Enumeration JavaDoc;
23 import java.util.Vector JavaDoc;
24
25 import freecs.interfaces.ICommand;
26 import freecs.content.MessageState;
27 import freecs.core.GroupManager;
28
29 /**
30  * @author Manfred Andres
31  *
32  * freecs.commands
33  */

34 public class CmdListBan extends AbstractCommand {
35     public final String JavaDoc cmd= "/wban";
36     private static final ICommand selve=new CmdListBan();
37
38     private CmdListBan () { }
39     
40     public static ICommand getInstance () {
41         return selve;
42     }
43     
44     public boolean execute (MessageState msgState, String JavaDoc param) {
45         if (isPunished (msgState)) return false;
46         if (param != null && param.length() > 1) {
47             msgState.targetGroup = GroupManager.mgr.getGroup(param);
48             if (msgState.targetGroup == null) {
49                 msgState.msgTemplate="error.group.notExisting";
50                 msgState.param = param;
51                 msgState.sender.sendMessage(msgState.mp);
52                 return false;
53             }
54         } else
55             msgState.targetGroup = msgState.sender.getGroup();
56
57 /* if (!msgState.sender.hasRight(IUserRights.MAY_BAN)
58             && !msgState.targetGroup.usrIsSu(msgState.sender)) {
59             msgState.msgTemplate = "error.wban.noRight";
60             msgState.sender.sendMessage (msgState.mp);
61             return false;
62         } */

63         Vector JavaDoc bl = msgState.targetGroup.bannedUsers();
64         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
65         StringBuffer JavaDoc tsb = new StringBuffer JavaDoc();
66         for (Enumeration JavaDoc e = bl.elements(); e.hasMoreElements(); ) {
67             String JavaDoc uname = (String JavaDoc) e.nextElement();
68             sb.append ("<a HREF='/SEND?message=/uban ");
69             sb.append (uname);
70             sb.append ("' target=dummy>");
71             sb.append (uname);
72             sb.append ("</a>");
73             tsb.append (" ");
74             tsb.append (uname);
75             if (e.hasMoreElements())
76                 sb.append (", ");
77         }
78         if (sb.length() < 1) {
79             msgState.msgTemplate = "error.wban.nobodyBanned";
80             msgState.sender.sendMessage (msgState.mp);
81             return false;
82         }
83         sb.append ("<br><a HREF='/SEND?message=/uban");
84         sb.append (tsb);
85         sb.append ("' target=dummy>");
86         sb.append ("<b>ubanall</b>");
87         sb.append ("</a>");
88
89         msgState.message = sb.toString();
90         msgState.msgTemplate="message.wban";
91         msgState.sender.sendMessage (msgState.mp);
92         return false;
93     }
94 }
95
Popular Tags