KickJava   Java API By Example, From Geeks To Geeks.

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


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 javax.servlet.http.HttpServletRequest JavaDoc;
23 import javax.servlet.http.HttpServletResponse JavaDoc;
24
25 import org.apache.commons.logging.Log;
26 import org.apache.commons.logging.LogFactory;
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.CoreServlet;
32 import com.sslexplorer.core.CoreUtil;
33 import com.sslexplorer.core.actions.AuthenticatedDispatchAction;
34 import com.sslexplorer.policyframework.Permission;
35 import com.sslexplorer.policyframework.PolicyConstants;
36 import com.sslexplorer.properties.ProfilesFactory;
37 import com.sslexplorer.properties.attributes.AttributeDefinition;
38 import com.sslexplorer.properties.attributes.forms.AttributeDefinitionForm;
39 import com.sslexplorer.security.Constants;
40 import com.sslexplorer.security.SessionInfo;
41
42 /**
43  * Extension of {@link com.sslexplorer.core.actions.AuthenticatedDispatchAction}
44  * that allows an administrator to edit the details of an attribute
45  * definition.
46  *
47  * @author Brett Smith <a HREF="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
48  */

49 public class EditAttributeDefinitionDispatchAction extends AuthenticatedDispatchAction {
50
51     static Log log = LogFactory.getLog(EditAttributeDefinitionDispatchAction.class);
52
53     /**
54      * Constructor.
55      */

56     public EditAttributeDefinitionDispatchAction() {
57         super(PolicyConstants.ATTRIBUTE_DEFINITIONS_RESOURCE_TYPE, new Permission[] { PolicyConstants.PERM_MAINTAIN });
58     }
59
60     /*
61      * (non-Javadoc)
62      *
63      * @see com.sslexplorer.core.actions.CoreAction#getNavigationContext(org.apache.struts.action.ActionMapping,
64      * org.apache.struts.action.ActionForm,
65      * javax.servlet.http.HttpServletRequest,
66      * javax.servlet.http.HttpServletResponse)
67      */

68     public int getNavigationContext(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) {
69         return SessionInfo.MANAGEMENT_CONSOLE_CONTEXT;
70     }
71
72     /**
73      * Edit the user definition.
74      *
75      * @param mapping
76      * @param form
77      * @param request
78      * @param response
79      * @return forward
80      * @throws Exception
81      */

82     public ActionForward edit(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
83                     throws Exception JavaDoc {
84         AttributeDefinitionForm df = (AttributeDefinitionForm) form;
85         AttributeDefinition def = (AttributeDefinition) request.getSession().getAttribute(Constants.EDITING_ITEM);
86         if (def.isSystem()) {
87             throw new Exception JavaDoc("System attribute definitions may not be edited.");
88         }
89         df.initialise(def);
90         df.setEditing();
91         df.setReferer(CoreUtil.getReferer(request));
92         CoreUtil.addRequiredFieldMessage(this, request);
93         return mapping.findForward("display");
94     }
95
96     /**
97      * Edit the user definition.
98      *
99      * @param mapping
100      * @param form
101      * @param request
102      * @param response
103      * @return forward
104      * @throws Exception
105      */

106     public ActionForward create(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
107                     throws Exception JavaDoc {
108         AttributeDefinitionForm df = (AttributeDefinitionForm) form;
109         AttributeDefinition def = (AttributeDefinition) request.getSession().getAttribute(Constants.EDITING_ITEM);
110         if (def.isSystem()) {
111             throw new Exception JavaDoc("System attribute definitions may not be edited.");
112         }
113         
114         // Initialise the form
115
df.initialise(def);
116         df.setCreating();
117         df.setReferer(CoreUtil.getReferer(request));
118         
119         // Display
120
CoreUtil.addRequiredFieldMessage(this, request);
121         return mapping.findForward("display");
122     }
123
124     /**
125      * Commit the attribute definition.
126      *
127      * @param mapping
128      * @param form
129      * @param request
130      * @param response
131      * @return forward
132      * @throws Exception
133      */

134     public ActionForward commit(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
135                     throws Exception JavaDoc {
136         AttributeDefinitionForm df = (AttributeDefinitionForm) form;
137         df.applyToDefinition();
138         if (df.getEditing()) {
139             ProfilesFactory.getInstance().updateAttributeDefinition(df.getDefinition());
140             df.getDefinition().getPropertyClass().registerPropertyDefinition(df.getDefinition());
141         } else {
142             ProfilesFactory.getInstance().createAttributeDefinition(df.getDefinition());
143             df.getDefinition().getPropertyClass().registerPropertyDefinition(df.getDefinition());
144         }
145         return cleanUpAndReturnToReferer(mapping, form, request, response);
146     }
147
148     /**
149      * Cancel.
150      *
151      * @param mapping
152      * @param form
153      * @param request
154      * @param response
155      * @return forward
156      * @throws Exception
157      */

158     public ActionForward cancel(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
159                     throws Exception JavaDoc {
160         return cleanUpAndReturnToReferer(mapping, form, request, response);
161     }
162 }
Popular Tags