2
* Copyright 2002,2004 The Apache Software Foundation.
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
17
package org.apache.struts.faces.renderer;
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;
32
* <p><code>Renderer</code> implementation for the <code>write</code> tag
33
* from the <em>Struts-Faces Integration Library</em>.</p>
35
* @version $Rev: 55303 $ $Date: 2004-10-22 03:56:53 +0100 (Fri, 22 Oct 2004) $
38
public class WriteRenderer extends AbstractRenderer {
41
// -------------------------------------------------------- Static Variables
45
* <p>The <code>Log</code> instance for this class.</p>
47
private static Log log = LogFactory.getLog(WriteRenderer.class);
50
// ---------------------------------------------------------- Public Methods
54
* <p>Encode the specified text to our response.</p>
56
* @param context FacesContext for the response we are creating
57
* @param component Component to be rendered
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>
63
public void encodeEnd(FacesContext context, UIComponent component)
66
if ((context == null) || (component == null)) {
67
throw new NullPointerException();
70
ResponseWriter writer = context.getResponseWriter();
71
String id = component.getId();
72
if ((id != null) && id.startsWith(UIViewRoot.UNIQUE_ID_PREFIX)) {
76
(String) component.getAttributes().get("style");
78
(String) component.getAttributes().get("styleClass");
79
if (log.isTraceEnabled()) {
80
log.trace("id='" + id + "', style='" + style + "', styleClass='" +
83
if ((id != null) || (style != null) || (styleClass != null)) {
84
writer.startElement("span", component);
86
writer.writeAttribute("id", component.getClientId(context),
90
writer.writeAttribute("style", style, "style");
92
if (styleClass != null) {
93
writer.writeAttribute("class", styleClass, "styleClass");
95
writer.writeText("", null);
97
String text = getText(context, component);
98
if (log.isTraceEnabled()) {
99
log.trace("encodeEnd(" + component.getClientId(context) +
103
if ((id != null) || (style != null) || (styleClass != null)) {
104
writer.endElement("span");
110
// ------------------------------------------------------- Protected Methods
114
* <p>Return the text to be rendered for this component, optionally
115
* filtered if requested.</p>
117
* @param context FacesContext for the response we are creating
118
* @param component Component to be rendered
120
protected String getText(FacesContext context, UIComponent component) {
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;
128
if (filter.booleanValue()) {
129
return (ResponseUtils.filter(text));