Class HtmlResponseWriter

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

public class HtmlResponseWriter extends ResponseWriter

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

  • Constructor Details

    • HtmlResponseWriter

      public HtmlResponseWriter(Writer writer, String contentType, String encoding) throws 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:
      FacesException - the encoding is not recognized.
    • HtmlResponseWriter

      public HtmlResponseWriter(Writer writer, String contentType, String encoding, Boolean isScriptHidingEnabled, Boolean isScriptInAttributeValueEnabled, WebConfiguration.DisableUnicodeEscaping disableUnicodeEscaping, boolean isPartial) throws FacesException

      Constructor sets the ResponseWriter and encoding.

      The argument configPrefs is a map of configurable prefs that affect this instance's behavior. Supported keys are:

      BooleanWebContextInitParameter.EnableJSStyleHiding: true if the writer should attempt to hide JS from older browsers

      Parameters:
      writer - the ResponseWriter
      contentType - the content type.
      encoding - the character encoding.
      Throws:
      FacesException - the encoding is not recognized.
  • Method Details

    • close

      public void close() throws IOException
      Methods From java.io.Writer
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in class Writer
      Throws:
      IOException
    • flush

      public void flush() throws IOException
      Flush any buffered output to the contained writer.
      Specified by:
      flush in interface Flushable
      Specified by:
      flush in class ResponseWriter
      Throws:
      IOException - if an input/output error occurs.
    • getContentType

      public String getContentType()
      Description copied from class: ResponseWriter

      Return the content type (such as "text/html") for this ResponseWriter. Note: this must not include the "charset=" suffix.

      Specified by:
      getContentType in class ResponseWriter
      Returns:
      the content type such as "text/html" for this ResponseWriter.
    • cloneWithWriter

      public ResponseWriter cloneWithWriter(Writer writer)

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

      Specified by:
      cloneWithWriter in class ResponseWriter
      Parameters:
      writer - The Writer that will be used to create another ResponseWriter.
      Returns:
      the new ResponseWriter
    • endDocument

      public void endDocument() throws IOException
      Output the text for the end of a document.
      Specified by:
      endDocument in class ResponseWriter
      Throws:
      IOException - if an input/output error occurs
    • endElement

      public void endElement(String name) throws 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 ResponseWriter
      Parameters:
      name - Name of the element to be ended
      Throws:
      IOException - if an input/output error occurs
      NullPointerException - if name is null
    • getCharacterEncoding

      public String getCharacterEncoding()
      Description copied from class: ResponseWriter

      Return the character encoding (such as "ISO-8859-1") for this ResponseWriter. Please see the IANA for a list of character encodings.

      Specified by:
      getCharacterEncoding in class 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 IOException

      Write the text that should begin a response.

      Specified by:
      startDocument in class ResponseWriter
      Throws:
      IOException - if an input/output error occurs
    • startElement

      public void startElement(String name, UIComponent componentForElement) throws 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 ResponseWriter
      Parameters:
      name - Name of the starting element
      componentForElement - The UIComponent instance that applies to this element. This argument may be null.
      Throws:
      IOException - if an input/output error occurs
      NullPointerException - if name is null
    • startCDATA

      public void startCDATA() throws IOException
      Starts a CDATA block. Nested blocks are not allowed.
      Overrides:
      startCDATA in class ResponseWriter
      Throws:
      IOException - on a read/write error
      IllegalStateException - If startCDATA is called a second time before endCDATA.
      Since:
      2.0
    • endCDATA

      public void endCDATA() throws IOException
      Closes the CDATA block.
      Overrides:
      endCDATA in class ResponseWriter
      Throws:
      IOException
      Since:
      2.0
    • 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) throws IOException
      Overrides:
      write in class Writer
      Throws:
      IOException
    • write

      public void write(char[] cbuf, int off, int len) throws IOException
      Specified by:
      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
    • writeAttribute

      public void writeAttribute(String name, Object value, String componentPropertyName) throws 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 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:
      IllegalStateException - if this method is called when there is no currently open element
      IOException - if an input/output error occurs
      NullPointerException - if name is null
    • writeComment

      public void writeComment(Object comment) throws 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 ResponseWriter
      Parameters:
      comment - Text content of the comment
      Throws:
      IOException - if an input/output error occurs
      NullPointerException - if comment is null
    • writeText

      public void writeText(char text) throws 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:
      IOException - if an input/output error occurs
    • writeText

      public void writeText(char[] text) throws 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:
      IOException - if an input/output error occurs
      NullPointerException - if text is null
    • writeText

      public void writeText(Object text, String componentPropertyName) throws 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 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:
      IOException - if an input/output error occurs
      NullPointerException - if text is null
    • writeText

      public void writeText(char[] text, int off, int len) throws 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 ResponseWriter
      Parameters:
      text - Text to be written
      off - Starting offset (zero-relative)
      len - Number of characters to be written
      Throws:
      IndexOutOfBoundsException - if the calculated starting or ending position is outside the bounds of the character array
      IOException - if an input/output error occurs
      NullPointerException - if text is null
    • writeURIAttribute

      public void writeURIAttribute(String name, Object value, String componentPropertyName) throws 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 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:
      IllegalStateException - if this method is called when there is no currently open element
      IOException - if an input/output error occurs
      NullPointerException - if name or value is null