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.io.Writer;
23 import javax.faces.FacesException;
24 import javax.faces.component.UIComponent;
25 import javax.faces.context.FacesContext;
26 import javax.faces.context.ResponseWriter;
27 import org.apache.myfaces.shared.renderkit.html.HTML;
28 import org.apache.myfaces.shared.renderkit.html.HtmlResponseWriterImpl;
29
30
31
32
33
34
35
36
37 public class EarlyFlushHtmlResponseWriterImpl extends HtmlResponseWriterImpl
38 {
39
40
41
42 private boolean _endHeadTag;
43
44 public EarlyFlushHtmlResponseWriterImpl(Writer writer, String contentType, String characterEncoding)
45 {
46 super(writer, contentType, characterEncoding);
47 }
48
49 public EarlyFlushHtmlResponseWriterImpl(Writer writer, String contentType, String characterEncoding,
50 boolean wrapScriptContentWithXmlCommentTag)
51 {
52 super(writer, contentType, characterEncoding, wrapScriptContentWithXmlCommentTag);
53 }
54
55 public EarlyFlushHtmlResponseWriterImpl(Writer writer, String contentType, String characterEncoding,
56 boolean wrapScriptContentWithXmlCommentTag, String writerContentTypeMode) throws FacesException
57 {
58 super(writer, contentType, characterEncoding, wrapScriptContentWithXmlCommentTag, writerContentTypeMode);
59 }
60
61 @Override
62 public ResponseWriter cloneWithWriter(Writer writer)
63 {
64 EarlyFlushHtmlResponseWriterImpl newWriter
65 = new EarlyFlushHtmlResponseWriterImpl(writer, getContentType(), getCharacterEncoding(),
66 getWrapScriptContentWithXmlCommentTag(), getWriterContentTypeMode());
67 return newWriter;
68 }
69
70 @Override
71 public void startElement(String name, UIComponent uiComponent) throws IOException
72 {
73 _endHeadTag = false;
74 super.startElement(name, uiComponent);
75 }
76
77 @Override
78 public void endElement(String name) throws IOException
79 {
80 super.endElement(name);
81 if (HTML.HEAD_ELEM.equalsIgnoreCase(name))
82 {
83 _endHeadTag = true;
84 }
85 }
86
87 @Override
88 public void flush() throws IOException
89 {
90 super.flush();
91
92 if (_endHeadTag)
93 {
94 FacesContext facesContext = getFacesContext();
95 if (!facesContext.getPartialViewContext().isAjaxRequest() &&
96 !facesContext.getPartialViewContext().isPartialRequest())
97 {
98 forceFlush();
99 }
100 }
101 }
102 }