| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 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 |
|
|
| 13 |
|
|
| 14 |
|
class UserController { |
| 15 |
24 |
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 |
104 |
public UserController() {} |
| 20 |
|
|
| 21 |
|
public ActionErrors control(UserView user) { |
| 22 |
92 |
ActionErrors errors = new ActionErrors(); |
| 23 |
|
|
| 24 |
92 |
if (StringUtils.isEmpty(user.getId()) || user.getId().length() < 2) { |
| 25 |
8 |
errors.add("id", new ActionError("user.control.id.empty")); |
| 26 |
|
} |
| 27 |
|
|
| 28 |
92 |
if (StringUtils.isEmpty(user.getName()) || user.getName().length() < 2) { |
| 29 |
12 |
errors.add("name", new ActionError("user.control.name.empty")); |
| 30 |
|
} |
| 31 |
|
|
| 32 |
92 |
if (StringUtils.isNotEmpty(user.getEmail()) |
| 33 |
|
&& !perl.match(EMAIL_PATTERN, user.getEmail())) { |
| 34 |
8 |
errors.add("email", new ActionError("user.control.email.invalid")); |
| 35 |
|
} |
| 36 |
|
|
| 37 |
92 |
return errors; |
| 38 |
|
} |
| 39 |
|
} |