1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package javax.faces.component.html; |
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 | |
class _ParametrizableFacesMessage extends FacesMessage |
34 | |
{ |
35 | |
|
36 | |
|
37 | |
|
38 | |
private static final long serialVersionUID = 7792947730961657948L; |
39 | |
|
40 | |
private final Object _args[]; |
41 | |
private String _evaluatedDetail; |
42 | |
private String _evaluatedSummary; |
43 | |
private transient Object _evaluatedArgs[]; |
44 | |
private Locale _locale; |
45 | |
|
46 | |
public _ParametrizableFacesMessage( |
47 | |
String summary, String detail, Object[] args, Locale locale) |
48 | |
{ |
49 | 0 | super(summary, detail); |
50 | 0 | if(locale == null) |
51 | |
{ |
52 | 0 | throw new NullPointerException("locale"); |
53 | |
} |
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) |
63 | |
{ |
64 | 0 | throw new NullPointerException("locale"); |
65 | |
} |
66 | 0 | _locale = locale; |
67 | 0 | _args = args; |
68 | 0 | } |
69 | |
|
70 | |
@Override |
71 | |
public String getDetail() |
72 | |
{ |
73 | 0 | if (_evaluatedArgs == null && _args != null) |
74 | |
{ |
75 | 0 | evaluateArgs(); |
76 | |
} |
77 | 0 | if (_evaluatedDetail == null) |
78 | |
{ |
79 | 0 | MessageFormat format = new MessageFormat(super.getDetail(), _locale); |
80 | 0 | _evaluatedDetail = format.format(_evaluatedArgs); |
81 | |
} |
82 | 0 | return _evaluatedDetail; |
83 | |
} |
84 | |
|
85 | |
@Override |
86 | |
public void setDetail(String detail) |
87 | |
{ |
88 | 0 | super.setDetail(detail); |
89 | 0 | _evaluatedDetail = null; |
90 | 0 | } |
91 | |
|
92 | |
public String getUnformattedDetail() |
93 | |
{ |
94 | 0 | return super.getDetail(); |
95 | |
} |
96 | |
|
97 | |
@Override |
98 | |
public String getSummary() |
99 | |
{ |
100 | 0 | if (_evaluatedArgs == null && _args != null) |
101 | |
{ |
102 | 0 | evaluateArgs(); |
103 | |
} |
104 | 0 | if (_evaluatedSummary == null) |
105 | |
{ |
106 | 0 | MessageFormat format = new MessageFormat(super.getSummary(), _locale); |
107 | 0 | _evaluatedSummary = format.format(_evaluatedArgs); |
108 | |
} |
109 | 0 | return _evaluatedSummary; |
110 | |
} |
111 | |
|
112 | |
@Override |
113 | |
public void setSummary(String summary) |
114 | |
{ |
115 | 0 | super.setSummary(summary); |
116 | 0 | _evaluatedSummary = null; |
117 | 0 | } |
118 | |
|
119 | |
public String getUnformattedSummary() |
120 | |
{ |
121 | 0 | return super.getSummary(); |
122 | |
} |
123 | |
|
124 | |
private void evaluateArgs() |
125 | |
{ |
126 | 0 | _evaluatedArgs = new Object[_args.length]; |
127 | 0 | FacesContext facesContext = null; |
128 | 0 | for (int i = 0; i < _args.length; i++) |
129 | |
{ |
130 | 0 | if (_args[i] == null) |
131 | |
{ |
132 | 0 | continue; |
133 | |
} |
134 | 0 | else if (_args[i] instanceof ValueBinding) |
135 | |
{ |
136 | 0 | if (facesContext == null) |
137 | |
{ |
138 | 0 | facesContext = FacesContext.getCurrentInstance(); |
139 | |
} |
140 | 0 | _evaluatedArgs[i] = ((ValueBinding)_args[i]).getValue(facesContext); |
141 | |
} |
142 | 0 | else if (_args[i] instanceof ValueExpression) |
143 | |
{ |
144 | 0 | if (facesContext == null) |
145 | |
{ |
146 | 0 | facesContext = FacesContext.getCurrentInstance(); |
147 | |
} |
148 | 0 | _evaluatedArgs[i] = ((ValueExpression)_args[i]).getValue(facesContext.getELContext()); |
149 | |
} |
150 | |
else |
151 | |
{ |
152 | 0 | _evaluatedArgs[i] = _args[i]; |
153 | |
} |
154 | |
} |
155 | 0 | } |
156 | |
} |