1 25 29 package org.jresearch.gossip.validator; 30 31 import javax.servlet.http.HttpServletRequest ; 32 import javax.servlet.http.HttpSession ; 33 34 import org.apache.commons.validator.Field; 35 import org.apache.commons.validator.GenericValidator; 36 import org.apache.commons.validator.ValidatorAction; 37 import org.apache.commons.validator.util.ValidatorUtils; 38 import org.apache.oro.text.perl.Perl5Util; 39 import org.apache.struts.action.ActionMessages; 40 import org.apache.struts.validator.Resources; 41 import org.jresearch.gossip.IConst; 42 43 48 public class Validator { 49 65 public boolean validateEmail(Object bean, ValidatorAction va, Field field, 66 ActionMessages errors, HttpServletRequest request) { 67 String value = ValidatorUtils.getValueAsString(bean, field 68 .getProperty()); 69 Perl5Util util = new Perl5Util(); 70 71 if (!GenericValidator.isBlankOrNull(value)) { 72 if ((!util 73 .match( 74 "/( )|(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)|(^_+@)|(^\\-+@)/", 75 value)) 76 && util 77 .match( 78 "/^[\\w\\'\\.\\-]+@((\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)|[a-zA-Z0-9\\-]{2,})$/", 79 value)) { 80 return true; 81 } else { 82 83 errors.add(field.getKey(), Resources.getActionMessage(request, 84 va, field)); 85 86 return false; 87 } 88 } 89 90 return true; 91 } 92 93 109 public boolean validateTwoFields(Object bean, ValidatorAction va, 110 Field field, ActionMessages errors, HttpServletRequest request) { 111 String value = ValidatorUtils.getValueAsString(bean, field 112 .getProperty()); 113 String sProperty2 = field.getVarValue("secondProperty"); 114 String value2 = ValidatorUtils.getValueAsString(bean, sProperty2); 115 116 if (!GenericValidator.isBlankOrNull(value)) { 117 try { 118 if (!value.equals(value2)) { 119 errors.add(field.getKey(), Resources.getActionMessage( 120 request, va, field)); 121 122 return false; 123 } 124 } catch (Exception e) { 125 errors.add(field.getKey(), Resources.getActionMessage(request, 126 va, field)); 127 128 return false; 129 } 130 } 131 132 return true; 133 } 134 135 public boolean validateConfirmCode(Object bean, ValidatorAction va, 136 Field field, ActionMessages errors, HttpServletRequest request) { 137 String value = ValidatorUtils.getValueAsString(bean, field 138 .getProperty()); 139 HttpSession session = request.getSession(); 140 String value2 = (String ) session 141 .getAttribute(IConst.SESSION.CONFIRM_CODE); 142 143 if (!GenericValidator.isBlankOrNull(value)) { 144 try { 145 if (!value.equals(value2)) { 146 errors.add(field.getKey(), Resources.getActionMessage( 147 request, va, field)); 148 149 return false; 150 } 151 } catch (Exception e) { 152 errors.add(field.getKey(), Resources.getActionMessage(request, 153 va, field)); 154 155 return false; 156 } 157 } 158 159 return true; 160 } 161 } 162 | Popular Tags |