com.sun.faces.renderkit.html_basic
Class HtmlResponseWriter

java.lang.Object
  extended by java.io.Writer
      extended by javax.faces.context.ResponseWriter
          extended by com.sun.faces.renderkit.html_basic.HtmlResponseWriter
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable, java.lang.Appendable

public class HtmlResponseWriter
extends javax.faces.context.ResponseWriter

HtmlResponseWriter is an Html specific implementation of the ResponseWriter abstract class. Kudos to Adam Winer (Oracle) for much of this code.


Field Summary
 
Fields inherited from class java.io.Writer
lock
 
Constructor Summary
HtmlResponseWriter(java.io.Writer writer, java.lang.String contentType, java.lang.String encoding)
          Constructor sets the ResponseWriter and encoding, and enables script hiding by default.
HtmlResponseWriter(java.io.Writer writer, java.lang.String contentType, java.lang.String encoding, java.lang.Boolean isScriptHidingEnabled)
          Constructor sets the ResponseWriter and encoding.
 
Method Summary
 javax.faces.context.ResponseWriter cloneWithWriter(java.io.Writer writer)
          Create a new instance of this ResponseWriter using a different Writer.
 void close()
          Methods From java.io.Writer
 void endDocument()
          Output the text for the end of a document.
 void endElement(java.lang.String name)
          Write the end of an element.
 void flush()
          Flush any buffered output to the contained writer.
 java.lang.String getCharacterEncoding()
           
 java.lang.String getContentType()
           
 void startDocument()
          Write the text that should begin a response.
 void startElement(java.lang.String name, javax.faces.component.UIComponent componentForElement)
          Write the start of an element, up to and including the element name.
 void write(char[] cbuf)
           
 void write(char[] cbuf, int off, int len)
           
 void write(int c)
           
 void write(java.lang.String str)
           
 void write(java.lang.String str, int off, int len)
           
 void writeAttribute(java.lang.String name, java.lang.Object value, java.lang.String componentPropertyName)
          Write a properly escaped attribute name and the corresponding value.
 void writeComment(java.lang.Object comment)
          Write a comment string containing the specified text.
 void writeText(char text)
          Write a properly escaped single character, If there is an open element that has been created by a call to startElement(), that element will be closed first.
 void writeText(char[] text)
          Write properly escaped text from a character array.
 void writeText(char[] text, int off, int len)
          Write properly escaped text from a character array.
 void writeText(java.lang.Object text, java.lang.String componentPropertyName)
          Write a properly escaped object.
 void writeURIAttribute(java.lang.String name, java.lang.Object value, java.lang.String componentPropertyName)
          Write a properly encoded URI attribute name and the corresponding value.
 
Methods inherited from class javax.faces.context.ResponseWriter
writeText
 
Methods inherited from class java.io.Writer
append, append, append
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HtmlResponseWriter

public HtmlResponseWriter(java.io.Writer writer,
                          java.lang.String contentType,
                          java.lang.String encoding)
                   throws javax.faces.FacesException
Constructor sets the ResponseWriter and encoding, and enables script hiding by default.

Parameters:
writer - the ResponseWriter
contentType - the content type.
encoding - the character encoding.
Throws:
javax.faces.FacesException - the encoding is not recognized.

HtmlResponseWriter

public HtmlResponseWriter(java.io.Writer writer,
                          java.lang.String contentType,
                          java.lang.String encoding,
                          java.lang.Boolean isScriptHidingEnabled)
                   throws javax.faces.FacesException
Constructor sets the ResponseWriter and encoding.

Parameters:
writer - the ResponseWriter
contentType - the content type.
encoding - the character encoding.
isScriptHidingEnabled - true if the writer should attempt to hide JS from older browsers
Throws:
javax.faces.FacesException - the encoding is not recognized.
Method Detail

close

public void close()
           throws java.io.IOException
Methods From java.io.Writer

Specified by:
close in interface java.io.Closeable
Specified by:
close in class java.io.Writer
Throws:
java.io.IOException

flush

public void flush()
           throws java.io.IOException
Flush any buffered output to the contained writer.

Specified by:
flush in interface java.io.Flushable
Specified by:
flush in class javax.faces.context.ResponseWriter
Throws:
java.io.IOException - if an input/output error occurs.

getContentType

public java.lang.String getContentType()
Specified by:
getContentType in class javax.faces.context.ResponseWriter
Returns:
the content type such as "text/html" for this ResponseWriter.

cloneWithWriter

public javax.faces.context.ResponseWriter cloneWithWriter(java.io.Writer writer)

Create a new instance of this ResponseWriter using a different Writer.

Specified by:
cloneWithWriter in class javax.faces.context.ResponseWriter
Parameters:
writer - The Writer that will be used to create another ResponseWriter.

endDocument

public void endDocument()
                 throws java.io.IOException
Output the text for the end of a document.

Specified by:
endDocument in class javax.faces.context.ResponseWriter
Throws:
java.io.IOException

endElement

public void endElement(java.lang.String name)
                throws java.io.IOException

Write the end of an element. This method will first close any open element created by a call to startElement().

Specified by:
endElement in class javax.faces.context.ResponseWriter
Parameters:
name - Name of the element to be ended
Throws:
java.io.IOException - if an input/output error occurs
java.lang.NullPointerException - if name is null

