KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > freecs > commands > CmdListAllFriends


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
24 import freecs.interfaces.ICommand;
25 import freecs.core.UserManager;
26 import freecs.content.MessageState;
27
28 /**
29  * @author Manfred Andres
30  *
31  * freecs.commands
32  */

33 public class CmdListAllFriends extends AbstractCommand {
34     public final String JavaDoc cmd= "/fl";
35     private static final ICommand selve=new CmdListAllFriends ();
36
37     private CmdListAllFriends () { }
38     
39     public static ICommand getInstance () {
40         return selve;
41     }
42     
43     public boolean execute (MessageState msgState, String JavaDoc param) {
44         if (msgState.sender.numberOfFriends () < 1) {
45             msgState.msgTemplate = "error.fl.nofriends";
46             msgState.sender.sendMessage (msgState.mp);
47             return false;
48         }
49         msgState.msgTemplate = "message.fl.headline";
50         msgState.sender.sendMessage (msgState.mp);
51         msgState.useRenderCache = false;
52         for (Enumeration JavaDoc e = msgState.sender.friends (); e.hasMoreElements (); ) {
53             String JavaDoc uname = (String JavaDoc) e.nextElement ();
54             msgState.usercontext = UserManager.mgr.getUserByName (uname);
55             if (msgState.usercontext == null) {
56                 msgState.msgTemplate = "message.fl.entry.offline";
57                 msgState.targetGroup = null;
58                 msgState.param = uname;
59             } else {
60                 msgState.msgTemplate = "message.fl.entry.online";
61                 msgState.targetGroup = msgState.usercontext.getGroup ();
62                 msgState.param = "";
63             }
64             msgState.sender.sendMessage (msgState.mp);
65         }
66         msgState.param = String.valueOf (msgState.sender.numberOfFriends ());
67         msgState.msgTemplate = "message.fl.count";
68         msgState.sender.sendMessage (msgState.mp);
69         return false;
70     }
71 }
72
Popular Tags