1 19 20 package com.sslexplorer.properties.attributes.wizards.forms; 21 22 import javax.servlet.http.HttpServletRequest ; 23 24 import org.apache.commons.logging.Log; 25 import org.apache.commons.logging.LogFactory; 26 import org.apache.struts.Globals; 27 import org.apache.struts.action.ActionErrors; 28 import org.apache.struts.action.ActionMapping; 29 import org.apache.struts.action.ActionMessage; 30 31 import com.sslexplorer.boot.CodedException; 32 import com.sslexplorer.boot.DefaultPropertyDefinition; 33 import com.sslexplorer.boot.PropertyClassManager; 34 import com.sslexplorer.boot.PropertyDefinition; 35 import com.sslexplorer.core.CoreException; 36 import com.sslexplorer.properties.attributes.AttributeDefinition; 37 import com.sslexplorer.properties.attributes.AttributesPropertyClass; 38 import com.sslexplorer.properties.attributes.forms.AttributeDefinitionForm; 39 import com.sslexplorer.properties.attributes.wizards.actions.AttributeDefinitionDetailsAction; 40 import com.sslexplorer.properties.attributes.wizards.actions.AttributeDefinitionOptionsAction; 41 import com.sslexplorer.properties.impl.userattributes.UserAttributes; 42 import com.sslexplorer.wizard.AbstractWizardSequence; 43 import com.sslexplorer.wizard.forms.DefaultWizardForm; 44 45 51 public class AttributeDefinitionOptionsForm extends DefaultWizardForm { 52 53 final static Log log = LogFactory.getLog(AttributeDefinitionOptionsForm.class); 54 55 57 protected String label; 58 protected String category; 59 protected String typeMeta; 60 protected int type; 61 protected String validationString; 62 protected String defaultValue; 63 protected int visibility; 64 protected int sortOrder; 65 protected AttributesPropertyClass attributesClass; 66 67 70 public AttributeDefinitionOptionsForm() { 71 super(true, true, "/WEB-INF/jsp/content/properties/attributeDefinitionWizard/attributeDefinitionOptions.jspf", "type", true, false, 72 "attributeDefinitionOptions", "properties", "attributeDefinitionWizard.attributeDefinitionOptions", 2); 73 } 74 75 81 public void init(AbstractWizardSequence sequence, HttpServletRequest request) throws Exception { 82 super.init(sequence, request); 83 label = (String )sequence.getAttribute(AttributeDefinitionOptionsAction.ATTR_LABEL, ""); 84 category = (String )sequence.getAttribute(AttributeDefinitionOptionsAction.ATTR_CATEGORY, ""); 85 typeMeta = (String )sequence.getAttribute(AttributeDefinitionOptionsAction.ATTR_TYPE_META, ""); 86 type = ((Integer )sequence.getAttribute(AttributeDefinitionOptionsAction.ATTR_TYPE, PropertyDefinition.TYPE_STRING)).intValue(); 87 validationString = (String )sequence.getAttribute(AttributeDefinitionOptionsAction.ATTR_VALIDATION_STRING, "com.sslexplorer.input.validators.StringValidator(minLength=0,maxLength=30,trim=true,regExp=,pattern=)"); 88 defaultValue = (String )sequence.getAttribute(AttributeDefinitionOptionsAction.ATTR_DEFAULT_VALUE, ""); 89 visibility = ((Integer )sequence.getAttribute(AttributeDefinitionOptionsAction.ATTR_VISIBILITY, AttributeDefinition.USER_USEABLE_ATTRIBUTE)).intValue(); 90 sortOrder = ((Integer )sequence.getAttribute(AttributeDefinitionOptionsAction.ATTR_SORT_ORDER, 0)).intValue(); 91 attributesClass = (AttributesPropertyClass)PropertyClassManager.getInstance().getPropertyClass((String )sequence.getAttribute(AttributeDefinitionDetailsAction.ATTR_CLASS, UserAttributes.NAME)); 92 } 93 94 99 public void apply(AbstractWizardSequence sequence) throws Exception { 100 super.apply(sequence); 101 sequence.putAttribute(AttributeDefinitionOptionsAction.ATTR_LABEL, label); 102 sequence.putAttribute(AttributeDefinitionOptionsAction.ATTR_CATEGORY, category); 103 sequence.putAttribute(AttributeDefinitionOptionsAction.ATTR_TYPE_META, typeMeta); 104 sequence.putAttribute(AttributeDefinitionOptionsAction.ATTR_TYPE, new Integer (type)); 105 sequence.putAttribute(AttributeDefinitionOptionsAction.ATTR_VALIDATION_STRING, validationString); 106 sequence.putAttribute(AttributeDefinitionOptionsAction.ATTR_DEFAULT_VALUE, defaultValue); 107 sequence.putAttribute(AttributeDefinitionOptionsAction.ATTR_VISIBILITY, new Integer (visibility)); 108 sequence.putAttribute(AttributeDefinitionOptionsAction.ATTR_SORT_ORDER, new Integer (sortOrder)); 109 } 110 111 116 public AttributesPropertyClass getAttributesClass() { 117 return attributesClass; 118 } 119 120 125 public String getDefaultValue() { 126 return defaultValue; 127 } 128 129 134 public void setDefaultValue(String defaultValue) { 135 this.defaultValue = defaultValue; 136 } 137 138 143 public String getLabel() { 144 return label; 145 } 146 147 152 public void setLabel(String label) { 153 this.label = label; 154 } 155 156 161 public String getTypeMeta() { 162 return typeMeta; 163 } 164 165 170 public void setTypeMeta(String typeMeta) { 171 this.typeMeta = typeMeta; 172 } 173 174 179 public String getCategory() { 180 return category; 181 } 182 183 188 public void setCategory(String category) { 189 this.category = category; 190 } 191 192 198 public int getVisibility() { 199 return visibility; 200 } 201 202 208 public void setVisibility(int visibility) { 209 this.visibility = visibility; 210 } 211 212 217 public void setSortOrder(int sortOrder) { 218 this.sortOrder = sortOrder; 219 } 220 221 226 public int getSortOrder() { 227 return sortOrder; 228 } 229 230 235 public int getType() { 236 return type; 237 } 238 239 244 public void setType(int type) { 245 this.type = type; 246 } 247 248 254 public String getValidationString() { 255 return validationString; 256 } 257 258 264 public void setValidationString(String validationString) { 265 this.validationString = validationString; 266 } 267 268 269 272 public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) { 273 if(isCommiting()) { 274 ActionErrors errs = new ActionErrors(); 275 if(!validationString.trim().equals("")) { 276 String className = null; 277 int idx = validationString.indexOf('('); 278 if(idx == -1) { 279 className = validationString; 280 } 281 else { 282 if(!validationString.endsWith(")")) { 283 errs = new ActionErrors(); 284 errs.add(Globals.ERROR_KEY, new ActionMessage(getResourcePrefix() + ".error.invalidValidationStringFormat")); 285 } 286 className = validationString.substring(0, idx); 287 } 288 289 try { 290 Class.forName(className); 291 } 292 catch(ClassNotFoundException cnfe) { 293 errs.add(Globals.ERROR_KEY, new ActionMessage(getResourcePrefix() + ".error.noSuchValidator", className)); 294 } 295 296 try { 297 299 String defaultValue = getDefaultValue().trim(); 300 if(!defaultValue.equals("")) { 301 AttributeDefinition def = getAttributesClass().createAttributeDefinition(type, 302 (String )getWizardSequence().getAttribute(AttributeDefinitionDetailsAction.ATTR_NAME, null), 303 typeMeta, 304 -1, 305 category, 306 defaultValue, 307 visibility, 308 sortOrder, 309 null, 310 false, 311 label, 312 (String )getWizardSequence().getAttribute(AttributeDefinitionDetailsAction.ATTR_DESCRIPTION, null), 313 false, 314 true, 315 validationString); 316 try { 317 def.validate(defaultValue, getClass().getClassLoader()); 318 } catch (CoreException ce) { 319 ce.getBundleActionMessage().setArg3(def.getLabel()); 320 if (errs == null) { 321 errs = new ActionErrors(); 322 } 323 errs.add(Globals.ERROR_KEY, ce.getBundleActionMessage()); 324 } 325 } 326 } 327 catch(Exception e) { 328 if(errs == null) { 329 errs = new ActionErrors(); 330 } 331 errs.add(Globals.ERROR_KEY, new ActionMessage(getResourcePrefix() + ".error.failedToValidate", className)); 332 } 333 } 334 return errs; 335 } 336 return null; 337 } 338 } 339 | Popular Tags |