1 19 20 package com.sslexplorer.properties.attributes.wizards.actions; 21 22 import java.util.ArrayList ; 23 import java.util.List ; 24 25 import javax.servlet.http.HttpServletRequest ; 26 import javax.servlet.http.HttpServletResponse ; 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.boot.PropertyClassManager; 35 import com.sslexplorer.core.CoreEvent; 36 import com.sslexplorer.core.CoreEventConstants; 37 import com.sslexplorer.core.CoreServlet; 38 import com.sslexplorer.properties.ProfilesFactory; 39 import com.sslexplorer.properties.attributes.AttributeDefinition; 40 import com.sslexplorer.properties.attributes.AttributesPropertyClass; 41 import com.sslexplorer.security.SessionInfo; 42 import com.sslexplorer.wizard.AbstractWizardSequence; 43 import com.sslexplorer.wizard.WizardActionStatus; 44 import com.sslexplorer.wizard.actions.AbstractWizardAction; 45 import com.sslexplorer.wizard.forms.AbstractWizardFinishForm; 46 47 54 public class AttributeDefinitionFinishAction extends AbstractWizardAction { 55 final static Log log = LogFactory.getLog(AttributeDefinitionFinishAction.class); 56 57 60 public AttributeDefinitionFinishAction() { 61 super(); 62 } 63 64 public int getNavigationContext(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { 65 return SessionInfo.MANAGEMENT_CONSOLE_CONTEXT; 66 } 67 68 public static AttributeDefinition createDefinition(AbstractWizardSequence seq) { 69 70 String name = (String ) seq.getAttribute(AttributeDefinitionDetailsAction.ATTR_NAME, null); 71 String description = (String ) seq.getAttribute(AttributeDefinitionDetailsAction.ATTR_DESCRIPTION, null); 72 String attributeClassName = (String ) seq.getAttribute(AttributeDefinitionDetailsAction.ATTR_CLASS, null); 73 String typeMeta = (String ) seq.getAttribute(AttributeDefinitionOptionsAction.ATTR_TYPE_META, null); 74 String label = (String ) seq.getAttribute(AttributeDefinitionOptionsAction.ATTR_LABEL, null); 75 String category = (String ) seq.getAttribute(AttributeDefinitionOptionsAction.ATTR_CATEGORY, null); 76 String defaultValue = (String ) seq.getAttribute(AttributeDefinitionOptionsAction.ATTR_DEFAULT_VALUE, null); 77 String validationString = (String ) seq.getAttribute(AttributeDefinitionOptionsAction.ATTR_VALIDATION_STRING, null); 78 int visibility = ((Integer ) seq.getAttribute(AttributeDefinitionOptionsAction.ATTR_VISIBILITY, null)).intValue(); 79 int sortOrder = ((Integer ) seq.getAttribute(AttributeDefinitionOptionsAction.ATTR_SORT_ORDER, null)).intValue(); 80 int type = ((Integer ) seq.getAttribute(AttributeDefinitionOptionsAction.ATTR_TYPE, null)).intValue(); 81 AttributesPropertyClass attributeClass = (AttributesPropertyClass) PropertyClassManager.getInstance() 82 .getPropertyClass(attributeClassName); 83 AttributeDefinition def = attributeClass.createAttributeDefinition(type, 84 name, 85 typeMeta, 86 -1, 87 category, 88 defaultValue, 89 visibility, 90 sortOrder, 91 null, 92 false, 93 label, 94 description, 95 false, 96 true, 97 validationString); 98 return def; 99 100 } 101 102 public ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest request, 103 HttpServletResponse response) throws Exception { 104 List actionStatus = new ArrayList (); 105 AbstractWizardSequence seq = getWizardSequence(request); 106 try { 107 try { 108 AttributeDefinition def = createDefinition(seq); 109 ProfilesFactory.getInstance().createAttributeDefinition(def); 110 def.getPropertyClass().registerPropertyDefinition(def); 111 CoreServlet.getServlet().fireCoreEvent(new CoreEvent(this, 112 CoreEventConstants.ATTRIBUTE_DEFINITION_CREATED, 113 def, 114 getSessionInfo(request), 115 CoreEvent.STATE_SUCCESSFUL)); 116 } catch (Exception e) { 117 CoreServlet.getServlet().fireCoreEvent(new CoreEvent(this, 118 CoreEventConstants.ATTRIBUTE_DEFINITION_CREATED, 119 null, 120 getSessionInfo(request), 121 e)); 122 throw e; 123 } 124 actionStatus.add(new WizardActionStatus(WizardActionStatus.COMPLETED_OK, 125 "attributeDefinitionWizard.attributeDefinitionFinish.status.attributeCreated")); 126 } catch (Exception e) { 127 log.error("Failed to create profile.", e); 128 actionStatus.add(new WizardActionStatus(WizardActionStatus.COMPLETED_WITH_ERRORS, 129 "attributeDefinitionWizard.attributeDefinitionFinish.status.failedToCreateAttribute", 130 e.getMessage())); 131 } 132 ((AbstractWizardFinishForm) form).setActionStatus(actionStatus); 133 return super.unspecified(mapping, form, request, response); 134 } 135 136 public ActionForward exit(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) 137 throws Exception { 138 return cancel(mapping, form, request, response); 139 } 140 141 } 142 | Popular Tags |