- All Implemented Interfaces:
Closeable,Flushable,Appendable,AutoCloseable
HtmlResponseWriter is an Html specific implementation of the ResponseWriter abstract
class. Kudos to Adam Winer (Oracle) for much of this code.
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionHtmlResponseWriter(Writer writer, String contentType, String encoding) Constructor sets theResponseWriterand encoding, and enables script hiding by default.HtmlResponseWriter(Writer writer, String contentType, String encoding, Boolean isScriptHidingEnabled, Boolean isScriptInAttributeValueEnabled, WebConfiguration.DisableUnicodeEscaping disableUnicodeEscaping, boolean isPartial) Constructor sets theResponseWriterand encoding. -
Method Summary
Modifier and TypeMethodDescriptioncloneWithWriter(Writer writer) Create a new instance of thisResponseWriterusing a differentWriter.voidclose()Methods Fromjava.io.WritervoidendCDATA()Closes the CDATA block.voidOutput the text for the end of a document.voidendElement(String name) Write the end of an element.voidflush()Flush any buffered output to the contained writer.Return the character encoding (such as "ISO-8859-1") for thisResponseWriter.Return the content type (such as "text/html") for thisResponseWriter.voidStarts a CDATA block.voidWrite the text that should begin a response.voidstartElement(String name, UIComponent componentForElement) Write the start of an element, up to and including the element name.voidwrite(char[] cbuf) voidwrite(char[] cbuf, int off, int len) voidwrite(int c) voidvoidvoidwriteAttribute(String name, Object value, String componentPropertyName) Write a properly escaped attribute name and the corresponding value.voidwriteComment(Object comment) Write a comment string containing the specified text.voidwriteText(char text) Write a properly escaped single character, If there is an open element that has been created by a call tostartElement(), that element will be closed first.voidwriteText(char[] text) Write properly escaped text from a character array.voidwriteText(char[] text, int off, int len) Write properly escaped text from a character array.voidWrite a properly escaped object.voidwriteURIAttribute(String name, Object value, String componentPropertyName) Write a properly encoded URI attribute name and the corresponding value.Methods inherited from class jakarta.faces.context.ResponseWriter
writeDoctype, writePreamble, writeTextMethods inherited from class java.io.Writer
append, append, append, nullWriter
-
Constructor Details
-
HtmlResponseWriter
Constructor sets theResponseWriterand encoding, and enables script hiding by default.- Parameters:
writer- theResponseWritercontentType- 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
ResponseWriterand encoding.The argument configPrefs is a map of configurable prefs that affect this instance's behavior. Supported keys are:
BooleanWebContextInitParameter.EnableJSStyleHiding:
trueif the writer should attempt to hide JS from older browsers- Parameters:
writer- theResponseWritercontentType- the content type.encoding- the character encoding.- Throws:
FacesException- the encoding is not recognized.
-
-
Method Details
-
close
Methods Fromjava.io.Writer- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein classWriter- Throws:
IOException
-
flush
Flush any buffered output to the contained writer.- Specified by:
flushin interfaceFlushable- Specified by:
flushin classResponseWriter- Throws:
IOException- if an input/output error occurs.
-
getContentType
Description copied from class:ResponseWriterReturn the content type (such as "text/html") for this
ResponseWriter. Note: this must not include the "charset=" suffix.- Specified by:
getContentTypein classResponseWriter- Returns:
- the content type such as "text/html" for this ResponseWriter.
-
cloneWithWriter
Create a new instance of this
ResponseWriterusing a differentWriter.- Specified by:
cloneWithWriterin classResponseWriter- Parameters:
writer- TheWriterthat will be used to create anotherResponseWriter.- Returns:
- the new
ResponseWriter
-
endDocument
Output the text for the end of a document.- Specified by:
endDocumentin classResponseWriter- Throws:
IOException- if an input/output error occurs
-
endElement
Write the end of an element. This method will first close any open element created by a call to
startElement().- Specified by:
endElementin classResponseWriter- Parameters:
name- Name of the element to be ended- Throws:
IOException- if an input/output error occursNullPointerException- ifnameisnull
-
getCharacterEncoding
Description copied from class:ResponseWriterReturn the character encoding (such as "ISO-8859-1") for this
ResponseWriter. Please see the IANA for a list of character encodings.- Specified by:
getCharacterEncodingin classResponseWriter- Returns:
- the character encoding, such as "ISO-8859-1" for this ResponseWriter. Refer to: theIANA for a list of character encodings.
-
startDocument
Write the text that should begin a response.
- Specified by:
startDocumentin classResponseWriter- Throws:
IOException- if an input/output error occurs
-
startElement
Write the start of an element, up to and including the element name. Clients call
writeAttribute()orwriteURIAttribute()methods to add attributes after calling this method.- Specified by:
startElementin classResponseWriter- Parameters:
name- Name of the starting elementcomponentForElement- The UIComponent instance that applies to this element. This argument may benull.- Throws:
IOException- if an input/output error occursNullPointerException- ifnameisnull
-
startCDATA
Starts a CDATA block. Nested blocks are not allowed.- Overrides:
startCDATAin classResponseWriter- Throws:
IOException- on a read/write errorIllegalStateException- If startCDATA is called a second time before endCDATA.- Since:
- 2.0
-
endCDATA
Closes the CDATA block.- Overrides:
endCDATAin classResponseWriter- Throws:
IOException- Since:
- 2.0
-
write
- Overrides:
writein classWriter- Throws:
IOException
-
write
- Overrides:
writein classWriter- Throws:
IOException
-
write
- Overrides:
writein classWriter- Throws:
IOException
-
write
- Specified by:
writein classWriter- Throws:
IOException
-
write
- Overrides:
writein classWriter- 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:
writeAttributein classResponseWriter- Parameters:
name- Attribute name to be addedvalue- Attribute value to be addedcomponentPropertyName- The name of the component property to which this attribute argument applies. This argument may benull.- Throws:
IllegalStateException- if this method is called when there is no currently open elementIOException- if an input/output error occursNullPointerException- ifnameisnull
-
writeComment
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:
writeCommentin classResponseWriter- Parameters:
comment- Text content of the comment- Throws:
IOException- if an input/output error occursNullPointerException- ifcommentisnull
-
writeText
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
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 tostartElement(), 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 occursNullPointerException- iftextisnull
-
writeText
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:
writeTextin classResponseWriter- Parameters:
text- Text to be writtencomponentPropertyName- The name of the component property to which this text argument applies. This argument may benull.- Throws:
IOException- if an input/output error occursNullPointerException- iftextisnull
-
writeText
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:
writeTextin classResponseWriter- Parameters:
text- Text to be writtenoff- 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 arrayIOException- if an input/output error occursNullPointerException- iftextisnull
-
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:
writeURIAttributein classResponseWriter- Parameters:
name- Attribute name to be addedvalue- Attribute value to be addedcomponentPropertyName- The name of the component property to which this attribute argument applies. This argument may benull.- Throws:
IllegalStateException- if this method is called when there is no currently open elementIOException- if an input/output error occursNullPointerException- ifnameorvalueisnull
-