1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.struts.faces.renderer;
18
19
20 import java.io.IOException;
21 import javax.faces.component.UIComponent;
22 import javax.faces.component.UIViewRoot;
23 import javax.faces.component.ValueHolder;
24 import javax.faces.context.FacesContext;
25 import javax.faces.context.ResponseWriter;
26 import org.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28 import org.apache.struts.util.ResponseUtils;
29
30
31 /***
32 * <p><code>Renderer</code> implementation for the <code>write</code> tag
33 * from the <em>Struts-Faces Integration Library</em>.</p>
34 *
35 * @version $Rev: 421138 $ $Date: 2006-07-11 22:41:40 -0700 (Tue, 11 Jul 2006) $
36 */
37
38 public class WriteRenderer extends AbstractRenderer {
39
40
41
42
43
44 /***
45 * <p>The <code>Log</code> instance for this class.</p>
46 */
47 private static Log log = LogFactory.getLog(WriteRenderer.class);
48
49
50
51
52
53 /***
54 * <p>Encode the specified text to our response.</p>
55 *
56 * @param context FacesContext for the response we are creating
57 * @param component Component to be rendered
58 *
59 * @exception IOException if an input/output error occurs
60 * @exception NullPointerException if <code>context</code>
61 * or <code>component</code> is <code>null</code>
62 */
63 public void encodeEnd(FacesContext context, UIComponent component)
64 throws IOException {
65
66 if ((context == null) || (component == null)) {
67 throw new NullPointerException();
68 }
69
70 ResponseWriter writer = context.getResponseWriter();
71 String id = component.getId();
72 if ((id != null) && id.startsWith(UIViewRoot.UNIQUE_ID_PREFIX)) {
73 id = null;
74 }
75 String style =
76 (String) component.getAttributes().get("style");
77 String styleClass =
78 (String) component.getAttributes().get("styleClass");
79 if (log.isTraceEnabled()) {
80 log.trace("id='" + id + "', style='" + style + "', styleClass='" +
81 styleClass + "'");
82 }
83 if ((id != null) || (style != null) || (styleClass != null)) {
84 writer.startElement("span", component);
85 if (id != null) {
86 writer.writeAttribute("id", component.getClientId(context),
87 "id");
88 }
89 if (style != null) {
90 writer.writeAttribute("style", style, "style");
91 }
92 if (styleClass != null) {
93 writer.writeAttribute("class", styleClass, "styleClass");
94 }
95 writer.writeText("", null);
96 }
97 String text = getText(context, component);
98 if (log.isTraceEnabled()) {
99 log.trace("encodeEnd(" + component.getClientId(context) +
100 "," + text + ")");
101 }
102 writer.write(text);
103 if ((id != null) || (style != null) || (styleClass != null)) {
104 writer.endElement("span");
105 }
106
107 }
108
109
110
111
112
113 /***
114 * <p>Return the text to be rendered for this component, optionally
115 * filtered if requested.</p>
116 *
117 * @param context FacesContext for the response we are creating
118 * @param component Component to be rendered
119 */
120 protected String getText(FacesContext context, UIComponent component) {
121
122 String text = getAsString(context, component,
123 ((ValueHolder) component).getValue());
124 Boolean filter = (Boolean) component.getAttributes().get("filter");
125 if (filter == null) {
126 filter = Boolean.FALSE;
127 }
128 if (filter.booleanValue()) {
129 return (ResponseUtils.filter(text));
130 } else {
131 return (text);
132 }
133
134 }
135
136
137 }