Class 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 Detail

      • 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 Detail

      • 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
      • 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.
      • 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
      • 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