View Javadoc
1 /* 2 * Demosys. 3 * 4 * Terms of license - http://opensource.org/licenses/apachepl.php 5 */ 6 package org.demosys.web.user; 7 import org.apache.commons.lang.StringUtils; 8 import org.apache.oro.text.perl.Perl5Util; 9 import org.apache.struts.action.ActionError; 10 import org.apache.struts.action.ActionErrors; 11 /*** 12 * Controle a UserView . 13 */ 14 class UserController { 15 private static Perl5Util perl = new Perl5Util(); 16 private static final String EMAIL_PATTERN = 17 "/[a-zA-Z]//w*[@][a-zA-Z]+[//.][a-z]{2,3}$/"; 18 19 public UserController() {} 20 21 public ActionErrors control(UserView user) { 22 ActionErrors errors = new ActionErrors(); 23 24 if (StringUtils.isEmpty(user.getId()) || user.getId().length() < 2) { 25 errors.add("id", new ActionError("user.control.id.empty")); 26 } 27 28 if (StringUtils.isEmpty(user.getName()) || user.getName().length() < 2) { 29 errors.add("name", new ActionError("user.control.name.empty")); 30 } 31 32 if (StringUtils.isNotEmpty(user.getEmail()) 33 && !perl.match(EMAIL_PATTERN, user.getEmail())) { 34 errors.add("email", new ActionError("user.control.email.invalid")); 35 } 36 37 return errors; 38 } 39 }

This page was automatically generated by Maven