1 19 20 package com.sslexplorer.properties.attributes.actions; 21 22 import java.util.Collection ; 23 24 import javax.servlet.http.HttpServletRequest ; 25 import javax.servlet.http.HttpServletResponse ; 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 57 public class ShowAttributeDefinitionsDispatchAction extends AbstractPagerAction { 58 61 public ShowAttributeDefinitionsDispatchAction() { 62 super(PolicyConstants.ATTRIBUTE_DEFINITIONS_RESOURCE_TYPE, new Permission[] { PolicyConstants.PERM_MAINTAIN }); 63 } 64 65 73 public ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest request, 74 HttpServletResponse response) throws Exception { 75 return list(mapping, form, request, response); 76 } 77 78 88 public ActionForward confirmRemove(ActionMapping mapping, ActionForm form, HttpServletRequest request, 89 HttpServletResponse response) throws Exception { 90 PolicyUtil.checkPermission(getResourceType(), PolicyConstants.PERM_MAINTAIN, request); 91 AttributeDefinitionsForm schemesForm = (AttributeDefinitionsForm) form; 92 String name = schemesForm.getSelectedItem(); 93 int idx = name.indexOf('/'); 94 String 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 ("No attribute definition with name of " + name + "."); 101 } 102 return mapping.findForward("confirmRemove"); 103 } 104 105 115 public ActionForward remove(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) 116 throws Exception { 117 PolicyUtil.checkPermission(getResourceType(), PolicyConstants.PERM_MAINTAIN, request); 118 AttributeDefinitionsForm f = (AttributeDefinitionsForm) form; 119 String name = f.getSelectedItem(); 120 int idx = name.indexOf('/'); 121 String 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 ("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 147 public ActionForward edit(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) 148 throws Exception { 149 PolicyUtil.checkPermission(getResourceType(), PolicyConstants.PERM_MAINTAIN, request); 150 AttributeDefinitionsForm f = (AttributeDefinitionsForm) form; 151 String selected = f.getSelectedItem(); 152 int idx = selected.indexOf('/'); 153 String attributeClass = selected.substring(0, idx); 154 String 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 ("No attribute definition with name of " + name + "."); 160 } 161 request.getSession().setAttribute(Constants.EDITING_ITEM, def); 162 return mapping.findForward("edit"); 163 } 164 165 175 public ActionForward create(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) 176 throws Exception { 177 PolicyUtil.checkPermission(getResourceType(), PolicyConstants.PERM_MAINTAIN, request); 178 AttributeDefinitionsForm f = (AttributeDefinitionsForm) form; 179 180 AttributesPropertyClass attributesPropertyClass = (AttributesPropertyClass) PropertyClassManager.getInstance() 182 .getPropertyClass(f.getPropertyClassName()); 183 if (attributesPropertyClass == null) { 184 throw new Exception ("Invalid property class."); 185 } 186 187 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 return mapping.findForward("create"); 208 } 209 210 220 public ActionForward list(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) 221 throws Exception { 222 PolicyUtil.checkPermission(getResourceType(), PolicyConstants.PERM_MAINTAIN, request); 223 AttributeDefinitionsForm f = (AttributeDefinitionsForm) form; 224 getResources(request); 225 Collection <AttributeDefinition> defs = (Collection ) PropertyClassManager.getInstance() 226 .getDefinitions(AttributesPropertyClass.class); 227 f.initialize(request.getSession(), defs); 228 Util.noCache(response); 229 return mapping.findForward("display"); 230 } 231 232 240 public int getNavigationContext(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { 241 return SessionInfo.MANAGEMENT_CONSOLE_CONTEXT; 242 } 243 } | Popular Tags |