KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > navigation > actions > ShowSelectPropertyProfileAction


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program 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
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.navigation.actions;
21
22 import java.util.List JavaDoc;
23
24 import javax.servlet.http.HttpServletRequest JavaDoc;
25 import javax.servlet.http.HttpServletResponse JavaDoc;
26
27 import org.apache.struts.action.ActionForm;
28 import org.apache.struts.action.ActionForward;
29 import org.apache.struts.action.ActionMapping;
30
31 import com.sslexplorer.core.CoreUtil;
32 import com.sslexplorer.core.actions.AuthenticatedAction;
33 import com.sslexplorer.navigation.forms.ProfileSelectionForm;
34 import com.sslexplorer.properties.ProfilesListDataSource;
35 import com.sslexplorer.properties.Property;
36 import com.sslexplorer.properties.impl.userattributes.UserAttributeKey;
37 import com.sslexplorer.security.Constants;
38 import com.sslexplorer.security.LogonController;
39 import com.sslexplorer.security.LogonControllerFactory;
40 import com.sslexplorer.security.SessionInfo;
41 import com.sslexplorer.security.User;
42
43 /**
44  * Action to
45  * @author brett
46  *
47  */

48
49 public class ShowSelectPropertyProfileAction extends AuthenticatedAction {
50
51     /* (non-Javadoc)
52      * @see com.sslexplorer.core.actions.AuthenticatedAction#onExecute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
53      */

54     public ActionForward onExecute(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
55                     throws Exception JavaDoc {
56         ProfileSelectionForm profileSelectionForm = (ProfileSelectionForm) form;
57         if (LogonControllerFactory.getInstance().hasClientLoggedOn(request, response) != LogonController.LOGGED_ON) {
58             throw new Exception JavaDoc("You must be logged on to select a property.");
59         }
60         List JavaDoc propertyProfiles = null;
61         int selectedPropertyProfile = 0;
62         User user = LogonControllerFactory.getInstance().getUser(request);
63         if (user != null) {
64             propertyProfiles = (List JavaDoc)request.getSession().getAttribute(Constants.PROFILES);
65             String JavaDoc selectedProfile = Property.getProperty(new UserAttributeKey(user, User.USER_STARTUP_PROFILE));
66             if(selectedProfile.equals(ProfilesListDataSource.SELECT_ON_LOGIN)) {
67                 selectedPropertyProfile = 0;
68             }
69             else {
70                 try {
71                     selectedPropertyProfile = Integer.parseInt(selectedProfile);
72                 }
73                 catch(NumberFormatException JavaDoc nfe) {
74                     selectedPropertyProfile = 0;
75                 }
76             }
77         } else {
78             throw new Exception JavaDoc("Not logged on.");
79         }
80         profileSelectionForm.setReferer(CoreUtil.getReferer(request));
81         profileSelectionForm.setPropertyProfiles(propertyProfiles);
82         profileSelectionForm.setSelectedPropertyProfile(selectedPropertyProfile);
83         return mapping.findForward("success");
84     }
85     
86     /* (non-Javadoc)
87      * @see com.sslexplorer.core.actions.AuthenticatedAction#requiresProfile()
88      */

89     public boolean requiresProfile() {
90         // Profile is not required because this is where one might be set!
91
return false;
92     }
93
94    
95     @Override JavaDoc
96     public ActionForward checkIntercept(ActionMapping mapping, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws Exception JavaDoc {
97         return null;
98     }
99
100     /* (non-Javadoc)
101      * @see com.sslexplorer.core.actions.CoreAction#getNavigationContext(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
102      */

103     public int getNavigationContext(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) {
104         return SessionInfo.ALL_CONTEXTS;
105     }
106 }
Popular Tags