1 16 package org.apache.myfaces.renderkit.html; 17 18 import org.apache.commons.logging.Log; 19 import org.apache.commons.logging.LogFactory; 20 21 import javax.faces.context.ResponseStream; 22 import javax.faces.context.ResponseWriter; 23 import javax.faces.render.RenderKit; 24 import javax.faces.render.Renderer; 25 import javax.faces.render.ResponseStateManager; 26 import java.io.OutputStream ; 27 import java.io.Writer ; 28 import java.util.HashMap ; 29 import java.util.Map ; 30 import java.util.StringTokenizer ; 31 32 33 37 public class HtmlRenderKitImpl 38 extends RenderKit 39 { 40 private static final Log log = LogFactory.getLog(HtmlRenderKitImpl.class); 41 42 44 private Map _renderers; 45 private ResponseStateManager _responseStateManager; 46 47 49 public HtmlRenderKitImpl() 50 { 51 _renderers = new HashMap (); 52 _responseStateManager = new HtmlResponseStateManager(); 53 } 54 55 57 private String key(String componentFamily, String rendererType) 58 { 59 return componentFamily + "." + rendererType; 60 } 61 62 public Renderer getRenderer(String componentFamily, String rendererType) 63 { 64 Renderer renderer = (Renderer) _renderers.get(key(componentFamily, rendererType)); 65 if (renderer == null) 66 { 67 log.warn("Unsupported component-family/renderer-type: " + componentFamily + "/" + rendererType); 68 } 69 return renderer; 70 } 71 72 public void addRenderer(String componentFamily, String rendererType, Renderer renderer) 73 { 74 _renderers.put(key(componentFamily, rendererType), renderer); 75 } 76 77 public ResponseStateManager getResponseStateManager() 78 { 79 return _responseStateManager; 80 } 81 82 public ResponseWriter createResponseWriter(Writer writer, 83 String contentTypeList, 84 String characterEncoding) 85 { 86 if (contentTypeList == null) 87 { 88 if (log.isInfoEnabled()) log.debug("No content type list given, creating HtmlResponseWriterImpl with default content type."); 89 return new HtmlResponseWriterImpl(writer, null, characterEncoding); 90 } 91 92 StringTokenizer st = new StringTokenizer (contentTypeList, ","); 93 while (st.hasMoreTokens()) 94 { 95 String contentType = st.nextToken().trim(); 96 if (HtmlResponseWriterImpl.supportsContentType(contentType)) 97 { 98 return new HtmlResponseWriterImpl(writer, contentType, characterEncoding); 99 } 100 } 101 102 throw new IllegalArgumentException ("ContentTypeList does not contain a supported content type: " + contentTypeList); 103 } 104 105 public ResponseStream createResponseStream(OutputStream outputstream) 106 { 107 throw new UnsupportedOperationException (this.getClass().getName() + " UnsupportedOperationException"); 108 } 109 } 110 | Popular Tags |