KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > raptus > owxv3 > api > VModuleRoleAction


1 /*
2  * eAdmin/OWX
3  * Copyright (C) 1996-2003 OWX-Project Team <owx-team@gmx.net>
4  */

5
6 package com.raptus.owxv3.api;
7
8 import java.io.IOException JavaDoc;
9 import java.util.Locale JavaDoc;
10
11 import javax.servlet.ServletException JavaDoc;
12 import javax.servlet.http.*;
13
14 import org.apache.struts.action.*;
15 import org.apache.struts.util.MessageResources;
16
17 import com.raptus.owxv3.*;
18 import com.raptus.owxv3.api.securitymgr.*;
19
20 /**
21  *
22  * <hr>
23  * <table width="100%" border="0">
24  * <tr>
25  * <td width="24%"><b>Filename</b></td><td width="76%">VModuleAuthAction.java</td>
26  * </tr>
27  * <tr>
28  * <td width="24%"><b>Author</b></td><td width="76%">Guy Z�rcher (gzuercher@raptus.com)</td>
29  * </tr>
30  * <tr>
31  * <td width="24%"><b>Date</b></td><td width="76%">19th of April 2001</td>
32  * </tr>
33  * </table>
34  * <hr>
35  * <table width="100%" border="0">
36  * <tr>
37  * <td width="24%"><b>Date / Author</b></td><td width="76%"><b>Changes</b></td>
38  * </tr>
39  * </table>
40  * <hr>
41  */

