KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ivata > groupware > admin > security > struts > JavaScriptAction


1 // Source file: h:/cvslocal/ivata groupware/src/com.ivata.groupware/admin/security/struts/JavaScriptAction.java
2

3 /*
4  * Copyright (c) 2001 - 2005 ivata limited.
5  * All rights reserved.
6  * -----------------------------------------------------------------------------
7  * ivata groupware may be redistributed under the GNU General Public
8  * License as published by the Free Software Foundation;
9  * version 2 of the License.
10  *
11  * These programs are free software; you can redistribute them and/or
12  * modify them under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; version 2 of the License.
14  *
15  * These programs are distributed in the hope that they will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18  *
19  * See the GNU General Public License in the file LICENSE.txt for more
20  * details.
21  *
22  * If you would like a copy of the GNU General Public License write to
23  *
24  * Free Software Foundation, Inc.
25  * 59 Temple Place - Suite 330
26  * Boston, MA 02111-1307, USA.
27  *
28  *
29  * To arrange commercial support and licensing, contact ivata at
30  * http://www.ivata.com/contact.jsp
31  * -----------------------------------------------------------------------------
32  * $Log: JavaScriptAction.java,v $
33  * Revision 1.3 2005/04/10 18:47:41 colinmacleod
34  * Changed i tag to em and b tag to strong.
35  *
36  * Revision 1.2 2005/04/09 17:19:57 colinmacleod
37  * Changed copyright text to GPL v2 explicitly.
38  *
39  * Revision 1.1.1.1 2005/03/10 17:51:40 colinmacleod
40  * Restructured ivata op around Hibernate/PicoContainer.
41  * Renamed ivata groupware.
42  *
43  * Revision 1.5 2004/12/31 18:27:44 colinmacleod
44  * Added MaskFactory to constructor of MaskAction.
45  *
46  * Revision 1.4 2004/12/23 21:01:30 colinmacleod
47  * Updated Struts to v1.2.4.
48  * Changed base classes to use ivata masks.
49  *
50  * Revision 1.3 2004/11/12 18:19:16 colinmacleod
51  * Change action and form classes to extend MaskAction, MaskForm respectively.
52  *
53  * Revision 1.2 2004/11/03 15:31:51 colinmacleod
54  * Change method interfaces to remove log.
55  *
56  * Revision 1.1 2004/09/30 15:15:59 colinmacleod
57  * Split off addressbook elements into security subproject.
58  *
59  * Revision 1.4 2004/07/13 19:41:12 colinmacleod
60  * Moved project to POJOs from EJBs.
61  * Applied PicoContainer to services layer (replacing session EJBs).
62  * Applied Hibernate to persistence layer (replacing entity EJBs).
63  *
64  * Revision 1.3 2004/03/21 21:16:05 colinmacleod
65  * Shortened name to ivata op.
66  *
67  * Revision 1.2 2004/02/01 22:00:32 colinmacleod
68  * Added full names to author tags
69  *
70  * Revision 1.1.1.1 2004/01/27 20:57:45 colinmacleod
71  * Moved ivata openportal to SourceForge..
72  *
73  * Revision 1.3 2003/11/13 16:03:15 jano
74  * commitng everything to CVS
75  * can deploy and application is ruuning, can login into
76  *
77  * Revision 1.2 2003/10/17 12:36:12 jano
78  * fixing problems with building
79  * converting intranet -> portal
80  * Eclipse building
81  *
82  * Revision 1.1.1.1 2003/10/13 20:50:06 colin
83  * Restructured portal into subprojects
84  *
85  * Revision 1.1 2003/02/24 18:53:57 colin
86  * added to admin
87  *
88  * Revision 1.2 2003/02/04 17:38:13 colin
89  * updated for new execute interface
90  *
91  * Revision 1.1 2003/01/18 20:29:42 colin
92  * converted login process to struts
93  * added checking for javascript at login
94  * -----------------------------------------------------------------------------
95  */

