Coverage Report - org.apache.myfaces.renderkit.html.EarlyFlushHtmlResponseWriterImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
EarlyFlushHtmlResponseWriterImpl
0%
0/21
0%
0/8
1.571
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one
 3  
  * or more contributor license agreements.  See the NOTICE file
 4  
  * distributed with this work for additional information
 5  
  * regarding copyright ownership.  The ASF licenses this file
 6  
  * to you under the Apache License, Version 2.0 (the
 7  
  * "License"); you may not use this file except in compliance
 8  
  * with the License.  You may obtain a copy of the License at
 9  
  *
 10  
  *   http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing,
 13  
  * software distributed under the License is distributed on an
 14  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 15  
  * KIND, either express or implied.  See the License for the
 16  
  * specific language governing permissions and limitations
 17  
  * under the License.
 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  
  * This implementation is just the default html response writer with the early flush logic. The
 32  
  * idea is detect when the end "head" element is rendered and in that moment, when the flush call
 33  
  * is done, force the flush of the current underlying writer.
 34  
  *
 35  
  * @author Leonardo Uribe
 36  
  */
 37  
 public class EarlyFlushHtmlResponseWriterImpl extends HtmlResponseWriterImpl
 38  
 {
 39  
     /**
 40  
      * Check if a end head tag was recently done. The idea is 
 41  
      */
 42  
     private boolean _endHeadTag;
 43  
 
 44  
     public EarlyFlushHtmlResponseWriterImpl(Writer writer, String contentType, String characterEncoding)
 45  
     {
 46  0
         super(writer, contentType, characterEncoding);
 47  0
     }
 48  
 
 49  
     public EarlyFlushHtmlResponseWriterImpl(Writer writer, String contentType, String characterEncoding, 
 50  
             boolean wrapScriptContentWithXmlCommentTag)
 51  
     {
 52  0
         super(writer, contentType, characterEncoding, wrapScriptContentWithXmlCommentTag);
 53  0
     }
 54  
 
 55  
     public EarlyFlushHtmlResponseWriterImpl(Writer writer, String contentType, String characterEncoding,
 56  
             boolean wrapScriptContentWithXmlCommentTag, String writerContentTypeMode) throws FacesException
 57  
     {
 58  0
         super(writer, contentType, characterEncoding, wrapScriptContentWithXmlCommentTag, writerContentTypeMode);
 59  0
     }
 60  
 
 61  
     @Override
 62  
     public ResponseWriter cloneWithWriter(Writer writer)
 63  
     {
 64  0
         EarlyFlushHtmlResponseWriterImpl newWriter
 65  
                 = new EarlyFlushHtmlResponseWriterImpl(writer, getContentType(), getCharacterEncoding(), 
 66  
                         getWrapScriptContentWithXmlCommentTag(), getWriterContentTypeMode());
 67  0
         return newWriter;        
 68  
     }
 69  
 
 70  
     @Override
 71  
     public void startElement(String name, UIComponent uiComponent) throws IOException
 72  
     {
 73  0
         _endHeadTag = false;
 74  0
         super.startElement(name, uiComponent);
 75  0
     }
 76  
 
 77  
     @Override
 78  
     public void endElement(String name) throws IOException
 79  
     {
 80  0
         super.endElement(name);
 81  0
         if (HTML.HEAD_ELEM.equalsIgnoreCase(name))
 82  
         {
 83  0
             _endHeadTag = true;
 84  
         }
 85  0
     }
 86  
     
 87  
     @Override
 88  
     public void flush() throws IOException
 89  
     {
 90  0
         super.flush();
 91  
         
 92  0
         if (_endHeadTag)
 93  
         {
 94  0
             FacesContext facesContext = getFacesContext();
 95  0
             if (!facesContext.getPartialViewContext().isAjaxRequest() &&
 96  
                 !facesContext.getPartialViewContext().isPartialRequest())
 97  
             {
 98  0
                 forceFlush();
 99  
             }
 100  
         }
 101  0
     }
 102  
 }