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