42 public class VModuleRoleAction extends OmniaWebAction
43 {
44     /**
45      * Process the specified HTTP request, and create the corresponding HTTP
46      * response (or forward to another web component that will create it).
47      * Return an <code>ActionForward</code> instance describing where and how
48      * control should be forwarded, or <code>null</code> if the response has
49      * already been completed.
50      *
51      * @param mapping The ActionMapping used to select this instance
52      * @param actionForm The optional ActionForm bean for this request (if any)
53      * @param request The HTTP request we are processing
54      * @param response The HTTP response we are creating
55      *
56      * @exception IOException if an input/output error occurs
57      * @exception ServletException if a servlet exception occurs
58      */

59     public ActionForward perform(ActionMapping mapping,
60                  ActionForm form,
61                  HttpServletRequest request,
62                  HttpServletResponse response)
63     throws IOException JavaDoc, ServletException JavaDoc
64     {
65 // LoggingManager.log("VModuleRoleAction!",this);
66
SecurityMgrIF securityManager = SecurityMgrFactory.getInstance().createSecurityManager(request);
67         
68         String JavaDoc vmid = getSelectedVModule(form, request);
69         if(vmid == null || vmid.length() == 0)
70         {
71             LoggingManager.log("Parameter <vmodule> not specified. Displaying error screen.", this);
72             return mapping.findForward(Constants.SCREEN_ERROR_UNKNOWNVMODULE);
73         }
74
75         String JavaDoc element = getSelectedElement(form, request);
76         if(element == null || element.length() == 0)
77         {
78             LoggingManager.log("Parameter <element> not specified. Displaying " +
79                                "error screen.", this);
80             
81             System.out.println("Parameter <element> not specified. Displaying " +
82                                "error screen.");
83
84             return mapping.findForward(Constants.SCREEN_ERROR_UNKNOWNELEMENT);
85         }
86
87
88         String JavaDoc section = getSelectedSection(form, request);
89         if(section == null || section.length() == 0)
90         {
91             LoggingManager.log("Parameter <section> not specified. Displaying " +
92                                "error screen.", this);
93             System.out.println("Parameter <section> not specified. Displaying " +
94                                "error screen.");
95
96             return mapping.findForward(Constants.SCREEN_ERROR_UNKNOWNSECTION);
97         }
98
99         VModule vm = null;
100
101         vm = cachedVModuleAccess(request.getSession(), vmid);
102         if(vm == null)
103         {
104             LoggingManager.log("FAILED to retrieve a valid virtual module from session.", this);
105             System.out.println("FAILED to retrieve a valid virtual module from session.");
106             return mapping.findForward(Constants.SCREEN_ERROR_UNKNOWNVMODULE);
107         }
108         
109         VModuleSection sect = vm.getSection(section);
110         if(sect == null)
111         {
112             LoggingManager.log("Unknown section "+section+". Displaying " +
113                                "error screen.", this);
114             System.out.println("Unknown section "+section+". Displaying " +
115                                "error screen.");
116             return mapping.findForward(Constants.SCREEN_ERROR_UNKNOWNSECTION);
117         }
118
119         VModuleSectionElement elem = sect.getElement(element);
120         if(elem == null)
121         {
122             LoggingManager.log("Unknown element "+element+". Displaying " +
123                                "error screen.", this);
124             System.out.println("Unknown element "+element+". Displaying " +
125                                "error screen.");
126
127             return mapping.findForward(Constants.SCREEN_ERROR_UNKNOWNELEMENT);
128         }
129         
130         // check if user has access to this vmodule/section/element
131
if(!securityManager.hasAccess(elem))
132         {
133             if(!securityManager.needLogin(elem))
134             {
135                 LoggingManager.log("User has no access!!!!!",this);
136                 return mapping.findForward(Constants.SCREEN_ERROR_ACCESSDENIED);
137             }
138             else
139             {
140                 LoggingManager.log("User must log in, section="+section+" !!!!!!!!!!",this);
141
142                 //String path="";
143
if("eadmin".equals(section))
144                 {
145                     return mapping.findForward(Constants.SCREEN_LOGIN);
146                 }
147                 else
148                 {
149                     return mapping.findForward(Constants.SCREEN_PUBLIC_LOGIN);
150                 }
151             }
152         }
153
154         // put the titletag for the selected section/vmodule/element into the request session
155
MessageResources msgRes = MessageResources.getMessageResources(Constants.OWXRESOURCES);
156         if(msgRes != null)
157         {
158             String JavaDoc bid = "base"; // for all virtuals
159
if(vm.isVirtual())
160                 bid = vm.getIdentification();
161             
162             String JavaDoc key = "module" + bid + Constants.VMODULE_SECTION_ELEMENT_PREFIX +
163                          element + ".titletag"; // will cause problems with non standard elements!
164

165             String JavaDoc titleTag = msgRes.getMessage(securityManager.getLocale(),key);
166             if(titleTag != null)
167                 request.setAttribute(Constants.SESSIONKEY_TITLETAG, titleTag);
168         }
169
170         //User user = new User();
171
//user.setLocale(securityManager.getLocale());
172
com.raptus.owxv3.api.usermgr.User user = (com.raptus.owxv3.api.usermgr.User)
173             request.getSession().getAttribute(Constants.SESSIONKEY_USER);
174        // if(user != null)
175
// {
176
// //request.getSession().setAttribute(Constants.SESSIONKEY_USER, user);
177
// setLocale(request, user.getLocale());
178
// }
179
// now pass control to an eventual subclass
180
//String fwdTo = dispatchVModuleElement(request, element, form, vm, user);
181
LoggingManager.log("vmoduleroleaction vmodule="+vmid+",section="+section+",element="+element,this);
182         String JavaDoc fwdTo = dispatchVModuleElement(request, element, form, vm, user);
183         if(fwdTo == null)
184         {
185             fwdTo = dispatchVModuleElement(request, element, form, vm, securityManager.getLocale());
186             if(fwdTo == null)
187             {
188                 LoggingManager.log("Dispatcher wasn't able to dispatch element " + element, this);
189                 return mapping.findForward(Constants.SCREEN_ERROR_UNKNOWNELEMENT);
190             }
191         }
192
193         return mapping.findForward(vm.getIdentification() + Constants.DEFAULT_SPACER + fwdTo);
194     }
195
196     
197     
198     /**
199      * Override just this method in your virtual module implementations ...
200      */

201     public String JavaDoc dispatchVModuleElement(HttpServletRequest request,
202                                          String JavaDoc element,
203                                          ActionForm form,
204                                          VModule vm,
205                                          com.raptus.owxv3.api.usermgr.User user)
206     {
207         return null;
208     }
209     
210 /**
211      * Override just this method in your virtual module implementations ...
212      */

213     protected String JavaDoc dispatchVModuleElement(HttpServletRequest request,
214                                             String JavaDoc element,
215                                             ActionForm form,
216                                             VModule vm,
217                                             Locale JavaDoc locale)
218     {
219         return null;
220     }
221 }
222
223
224
Popular Tags