2009/05/20 - Apache Shale has been retired.
For more information, please explore the Attic.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.shale.validator.faces;
19
20 import java.io.OutputStream;
21 import java.io.Writer;
22 import javax.faces.context.ResponseStream;
23 import javax.faces.context.ResponseWriter;
24 import javax.faces.render.RenderKit;
25 import javax.faces.render.Renderer;
26 import javax.faces.render.ResponseStateManager;
27
28 /***
29 * <p>Decorates the original <code>RenderKit</code> passed by the
30 * overloaded constructor in the {@link org.apache.shale.view.faces.ViewViewHandler}.
31 * The majority of the implementation is passed on the the original
32 * <code>RenderKit</code> but requests for renderers registered with the
33 * "javax.faces.Command" and "javax.faces.Input" families are decorated.
34 * Only renderers in the "javax.faces.Command" family of types
35 * "javax.faces.Link" and "javax.faces.Button" are considered. These are
36 * renderers from the vanilla JSF runtime that have predictable behavior.
37 * The wrapper adds special behavior for the
38 * {@link org.apache.shale.validator.CommonsValidator} validator and
39 * {@link org.apache.shale.component.ValidatorScript} component.</p>
40 */
41 public class ValidatorRenderKit extends RenderKit {
42
43 private static final String COMMAND_FAMILY = "javax.faces.Command";
44 private static final String INPUT_FAMILY = "javax.faces.Input";
45 private static final String COMMAND_LINK_TYPE = "javax.faces.Link";
46 private static final String COMMAND_BUTTON_TYPE = "javax.faces.Button";
47
48
49 /***
50 * <p>The original RenderKit.</p>
51 */
52 private RenderKit defaultRenderKit = null;
53
54
55 /***
56 * <p>This constructor is overloaded to pass the original
57 * <code>RenderKit</code></p>.
58 *
59 * @param defaultRenderKit The default RenderKit that we will be wrapping
60 */
61 public ValidatorRenderKit(RenderKit defaultRenderKit) {
62 this.defaultRenderKit = defaultRenderKit;
63 }
64
65
66 /*** {@inheritDoc} */
67 public void addRenderer(String componentFamily, String rendererType, Renderer renderer) {
68 this.defaultRenderKit.addRenderer(componentFamily, rendererType, renderer);
69 }
70
71
72 /***
73 * <p>If the component family is not "javax.faces.Command" or
74 * "javax.faces.Input", the <code>defaultRenderKit</code> handles the
75 * request. If the family is "javax.faces.Command", and the renderer type
76 * is "javax.faces.Link" or "javax.faces.Button" the default
77 * renderer is decorated with {@link org.apache.shale.renderer.ValidatorCommandRenderer}.
78 * If the component family is "javax.faces.Input", the default
79 * renderer is decorated with {@link org.apache.shale.renderer.ValidatorInputRenderer}.
80 *
81 * @param componentFamily Component family for which to retrieve a Renderer
82 * @param rendererType Renderer type for which to retrieve a Renderer
83 */
84 public Renderer getRenderer(String componentFamily, String rendererType) {
85 Renderer target = defaultRenderKit.getRenderer(componentFamily, rendererType);
86 if (componentFamily.equals(COMMAND_FAMILY) &&
87 (rendererType.equals(COMMAND_LINK_TYPE) ||
88 rendererType.equals(COMMAND_BUTTON_TYPE))) {
89 if (!(target instanceof ValidatorCommandRenderer)) {
90 target = new ValidatorCommandRenderer(target);
91 addRenderer(componentFamily, rendererType, target);
92 }
93 } else if (componentFamily.equals(INPUT_FAMILY)) {
94 if (!(target instanceof ValidatorInputRenderer)) {
95 target = new ValidatorInputRenderer(target);
96 addRenderer(componentFamily, rendererType, target);
97 }
98 }
99 return target;
100 }
101
102
103 /*** {@inheritDoc} */
104 public ResponseStateManager getResponseStateManager() {
105 return defaultRenderKit.getResponseStateManager();
106 }
107
108
109 /*** {@inheritDoc} */
110 public ResponseWriter createResponseWriter(Writer writer,
111 String contentTypeList,
112 String characterEncoding) {
113 return defaultRenderKit.createResponseWriter(writer, contentTypeList, characterEncoding);
114 }
115
116
117 /*** {@inheritDoc} */
118 public ResponseStream createResponseStream(OutputStream outputStream) {
119 return defaultRenderKit.createResponseStream(outputStream);
120 }
121
122
123 }