96 package com.ivata.groupware.admin.security.struts;
97
98 import java.lang.reflect.InvocationTargetException JavaDoc;
99
100 import javax.servlet.http.HttpServletRequest JavaDoc;
101 import javax.servlet.http.HttpServletResponse JavaDoc;
102 import javax.servlet.http.HttpSession JavaDoc;
103
104 import org.apache.commons.beanutils.PropertyUtils;
105 import org.apache.struts.action.ActionErrors;
106 import org.apache.struts.action.ActionForm;
107 import org.apache.struts.action.ActionMapping;
108
109 import com.ivata.groupware.admin.security.Security;
110 import com.ivata.groupware.admin.setting.Settings;
111 import com.ivata.mask.MaskFactory;
112 import com.ivata.mask.util.StringHandling;
113 import com.ivata.mask.util.SystemException;
114 import com.ivata.mask.web.struts.MaskAuthenticator;
115
116 /**
117  * <p>Detects whether or not the browser has <em>JavaScript</em>.</p>
118  *
119  * @since 2003-01-18
120  * @author Colin MacLeod
121  * <a HREF='mailto:colin.macleod@ivata.com'>colin.macleod@ivata.com</a>
122  * @version $Revision: 1.3 $
123  */

124 public class JavaScriptAction extends LoginAction {
125     /**
126      * <p>
127      * Construct the javascript action.
128      * </p>
129      *
130      * @param security see {@link LoginAction}
131      * @param settings see {@link LoginAction}
132      * @param maskFactory This factory is needed to access the masks and groups
133      * of masks.
134      * @param authenticator used to confirm whether or not the
135      * user should be allowed to continue, in the <code>execute</code> method.
136      */

137     public JavaScriptAction(Security security, Settings settings,
138             MaskFactory maskFactory, MaskAuthenticator authenticator) {
139         super(security, settings, maskFactory, authenticator);
140     }
141
142     /**
143      * <p>Overridden from the default intranet implementation to
144      * detect <em>JavaScript</em>.</p>
145      *
146      * @param mapping current action mapping from <em>Struts</em> config.
147      * @param log valid logging object to write messages to.
148      * @param errors valid errors object to append errors to. If there are
149      * any errors, the action will return to the input.
150      * @param form optional ActionForm bean for this request (if any)
151      * @param request non-HTTP request we are processing
152      * @param response The non-HTTP response we are creating
153      * @param session returned from the <code>request</code> parameter.
154      * @param guestUserName current user name from session. Not needed for
155      * this aciton.
156      * @param settings valid, non-null settings from session.
157      * @exception SystemException if there is any problem which
158      * prevents processing. It will result in the webapp being forwarded
159      * to
160      * the standard error page.
161      * @return this method returns the string used to identify the correct
162      * <em>Struts</em> <code>ActionForward</code> which should follow this
163      * page, or <code>null</code> if it should return to the input.
164      *
165      */

166     public String JavaDoc execute(final ActionMapping mapping,
167             final ActionErrors errors,
168             final ActionForm form,
169             final HttpServletRequest JavaDoc request,
170             final HttpServletResponse JavaDoc response,
171             final HttpSession JavaDoc session)
172             throws SystemException {
173
174         // if we don't have a form or the form doesn't have java script set
175
// then just forward to the intranet login - that's our input screen
176
if (form == null) {
177             return null;
178         }
179         String JavaDoc javaScriptVersion = null;
180         ActionForm loginForm = (ActionForm) session.getAttribute("loginForm");
181         try {
182             javaScriptVersion = (String JavaDoc) PropertyUtils.getSimpleProperty(form, "javaScriptVersion");
183         } catch (NoSuchMethodException JavaDoc e) {
184             throw new SystemException(e);
185         } catch (InvocationTargetException JavaDoc e) {
186             throw new SystemException(e);
187         } catch (IllegalAccessException JavaDoc e) {
188             throw new SystemException(e);
189         }
190         if (StringHandling.isNullOrEmpty(javaScriptVersion)) {
191             return super.execute(mapping, errors, loginForm, request, response, session);
192         }
193
194         // if it gets here, set the javascript version in the login form
195
if (loginForm == null) {
196             return super.execute(mapping, errors, loginForm, request, response, session);
197         }
198         try {
199             PropertyUtils.setSimpleProperty(loginForm, "javaScriptVersion",
200                 javaScriptVersion);
201         } catch (NoSuchMethodException JavaDoc e) {
202             throw new SystemException(e);
203         } catch (InvocationTargetException JavaDoc e) {
204             throw new SystemException(e);
205         } catch (IllegalAccessException JavaDoc e) {
206             throw new SystemException(e);
207         }
208         return super.execute(mapping, errors, loginForm, request, response, session);
209     }
210 }
211
Popular Tags