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 super(summary, detail);
53 if(locale == null) throw new NullPointerException("locale");
54 _locale = locale;
55 _args = args;
56 }
57
58 public _ParametrizableFacesMessage(FacesMessage.Severity severity,
59 String summary, String detail, Object[] args, Locale locale)
60 {
61 super(severity, summary, detail);
62 if(locale == null) throw new NullPointerException("locale");
63 _locale = locale;
64 _args = args;
65 }
66
67 @Override
68 public String getDetail()
69 {
70 if (_evaluatedArgs == null && _args != null)
71 {
72 evaluateArgs();
73 }
74 if (_evaluatedDetail == null)
75 {
76 MessageFormat format = new MessageFormat(super.getDetail(), _locale);
77 _evaluatedDetail = format.format(_evaluatedArgs);
78 }
79 return _evaluatedDetail;
80 }
81
82 @Override
83 public void setDetail(String detail)
84 {
85 super.setDetail(detail);
86 _evaluatedDetail = null;
87 }
88
89 public String getUnformattedDetail()
90 {
91 return super.getDetail();
92 }
93
94 @Override
95 public String getSummary()
96 {
97 if (_evaluatedArgs == null && _args != null)
98 {
99 evaluateArgs();
100 }
101 if (_evaluatedSummary == null)
102 {
103 MessageFormat format = new MessageFormat(super.getSummary(), _locale);
104 _evaluatedSummary = format.format(_evaluatedArgs);
105 }
106 return _evaluatedSummary;
107 }
108
109 @Override
110 public void setSummary(String summary)
111 {
112 super.setSummary(summary);
113 _evaluatedSummary = null;
114 }
115
116 public String getUnformattedSummary()
117 {
118 return super.getSummary();
119 }
120
121 private void evaluateArgs()
122 {
123 _evaluatedArgs = new Object[_args.length];
124 FacesContext facesContext = null;
125 for (int i = 0; i < _args.length; i++)
126 {
127 if (_args[i] == null)
128 {
129 continue;
130 }
131 else if (_args[i] instanceof ValueBinding)
132 {
133 if (facesContext == null)
134 {
135 facesContext = FacesContext.getCurrentInstance();
136 }
137 _evaluatedArgs[i] = ((ValueBinding)_args[i]).getValue(facesContext);
138 }
139 else if (_args[i] instanceof ValueExpression)
140 {
141 if (facesContext == null)
142 {
143 facesContext = FacesContext.getCurrentInstance();
144 }
145 _evaluatedArgs[i] = ((ValueExpression)_args[i]).getValue(facesContext.getELContext());
146 }
147 else
148 {
149 _evaluatedArgs[i] = _args[i];
150 }
151 }
152 }
153 }