1 16 17 package org.apache.struts.chain; 18 19 20 import org.apache.commons.chain.Command; 21 import org.apache.commons.chain.Context; 22 import org.apache.commons.logging.Log; 23 import org.apache.commons.logging.LogFactory; 24 import org.apache.struts.action.ActionErrors; 25 import org.apache.struts.action.ActionForm; 26 import org.apache.struts.config.ActionConfig; 27 28 29 37 38 public abstract class AbstractValidateActionForm implements Command { 39 40 41 43 44 private String actionConfigKey = Constants.ACTION_CONFIG_KEY; 45 private String actionFormKey = Constants.ACTION_FORM_KEY; 46 private String cancelKey = Constants.CANCEL_KEY; 47 private String validKey = Constants.VALID_KEY; 48 49 private static final Log log = 50 LogFactory.getLog(AbstractValidateActionForm.class); 51 52 53 55 56 61 public String getActionConfigKey() { 62 63 return (this.actionConfigKey); 64 65 } 66 67 68 75 public void setActionConfigKey(String actionConfigKey) { 76 77 this.actionConfigKey = actionConfigKey; 78 79 } 80 81 82 87 public String getActionFormKey() { 88 89 return (this.actionFormKey); 90 91 } 92 93 94 101 public void setActionFormKey(String actionFormKey) { 102 103 this.actionFormKey = actionFormKey; 104 105 } 106 107 108 112 public String getCancelKey() { 113 114 return (this.cancelKey); 115 116 } 117 118 119 125 public void setCancelKey(String cancelKey) { 126 127 this.cancelKey = cancelKey; 128 129 } 130 131 132 136 public String getValidKey() { 137 138 return (this.validKey); 139 140 } 141 142 143 149 public void setValidKey(String validKey) { 150 151 this.validKey = validKey; 152 153 } 154 155 156 158 159 169 public boolean execute(Context context) throws Exception { 170 171 ActionForm actionForm = (ActionForm) 173 context.get(getActionFormKey()); 174 if (actionForm == null) { 175 context.put(getValidKey(), Boolean.TRUE); 176 return (false); 177 } 178 179 Boolean cancel = (Boolean ) 181 context.get(getCancelKey()); 182 if ((cancel != null) && cancel.booleanValue()) { 183 context.put(getValidKey(), Boolean.TRUE); 184 return (false); 185 } 186 187 ActionConfig actionConfig = (ActionConfig) 189 context.get(getActionConfigKey()); 190 if (!actionConfig.getValidate()) { 191 context.put(getValidKey(), Boolean.TRUE); 192 return (false); 193 } 194 195 ActionErrors errors = validate(context, actionConfig, actionForm); 197 198 if ((errors == null) || (errors.isEmpty())) { 200 context.put(getValidKey(), Boolean.TRUE); 201 return (false); 202 } 203 204 context.put(getValidKey(), Boolean.FALSE); 206 return (false); 207 208 } 209 210 211 213 214 222 protected abstract ActionErrors validate(Context context, 223 ActionConfig actionConfig, 224 ActionForm actionForm); 225 226 227 } 228 | Popular Tags |