1 19 20 package com.sslexplorer.properties.attributes.wizards.forms; 21 22 import java.util.ArrayList ; 23 import java.util.List ; 24 25 import javax.servlet.http.HttpServletRequest ; 26 27 import org.apache.commons.logging.Log; 28 import org.apache.commons.logging.LogFactory; 29 import org.apache.struts.Globals; 30 import org.apache.struts.action.ActionErrors; 31 import org.apache.struts.action.ActionMapping; 32 import org.apache.struts.action.ActionMessage; 33 34 import com.sslexplorer.boot.PropertyClass; 35 import com.sslexplorer.boot.PropertyClassManager; 36 import com.sslexplorer.properties.attributes.AttributeDefinition; 37 import com.sslexplorer.properties.attributes.AttributesPropertyClass; 38 import com.sslexplorer.properties.attributes.wizards.actions.AttributeDefinitionDetailsAction; 39 import com.sslexplorer.properties.impl.userattributes.UserAttributes; 40 import com.sslexplorer.wizard.AbstractWizardSequence; 41 import com.sslexplorer.wizard.forms.DefaultWizardForm; 42 43 49 public class AttributeDefinitionDetailsForm extends DefaultWizardForm { 50 51 final static Log log = LogFactory.getLog(AttributeDefinitionDetailsForm.class); 52 53 private String attributeClass; 54 private String name; 55 private String description; 56 57 60 public AttributeDefinitionDetailsForm() { 61 super(true, false, "/WEB-INF/jsp/content/properties/attributeDefinitionWizard/attributeDefinitionDetails.jspf", "name", true, false, 62 "attributeDefinitionDetails", "properties", "attributeDefinitionWizard.attributeDefinitionDetails", 1); 63 } 64 65 70 public String getName() { 71 return name; 72 } 73 74 79 public void setName(String name) { 80 this.name = name; 81 } 82 83 88 public String getDescription() { 89 return description; 90 } 91 92 97 public void setDescription(String description) { 98 this.description = description; 99 } 100 101 110 public String getAttributeClass() { 111 return attributeClass; 112 } 113 114 120 public void setAttributeClass(String attributeClass) { 121 this.attributeClass = attributeClass; 122 } 123 124 130 public List <String > getAttributeClasses() { 131 List <String > l = new ArrayList <String >(); 132 for(PropertyClass propertyClass : PropertyClassManager.getInstance().getPropertyClasses()) { 133 if(propertyClass instanceof AttributesPropertyClass) { 134 l.add(propertyClass.getName()); 135 } 136 } 137 return l; 138 } 139 140 public void init(AbstractWizardSequence sequence, HttpServletRequest request) throws Exception { 141 super.init(sequence, request); 142 name = (String )sequence.getAttribute(AttributeDefinitionDetailsAction.ATTR_NAME, ""); 143 description = (String )sequence.getAttribute(AttributeDefinitionDetailsAction.ATTR_DESCRIPTION, ""); 144 attributeClass = (String )sequence.getAttribute(AttributeDefinitionDetailsAction.ATTR_CLASS, UserAttributes.NAME); 145 } 146 public void apply(AbstractWizardSequence sequence) throws Exception { 147 super.apply(sequence); 148 sequence.putAttribute(AttributeDefinitionDetailsAction.ATTR_NAME, name); 149 sequence.putAttribute(AttributeDefinitionDetailsAction.ATTR_DESCRIPTION, description); 150 sequence.putAttribute(AttributeDefinitionDetailsAction.ATTR_CLASS, attributeClass); 151 } 152 153 public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) { 154 if(isCommiting()) { 155 ActionErrors errs = new ActionErrors(); 156 if(getName().trim().equals("")) { 157 errs.add(Globals.ERROR_KEY, new ActionMessage(getResourcePrefix() + ".error.noName")); 158 } else if(getDescription().trim().equals("")) { 159 errs.add(Globals.ERROR_KEY, new ActionMessage(getResourcePrefix() + ".error.noDescription")); 160 } else { 161 if(!getEditing()) { 162 try { 163 PropertyClass propertyClass = PropertyClassManager.getInstance().getPropertyClass(getAttributeClass()); 164 AttributeDefinition def = (AttributeDefinition)propertyClass.getDefinition(getName()); 165 if(def != null) { 166 errs.add(Globals.ERROR_KEY, new ActionMessage(getResourcePrefix() + ".error.duplicateName", getName())); 167 } 168 } 169 catch(Exception e) { 170 log.error("Failed to test if attribute exists.", e); 171 errs.add(Globals.ERROR_KEY, new ActionMessage(getResourcePrefix() + ".error.duplicateName", getName())); 172 } 173 } 174 if (!getName().matches("^[a-zA-Z0-9_-]*$")) { 175 errs.add(Globals.ERROR_KEY, new ActionMessage(getResourcePrefix() + ".error.invalidName")); 176 } 177 } 178 return errs; 179 } 180 return null; 181 } 182 } 183 | Popular Tags |