1 19 20 package com.sslexplorer.properties.attributes.actions; 21 22 import javax.servlet.http.HttpServletRequest ; 23 import javax.servlet.http.HttpServletResponse ; 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 49 public class EditAttributeDefinitionDispatchAction extends AuthenticatedDispatchAction { 50 51 static Log log = LogFactory.getLog(EditAttributeDefinitionDispatchAction.class); 52 53 56 public EditAttributeDefinitionDispatchAction() { 57 super(PolicyConstants.ATTRIBUTE_DEFINITIONS_RESOURCE_TYPE, new Permission[] { PolicyConstants.PERM_MAINTAIN }); 58 } 59 60 68 public int getNavigationContext(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { 69 return SessionInfo.MANAGEMENT_CONSOLE_CONTEXT; 70 } 71 72 82 public ActionForward edit(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) 83 throws Exception { 84 AttributeDefinitionForm df = (AttributeDefinitionForm) form; 85 AttributeDefinition def = (AttributeDefinition) request.getSession().getAttribute(Constants.EDITING_ITEM); 86 if (def.isSystem()) { 87 throw new Exception ("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 106 public ActionForward create(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) 107 throws Exception { 108 AttributeDefinitionForm df = (AttributeDefinitionForm) form; 109 AttributeDefinition def = (AttributeDefinition) request.getSession().getAttribute(Constants.EDITING_ITEM); 110 if (def.isSystem()) { 111 throw new Exception ("System attribute definitions may not be edited."); 112 } 113 114 df.initialise(def); 116 df.setCreating(); 117 df.setReferer(CoreUtil.getReferer(request)); 118 119 CoreUtil.addRequiredFieldMessage(this, request); 121 return mapping.findForward("display"); 122 } 123 124 134 public ActionForward commit(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) 135 throws Exception { 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 158 public ActionForward cancel(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) 159 throws Exception { 160 return cleanUpAndReturnToReferer(mapping, form, request, response); 161 } 162 } | Popular Tags |