* @see org.apache.struts.action.ActionForm#validate(ActionMapping, HttpServletRequest)
*/
public ActionErrors myValidate(HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
if ("".equals(getName())) {
ActionError error =
new ActionError("error.editSection.nameMissing");
errors.add("name", error);
}
if (getTemplate() == null || "".equals(getTemplate())) {
ActionError error =
new ActionError("error.editSection.templateMissing");
errors.add("template", error);
}
// validate metadata
try {
Enumeration names = request.getParameterNames();
// dangerous ?
TypeBean type = SectionTypes.getSectionBean(null, getTemplate());
while (names.hasMoreElements()) {
String name = names.nextElement() + "";
if (name.startsWith("META_")) {
String tname = name.substring(5);
String value = request.getParameter(name);
PropertyBean prop = type.getProperty(tname);
if ("".equals(value.trim())) {
if ("true".equalsIgnoreCase(prop.getRequired())) {
ActionError error =
new ActionError("error.editSection.propertyMissing");
errors.add("META_" + tname, error);
}
} else {
if (prop.getRegexp() != null) {
RE re = new RE(prop.getRegexp());
if (!re.match(value)) {
ActionError error =
new ActionError("error.editSection.propertyMalformed", prop.getErrorMessage());
errors.add("META_" + tname, error);
}
}
}
}