View Javadoc
1   /**
2    * Copyright By Grandsoft Company Limited.  
3    * 2013-9-26 下午01:58:46
4    */
5   package gboat2.web.validators;
6   
7   import gboat2.web.Constants;
8   import gboat2.web.exception.ValidateException;
9   import gboat2.web.validate.AbstractValidator;
10  
11  import java.util.Map;
12  
13  import org.apache.commons.lang3.StringUtils;
14  import org.osgi.framework.BundleContext;
15  import org.springframework.util.Assert;
16  
17  /**
18   * 
19   * 非空验证
20   * @author zhangxj-a
21   * @since jdk1.6
22   * @date 2013-9-26
23   *  
24   */
25  public class NotNullValidator extends AbstractValidator {
26  
27  	public NotNullValidator(BundleContext bundleContext) {
28  		super(bundleContext);
29  		// TODO Auto-generated constructor stub
30  	}
31  
32  	@Override
33  	public void validate(Map<String,?> paraMap) throws ValidateException {
34  		Assert.notEmpty(paraMap);
35  		// 验证用户名非空
36  		String username = (String)paraMap.get("username");
37  		String password = (String)paraMap.get("password");
38  		if (StringUtils.isEmpty(username)) {//没有填写用户名
39  			throw new ValidateException(Constants.ERROR_MESSAGE_USERNAME_NULL);
40  		}	
41  		
42  		// 验证密码非空
43  		if (StringUtils.isEmpty(password)) {//没有填写密码
44  			throw new ValidateException(Constants.ERROR_MESSAGE_PASSWORD_NULL);
45  		} 
46  	}
47  
48  }