1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.shared.renderkit.html;
20
21 import org.apache.myfaces.shared.renderkit.JSFAttr;
22
23 import javax.faces.application.ViewHandler;
24 import javax.faces.component.UIComponent;
25 import javax.faces.component.UIViewRoot;
26 import javax.faces.context.FacesContext;
27 import javax.faces.render.Renderer;
28 import java.io.IOException;
29 import java.util.List;
30
31
32
33
34
35 public abstract class HtmlRenderer
36 extends Renderer
37 {
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53 public List<UIComponent> getChildren(UIComponent component)
54 {
55 return component.getChildren();
56 }
57
58
59
60
61
62
63 public int getChildCount(UIComponent component)
64 {
65 return component.getChildCount();
66 }
67
68
69
70
71
72 protected String getActionUrl(FacesContext facesContext)
73 {
74 ViewHandler viewHandler = facesContext.getApplication().getViewHandler();
75 String viewId = facesContext.getViewRoot().getViewId();
76 return viewHandler.getActionURL(facesContext, viewId);
77 }
78
79
80
81
82 protected void renderId(
83 FacesContext context,
84 UIComponent component) throws IOException
85 {
86 if (shouldRenderId(context, component))
87 {
88 String clientId = getClientId(context, component);
89 context.getResponseWriter().writeAttribute(HTML.ID_ATTR, clientId, JSFAttr.ID_ATTR);
90 }
91 }
92
93
94
95
96
97 protected String getClientId(
98 FacesContext context,
99 UIComponent component)
100 {
101 return component.getClientId(context);
102 }
103
104
105
106
107
108
109 protected boolean shouldRenderId(
110 FacesContext context,
111 UIComponent component)
112 {
113 String id = component.getId();
114
115
116 if (id == null)
117 {
118 return false;
119 }
120
121
122 if (id.startsWith(UIViewRoot.UNIQUE_ID_PREFIX))
123 {
124 return false;
125 }
126
127 return true;
128 }
129
130
131
132
133
134 static public String toUri(Object o)
135 {
136 if (o == null)
137 {
138 return null;
139 }
140
141 String uri = o.toString();
142 if (uri.startsWith("/"))
143 {
144
145 if (uri.startsWith("//"))
146 {
147 uri = uri.substring(1);
148 }
149 else
150 {
151 FacesContext fContext = FacesContext.getCurrentInstance();
152 uri = fContext.getExternalContext().getRequestContextPath() + uri;
153 }
154 }
155
156 return uri;
157 }
158
159 protected boolean isCommonPropertiesOptimizationEnabled(FacesContext facesContext)
160 {
161 return false;
162 }
163
164 protected boolean isCommonEventsOptimizationEnabled(FacesContext facesContext)
165 {
166 return false;
167 }
168 }