KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > freecs > commands > CmdListOnlineFriends


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.core.User;
27 import freecs.core.UserManager;
28 import freecs.content.MessageState;
29
30 /**
31  * @author Manfred Andres
32  *
33  * freecs.commands
34  */

35 public class CmdListOnlineFriends extends AbstractCommand {
36     public final String JavaDoc cmd= "/f";
37     private static final ICommand selve=new CmdListOnlineFriends();
38
39     private CmdListOnlineFriends () { }
40     
41     public static ICommand getInstance () {
42         return selve;
43     }
44     
45     public boolean execute (MessageState msgState, String JavaDoc param) {
46         if (msgState.sender.numberOfFriends () < 1) {
47             msgState.msgTemplate = "error.fl.nofriends";
48             msgState.sender.sendMessage (msgState.mp);
49             return false;
50         }
51         Vector JavaDoc onlineFriends = new Vector JavaDoc();
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                 continue;
57             onlineFriends.add(msgState.usercontext);
58         }
59         if (onlineFriends.size() < 1) {
60             msgState.msgTemplate="error.f.noFriendOnline";
61             msgState.sender.sendMessage (msgState.mp);
62             return false;
63         }
64         msgState.msgTemplate = "message.f.headline";
65         msgState.param = String.valueOf(onlineFriends.size());
66         msgState.sender.sendMessage (msgState.mp);
67         
68         msgState.useRenderCache = false;
69         msgState.msgTemplate = "message.f";
70         for (Enumeration JavaDoc e = onlineFriends.elements(); e.hasMoreElements(); ) {
71             msgState.usercontext = (User) e.nextElement();
72             msgState.sender.sendMessage(msgState.mp);
73         }
74         msgState.msgTemplate = "message.f.count";
75         msgState.sender.sendMessage(msgState.mp);
76         return true;
77     }
78 }
79
Popular Tags