getCharacterEncoding

public java.lang.String getCharacterEncoding()
Specified by:
getCharacterEncoding in class javax.faces.context.ResponseWriter
Returns:
the character encoding, such as "ISO-8859-1" for this ResponseWriter. Refer to: theIANA for a list of character encodings.

startDocument

public void startDocument()
                   throws java.io.IOException

Write the text that should begin a response.

Specified by:
startDocument in class javax.faces.context.ResponseWriter
Throws:
java.io.IOException - if an input/output error occurs

startElement

public void startElement(java.lang.String name,
                         javax.faces.component.UIComponent componentForElement)
                  throws java.io.IOException

Write the start of an element, up to and including the element name. Clients call writeAttribute() or writeURIAttribute() methods to add attributes after calling this method.

Specified by:
startElement in class javax.faces.context.ResponseWriter
Parameters:
name - Name of the starting element
componentForElement - The UIComponent instance that applies to this element. This argument may be null.
Throws:
java.io.IOException - if an input/output error occurs
java.lang.NullPointerException - if name is null

write

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

write

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

write

public void write(java.lang.String str)
           throws java.io.IOException
Overrides:
write in class java.io.Writer
Throws:
java.io.IOException

write

public void write(char[] cbuf,
                  int off,
                  int len)
           throws java.io.IOException
Specified by:
write in class java.io.Writer
Throws:
java.io.IOException

write

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

writeAttribute

public void writeAttribute(java.lang.String name,
                           java.lang.Object value,
                           java.lang.String componentPropertyName)
                    throws java.io.IOException

Write a properly escaped attribute name and the corresponding value. The value text will be converted to a String if necessary. This method may only be called after a call to startElement(), and before the opened element has been closed.

Specified by:
writeAttribute in class javax.faces.context.ResponseWriter
Parameters:
name - Attribute name to be added
value - Attribute value to be added
componentPropertyName - The name of the component property to which this attribute argument applies. This argument may be null.
Throws:
java.lang.IllegalStateException - if this method is called when there is no currently open element
java.io.IOException - if an input/output error occurs
java.lang.NullPointerException - if name is null

writeComment

public void writeComment(java.lang.Object comment)
                  throws java.io.IOException

Write a comment string containing the specified text. The text will be converted to a String if necessary. If there is an open element that has been created by a call to startElement(), that element will be closed first.

Specified by:
writeComment in class javax.faces.context.ResponseWriter
Parameters:
comment - Text content of the comment
Throws:
java.io.IOException - if an input/output error occurs
java.lang.NullPointerException - if comment is null

writeText

public void writeText(char text)
               throws java.io.IOException

Write a properly escaped single character, If there is an open element that has been created by a call to startElement(), that element will be closed first.

All angle bracket occurrences in the argument must be escaped using the > < syntax.

Parameters:
text - Text to be written
Throws:
java.io.IOException - if an input/output error occurs

writeText

public void writeText(char[] text)
               throws java.io.IOException

Write properly escaped text from a character array. The output from this command is identical to the invocation: writeText(c, 0, c.length). If there is an open element that has been created by a call to startElement(), that element will be closed first.

All angle bracket occurrences in the argument must be escaped using the > < syntax.

Parameters:
text - Text to be written
Throws:
java.io.IOException - if an input/output error occurs
java.lang.NullPointerException - if text is null

writeText

public void writeText(java.lang.Object text,
                      java.lang.String componentPropertyName)
               throws java.io.IOException

Write a properly escaped object. The object will be converted to a String if necessary. If there is an open element that has been created by a call to startElement(), that element will be closed first.

Specified by:
writeText in class javax.faces.context.ResponseWriter
Parameters:
text - Text to be written
componentPropertyName - The name of the component property to which this text argument applies. This argument may be null.
Throws:
java.io.IOException - if an input/output error occurs
java.lang.NullPointerException - if text is null

writeText

public void writeText(char[] text,
                      int off,
                      int len)
               throws java.io.IOException

Write properly escaped text from a character array. If there is an open element that has been created by a call to startElement(), that element will be closed first.

All angle bracket occurrences in the argument must be escaped using the > < syntax.

Specified by:
writeText in class javax.faces.context.ResponseWriter
Parameters:
text - Text to be written
off - Starting offset (zero-relative)
len - Number of characters to be written
Throws:
java.lang.IndexOutOfBoundsException - if the calculated starting or ending position is outside the bounds of the character array
java.io.IOException - if an input/output error occurs
java.lang.NullPointerException - if text is null

writeURIAttribute

public void writeURIAttribute(java.lang.String name,
                              java.lang.Object value,
                              java.lang.String componentPropertyName)
                       throws java.io.IOException

Write a properly encoded URI attribute name and the corresponding value. The value text will be converted to a String if necessary). This method may only be called after a call to startElement(), and before the opened element has been closed.

Specified by:
writeURIAttribute in class javax.faces.context.ResponseWriter
Parameters:
name - Attribute name to be added
value - Attribute value to be added
componentPropertyName - The name of the component property to which this attribute argument applies. This argument may be null.
Throws:
java.lang.IllegalStateException - if this method is called when there is no currently open element
java.io.IOException - if an input/output error occurs
java.lang.NullPointerException - if name or value is null


Copyright ? 2002-2006 Sun Microsystems, Inc. All Rights Reserved.