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 public abstract class HtmlRenderer
32 extends Renderer
33 {
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49 public List<UIComponent> getChildren(UIComponent component)
50 {
51 return component.getChildren();
52 }
53
54
55
56
57
58
59 public int getChildCount(UIComponent component)
60 {
61 return component.getChildCount();
62 }
63
64
65
66
67
68 protected String getActionUrl(FacesContext facesContext)
69 {
70 ViewHandler viewHandler = facesContext.getApplication().getViewHandler();
71 String viewId = facesContext.getViewRoot().getViewId();
72 return viewHandler.getActionURL(facesContext, viewId);
73 }
74
75
76
77
78 protected void renderId(
79 FacesContext context,
80 UIComponent component) throws IOException
81 {
82 if (shouldRenderId(context, component))
83 {
84 String clientId = getClientId(context, component);
85 context.getResponseWriter().writeAttribute(HTML.ID_ATTR, clientId, JSFAttr.ID_ATTR);
86 }
87 }
88
89
90
91
92
93 protected String getClientId(
94 FacesContext context,
95 UIComponent component)
96 {
97 return component.getClientId(context);
98 }
99
100
101
102
103
104
105 protected boolean shouldRenderId(
106 FacesContext context,
107 UIComponent component)
108 {
109 String id = component.getId();
110
111
112 if (id == null)
113 {
114 return false;
115 }
116
117
118 if (id.startsWith(UIViewRoot.UNIQUE_ID_PREFIX))
119 {
120 return false;
121 }
122
123 return true;
124 }
125
126
127
128
129
130 static public String toUri(Object o)
131 {
132 if (o == null)
133 {
134 return null;
135 }
136
137 String uri = o.toString();
138 if (uri.startsWith("/"))
139 {
140
141 if (uri.startsWith("//"))
142 {
143 uri = uri.substring(1);
144 }
145 else
146 {
147 FacesContext fContext = FacesContext.getCurrentInstance();
148 uri = fContext.getExternalContext().getRequestContextPath() + uri;
149 }
150 }
151
152 return uri;
153 }
154
155 protected boolean isCommonPropertiesOptimizationEnabled(FacesContext facesContext)
156 {
157 return false;
158 }
159
160 protected boolean isCommonEventsOptimizationEnabled(FacesContext facesContext)
161 {
162 return false;
163 }
164 }