org.apache.myfaces.context
Class PartialResponseWriterImpl

java.lang.Object
  extended by java.io.Writer
      extended by javax.faces.context.ResponseWriter
          extended by javax.faces.context.ResponseWriterWrapper
              extended by javax.faces.context.PartialResponseWriter
                  extended by org.apache.myfaces.context.PartialResponseWriterImpl
All Implemented Interfaces:
Closeable, Flushable, Appendable, FacesWrapper<ResponseWriter>

public class PartialResponseWriterImpl
extends PartialResponseWriter

Double buffering partial response writer to take care if embedded CDATA blocks in update delete etc...

According to the spec 13.4.4.1 Writing The Partial Response implementations have to take care to handle nested cdata blocks properly

This means we cannot allow nested CDATA according to the xml spec http://www.w3.org/TR/REC-xml/#sec-cdata-sect everything within a CDATA block is unparsed except for ]]>

Now we have following problem, that CDATA inserts can happen everywhere not only within the CDATA instructions.

What we have to do now is to double buffer CDATA blocks until their end and also!!! parse their content for CDATA embedding and replace it with an escaped end sequence.

Now parsing CDATA embedding is a little bit problematic in case of PPR because it can happen that someone simply adds a CDATA in a javascript string or somewhere else. Because he/she is not aware that we wrap the entire content into CDATA. Simply encoding and decoding of the CDATA is similarly problematic because the browser then chokes on embedded // sections

What we do for now is to simply remove // and replace all other pending cdatas with their cdata escapes ]]> becomes <![CDATA[]]]]><![CDATA[>

If this causes problems in corner cases we also can add a second encoding step in case of the cdata Javascript comment removal is not enough to cover all corner cases.

For now I will only implement this in the impl, due to the spec stating that implementations are responsible of the correct CDATA handling!

Version:
$Revision: 1237537 $ $Date: 2012-01-29 22:41:18 -0500 (Sun, 29 Jan 2012) $
Author:
Werner Punz (latest modification by $Author: lu4242 $)

Field Summary
 
Fields inherited from class javax.faces.context.PartialResponseWriter
RENDER_ALL_MARKER, VIEW_STATE_MARKER
 
Fields inherited from class java.io.Writer
lock
 
Constructor Summary
PartialResponseWriterImpl(ResponseWriter writer)
           
 
Method Summary
 Writer append(char c)
           
 Writer append(CharSequence csq)
           
 Writer append(CharSequence csq, int start, int end)
           
 ResponseWriter cloneWithWriter(Writer writer)
           
 void close()
           
 void endCDATA()
           
 void endElement(String name)
           
 void endError()
           
 void endEval()
           
 void endExtension()
           
 void endInsert()
           
 void endUpdate()
           
 void flush()
           
 void startCDATA()
           
 void startElement(String name, UIComponent component)
           
 void write(char[] cbuf)
           
 void write(char[] cbuf, int off, int len)
           
 void write(int c)
           
 void write(String str)
           
 void write(String str, int off, int len)
           
 void writeAttribute(String name, Object value, String property)
           
 void writeComment(Object comment)
           
 void writeText(char[] text, int off, int len)
           
 void writeText(Object text, String property)
           
 void writeText(Object object, UIComponent component, String string)
           
 void writeURIAttribute(String name, Object value, String property)
           
 
Methods inherited from class javax.faces.context.PartialResponseWriter
delete, endDocument, getWrapped, redirect, startDocument, startError, startEval, startExtension, startInsertAfter, startInsertBefore, startUpdate, updateAttributes
 
Methods inherited from class javax.faces.context.ResponseWriterWrapper
getCharacterEncoding, getContentType
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PartialResponseWriterImpl

public PartialResponseWriterImpl(ResponseWriter writer)
Method Detail

startCDATA

public void startCDATA()
                throws IOException
Overrides:
startCDATA in class PartialResponseWriter
Throws:
IOException

endCDATA

public void endCDATA()
              throws IOException
Overrides:
endCDATA in class PartialResponseWriter
Throws:
IOException

endInsert

public void endInsert()
               throws IOException
Overrides:
endInsert in class PartialResponseWriter
Throws:
IOException

endUpdate

public void endUpdate()
               throws IOException
Overrides:
endUpdate in class PartialResponseWriter
Throws:
IOException

endExtension

public void endExtension()
                  throws IOException
Overrides:
endExtension in class PartialResponseWriter
Throws:
IOException

endEval

public void endEval()
             throws IOException
Overrides:
endEval in class PartialResponseWriter
Throws:
IOException

endError

public void endError()
              throws IOException
Overrides:
endError in class PartialResponseWriter
Throws:
IOException

endElement

public void endElement(String name)
                throws IOException
Overrides:
endElement in class ResponseWriterWrapper
Throws:
IOException

writeComment

public void writeComment(Object comment)
                  throws IOException
Overrides:
writeComment in class ResponseWriterWrapper
Throws:
IOException

startElement

public void startElement(String name,
                         UIComponent component)
                  throws IOException
Overrides:
startElement in class ResponseWriterWrapper
Throws:
IOException

writeText

public void writeText(Object text,
                      String property)
               throws IOException
Overrides:
writeText in class ResponseWriterWrapper
Throws:
IOException

writeText

public void writeText(char[] text,
                      int off,
                      int len)
               throws IOException
Overrides:
writeText in class ResponseWriterWrapper
Throws:
IOException

write

public void write(char[] cbuf,
                  int off,
                  int len)
           throws IOException
Overrides:
write in class ResponseWriterWrapper
Throws:
IOException

cloneWithWriter

public ResponseWriter cloneWithWriter(Writer writer)
Overrides:
cloneWithWriter in class ResponseWriterWrapper

writeURIAttribute

public void writeURIAttribute(String name,
                              Object value,
                              String property)
                       throws IOException
Overrides:
writeURIAttribute in class ResponseWriterWrapper
Throws:
IOException

close

public void close()
           throws IOException
Specified by:
close in interface Closeable
Overrides:
close in class ResponseWriterWrapper
Throws:
IOException

flush

public void flush()
           throws IOException
Specified by:
flush in interface Flushable
Overrides:
flush in class ResponseWriterWrapper
Throws:
IOException

writeAttribute

public void writeAttribute(String name,
                           Object value,
                           String property)
                    throws IOException
Overrides:
writeAttribute in class ResponseWriterWrapper
Throws:
IOException

writeText

public void writeText(Object object,
                      UIComponent component,
                      String string)
               throws IOException
Overrides:
writeText in class ResponseWriterWrapper
Throws:
IOException

append

public Writer append(char c)
              throws IOException
Specified by:
append in interface Appendable
Overrides:
append in class Writer
Throws:
IOException

append

public Writer append(CharSequence csq,
                     int start,
                     int end)
              throws IOException
Specified by:
append in interface Appendable
Overrides:
append in class Writer
Throws:
IOException

append

public Writer append(CharSequence csq)
              throws IOException
Specified by:
append in interface Appendable
Overrides:
append in class Writer
Throws:
IOException

write

public void write(char[] cbuf)
           throws IOException
Overrides:
write in class Writer
Throws:
IOException

write

public void write(int c)
           throws IOException
Overrides:
write in class Writer
Throws:
IOException

write

public void write(String str,
                  int off,
                  int len)
           throws IOException
Overrides:
write in class Writer
Throws:
IOException

write

public void write(String str)
           throws IOException
Overrides:
write in class Writer
Throws:
IOException


Copyright © 2014 The Apache Software Foundation. All Rights Reserved.