KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > za > org > coefficient > modules > information > Welcome


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.information;
21
22 import org.apache.commons.lang.StringUtils;
23
24 import net.sf.hibernate.Hibernate;
25 import net.sf.hibernate.Session;
26 import net.sf.hibernate.type.Type;
27
28 import za.org.coefficient.authentication.CoefficientUser;
29 import za.org.coefficient.core.Project;
30 import za.org.coefficient.interfaces.CoefficientContext;
31 import za.org.coefficient.modules.BaseModule;
32 import za.org.coefficient.modules.project.ProjectConstants;
33 import net.sf.hibernate.util.HibernateUtil;
34 import za.org.coefficient.util.ejb.SecurityUtil;
35 import za.org.coefficient.util.ejb.VelocityScreenUtil;
36
37 import java.util.HashMap JavaDoc;
38
39 /**
40  * @pojo2ejb.class
41  * name="Welcome"
42  * jndi-prefix="za/org/coefficient/default/"
43  * interface-extends="za.org.coefficient.interfaces.Module"
44  * interface-local-extends="za.org.coefficient.interfaces.ModuleLocal"
45  *
46  * @web.resource-env-ref
47  * name="za/org/coefficient/default/Welcome"
48  * type="za.org.coefficient.modules.information.Welcome"
49  * @web.resource-env-ref
50  * name="Welcome"
51  * type="za.org.coefficient.modules.information.Welcome"
52  */

53 public class Welcome extends BaseModule {
54     //~ Methods ================================================================
55

56     public String JavaDoc getMainMethod() {
57         return "view";
58     }
59
60     public String JavaDoc getModuleDescription() {
61         return "Module that is viewed when first entering the site";
62     }
63
64     public String JavaDoc getModuleDisplayName() {
65         return "Welcome";
66     }
67
68     public CoefficientContext view(CoefficientContext ctx) throws Exception JavaDoc {
69         HashMap JavaDoc map = new HashMap JavaDoc();
70         String JavaDoc welcomeContent = ctx.getPage()
71                                    .getThemeWelcomeContent();
72         if ((welcomeContent == null) || welcomeContent.trim()
73                                                       .equals("")) {
74             map.put("themeContent",
75                 VelocityScreenUtil.getProcessedScreen("defaultWelcome.vm", map).toString());
76         } else {
77             map.put("themeContent", welcomeContent);
78         }
79         Session sess = HibernateUtil.getSession();
80         map.put("totalProjects",
81             ((Integer JavaDoc) sess.iterate("select count(projects) from "
82                 + Project.class.getName()
83                 + " as projects where projects.active = ?",
84                 new Boolean JavaDoc(true), Hibernate.BOOLEAN).next()));
85         map.put("totalUsers",
86             ((Integer JavaDoc) sess.iterate("select count(pe_users) from "
87                 + CoefficientUser.class.getName()
88                 + " as pe_users where pe_users.active = ? and pe_users.systemRole.roleValue = ?",
89                 new Object JavaDoc[] {
90                     new Boolean JavaDoc(true),
91                     new Long JavaDoc(SecurityUtil.SITE_MEMBER_ROLE_VAL)
92                 }, new Type[] { Hibernate.BOOLEAN, Hibernate.LONG }).next()));
93         // TODO: remove this when the hibernate util is all fixed up, this won't
94
// be needed.
95
HibernateUtil.finalizeSession();
96
97         map.put("project_name", ProjectConstants.PROJECT_NAME);
98         map.put("project_name_cap",
99                 StringUtils.capitalise(ProjectConstants.PROJECT_NAME));
100         StringBuffer JavaDoc sb =
101             VelocityScreenUtil.getProcessedScreen("view.vm", map);
102
103         // Set the html into the context
104
ctx.setModuleContent(sb.toString(), getModuleDisplayName());
105         return ctx;
106     }
107 }
108
Popular Tags