KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > jsf > html > HtmlBasicRenderKit


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License version 2
11  * as published by the Free Software Foundation.
12  *
13  * Resin Open Source is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
16  * of NON-INFRINGEMENT. See the GNU General Public License for more
17  * details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with Resin Open Source; if not, write to the
21  *
22  * Free Software Foundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Scott Ferguson
27  */

28
29 package com.caucho.jsf.html;
30
31 import java.io.*;
32 import java.util.*;
33
34 import javax.faces.context.*;
35 import javax.faces.render.*;
36
37 public class HtmlBasicRenderKit extends RenderKit {
38   private HashMap<Key,Renderer> _rendererMap
39     = new HashMap<Key,Renderer>();
40
41   private Key _key = new Key();
42
43   public HtmlBasicRenderKit()
44   {
45     addRenderer("javax.faces.Output", "javax.faces.Text",
46         HtmlOutputTextRenderer.RENDERER);
47     
48     addRenderer("javax.faces.Panel", "javax.faces.Grid",
49         HtmlPanelGridRenderer.RENDERER);
50   }
51   
52   public void addRenderer(String JavaDoc family,
53               String JavaDoc rendererType,
54               Renderer renderer)
55   {
56     _rendererMap.put(new Key(family, rendererType), renderer);
57   }
58   
59   public Renderer getRenderer(String JavaDoc family,
60                   String JavaDoc rendererType)
61   {
62     if (family == null || rendererType == null)
63       return null;
64     
65     _key.init(family, rendererType);
66     
67     return _rendererMap.get(_key);
68   }
69
70   public ResponseStateManager getResponseStateManager()
71   {
72     return null;
73   }
74
75   public ResponseWriter createResponseWriter(Writer writer,
76                          String JavaDoc contentTypeList,
77                          String JavaDoc characterEncoding)
78   {
79     return new HtmlResponseWriter(writer, contentTypeList, characterEncoding);
80   }
81
82   public ResponseStream createResponseStream(OutputStream out)
83   {
84     throw new UnsupportedOperationException JavaDoc();
85   }
86
87   public String JavaDoc toString()
88   {
89     return "HtmlBasicRenderKit[]";
90   }
91
92   static final class Key {
93     private String JavaDoc _family;
94     private String JavaDoc _type;
95
96     Key()
97     {
98     }
99       
100     Key(String JavaDoc family, String JavaDoc type)
101     {
102       _family = family;
103       _type = type;
104     }
105
106     public void init(String JavaDoc family, String JavaDoc type)
107     {
108       _family = family;
109       _type = type;
110     }
111
112     @Override JavaDoc
113     public int hashCode()
114     {
115       if (_type != null)
116     return _family.hashCode() * 65521 + _type.hashCode();
117       else
118     return _family.hashCode();
119     }
120
121     public boolean equals(Object JavaDoc o)
122     {
123       Key key = (Key) o;
124
125       if (_type != null)
126     return _family.equals(key._family) && _type.equals(key._type);
127       else
128     return _family.equals(key._family) && key._type != null;
129     }
130
131     public String JavaDoc toString()
132     {
133       return "Key[" + _family + ", " + _type + "]";
134     }
135   }
136 }
137
Popular Tags