KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > myfaces > renderkit > html > HtmlRenderKitImpl


1 /*
2  * Copyright 2004 The Apache Software Foundation.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */

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 JavaDoc;
27 import java.io.Writer JavaDoc;
28 import java.util.HashMap JavaDoc;
29 import java.util.Map JavaDoc;
30 import java.util.StringTokenizer JavaDoc;
31
32
33 /**
34  * @author Manfred Geiler (latest modification by $Author: grantsmith $)
35  * @version $Revision: 1.12 $ $Date: 2004/12/17 22:06:32 $
36  */

37 public class HtmlRenderKitImpl
38     extends RenderKit
39 {
40     private static final Log log = LogFactory.getLog(HtmlRenderKitImpl.class);
41
42     //~ Instance fields ----------------------------------------------------------------------------
43

44     private Map JavaDoc _renderers;
45     private ResponseStateManager _responseStateManager;
46
47     //~ Constructors -------------------------------------------------------------------------------
48

49     public HtmlRenderKitImpl()
50     {
51         _renderers = new HashMap JavaDoc();
52         _responseStateManager = new HtmlResponseStateManager();
53     }
54
55     //~ Methods ------------------------------------------------------------------------------------
56

57     private String JavaDoc key(String JavaDoc componentFamily, String JavaDoc rendererType)
58     {
59         return componentFamily + "." + rendererType;
60     }
61
62     public Renderer getRenderer(String JavaDoc componentFamily, String JavaDoc 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 JavaDoc componentFamily, String JavaDoc 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 JavaDoc contentTypeList,
84                                                String JavaDoc 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 JavaDoc st = new StringTokenizer JavaDoc(contentTypeList, ",");
93         while (st.hasMoreTokens())
94         {
95             String JavaDoc contentType = st.nextToken().trim();
96             if (HtmlResponseWriterImpl.supportsContentType(contentType))
97             {
98                 return new HtmlResponseWriterImpl(writer, contentType, characterEncoding);
99             }
100         }
101
102         throw new IllegalArgumentException JavaDoc("ContentTypeList does not contain a supported content type: " + contentTypeList);
103     }
104
105     public ResponseStream createResponseStream(OutputStream JavaDoc outputstream)
106     {
107         throw new UnsupportedOperationException JavaDoc(this.getClass().getName() + " UnsupportedOperationException");
108     }
109 }
110
Popular Tags