1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19 package javax.faces.render;
20
21 import java.io.IOException;
22
23 import javax.faces.component.UIComponent;
24 import javax.faces.context.FacesContext;
25 import javax.faces.convert.ConverterException;
26
27 /**
28 * see Javadoc of <a href="http://java.sun.com/javaee/javaserverfaces/1.2/docs/api/index.html">JSF Specification</a>
29 *
30 * @author Manfred Geiler (latest modification by $Author: bommel $)
31 * @version $Revision: 1187700 $ $Date: 2011-10-22 07:19:37 -0500 (Sat, 22 Oct 2011) $
32 */
33 public abstract class Renderer
34 {
35 public void decode(FacesContext context, UIComponent component)
36 {
37 if (context == null)
38 throw new NullPointerException("context");
39 if (component == null)
40 throw new NullPointerException("component");
41 }
42
43 /**
44 * @throws IOException if an input/output error occurs while rendering
45 */
46 public void encodeBegin(FacesContext context, UIComponent component) throws IOException
47 {
48 if (context == null)
49 throw new NullPointerException("context");
50 if (component == null)
51 throw new NullPointerException("component");
52 }
53
54 /**
55 * Render all children if there are any.
56 *
57 * Note: this will only be called if getRendersChildren() returns true. A component which has a renderer with
58 * getRendersChildren() set to true will typically contain the rendering logic for its children in this method.
59 *
60 * @param context
61 * @param component
62 * @throws IOException
63 */
64 public void encodeChildren(FacesContext context, UIComponent component) throws IOException
65 {
66 if (context == null)
67 throw new NullPointerException("context");
68 if (component == null)
69 throw new NullPointerException("component");
70
71 if (component.getChildCount() > 0)
72 {
73 for (int i = 0, childCount = component.getChildCount(); i < childCount; i++)
74 {
75 UIComponent child = component.getChildren().get(i);
76 if (!child.isRendered())
77 {
78 continue;
79 }
80
81 child.encodeAll(context);
82 }
83 }
84 }
85
86 /**
87 * @throws IOException if an input/output error occurs while rendering
88 */
89 public void encodeEnd(FacesContext context, UIComponent component) throws IOException
90 {
91 if (context == null)
92 throw new NullPointerException("context");
93 if (component == null)
94 throw new NullPointerException("component");
95 }
96
97 public String convertClientId(FacesContext context, String clientId)
98 {
99 if (context == null)
100 throw new NullPointerException("context");
101 if (clientId == null)
102 throw new NullPointerException("clientId");
103 return clientId;
104 }
105
106 /**
107 * Switch for deciding who renders the children.
108 *
109 * @return <b>true</b> - if the component takes care of rendering its children. In this case, encodeChildren() ought
110 * to be called by the rendering controller (e.g., the rendering controller could be the method encodeAll()
111 * in UIComponent). In the method encodeChildren(), the component should therefore provide all children
112 * encode logic. <br/> <b>false</b> - if the component does not take care of rendering its children. In this
113 * case, encodeChildren() should not be called by the rendering controller. Instead, the children-list
114 * should be retrieved and the children should directly be rendered by the rendering controller one by one.
115 */
116 public boolean getRendersChildren()
117 {
118 return false;
119 }
120
121 public Object getConvertedValue(FacesContext context, UIComponent component, Object submittedValue)
122 throws ConverterException
123 {
124 if (context == null)
125 throw new NullPointerException("context");
126 if (component == null)
127 throw new NullPointerException("component");
128 return submittedValue;
129 }
130
131 }