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