KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > freecs > commands > CmdSetTheme


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

33 public class CmdSetTheme extends AbstractCommand {
34     public final String JavaDoc cmd= "/t";
35     private static final ICommand selve=new CmdSetTheme();
36
37     private CmdSetTheme () { }
38     
39     public static ICommand getInstance () {
40         return selve;
41     }
42     
43     public boolean execute (MessageState msgState, String JavaDoc param) {
44         if (isPunished (msgState))
45             return false;
46         msgState.targetGroup = msgState.sender.getGroup ();
47         // check rights
48
if (!msgState.sender.hasRight(IUserStates.ROLE_VIP)) {
49             if (msgState.targetGroup.hasState(IGroupState.ENTRANCE)) {
50                 msgState.msgTemplate = "error.noRight.noVipAdmin";
51                 msgState.sender.sendMessage (msgState.mp);
52                 return false;
53             } else if (!msgState.targetGroup.usrIsSu (msgState.sender)) {
54                 msgState.msgTemplate = "error.noRight.noSuVipAdmin";
55                 msgState.sender.sendMessage (msgState.mp);
56                 return false;
57             }
58         } else if (!isVip(msgState.sender, msgState.targetGroup, msgState)) {
59             if (msgState.usrList.length > 1)
60                 msgState.msgTemplate = "error.membership.notMember.many";
61             else
62                 msgState.msgTemplate = "error.membership.notMember";
63             msgState.usercontext=null;
64             msgState.sender.sendMessage(msgState.mp);
65             return false;
66         }
67         if (param.length() < 1) {
68             if (msgState.sender.getGroup().getTheme()!= null) {
69                 msgState.param = msgState.sender.getGroup().getTheme();
70             } else msgState.param = "";
71             msgState.sender.getGroup().setTheme(null);
72             msgState.msgTemplate="message.t.removed";
73             msgState.sender.getGroup().sendMessage(msgState.mp);
74             return true;
75         }
76         if (Server.srv.MAX_GROUPTHEME_LENGTH > 0 && param.length() > Server.srv.MAX_GROUPTHEME_LENGTH) {
77             param = param.substring(0,Server.srv.MAX_GROUPTHEME_LENGTH);
78         }
79         msgState.param = msgState.targetGroup.getTheme();
80         msgState.targetGroup.setTheme (param);
81         msgState.msgTemplate = "message.t";
82         msgState.targetGroup.sendModeratedMessage (msgState.mp);
83         return true;
84     }
85 }
86
Popular Tags