KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > za > org > coefficient > modules > theme > ChangeTheme


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

19
20 package za.org.coefficient.modules.theme;
21
22 import za.org.coefficient.authentication.Role;
23 import za.org.coefficient.html.ThemeSupport;
24 import za.org.coefficient.interfaces.CoefficientContext;
25 import za.org.coefficient.modules.BaseModule;
26 import za.org.coefficient.util.ejb.SecurityUtil;
27 import za.org.coefficient.util.ejb.VelocityScreenUtil;
28
29 import java.util.HashMap JavaDoc;
30 import java.util.Vector JavaDoc;
31
32 /**
33  * @pojo2ejb.class
34  * name="ChangeTheme"
35  * jndi-prefix="za/org/coefficient/admin/"
36  * interface-extends="za.org.coefficient.interfaces.Module"
37  * interface-local-extends="za.org.coefficient.interfaces.ModuleLocal"
38  *
39  * @web.resource-env-ref
40  * name="za/org/coefficient/admin/ChangeTheme"
41  * type="za.org.coefficient.modules.theme.ChangeTheme"
42  * @web.resource-env-ref
43  * name="ChangeTheme"
44  * type="za.org.coefficient.modules.theme.ChangeTheme"
45  */

46 public class ChangeTheme extends BaseModule {
47     //~ Methods ================================================================
48

49     public String JavaDoc getMainMethod() {
50         // NOTE: this can be any method of this class that makes sense
51
return "viewThemes";
52     }
53
54     public String JavaDoc getModuleDescription() {
55         return "This module allows you to change the overall theme used on the site";
56     }
57
58     public String JavaDoc getModuleDisplayName() {
59         return "Change Theme";
60     }
61
62     public String JavaDoc canExecuteForRole(CoefficientContext ctx, String JavaDoc methodName,
63         Role usersHighestRole) {
64         if (usersHighestRole.getRoleValue() > SecurityUtil.SITE_ADMIN_ROLE_VAL) {
65             return "Only a site administrator can change the sites theme";
66         } else {
67             return null;
68         }
69     }
70
71     public CoefficientContext change(CoefficientContext ctx) {
72         Vector JavaDoc v = ThemeSupport.getThemes();
73         String JavaDoc theme = ctx.getParameter("theme");
74         System.out.println("changeTheme.change");
75         ThemeSupport.changeTheme(theme);
76         ctx.setForward("ChangeTheme");
77         return ctx;
78     }
79
80     public CoefficientContext viewThemes(CoefficientContext ctx) {
81         Vector JavaDoc v = ThemeSupport.getThemes();
82         //System.out.println("Themes are " + v);
83

84         // Get html content
85
HashMap JavaDoc map = new HashMap JavaDoc();
86         map.put("module", this);
87         map.put("themes", v);
88         StringBuffer JavaDoc sb =
89             VelocityScreenUtil.getProcessedScreen("index.vm", map);
90
91         // Set the html into the context
92
ctx.setModuleContent(sb.toString(), getModuleDisplayName());
93         return ctx;
94     }
95 }
96
Popular Tags