KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > properties > actions > AbstractProfilePropertiesAction


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.properties.actions;
21
22 import java.util.Iterator JavaDoc;
23 import java.util.List JavaDoc;
24
25 import javax.servlet.http.HttpServletRequest JavaDoc;
26 import javax.servlet.http.HttpServletResponse JavaDoc;
27
28 import org.apache.commons.logging.Log;
29 import org.apache.commons.logging.LogFactory;
30 import org.apache.struts.action.ActionForm;
31 import org.apache.struts.action.ActionForward;
32 import org.apache.struts.action.ActionMapping;
33
34 import com.sslexplorer.core.UserDatabaseManager;
35 import com.sslexplorer.policyframework.ResourceStack;
36 import com.sslexplorer.properties.ProfilesFactory;
37 import com.sslexplorer.properties.PropertyProfile;
38 import com.sslexplorer.properties.forms.ProfilePropertiesForm;
39 import com.sslexplorer.security.Constants;
40
41 /**
42  *
43  * @author James D Robinson <a HREF="mailto:james@3sp.com">&lt;james@3sp.com&gt;</a>
44  *
45  */

46 public abstract class AbstractProfilePropertiesAction extends AbstractPropertiesAction {
47     static Log log = LogFactory.getLog(AbstractProfilePropertiesAction.class);
48
49     /* (non-Javadoc)
50      * @see com.sslexplorer.properties.actions.AbstractPropertiesAction#unspecified(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
51      */

52     public ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request,
53                     HttpServletResponse JavaDoc response) throws Exception JavaDoc {
54         super.unspecified(mapping, form, request, response);
55         ProfilePropertiesForm pf = (ProfilePropertiesForm)form;
56         
57         if (pf.getSelectedPropertyProfile() == -1) {
58             if (request.getSession().getAttribute(Constants.SELECTED_PROFILE) != null) {
59                 pf.setSelectedPropertyProfile(((PropertyProfile) request.getSession().getAttribute(Constants.SELECTED_PROFILE)).getResourceId());
60             } else {
61                 pf.setSelectedPropertyProfile(0);
62             }
63         }
64         PropertyProfile selectedPropertyProfile = ProfilesFactory.getInstance().getPropertyProfile(pf.getSelectedPropertyProfile());
65         if (selectedPropertyProfile == null) {
66             selectedPropertyProfile = ProfilesFactory.getInstance().getPropertyProfile(getSessionInfo(request).getUser().getPrincipalName(),
67                 "Default", getSessionInfo(request).getUser().getRealm().getResourceId());
68             if (selectedPropertyProfile == null) {
69                 selectedPropertyProfile = ProfilesFactory.getInstance().getPropertyProfile(null, "Default",
70                                 UserDatabaseManager.getInstance().getDefaultUserDatabase().getRealm().getResourceId());
71             }
72         }
73         ResourceStack.pushToEditingStack(request.getSession(), selectedPropertyProfile);
74         
75         // Get the property profiles
76
List JavaDoc propertyProfiles = (List JavaDoc)request.getSession().getAttribute(Constants.PROFILES);
77         if (selectedPropertyProfile == null) {
78             for (Iterator JavaDoc i = propertyProfiles.iterator(); i.hasNext();) {
79                 selectedPropertyProfile = (PropertyProfile) i.next();
80                 if (selectedPropertyProfile.getResourceName().equals("Default")) {
81                     break;
82                 }
83             }
84         }
85         pf.setPropertyProfiles(propertyProfiles);
86         pf.setSelectedPropertyProfile(selectedPropertyProfile.getResourceId());
87         
88         // Build an display
89
return rebuildItems(mapping, pf.getParentCategory(), pf, request, getSessionInfo(request).getUser());
90     }
91
92     /**
93      * @param mapping
94      * @param form
95      * @param request
96      * @param response
97      * @return ActionForward
98      * @throws Exception
99      */

100     public ActionForward configureProfiles(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request,
101                     HttpServletResponse JavaDoc response) throws Exception JavaDoc {
102         ResourceStack.popFromEditingStack(request.getSession());
103         return mapping.findForward("configureProfiles");
104     }
105 }
Popular Tags