public class OutRenderer extends LayoutComponentRendererBase {
@Override
public void encodeEnd(final FacesContext facesContext, final UIComponent component) throws IOException {
final UIOut out = (UIOut) component;
String text = RenderUtils.currentValue(out);
if (text == null) {
text = "";
}
final TobagoResponseWriter writer = HtmlRendererUtils.getTobagoResponseWriter(facesContext);
final boolean escape = out.isEscape();
final boolean createSpan = out.isCreateSpan();
if (createSpan) {
final String id = out.getClientId(facesContext);
writer.startElement(HtmlElements.SPAN, out);
writer.writeIdAttribute(id);
HtmlRendererUtils.writeDataAttributes(facesContext, writer, out);
final Style style = new Style(facesContext, out);
writer.writeStyleAttribute(style);
writer.writeClassAttribute(Classes.create(out));
final String title = HtmlRendererUtils.getTitleFromTipAndMessages(facesContext, out);
if (title != null) {
writer.writeAttribute(HtmlAttributes.TITLE, title, true);
}
}
if (escape) {
final StringTokenizer tokenizer = new StringTokenizer(text, "\r\n");
while (tokenizer.hasMoreTokens()) {
final String token = tokenizer.nextToken();
writer.writeText(token);
if (tokenizer.hasMoreTokens()) {
writer.startElement(HtmlElements.BR, null);
writer.endElement(HtmlElements.BR);
}
}
} else { // escape="false"
writer.writeText("", null); // to ensure the closing > of the <span> start tag.
if ("auto".equals(out.getSanitize())) {
final Sanitizer sanitizer = TobagoConfig.getInstance(facesContext).getSanitizer();
text = sanitizer.sanitize(text);
}
writer.write(text);
}