1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package javax.faces.convert; |
20 | |
|
21 | |
import java.text.MessageFormat; |
22 | |
import java.util.Locale; |
23 | |
|
24 | |
import javax.el.ValueExpression; |
25 | |
import javax.faces.application.FacesMessage; |
26 | |
import javax.faces.context.FacesContext; |
27 | |
import javax.faces.el.ValueBinding; |
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
class _ParametrizableFacesMessage extends FacesMessage |
37 | |
{ |
38 | |
|
39 | |
|
40 | |
|
41 | |
private static final long serialVersionUID = 7792947730961657948L; |
42 | |
|
43 | |
private final Object _args[]; |
44 | |
private String _evaluatedDetail; |
45 | |
private String _evaluatedSummary; |
46 | |
private transient Object _evaluatedArgs[]; |
47 | |
private Locale _locale; |
48 | |
|
49 | |
public _ParametrizableFacesMessage( |
50 | |
String summary, String detail, Object[] args, Locale locale) |
51 | |
{ |
52 | 0 | super(summary, detail); |
53 | 0 | if(locale == null) throw new NullPointerException("locale"); |
54 | 0 | _locale = locale; |
55 | 0 | _args = args; |
56 | 0 | } |
57 | |
|
58 | |
public _ParametrizableFacesMessage(FacesMessage.Severity severity, |
59 | |
String summary, String detail, Object[] args, Locale locale) |
60 | |
{ |
61 | 0 | super(severity, summary, detail); |
62 | 0 | if(locale == null) throw new NullPointerException("locale"); |
63 | 0 | _locale = locale; |
64 | 0 | _args = args; |
65 | 0 | } |
66 | |
|
67 | |
@Override |
68 | |
public String getDetail() |
69 | |
{ |
70 | 0 | if (_evaluatedArgs == null && _args != null) |
71 | |
{ |
72 | 0 | evaluateArgs(); |
73 | |
} |
74 | 0 | if (_evaluatedDetail == null) |
75 | |
{ |
76 | 0 | MessageFormat format = new MessageFormat(super.getDetail(), _locale); |
77 | 0 | _evaluatedDetail = format.format(_evaluatedArgs); |
78 | |
} |
79 | 0 | return _evaluatedDetail; |
80 | |
} |
81 | |
|
82 | |
@Override |
83 | |
public String getSummary() |
84 | |
{ |
85 | 0 | if (_evaluatedArgs == null && _args != null) |
86 | |
{ |
87 | 0 | evaluateArgs(); |
88 | |
} |
89 | 0 | if (_evaluatedSummary == null) |
90 | |
{ |
91 | 0 | MessageFormat format = new MessageFormat(super.getSummary(), _locale); |
92 | 0 | _evaluatedSummary = format.format(_evaluatedArgs); |
93 | |
} |
94 | 0 | return _evaluatedSummary; |
95 | |
} |
96 | |
|
97 | |
private void evaluateArgs() |
98 | |
{ |
99 | 0 | _evaluatedArgs = new Object[_args.length]; |
100 | 0 | FacesContext facesContext = null; |
101 | 0 | for (int i = 0; i < _args.length; i++) |
102 | |
{ |
103 | 0 | if (_args[i] == null) |
104 | |
{ |
105 | 0 | continue; |
106 | |
} |
107 | 0 | else if (_args[i] instanceof ValueBinding) |
108 | |
{ |
109 | 0 | if (facesContext == null) |
110 | |
{ |
111 | 0 | facesContext = FacesContext.getCurrentInstance(); |
112 | |
} |
113 | 0 | _evaluatedArgs[i] = ((ValueBinding)_args[i]).getValue(facesContext); |
114 | |
} |
115 | 0 | else if (_args[i] instanceof ValueExpression) |
116 | |
{ |
117 | 0 | if (facesContext == null) |
118 | |
{ |
119 | 0 | facesContext = FacesContext.getCurrentInstance(); |
120 | |
} |
121 | 0 | _evaluatedArgs[i] = ((ValueExpression)_args[i]).getValue(facesContext.getELContext()); |
122 | |
} |
123 | |
else |
124 | |
{ |
125 | 0 | _evaluatedArgs[i] = _args[i]; |
126 | |
} |
127 | |
} |
128 | 0 | } |
129 | |
} |