1 16 package org.jmanage.webui.forms; 17 18 import org.apache.struts.action.ActionErrors; 19 import org.apache.struts.action.ActionMapping; 20 import org.apache.struts.action.ActionError; 21 import org.apache.commons.validator.GenericValidator; 22 import org.jmanage.core.util.ErrorCodes; 23 import org.jmanage.webui.util.RequestParams; 24 25 import javax.servlet.http.HttpServletRequest ; 26 27 32 public class MBeanConfigForm extends BaseForm { 33 private String [] name; 35 private String objectName; 36 private boolean applicationCluster; 37 38 public final ActionErrors validate(ActionMapping mapping, 39 HttpServletRequest request) { 40 if(request.getParameter(RequestParams.MULTI_MBEAN_CONFIG) != null){ 41 boolean validValue = false, invalidValue = false, nullValue = false; 42 final String [] objectNames = request.getParameterValues("name"); 43 for(int mbeanCtr=0; mbeanCtr < objectNames.length; mbeanCtr++ ){ 44 final String configName = request.getParameter(objectNames[mbeanCtr]); 45 if(GenericValidator.isBlankOrNull(configName)){ 46 nullValue = true; 47 }else{ 48 if(configName.indexOf("/") != -1){ 49 invalidValue = true; 50 }else{ 51 validValue = true; 52 } 53 } 54 } 55 ActionErrors errors = new ActionErrors(); 56 if(invalidValue){ 57 errors.add(ActionErrors.GLOBAL_ERROR, 58 new ActionError(ErrorCodes.INVALID_CHAR_APP_NAME)); 59 return errors; 60 }else if(nullValue && !validValue){ 61 errors.add(ActionErrors.GLOBAL_ERROR, 62 new ActionError("errors.required", "application name")); 63 return errors; 64 } 65 return null; 66 }else{ 67 final String configName = request.getParameter("name"); 68 ActionErrors errors = new ActionErrors(); 69 if(GenericValidator.isBlankOrNull(configName)){ 70 errors.add(ActionErrors.GLOBAL_ERROR, 71 new ActionError("errors.required", "application name")); 72 return errors; 73 }else if(configName.indexOf("/") != -1){ 74 errors.add(ActionErrors.GLOBAL_ERROR, 75 new ActionError(ErrorCodes.INVALID_CHAR_APP_NAME)); 76 return errors; 77 }else{ 78 return null; 79 } 80 } 81 } 82 83 public String [] getName() { 84 return name; 85 } 86 87 public void setName(String [] name) { 88 this.name = name; 89 } 90 91 public String getObjectName() { 92 return objectName; 93 } 94 95 public void setObjectName(String objectName) { 96 this.objectName = objectName; 97 } 98 99 public boolean isApplicationCluster(){ 100 return applicationCluster; 101 } 102 103 public void setApplicationCluster(boolean applicationCluster){ 104 this.applicationCluster = applicationCluster; 105 } 106 } 107 | Popular Tags |