1 | 0 | package pt.digitalis.dif.dem.objects.parameters.constraints.impl; |
2 | |
|
3 | |
import java.util.HashMap; |
4 | |
import java.util.Map; |
5 | |
|
6 | |
import pt.digitalis.dif.dem.interfaces.IStageInstance; |
7 | |
import pt.digitalis.utils.common.StringUtils; |
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | 0 | public class ParameterConstraintEmailImpl extends ParameterConstraintRegexImpl { |
14 | |
|
15 | |
|
16 | |
private static final String MAIL_REGEX_JAVA = "^([\\w-]+(?:\\.[\\w-]+)*)@((?:[\\w-]+\\.)*\\w[\\w-]{0,66})\\.([a-z]{2,6}(?:\\.[a-z]{2})?)$"; |
17 | |
|
18 | |
|
19 | |
private static final String MAIL_REGEX_JAVASCRIPT = "/^(([^<>()[\\]\\\\.,;:\\s@\\\"]+(\\.[^<>()[\\]\\\\.,;:\\s@\\\"]+)*)|(\\\".+\\\"))@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$/"; |
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
@Override |
25 | |
public void configureConstraint(String configurationString) |
26 | |
{ |
27 | 0 | this.regexJava = MAIL_REGEX_JAVA; |
28 | 0 | this.regexJavaScript = MAIL_REGEX_JAVASCRIPT; |
29 | 0 | } |
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
@Override |
35 | |
protected Map<String, String> getErrorMessageValues(boolean parseValues) |
36 | |
{ |
37 | 0 | Map<String, String> substitutions = new HashMap<String, String>(); |
38 | |
|
39 | 0 | if (parseValues) |
40 | |
{ |
41 | 0 | substitutions.put("value", lastTestedValue); |
42 | |
} |
43 | |
|
44 | 0 | return substitutions; |
45 | |
} |
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
@Override |
52 | |
public boolean validateConstraint(String value, IStageInstance stageInstance) |
53 | |
{ |
54 | 0 | boolean result = super.validateConstraint(value, stageInstance); |
55 | |
|
56 | 0 | return result && (StringUtils.isBlank(value) || ((value.indexOf(".") > 2) && (value.indexOf("@") > 0))); |
57 | |
} |
58 | |
|
59 | |
} |