1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.apache.struts.faces.renderer;
23
24
25 import java.util.ArrayList;
26
27 import org.apache.struts.Globals;
28 import org.apache.struts.util.MessageResources;
29 import org.apache.struts.util.ResponseUtils;
30
31 import jakarta.faces.component.UIComponent;
32 import jakarta.faces.component.UIParameter;
33 import jakarta.faces.component.ValueHolder;
34 import jakarta.faces.context.FacesContext;
35
36
37
38
39
40
41
42
43
44 public class MessageRenderer extends WriteRenderer {
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67 protected String getText(FacesContext context, UIComponent component) {
68
69
70 String bundle = (String) component.getAttributes().get("bundle");
71 if (bundle == null) {
72 bundle = Globals.MESSAGES_KEY;
73 }
74 MessageResources resources = (MessageResources)
75 context.getExternalContext().getApplicationMap().get(bundle);
76 if (resources == null) {
77 throw new IllegalArgumentException("MessageResources bundle " +
78 bundle + " not found");
79 }
80
81
82 Object value = component.getAttributes().get("key");
83 if (value == null) {
84 value = ((ValueHolder) component).getValue();
85 }
86 if (value == null) {
87 throw new NullPointerException("Component '" +
88 component.getClientId(context) +
89 "' has no current value");
90 }
91 String key = value.toString();
92
93
94 ArrayList<Object> list = new ArrayList<>();
95 for (UIComponent kid : component.getChildren()) {
96 if (!(kid instanceof UIParameter)) {
97 continue;
98 }
99 list.add(((UIParameter) kid).getValue());
100 }
101 Object args[] = list.toArray(new Object[0]);
102
103
104 String text = resources.getMessage(context.getViewRoot().getLocale(),
105 key, args);
106 Boolean filter = (Boolean) component.getAttributes().get("filter");
107 if (filter == null) {
108 filter = Boolean.FALSE;
109 }
110 if (filter.booleanValue()) {
111 return (ResponseUtils.filter(text));
112 } else {
113 return (text);
114 }
115
116 }
117
118
119 }