KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > properties > attributes > actions > ShowAttributeDefinitionsDispatchAction


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.attributes.actions;
21
22 import java.util.Collection JavaDoc;
23
24 import javax.servlet.http.HttpServletRequest JavaDoc;
25 import javax.servlet.http.HttpServletResponse JavaDoc;
26
27 import org.apache.struts.Globals;
28 import org.apache.struts.action.ActionForm;
29 import org.apache.struts.action.ActionForward;
30 import org.apache.struts.action.ActionMapping;
31 import org.apache.struts.action.ActionMessage;
32 import org.apache.struts.action.ActionMessages;
33
34 import com.sslexplorer.boot.PropertyClassManager;
35 import com.sslexplorer.boot.Util;
36 import com.sslexplorer.core.CoreServlet;
37 import com.sslexplorer.policyframework.Permission;
38 import com.sslexplorer.policyframework.PolicyConstants;
39 import com.sslexplorer.policyframework.PolicyUtil;
40 import com.sslexplorer.properties.ProfilesFactory;
41 import com.sslexplorer.properties.attributes.AttributeDefinition;
42 import com.sslexplorer.properties.attributes.AttributesPropertyClass;
43 import com.sslexplorer.properties.attributes.DefaultAttributeDefinition;
44 import com.sslexplorer.properties.attributes.forms.AttributeDefinitionsForm;
45 import com.sslexplorer.security.Constants;
46 import com.sslexplorer.security.SessionInfo;
47 import com.sslexplorer.table.actions.AbstractPagerAction;
48
49 /**
50  * Implementation of a {@link com.sslexplorer.table.actions.AbstractPagerAction}
51  * that allows an administrator to create, edit and delete <i>Attribute
52  * Definitions</i>.
53  *
54  * @author Brett Smith <a HREF="mailto:brett@3sp.com">&lt;brett@3sp.com&gt;</a>
55  * @see com.sslexplorer.properties.attributes.AttributeDefinition
56  */

57 public class ShowAttributeDefinitionsDispatchAction extends AbstractPagerAction {
58     /**
59      * Constructor
60      */

61     public ShowAttributeDefinitionsDispatchAction() {
62         super(PolicyConstants.ATTRIBUTE_DEFINITIONS_RESOURCE_TYPE, new Permission[] { PolicyConstants.PERM_MAINTAIN });
63     }
64
65     /*
66      * (non-Javadoc)
67      *
68      * @see org.apache.struts.actions.DispatchAction#unspecified(org.apache.struts.action.ActionMapping,
69      * org.apache.struts.action.ActionForm,
70      * javax.servlet.http.HttpServletRequest,
71      * javax.servlet.http.HttpServletResponse)
72      */

73     public ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request,
74                                      HttpServletResponse JavaDoc response) throws Exception JavaDoc {
75         return list(mapping, form, request, response);
76     }
77
78     /**
79      * Confirm removal of the selected attribute definition.
80      *
81      * @param mapping mapping
82      * @param form form
83      * @param request request
84      * @param response response
85      * @return forward
86      * @throws Exception on any error
87      */

88     public ActionForward confirmRemove(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request,
89                                        HttpServletResponse JavaDoc response) throws Exception JavaDoc {
90         PolicyUtil.checkPermission(getResourceType(), PolicyConstants.PERM_MAINTAIN, request);
91         AttributeDefinitionsForm schemesForm = (AttributeDefinitionsForm) form;
92         String JavaDoc name = schemesForm.getSelectedItem();
93         int idx = name.indexOf('/');
94         String JavaDoc propertyClass = name.substring(0, idx);
95         name = name.substring(idx + 1);
96         AttributeDefinition def = (AttributeDefinition) PropertyClassManager.getInstance()
97                         .getPropertyClass(propertyClass)
98                         .getDefinition(name);
99         if (def == null) {
100             throw new Exception JavaDoc("No attribute definition with name of " + name + ".");
101         }
102         return mapping.findForward("confirmRemove");
103     }
104
105     /**
106      * Delete the selected attribute definition.
107      *
108      * @param mapping mapping
109      * @param form form
110      * @param request request
111      * @param response response
112      * @return forward
113      * @throws Exception on any error
114      */

