KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > freecs > commands > CmdListUsers


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.nio.ByteBuffer JavaDoc;
23
24 import freecs.interfaces.ICommand;
25 import freecs.core.Group;
26 import freecs.core.GroupManager;
27 import freecs.core.MessageRenderer;
28 import freecs.core.UserManager;
29 import freecs.content.MessageState;
30 import freecs.content.PersonalizedMessage;
31
32 /**
33  * @author Manfred Andres
34  *
35  * freecs.commands
36  */

37 public class CmdListUsers extends AbstractCommand {
38     public final String JavaDoc cmd= "/wc";
39     private static final ICommand selve=new CmdListUsers();
40
41     private CmdListUsers () { }
42     
43     public static ICommand getInstance () {
44         return selve;
45     }
46     
47     public boolean execute (MessageState msgState, String JavaDoc param) {
48         if (param == null || param.length () < 1) {
49             msgState.useRenderCache = false;
50             if ("false".equals(msgState.sender.getTemplateSet().getMessageTemplate("status.wc.renderUserlist")))
51                 return true;
52             StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
53             Group[] grps = GroupManager.mgr.currentGroupList();
54             for (int i = 0; i < grps.length; i++) {
55                 Group g = grps[i];
56                 if (!g.isValid()) {
57                     GroupManager.mgr.removeGroup(g);
58                     continue;
59                 }
60                 msgState.sourceGroup=g;
61                 msgState.targetGroup=g;
62                 sb.append (getUserList (msgState, true));
63             }
64             ByteBuffer JavaDoc bb = MessageRenderer.encode(sb.toString());
65             if (bb==null)
66                 return false;
67             msgState.msgTemplate = "message.wc.headline";
68             msgState.sender.sendMessage (msgState.mp);
69             msgState.sender.sendMessage(new PersonalizedMessage(bb));
70             msgState.msgTemplate = "message.wc.underline";
71             msgState.param = String.valueOf (UserManager.mgr.getActiveUserCount());
72             msgState.reason = String.valueOf (GroupManager.mgr.openGroupsCount());
73             msgState.sender.sendMessage (msgState.mp);
74         } else {
75            Group g = GroupManager.mgr.getGroup (param);
76            if (g == null) {
77               msgState.msgTemplate = "error.group.notExisting";
78               msgState.param = param;
79               msgState.sender.sendMessage (msgState.mp);
80            } else {
81               msgState.sourceGroup = g;
82               sendUserList (msgState, false);
83            }
84         }
85         return true;
86     }
87 }
88
Popular Tags