KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > za > org > coefficient > modules > sample > Sample


1 package za.org.coefficient.modules.sample;
2
3 import java.util.HashMap JavaDoc;
4
5 import za.org.coefficient.authentication.CoefficientUser;
6 import za.org.coefficient.authentication.Role;
7 import za.org.coefficient.core.Project;
8 import za.org.coefficient.interfaces.CoefficientContext;
9 import za.org.coefficient.modules.BaseProjectModule;
10 import za.org.coefficient.util.ejb.SecurityUtil;
11 import za.org.coefficient.util.ejb.VelocityScreenUtil;
12
13 /**
14  * This is a sample module that is meant for instructional purposes only.
15  * NOTE: Methods that modify the CoefficientContext in any way, setModuleContent
16  * counts, should return the CoeffcientContext. This is so that in a remote
17  * environment we do not loose the data.
18  *
19  * @pojo2ejb.class
20  * name="Sample"
21  * jndi-prefix="za/org/coefficient/project/"
22  * interface-extends="za.org.coefficient.interfaces.Module"
23  * interface-local-extends="za.org.coefficient.interfaces.ModuleLocal"
24  *
25  * @web.resource-env-ref
26  * name="za/org/coefficient/project/Sample"
27  * type="za.org.coefficient.modules.sample.Sample"
28  * @web.resource-env-ref
29  * name="Sample"
30  * type="za.org.coefficient.modules.sample.Sample"
31  */

32 public class Sample extends BaseProjectModule {
33     
34     public String JavaDoc getModuleDisplayName () {
35         return "Sample";
36     }
37
38     public String JavaDoc getModuleDescription () {
39         return "Sample Module";
40     }
41
42     public String JavaDoc getMainMethod () {
43         // NOTE: this can be any method of this class that makes sense
44
return "doInitialWork";
45     }
46
47     // roles which can execute the method
48
String JavaDoc roles[] = {
49         SecurityUtil.SITE_ADMIN_ROLE_DESC,
50         SecurityUtil.PROJECT_CHAMPION_ROLE_DESC,
51         SecurityUtil.PROJECT_MEMBER_ROLE_DESC
52     };
53
54     public String JavaDoc canExecuteForRole (CoefficientContext ctx,
55                                      String JavaDoc methodName, Role usersHighestRole){
56         String JavaDoc role = usersHighestRole.getDescription();
57         
58         if ( methodName.equals("doInitialWork") ||
59              methodName.equals("displayUsersData") ||
60              methodName.equals("getSummaryForProject") ||
61              methodName.equals("showSummaryForProject")) {
62             for(int i = 0; i < roles.length; i++) {
63                 if (role.equals(roles[i])) {
64                     return null;
65                 }
66             }
67             return "not authorised";
68         }
69
70         return "not authorised";
71     }
72         
73     public CoefficientContext deleteAllForProject (CoefficientContext ctx) {
74         return ctx;
75     }
76
77     public String JavaDoc displayUsersData(CoefficientUser user) {
78         // If you would like to display data on the "My Data" module page
79
// this is where you should render the content for the provided
80
// user. In this example we only return a simple message
81
// NOTE: there is a default implementation that returns the
82
// empty string, only implement this method if you have information
83
// to display.
84
return "Users data for the Sample Module: Joe Bloggs, xxx-yyyy";
85     }
86
87     public String JavaDoc getSummaryForProject(CoefficientContext ctx) {
88         // This is where you put summary information that will show up
89
// in the 'title' tag of the link to your module from the project
90
// page. This should show information like what the status of the
91
// data is for your module.
92
// NOTE: there is a default implementation that returns the
93
// empty string, only implement this method if you have information
94
// to display.
95
return "There are a total of 1 elements in the Sample module";
96     }
97
98     public CoefficientContext showSummaryForProject(CoefficientContext ctx) {
99         // This is similar to getSummaryForProject except that you set the
100
// content into the context. This information will be shown as an
101
// in-line summary on the project page if you have configured the
102
// projects to show inline summaries.
103
// NOTE: there is a default implementation that returns the
104
// empty string, only implement this method if you have information
105
// to display.
106
String JavaDoc html = "<table width='100%'><tr><td>" + getSummaryForProject(ctx)
107             + "</td></tr></table>";
108         ctx.setModuleContent(html, getModuleDisplayName());
109         return ctx;
110     }
111
112     public CoefficientContext doInitialWork (CoefficientContext ctx) {
113         Project project = ctx.getProject();
114         HashMap JavaDoc map = new HashMap JavaDoc();
115         map.put("name", "Joe Bloggs");
116         map.put("telephone", "xxx-yyyy");
117         StringBuffer JavaDoc sb = new StringBuffer JavaDoc("Problem here");
118         sb = VelocityScreenUtil.getProcessedScreen("index.vm", map);
119
120         // Set the html into the context
121
ctx.setModuleContent(sb.toString(), getModuleDisplayName());
122         return ctx;
123     }
124
125 }
126
127
Popular Tags