| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.seasar.teeda.core.render.html; |
| 17 | |
|
| 18 | |
import java.io.IOException; |
| 19 | |
|
| 20 | |
import javax.faces.component.UIComponent; |
| 21 | |
import javax.faces.component.UIOutput; |
| 22 | |
import javax.faces.component.html.HtmlOutputText; |
| 23 | |
import javax.faces.context.FacesContext; |
| 24 | |
import javax.faces.context.ResponseWriter; |
| 25 | |
import javax.faces.internal.IgnoreAttribute; |
| 26 | |
|
| 27 | |
import org.seasar.teeda.core.JsfConstants; |
| 28 | |
import org.seasar.teeda.core.render.AbstractRenderer; |
| 29 | |
import org.seasar.teeda.core.util.RendererUtil; |
| 30 | |
import org.seasar.teeda.core.util.ValueHolderUtil; |
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | 174 | public class HtmlOutputTextRenderer extends AbstractRenderer { |
| 36 | |
|
| 37 | |
public static final String COMPONENT_FAMILY = "javax.faces.Output"; |
| 38 | |
|
| 39 | |
public static final String RENDERER_TYPE = "javax.faces.Text"; |
| 40 | |
|
| 41 | 174 | private final IgnoreAttribute ignoreComponent = new IgnoreAttribute(); |
| 42 | |
{ |
| 43 | 174 | ignoreComponent.addAttributeName(JsfConstants.ID_ATTR); |
| 44 | 174 | ignoreComponent.addAttributeName(JsfConstants.VALUE_ATTR); |
| 45 | 174 | ignoreComponent.addAttributeName(JsfConstants.ESCAPE_ATTR); |
| 46 | 174 | } |
| 47 | |
|
| 48 | |
public void encodeEnd(FacesContext context, UIComponent component) |
| 49 | |
throws IOException { |
| 50 | 147 | assertNotNull(context, component); |
| 51 | 145 | if (!component.isRendered()) { |
| 52 | 1 | return; |
| 53 | |
} |
| 54 | |
|
| 55 | 144 | if (component instanceof HtmlOutputText) { |
| 56 | 144 | encodeHtmlOutputTextEnd(context, (HtmlOutputText) component); |
| 57 | 0 | } else if (component instanceof UIOutput) { |
| 58 | 0 | encodeUIOutputEnd(context, (UIOutput) component); |
| 59 | |
} |
| 60 | 144 | } |
| 61 | |
|
| 62 | |
protected void encodeHtmlOutputTextEnd(FacesContext context, |
| 63 | |
HtmlOutputText htmlOutputText) throws IOException { |
| 64 | 144 | ResponseWriter writer = context.getResponseWriter(); |
| 65 | 144 | boolean startSpan = false; |
| 66 | 144 | if (containsAttributeForRender(htmlOutputText, ignoreComponent)) { |
| 67 | 5 | writer.startElement(JsfConstants.SPAN_ELEM, htmlOutputText); |
| 68 | 5 | startSpan = true; |
| 69 | 5 | RendererUtil.renderIdAttributeIfNecessary(writer, htmlOutputText, |
| 70 | |
getIdForRender(context, htmlOutputText)); |
| 71 | 5 | renderRemainAttributes(htmlOutputText, writer, ignoreComponent); |
| 72 | |
} |
| 73 | 144 | String value = ValueHolderUtil.getValueForRender(context, |
| 74 | |
htmlOutputText); |
| 75 | 144 | if (htmlOutputText.isEscape()) { |
| 76 | 142 | writer.writeText(value, null); |
| 77 | |
} else { |
| 78 | 2 | writer.write(value); |
| 79 | |
} |
| 80 | 144 | if (startSpan) { |
| 81 | 5 | writer.endElement(JsfConstants.SPAN_ELEM); |
| 82 | |
} |
| 83 | 144 | } |
| 84 | |
|
| 85 | |
protected void encodeUIOutputEnd(FacesContext context, UIOutput uiOutput) |
| 86 | |
throws IOException { |
| 87 | 0 | ResponseWriter writer = context.getResponseWriter(); |
| 88 | 0 | boolean startSpan = false; |
| 89 | 0 | if (containsAttributeForRender(uiOutput, ignoreComponent)) { |
| 90 | 0 | writer.startElement(JsfConstants.SPAN_ELEM, uiOutput); |
| 91 | 0 | startSpan = true; |
| 92 | 0 | RendererUtil.renderIdAttributeIfNecessary(writer, uiOutput, |
| 93 | |
getIdForRender(context, uiOutput)); |
| 94 | 0 | renderRemainAttributes(uiOutput, writer, ignoreComponent); |
| 95 | |
} |
| 96 | 0 | String value = ValueHolderUtil.getValueForRender(context, uiOutput); |
| 97 | 0 | Boolean b = (Boolean) uiOutput.getAttributes().get( |
| 98 | |
JsfConstants.ESCAPE_ATTR); |
| 99 | 0 | if (b != null && b.booleanValue()) { |
| 100 | 0 | writer.writeText(value, null); |
| 101 | |
} else { |
| 102 | 0 | writer.write(value); |
| 103 | |
} |
| 104 | 0 | if (startSpan) { |
| 105 | 0 | writer.endElement(JsfConstants.SPAN_ELEM); |
| 106 | |
} |
| 107 | 0 | } |
| 108 | |
|
| 109 | |
protected IgnoreAttribute getIgnoreAttribute() { |
| 110 | 0 | return ignoreComponent; |
| 111 | |
} |
| 112 | |
|
| 113 | |
protected void addIgnoreAttributeName(String attribute) { |
| 114 | 0 | ignoreComponent.addAttributeName(attribute); |
| 115 | 0 | } |
| 116 | |
} |