1 28 29 package com.caucho.jsf.html; 30 31 import java.io.*; 32 import java.util.*; 33 34 import javax.faces.*; 35 import javax.faces.component.*; 36 import javax.faces.component.html.*; 37 import javax.faces.context.*; 38 import javax.faces.render.*; 39 40 43 class HtmlOutputTextRenderer extends Renderer 44 { 45 public static final Renderer RENDERER = new HtmlOutputTextRenderer(); 46 47 50 @Override 51 public boolean getRendersChildren() 52 { 53 return true; 54 } 55 58 @Override 59 public void encodeBegin(FacesContext context, UIComponent component) 60 throws IOException 61 { 62 ResponseWriter out = context.getResponseWriter(); 63 64 String id = component.getId(); 65 String dir; 66 String lang; 67 String style; 68 String styleClass; 69 String title; 70 71 if (component instanceof HtmlOutputText) { 72 HtmlOutputText htmlOutput = (HtmlOutputText) component; 73 74 dir = htmlOutput.getDir(); 75 lang = htmlOutput.getLang(); 76 style = htmlOutput.getStyle(); 77 styleClass = htmlOutput.getStyleClass(); 78 title = htmlOutput.getTitle(); 79 } 80 else { 81 Map<String ,Object > attrMap = component.getAttributes(); 82 83 dir = (String ) attrMap.get("dir"); 84 lang = (String ) attrMap.get("lang"); 85 style = (String ) attrMap.get("style"); 86 styleClass = (String ) attrMap.get("styleClass"); 87 title = (String ) attrMap.get("title"); 88 } 89 90 if (dir == null && lang == null && style == null && styleClass == null) 91 return; 92 93 out.startElement("span", component); 94 95 if (id != null && ! id.startsWith(UIViewRoot.UNIQUE_ID_PREFIX)) 96 out.writeAttribute("id", component.getClientId(context), "id"); 97 98 if (dir != null) 99 out.writeAttribute("dir", dir, "dir"); 100 101 if (lang != null) 102 out.writeAttribute("lang", lang, "dir"); 103 104 if (style != null) 105 out.writeAttribute("style", style, "style"); 106 107 if (styleClass != null) 108 out.writeAttribute("class", styleClass, "class"); 109 110 if (title != null) 111 out.writeAttribute("title", title, "title"); 112 } 113 114 117 @Override 118 public void encodeChildren(FacesContext context, UIComponent component) 119 throws IOException 120 { 121 ResponseWriter out = context.getResponseWriter(); 122 123 if (component instanceof HtmlOutputText) { 124 HtmlOutputText htmlOutput = (HtmlOutputText) component; 125 126 Object value = htmlOutput.getValue(); 127 128 if (value == null) 129 return; 130 131 out.writeText(value, "value"); 132 } 133 else { 134 Map<String ,Object > attrMap = component.getAttributes(); 135 136 Object value = attrMap.get("value"); 137 138 if (value == null) 139 return; 140 141 out.writeText(value, "value"); 142 } 143 } 144 145 148 @Override 149 public void encodeEnd(FacesContext context, UIComponent component) 150 throws IOException 151 { 152 ResponseWriter out = context.getResponseWriter(); 153 154 if (component instanceof HtmlOutputText) { 155 HtmlOutputText htmlOutput = (HtmlOutputText) component; 156 157 if (htmlOutput.getStyleClass() != null 158 || htmlOutput.getStyle() != null 159 || htmlOutput.getDir() != null 160 || htmlOutput.getLang() != null) { 161 out.endElement("span"); 162 } 163 } 164 else { 165 Map<String ,Object > attrMap = component.getAttributes(); 166 167 if (attrMap.get("styleClass") != null 168 || attrMap.get("style") != null 169 || attrMap.get("dir") != null 170 || attrMap.get("lang") != null) { 171 out.endElement("span"); 172 } 173 } 174 } 175 176 public String toString() 177 { 178 return "HtmlOutputTextRenderer[]"; 179 } 180 } 181 | Popular Tags |