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.io.IOException;
26
27 import org.apache.struts.util.ResponseUtils;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30
31 import jakarta.faces.component.UIComponent;
32 import jakarta.faces.component.UIViewRoot;
33 import jakarta.faces.component.ValueHolder;
34 import jakarta.faces.context.FacesContext;
35 import jakarta.faces.context.ResponseWriter;
36
37
38
39
40
41
42
43
44
45 public class WriteRenderer extends AbstractRenderer {
46
47
48
49
50
51
52
53
54 private final Logger log =
55 LoggerFactory.getLogger(WriteRenderer.class);
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71 public void encodeEnd(FacesContext context, UIComponent component)
72 throws IOException {
73
74 if ((context == null) || (component == null)) {
75 throw new NullPointerException();
76 }
77
78 ResponseWriter writer = context.getResponseWriter();
79 String id = component.getId();
80 if ((id != null) && id.startsWith(UIViewRoot.UNIQUE_ID_PREFIX)) {
81 id = null;
82 }
83 String style =
84 (String) component.getAttributes().get("style");
85 String styleClass =
86 (String) component.getAttributes().get("styleClass");
87 log.trace("id='{}', style='{}', styleClass='{}'",
88 id, style, styleClass);
89 if ((id != null) || (style != null) || (styleClass != null)) {
90 writer.startElement("span", component);
91 if (id != null) {
92 writer.writeAttribute("id", component.getClientId(context),
93 "id");
94 }
95 if (style != null) {
96 writer.writeAttribute("style", style, "style");
97 }
98 if (styleClass != null) {
99 writer.writeAttribute("class", styleClass, "styleClass");
100 }
101 writer.writeText("", null);
102 }
103 String text = getText(context, component);
104 log.atTrace()
105 .setMessage("encodeEnd({},{})")
106 .addArgument(() -> component.getClientId(context))
107 .addArgument(text)
108 .log();
109 writer.write(text);
110 if ((id != null) || (style != null) || (styleClass != null)) {
111 writer.endElement("span");
112 }
113
114 }
115
116
117
118
119
120
121
122
123
124
125
126
127 protected String getText(FacesContext context, UIComponent component) {
128
129 String text = getAsString(context, component,
130 ((ValueHolder) component).getValue());
131 Boolean filter = (Boolean) component.getAttributes().get("filter");
132 if (filter == null) {
133 filter = Boolean.FALSE;
134 }
135 if (filter.booleanValue()) {
136 return (ResponseUtils.filter(text));
137 } else {
138 return (text);
139 }
140
141 }
142 }