115     public ActionForward remove(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
116                     throws Exception JavaDoc {
117         PolicyUtil.checkPermission(getResourceType(), PolicyConstants.PERM_MAINTAIN, request);
118         AttributeDefinitionsForm f = (AttributeDefinitionsForm) form;
119         String JavaDoc name = f.getSelectedItem();
120         int idx = name.indexOf('/');
121         String JavaDoc propertyClass = name.substring(0, idx);
122         name = name.substring(idx + 1);
123         AttributeDefinition def = (AttributeDefinition) PropertyClassManager.getInstance()
124                         .getPropertyClass(propertyClass)
125                         .getDefinition(name);
126         if (def == null) {
127             throw new Exception JavaDoc("No attribute definition with name of " + name + ".");
128         }
129         ProfilesFactory.getInstance().deleteAttributeDefinition(def.getPropertyClass().getName(), name);
130         def.getPropertyClass().deregisterPropertyDefinition(def.getName());
131         ActionMessages msgs = new ActionMessages();
132         msgs.add(Globals.MESSAGE_KEY, new ActionMessage("attributeDefinitions.message.definitionDeleted", name));
133         saveMessages(request, msgs);
134         return mapping.findForward("refresh");
135     }
136
137     /**
138      * Edit the selected attribute definition.
139      *
140      * @param mapping mapping
141      * @param form form
142      * @param request request
143      * @param response response
144      * @return forward
145      * @throws Exception on any error
146      */

147     public ActionForward edit(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
148                     throws Exception JavaDoc {
149         PolicyUtil.checkPermission(getResourceType(), PolicyConstants.PERM_MAINTAIN, request);
150         AttributeDefinitionsForm f = (AttributeDefinitionsForm) form;
151         String JavaDoc selected = f.getSelectedItem();
152         int idx = selected.indexOf('/');
153         String JavaDoc attributeClass = selected.substring(0, idx);
154         String JavaDoc name = selected.substring(idx + 1);
155         AttributeDefinition def = (AttributeDefinition) PropertyClassManager.getInstance()
156                         .getPropertyClass(attributeClass)
157                         .getDefinition(name);
158         if (def == null) {
159             throw new Exception JavaDoc("No attribute definition with name of " + name + ".");
160         }
161         request.getSession().setAttribute(Constants.EDITING_ITEM, def);
162         return mapping.findForward("edit");
163     }
164
165     /**
166      * Create a new attribute definition.
167      *
168      * @param mapping mapping
169      * @param form form
170      * @param request request
171      * @param response response
172      * @return forward
173      * @throws Exception on any error
174      */

175     public ActionForward create(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
176                     throws Exception JavaDoc {
177         PolicyUtil.checkPermission(getResourceType(), PolicyConstants.PERM_MAINTAIN, request);
178         AttributeDefinitionsForm f = (AttributeDefinitionsForm) form;
179
180         // Get the property class
181
AttributesPropertyClass attributesPropertyClass = (AttributesPropertyClass) PropertyClassManager.getInstance()
182                         .getPropertyClass(f.getPropertyClassName());
183         if (attributesPropertyClass == null) {
184             throw new Exception JavaDoc("Invalid property class.");
185         }
186
187         // Create the definition to edit
188
DefaultAttributeDefinition def = new DefaultAttributeDefinition(AttributeDefinition.TYPE_UNDEFINED,
189                         null,
190                         "",
191                         0,
192                         "",
193                         "",
194                         AttributeDefinition.USER_OVERRIDABLE_ATTRIBUTE,
195                         0,
196                         null,
197                         false,
198                         "",
199                         "",
200                         false,
201                         true,
202                         null);
203         def.init(attributesPropertyClass);
204         request.getSession().setAttribute(Constants.EDITING_ITEM, def);
205
206         // Create
207
return mapping.findForward("create");
208     }
209
210     /**
211      * List the authentication schemes configured.
212      *
213      * @param mapping mapping
214      * @param form form
215      * @param request request
216      * @param response response
217      * @return forward
218      * @throws Exception on any error
219      */

220     public ActionForward list(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
221                     throws Exception JavaDoc {
222         PolicyUtil.checkPermission(getResourceType(), PolicyConstants.PERM_MAINTAIN, request);
223         AttributeDefinitionsForm f = (AttributeDefinitionsForm) form;
224         getResources(request);
225         Collection JavaDoc<AttributeDefinition> defs = (Collection JavaDoc) PropertyClassManager.getInstance()
226                         .getDefinitions(AttributesPropertyClass.class);
227         f.initialize(request.getSession(), defs);
228         Util.noCache(response);
229         return mapping.findForward("display");
230     }
231
232     /*
233      * (non-Javadoc)
234      *
235      * @see com.sslexplorer.core.actions.CoreAction#getNavigationContext(org.apache.struts.action.ActionMapping,
236      * org.apache.struts.action.ActionForm,
237      * javax.servlet.http.HttpServletRequest,
238      * javax.servlet.http.HttpServletResponse)
239      */

240     public int getNavigationContext(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) {
241         return SessionInfo.MANAGEMENT_CONSOLE_CONTEXT;
242     }
243 }
Popular Tags