1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package org.apache.myfaces.renderkit.html; |
20 | |
|
21 | |
import java.io.IOException; |
22 | |
import java.util.List; |
23 | |
|
24 | |
import javax.faces.application.ProjectStage; |
25 | |
import javax.faces.component.UIComponent; |
26 | |
import javax.faces.component.UIViewRoot; |
27 | |
import javax.faces.context.FacesContext; |
28 | |
import javax.faces.context.ResponseWriter; |
29 | |
import javax.faces.render.Renderer; |
30 | |
|
31 | |
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFRenderer; |
32 | |
import org.apache.myfaces.shared.config.MyfacesConfig; |
33 | |
import org.apache.myfaces.shared.renderkit.html.HTML; |
34 | |
import org.apache.myfaces.shared.renderkit.html.HtmlRendererUtils; |
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
@JSFRenderer(renderKitId = "HTML_BASIC", family = "javax.faces.Output", type = "javax.faces.Head") |
44 | 0 | public class HtmlHeadRenderer extends Renderer |
45 | |
{ |
46 | |
|
47 | |
private final static String HEAD_ELEM = "head"; |
48 | |
private final static String HEAD_TARGET = HEAD_ELEM; |
49 | |
|
50 | |
private final static String PROFILE_ATTR = "profile"; |
51 | |
|
52 | 0 | private final static String[] HEAD_PASSTHROUGH_ATTRIBUTES = { HTML.DIR_ATTR, |
53 | |
HTML.LANG_ATTR, PROFILE_ATTR}; |
54 | |
|
55 | |
@Override |
56 | |
public void encodeBegin(FacesContext facesContext, UIComponent component) |
57 | |
throws IOException |
58 | |
{ |
59 | 0 | super.encodeBegin(facesContext, component); |
60 | |
|
61 | 0 | ResponseWriter writer = facesContext.getResponseWriter(); |
62 | 0 | writer.startElement(HEAD_ELEM, component); |
63 | 0 | HtmlRendererUtils.writeIdIfNecessary(writer, component, facesContext); |
64 | 0 | HtmlRendererUtils.renderHTMLAttributes(writer, component, |
65 | |
HEAD_PASSTHROUGH_ATTRIBUTES); |
66 | 0 | HtmlRendererUtils.renderHTMLAttribute(writer, component, HTML.XMLNS_ATTR , HTML.XMLNS_ATTR); |
67 | 0 | } |
68 | |
|
69 | |
@Override |
70 | |
public void encodeEnd(FacesContext facesContext, UIComponent component) |
71 | |
throws IOException |
72 | |
{ |
73 | 0 | super.encodeEnd(facesContext, component); |
74 | |
|
75 | 0 | ResponseWriter writer = facesContext.getResponseWriter(); |
76 | 0 | UIViewRoot root = facesContext.getViewRoot(); |
77 | 0 | List<UIComponent> componentResources = root.getComponentResources(facesContext, |
78 | |
HEAD_TARGET); |
79 | |
|
80 | 0 | for (int i = 0, childCount = componentResources.size(); i < childCount; i++) |
81 | |
{ |
82 | 0 | UIComponent child = componentResources.get(i); |
83 | 0 | child.encodeAll(facesContext); |
84 | |
} |
85 | 0 | writer.endElement(HEAD_ELEM); |
86 | |
|
87 | 0 | if (MyfacesConfig.getCurrentInstance(facesContext.getExternalContext()).isEarlyFlushEnabled() && |
88 | |
facesContext.isProjectStage(ProjectStage.Production)) |
89 | |
{ |
90 | 0 | writer.flush(); |
91 | |
} |
92 | 0 | } |
93 | |
} |