1 package org.nextime.ion.backoffice.form; 2 3 import java.util.Enumeration ; 4 import javax.servlet.http.HttpServletRequest ; 5 6 import org.apache.regexp.RE; 7 import org.apache.struts.action.ActionError; 8 import org.apache.struts.action.ActionErrors; 9 import org.apache.struts.action.ActionForm; 10 import org.apache.struts.action.ActionMapping; 11 import org.nextime.ion.backoffice.bean.PropertyBean; 12 import org.nextime.ion.backoffice.bean.SectionTypes; 13 import org.nextime.ion.backoffice.bean.TypeBean; 14 15 public class EditSectionForm extends ActionForm { 16 17 private String name; 18 private String template; 19 private String status; 20 private String workflow; 21 22 25 public ActionErrors myValidate(HttpServletRequest request) { 26 ActionErrors errors = new ActionErrors(); 27 if (getTemplate() == null || "".equals(getTemplate())) { 28 ActionError error = 29 new ActionError("error.editSection.templateMissing"); 30 errors.add("template", error); 31 } 32 try { 34 Enumeration names = request.getParameterNames(); 35 TypeBean type = SectionTypes.getSectionBean(null, getTemplate(), request); 37 while (names.hasMoreElements()) { 38 String name = names.nextElement() + ""; 39 if (name.startsWith("META_")) { 40 String tname = name.substring(5); 41 String value = request.getParameter(name); 42 PropertyBean prop = type.getProperty(tname); 43 if ("".equals(value.trim())) { 44 if ("true".equalsIgnoreCase(prop.getRequired())) { 45 ActionError error = 46 new ActionError("error.editSection.propertyMissing"); 47 errors.add("META_" + tname, error); 48 } 49 } else { 50 if (prop.getRegexp() != null) { 51 RE re = new RE(prop.getRegexp()); 52 if (!re.match(value)) { 53 ActionError error = 54 new ActionError("error.editSection.propertyMalformed", prop.getErrorMessage()); 55 errors.add("META_" + tname, error); 56 } 57 } 58 } 59 } 60 } 61 } catch (Exception e) { 62 e.printStackTrace(); 63 } 64 return errors; 65 } 66 67 70 public void reset(ActionMapping arg0, HttpServletRequest arg1) { 71 setName(null); 72 setTemplate(null); 73 setStatus(null); 74 setWorkflow(null); 75 } 76 77 81 public String getName() { 82 return name; 83 } 84 85 89 public String getTemplate() { 90 return template; 91 } 92 93 97 public void setName(String name) { 98 this.name = name; 99 } 100 101 105 public void setTemplate(String template) { 106 this.template = template; 107 } 108 109 113 public String getStatus() { 114 return status; 115 } 116 117 121 public void setStatus(String status) { 122 this.status = status; 123 } 124 125 129 public String getWorkflow() { 130 return workflow; 131 } 132 133 137 public void setWorkflow(String workflow) { 138 this.workflow = workflow; 139 } 140 141 } 142 | Popular Tags |