1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package org.apache.myfaces.taglib.core; |
20 | |
|
21 | |
import javax.el.ELContext; |
22 | |
import javax.el.ValueExpression; |
23 | |
import javax.faces.application.Application; |
24 | |
import javax.faces.context.FacesContext; |
25 | |
import javax.faces.validator.RegexValidator; |
26 | |
import javax.faces.validator.Validator; |
27 | |
import javax.faces.webapp.ValidatorELTag; |
28 | |
import javax.servlet.jsp.JspException; |
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | 0 | public class ValidateRegexTag extends ValidatorELTag |
37 | |
{ |
38 | |
private static final long serialVersionUID = 8363913774859484811L; |
39 | |
|
40 | |
private ValueExpression _pattern; |
41 | |
|
42 | |
private ValueExpression _binding; |
43 | |
|
44 | |
@Override |
45 | |
protected Validator createValidator() throws JspException |
46 | |
{ |
47 | 0 | FacesContext fc = FacesContext.getCurrentInstance(); |
48 | 0 | ELContext elc = fc.getELContext(); |
49 | 0 | if (_binding != null) |
50 | |
{ |
51 | |
Object validator; |
52 | |
try |
53 | |
{ |
54 | 0 | validator = _binding.getValue(elc); |
55 | |
} |
56 | 0 | catch (Exception e) |
57 | |
{ |
58 | 0 | throw new JspException("Error while creating the Validator", e); |
59 | 0 | } |
60 | 0 | if (validator instanceof RegexValidator) |
61 | |
{ |
62 | 0 | return (Validator)validator; |
63 | |
} |
64 | |
} |
65 | 0 | if (null != _pattern) |
66 | |
{ |
67 | 0 | Application appl = fc.getApplication(); |
68 | 0 | RegexValidator validator = (RegexValidator) appl.createValidator(RegexValidator.VALIDATOR_ID); |
69 | 0 | String pattern = (String)_pattern.getValue(elc); |
70 | 0 | validator.setPattern(pattern); |
71 | |
|
72 | 0 | if (_binding != null) |
73 | |
{ |
74 | 0 | _binding.setValue(elc, validator); |
75 | |
} |
76 | |
|
77 | 0 | return validator; |
78 | |
} |
79 | |
else |
80 | |
{ |
81 | 0 | throw new AssertionError("pattern may not be null"); |
82 | |
} |
83 | |
} |
84 | |
|
85 | |
public ValueExpression getBinding() |
86 | |
{ |
87 | 0 | return _binding; |
88 | |
} |
89 | |
|
90 | |
public void setBinding(ValueExpression binding) |
91 | |
{ |
92 | 0 | _binding = binding; |
93 | 0 | } |
94 | |
|
95 | |
public ValueExpression getPattern() |
96 | |
{ |
97 | 0 | return _pattern; |
98 | |
} |
99 | |
|
100 | |
public void setPattern(ValueExpression pattern) |
101 | |
{ |
102 | 0 | _pattern = pattern; |
103 | 0 | } |
104 | |
|
105 | |
@Override |
106 | |
public void release() |
107 | |
{ |
108 | 0 | _pattern = null; |
109 | 0 | _binding = null; |
110 | 0 | } |
111 | |
} |