- 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
ConstructorDescriptionHtmlResponseWriter
(Writer writer, String contentType, String encoding) Constructor sets theResponseWriter
and 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 theResponseWriter
and encoding. -
Method Summary
Modifier and TypeMethodDescriptioncloneWithWriter
(Writer writer) Create a new instance of thisResponseWriter
using a differentWriter
.void
close()
Methods Fromjava.io.Writer
void
endCDATA()
Closes the CDATA block.void
Output the text for the end of a document.void
endElement
(String name) Write the end of an element.void
flush()
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
.void
Starts a CDATA block.void
Write the text that should begin a response.void
startElement
(String name, 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
void
void
writeAttribute
(String name, Object value, String componentPropertyName) Write a properly escaped attribute name and the corresponding value.void
writeComment
(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 tostartElement()
, 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
Write a properly escaped object.void
writeURIAttribute
(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, writeText
Methods inherited from class java.io.Writer
append, append, append, nullWriter
-
Constructor Details
-
HtmlResponseWriter
Constructor sets theResponseWriter
and encoding, and enables script hiding by default.- Parameters:
writer
- theResponseWriter
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
- theResponseWriter
contentType
- the content type.encoding
- the character encoding.- Throws:
FacesException
- the encoding is not recognized.
-
-
Method Details
-
close
Methods Fromjava.io.Writer
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in classWriter
- Throws:
IOException
-
flush
Flush any buffered output to the contained writer.- Specified by:
flush
in interfaceFlushable
- Specified by:
flush
in classResponseWriter
- Throws:
IOException
- if an input/output error occurs.
-
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 classResponseWriter
- Returns:
- the content type such as "text/html" for this ResponseWriter.
-
cloneWithWriter
Create a new instance of this
ResponseWriter
using a differentWriter
.- Specified by:
cloneWithWriter
in classResponseWriter
- Parameters:
writer
- TheWriter
that will be used to create anotherResponseWriter
.- Returns:
- the new
ResponseWriter
-
endDocument
Output the text for the end of a document.- Specified by:
endDocument
in 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:
endElement
in classResponseWriter
- Parameters:
name
- Name of the element to be ended- Throws:
IOException
- if an input/output error occursNullPointerException
- ifname
isnull
-
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 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:
startDocument
in 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:
startElement
in 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
- ifname
isnull
-
startCDATA
Starts a CDATA block. Nested blocks are not allowed.- Overrides:
startCDATA
in 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:
endCDATA
in classResponseWriter
- Throws:
IOException
- Since:
- 2.0
-
write
- Overrides:
write
in classWriter
- Throws:
IOException
-
write
- Overrides:
write
in classWriter
- Throws:
IOException
-
write
- Overrides:
write
in classWriter
- Throws:
IOException
-
write
- Specified by:
write
in classWriter
- Throws:
IOException
-
write
- Overrides:
write
in 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:
writeAttribute
in 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
- ifname
isnull
-
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:
writeComment
in classResponseWriter
- Parameters:
comment
- Text content of the comment- Throws:
IOException
- if an input/output error occursNullPointerException
- ifcomment
isnull
-
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
- iftext
isnull
-
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:
writeText
in 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
- iftext
isnull
-
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:
writeText
in 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
- iftext
isnull
-
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 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
- ifname
orvalue
isnull
-