Top Description Fields Constructors Methods
com.sun.faces.renderkit.html_basic

public Class HtmlResponseWriter

extends ResponseWriter
Class Inheritance
Imports
java.io.IOException, .Writer, java.util.LinkedList, .Map, java.util.concurrent.ConcurrentHashMap, java.util.regex.Matcher, .Pattern, com.sun.faces.RIConstants, com.sun.faces.config.WebConfiguration, .WebConfiguration.BooleanWebContextInitParameter, com.sun.faces.io.FastStringWriter, com.sun.faces.util.HtmlUtils, .MessageUtils, jakarta.el.ValueExpression, jakarta.faces.FacesException, jakarta.faces.component.UIComponent, jakarta.faces.context.ExternalContext, .FacesContext, .ResponseWriter, jakarta.faces.render.Renderer

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

Field Summary

Modifier and TypeField and Description
private FastStringWriter
private static final String
private char[]
pack-priv static final Pattern
pack-priv static final Pattern
pack-priv static final Pattern
pack-priv static final Pattern
private char[]
private int
private static final int
private char[]
private static final int
private char[]
private boolean
private String
private WebConfiguration.DisableUnicodeEscaping
private boolean
private LinkedList<String>
private String
private static final char[]
private static final char[]
private static final char[]
private static final char[]
private boolean
private boolean
private boolean
private boolean
private boolean
private Boolean
private Boolean
private boolean
private boolean
private Writer
private Map<String, Object>
private FastStringWriter
private boolean
private char[]
private boolean
private boolean
private Writer
private boolean

Constructor Summary

AccessConstructor and Description
public
HtmlResponseWriter(Writer
the ResponseWriter
writer
,
String
the content type.
contentType
,
String
the character encoding.
encoding
)

Constructor sets the ResponseWriter and encoding, and enables script hiding by default.

public
HtmlResponseWriter(Writer
the ResponseWriter
writer
,
String
the content type.
contentType
,
String
the character encoding.
encoding
,
Boolean isScriptHidingEnabled, Boolean isScriptInAttributeValueEnabled, WebConfiguration.DisableUnicodeEscaping disableUnicodeEscaping, boolean isPartial)

Constructor sets the ResponseWriter and encoding.

Method Summary

Modifier and TypeMethod and Description
private void
appendBuffer(char[] cbuf)

private void
appendBuffer(char c)

public ResponseWriter
cloneWithWriter(Writer
The Writer that will be used to create another ResponseWriter.
writer
)

Implements abstract jakarta.faces.context.ResponseWriter.cloneWithWriter.

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

public void
close()

Implements abstract java.io.Writer.close.

Implements java.io.Closeable.close.

Methods From java.io.Writer

private void
closeStartIfNecessary()

This method automatically closes a previous element (if not already closed).

private void
private boolean
public void
endCDATA()

Overrides jakarta.faces.context.ResponseWriter.endCDATA.

Closes the CDATA block.

public void
endDocument()

Implements abstract jakarta.faces.context.ResponseWriter.endDocument.

Output the text for the end of a document.

public void
endElement(String
Name of the element to be ended
name
)

Implements abstract jakarta.faces.context.ResponseWriter.endElement.

Write the end of an element.

private void
public void
flush()

Implements abstract jakarta.faces.context.ResponseWriter.flush.

Implements java.io.Flushable.flush.

Flush any buffered output to the contained writer.

private void
private void
private String
public String

Returns:

the character encoding, such as "ISO-8859-1" for this ResponseWriter. Refer to: theIANA for a list of character encodings.
getCharacterEncoding
()

Implements abstract jakarta.faces.context.ResponseWriter.getCharacterEncoding.

Return the character encoding (such as "ISO-8859-1") for this ResponseWriter.

public String

Returns:

the content type such as "text/html" for this ResponseWriter.
getContentType
()

Implements abstract jakarta.faces.context.ResponseWriter.getContentType.

Return the content type (such as "text/html") for this ResponseWriter.

private String
private WebConfiguration
private boolean
private boolean
private String
private String
public void
public void
startDocument()

Implements abstract jakarta.faces.context.ResponseWriter.startDocument.

Write the text that should begin a response.

public void
startElement(String
Name of the starting element
name
,
UIComponent
The UIComponent instance that applies to this element. This argument may be null.
componentForElement
)

Implements abstract jakarta.faces.context.ResponseWriter.startElement.

Write the start of an element, up to and including the element name.

public void
write(char[]
Array of characters to be written
cbuf
)

Overrides java.io.Writer.write.

Writes an array of characters.

public void
write(int
int specifying a character to be written
c
)

Overrides java.io.Writer.write.

Writes a single character.

public void
write(String
String to be written
str
)

Overrides java.io.Writer.write.

Writes a string.

public void
write(char[]
Array of characters
cbuf
,
int
Offset from which to start writing characters
off
,
int
Number of characters to write
len
)

Implements abstract java.io.Writer.write.

Writes a portion of an array of characters.

public void
write(String
A String
str
,
int
Offset from which to start writing characters
off
,
int
Number of characters to write
len
)

Overrides java.io.Writer.write.

Writes a portion of a string.

public void
writeAttribute(String
Attribute name to be added
name
,
Object
Attribute value to be added
value
,
String
The name of the component property to which this attribute argument applies. This argument may be null.
componentPropertyName
)

Implements abstract jakarta.faces.context.ResponseWriter.writeAttribute.

Write a properly escaped attribute name and the corresponding value.

public void
writeComment(Object
Text content of the comment
comment
)

Implements abstract jakarta.faces.context.ResponseWriter.writeComment.

Write a comment string containing the specified text.

private void
writeEscaped(char[] cbuf, int offset, int length)

public void
writeText(char
Text to be written
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.

public void
writeText(char[]
Text to be written
text
)

Write properly escaped text from a character array.

public void
writeText(Object
Text to be written
text
,
String
The name of the component property to which this text argument applies. This argument may be null.
componentPropertyName
)

Implements abstract jakarta.faces.context.ResponseWriter.writeText.

Write a properly escaped object.

public void
writeText(char[]
Text to be written
text
,
int
Starting offset (zero-relative)
off
,
int
Number of characters to be written
len
)

Implements abstract jakarta.faces.context.ResponseWriter.writeText.

Write properly escaped text from a character array.

private void
writeUnescapedCData(char[] cbuf, int offset, int length)

When writing un-escaped CDATA, "]]>" sequence still has to be escaped by breaking CDATA block.

public void
writeURIAttribute(String
Attribute name to be added
name
,
Object
Attribute value to be added
value
,
String
The name of the component property to which this attribute argument applies. This argument may be null.
componentPropertyName
)

Implements abstract jakarta.faces.context.ResponseWriter.writeURIAttribute.

Write a properly encoded URI attribute name and the corresponding value.

private void
writeURIAttributeIgnoringPassThroughAttributes(String name, Object value, String componentPropertyName, boolean isPassthrough)

Inherited from jakarta.faces.context.ResponseWriter:
writeDoctypewritePreamblewriteText

Field Detail

attributesBufferback to summary
private FastStringWriter attributesBuffer
BREAKCDATAback to summary
private static final String BREAKCDATA
bufferback to summary
private char[] buffer
CDATA_END_SLASH_SLASHback to summary
pack-priv static final Pattern CDATA_END_SLASH_SLASH
CDATA_END_SLASH_STARback to summary
pack-priv static final Pattern CDATA_END_SLASH_STAR
CDATA_START_SLASH_SLASHback to summary
pack-priv static final Pattern CDATA_START_SLASH_SLASH
CDATA_START_SLASH_STARback to summary
pack-priv static final Pattern CDATA_START_SLASH_STAR
cdataBufferback to summary
private char[] cdataBuffer
cdataBufferLengthback to summary
private int cdataBufferLength
cdataBufferSizeback to summary
private static final int cdataBufferSize
cdataTextBufferback to summary
private char[] cdataTextBuffer
cdataTextBufferSizeback to summary
private static final int cdataTextBufferSize
charHolderback to summary
private char[] charHolder
closeStartback to summary
private boolean closeStart
contentTypeback to summary
private String contentType
disableUnicodeEscapingback to summary
private WebConfiguration.DisableUnicodeEscaping disableUnicodeEscaping
dontEscapeback to summary
private boolean dontEscape
elementNamesback to summary
private LinkedList<String> elementNames
encodingback to summary
private String encoding
ESCAPEDENDback to summary
private static final char[] ESCAPEDEND
ESCAPEDLTback to summary
private static final char[] ESCAPEDLT
ESCAPEDSINGLEBRACKETback to summary
private static final char[] ESCAPEDSINGLEBRACKET
ESCAPEDSTARTback to summary
private static final char[] ESCAPEDSTART
escapeIsoback to summary
private boolean escapeIso
escapeUnicodeback to summary
private boolean escapeUnicode
isCdataback to summary
private boolean isCdata
isPartialback to summary
private boolean isPartial
isScriptback to summary
private boolean isScript
isScriptHidingEnabledback to summary
private Boolean isScriptHidingEnabled
isScriptInAttributeValueEnabledback to summary
private Boolean isScriptInAttributeValueEnabled
isStyleback to summary
private boolean isStyle
isXhtmlback to summary
private boolean isXhtml
origWriterback to summary
private Writer origWriter
passthroughAttributesback to summary
private Map<String, Object> passthroughAttributes
scriptBufferback to summary
private FastStringWriter scriptBuffer
scriptOrStyleSrcback to summary
private boolean scriptOrStyleSrc
textBufferback to summary
private char[] textBuffer
withinScriptback to summary
private boolean withinScript
withinStyleback to summary
private boolean withinStyle
writerback to summary
private Writer writer
writingCdataback to summary
private boolean writingCdata

Constructor Detail

HtmlResponseWriterback to summary
public HtmlResponseWriter(Writer writer, String contentType, String encoding) throws FacesException

Constructor sets the ResponseWriter and encoding, and enables script hiding by default.

Parameters
writer:Writer

the ResponseWriter

contentType:String

the content type.

encoding:String

the character encoding.

Exceptions
FacesException:
the encoding is not recognized.
HtmlResponseWriterback to summary
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:Writer

the ResponseWriter

contentType:String

the content type.

encoding:String

the character encoding.

Exceptions
FacesException:
the encoding is not recognized.

Method Detail

appendBufferback to summary
private void appendBuffer(char[] cbuf) throws IOException
appendBufferback to summary
private void appendBuffer(char c) throws IOException
cloneWithWriterback to summary
public ResponseWriter cloneWithWriter(Writer writer)

Implements abstract jakarta.faces.context.ResponseWriter.cloneWithWriter.

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

Parameters
writer:Writer

The Writer that will be used to create another ResponseWriter.

Returns:ResponseWriter

Doc from jakarta.faces.context.ResponseWriter.cloneWithWriter.

the new ResponseWriter

Annotations
@Override
closeback to summary
public void close() throws IOException

Implements abstract java.io.Writer.close.

Implements java.io.Closeable.close.

Methods From java.io.Writer

Annotations
@Override
Exceptions
IOException:

Doc from java.io.Writer.close.

If an I/O error occurs

closeStartIfNecessaryback to summary
private void closeStartIfNecessary() throws IOException

This method automatically closes a previous element (if not already closed).

Exceptions
IOException:
if an error occurs writing
considerPassThroughAttributesback to summary
private void considerPassThroughAttributes(Map<String, Object> toCopy)
containsPassThroughAttributeback to summary
private boolean containsPassThroughAttribute(String attrName)
endCDATAback to summary
public void endCDATA() throws IOException

Overrides jakarta.faces.context.ResponseWriter.endCDATA.

Closes the CDATA block.

Annotations
@Override
Exceptions
IOException:

Doc from jakarta.faces.context.ResponseWriter.endCDATA.

if input/output error occures

Since
2.0
endDocumentback to summary
public void endDocument() throws IOException

Implements abstract jakarta.faces.context.ResponseWriter.endDocument.

Output the text for the end of a document.

Annotations
@Override
Exceptions
IOException:

Doc from jakarta.faces.context.ResponseWriter.endDocument.

if an input/output error occurs

endElementback to summary
public void endElement(String name) throws IOException

Implements abstract jakarta.faces.context.ResponseWriter.endElement.

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

Parameters
name:String

Name of the element to be ended

Annotations
@Override
Exceptions
IOException:
if an input/output error occurs
NullPointerException:
if name is null
ensureTextBufferCapacityback to summary
private void ensureTextBufferCapacity(String source)
flushback to summary
public void flush() throws IOException

Implements abstract jakarta.faces.context.ResponseWriter.flush.

Implements java.io.Flushable.flush.

Flush any buffered output to the contained writer.

Annotations
@Override
Exceptions
IOException:
if an input/output error occurs.
flushAttributesback to summary
private void flushAttributes() throws IOException
flushBufferback to summary
private void flushBuffer() throws IOException
getAttributeValueback to summary
private String getAttributeValue(FacesContext context, Object valObj)
getCharacterEncodingback to summary
public String getCharacterEncoding()

Implements abstract jakarta.faces.context.ResponseWriter.getCharacterEncoding.

Doc from jakarta.faces.context.ResponseWriter.getCharacterEncoding.

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

Returns:String

the character encoding, such as "ISO-8859-1" for this ResponseWriter. Refer to: theIANA for a list of character encodings.

Annotations
@Override
getContentTypeback to summary
public String getContentType()

Implements abstract jakarta.faces.context.ResponseWriter.getContentType.

Doc from jakarta.faces.context.ResponseWriter.getContentType.

Return the content type (such as "text/html") for this ResponseWriter.

Note

this must not include the "charset=" suffix.

Returns:String

the content type such as "text/html" for this ResponseWriter.

Annotations
@Override
getElementNameback to summary
private String getElementName(String name)
getWebConfigurationback to summary
private WebConfiguration getWebConfiguration(WebConfiguration webConfig)
isScriptOrStyleback to summary
private boolean isScriptOrStyle(String name)
isScriptOrStyleback to summary
private boolean isScriptOrStyle()
popElementNameback to summary
private String popElementName(String original)
pushElementNameback to summary
private String pushElementName(String original)
startCDATAback to summary
public void startCDATA() throws IOException

Overrides jakarta.faces.context.ResponseWriter.startCDATA.

Starts a CDATA block. Nested blocks are not allowed.

Annotations
@Override
Exceptions
IOException:
on a read/write error
IllegalStateException:
If startCDATA is called a second time before endCDATA.
Since
2.0
startDocumentback to summary
public void startDocument() throws IOException

Implements abstract jakarta.faces.context.ResponseWriter.startDocument.

Write the text that should begin a response.

Annotations
@Override
Exceptions
IOException:
if an input/output error occurs
startElementback to summary
public void startElement(String name, UIComponent componentForElement) throws IOException

Implements abstract jakarta.faces.context.ResponseWriter.startElement.

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.

Parameters
name:String

Name of the starting element

componentForElement:UIComponent

The UIComponent instance that applies to this element. This argument may be null.

Annotations
@Override
Exceptions
IOException:
if an input/output error occurs
NullPointerException:
if name is null
writeback to summary
public void write(char[] cbuf) throws IOException

Overrides java.io.Writer.write.

Doc from java.io.Writer.write.

Writes an array of characters.

Parameters
cbuf:char[]

Array of characters to be written

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
writeback to summary
public void write(int c) throws IOException

Overrides java.io.Writer.write.

Doc from java.io.Writer.write.

Writes a single character. The character to be written is contained in the 16 low-order bits of the given integer value; the 16 high-order bits are ignored.

Subclasses that intend to support efficient single-character output should override this method.

Parameters
c:int

int specifying a character to be written

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
writeback to summary
public void write(String str) throws IOException

Overrides java.io.Writer.write.

Doc from java.io.Writer.write.

Writes a string.

Parameters
str:String

String to be written

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
writeback to summary
public void write(char[] cbuf, int off, int len) throws IOException

Implements abstract java.io.Writer.write.

Doc from java.io.Writer.write.

Writes a portion of an array of characters.

Parameters
cbuf:char[]

Array of characters

off:int

Offset from which to start writing characters

len:int

Number of characters to write

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
writeback to summary
public void write(String str, int off, int len) throws IOException

Overrides java.io.Writer.write.

Doc from java.io.Writer.write.

Writes a portion of a string.

Parameters
str:String

A String

off:int

Offset from which to start writing characters

len:int

Number of characters to write

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
writeAttributeback to summary
public void writeAttribute(String name, Object value, String componentPropertyName) throws IOException

Implements abstract jakarta.faces.context.ResponseWriter.writeAttribute.

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.

Parameters
name:String

Attribute name to be added

value:Object

Attribute value to be added

componentPropertyName:String

The name of the component property to which this attribute argument applies. This argument may be null.

Annotations
@Override
Exceptions
IOException:
if an input/output error occurs
IllegalStateException:
if this method is called when there is no currently open element
NullPointerException:
if name is null
writeCommentback to summary
public void writeComment(Object comment) throws IOException

Implements abstract jakarta.faces.context.ResponseWriter.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.

Parameters
comment:Object

Text content of the comment

Annotations
@Override
Exceptions
IOException:
if an input/output error occurs
NullPointerException:
if comment is null
writeEscapedback to summary
private void writeEscaped(char[] cbuf, int offset, int length) throws IOException
writeTextback to summary
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 &gt; &lt; syntax.

Parameters
text:char

Text to be written

Exceptions
IOException:
if an input/output error occurs
writeTextback to summary
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 &gt; &lt; syntax.

Parameters
text:char[]

Text to be written

Exceptions
IOException:
if an input/output error occurs
NullPointerException:
if text is null
writeTextback to summary
public void writeText(Object text, String componentPropertyName) throws IOException

Implements abstract jakarta.faces.context.ResponseWriter.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.

Parameters
text:Object

Text to be written

componentPropertyName:String

The name of the component property to which this text argument applies. This argument may be null.

Annotations
@Override
Exceptions
IOException:
if an input/output error occurs
NullPointerException:
if text is null
writeTextback to summary
public void writeText(char[] text, int off, int len) throws IOException

Implements abstract jakarta.faces.context.ResponseWriter.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 &gt; &lt; syntax.

Parameters
text:char[]

Text to be written

off:int

Starting offset (zero-relative)

len:int

Number of characters to be written

Annotations
@Override
Exceptions
IOException:
if an input/output error occurs
IndexOutOfBoundsException:
if the calculated starting or ending position is outside the bounds of the character array
NullPointerException:
if text is null
writeUnescapedCDataback to summary
private void writeUnescapedCData(char[] cbuf, int offset, int length) throws IOException

When writing un-escaped CDATA, "]]>" sequence still has to be escaped by breaking CDATA block.

writeURIAttributeback to summary
public void writeURIAttribute(String name, Object value, String componentPropertyName) throws IOException

Implements abstract jakarta.faces.context.ResponseWriter.writeURIAttribute.

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.

Parameters
name:String

Attribute name to be added

value:Object

Attribute value to be added

componentPropertyName:String

The name of the component property to which this attribute argument applies. This argument may be null.

Annotations
@Override
Exceptions
IOException:
if an input/output error occurs
IllegalStateException:
if this method is called when there is no currently open element
NullPointerException:
if name or value is null
writeURIAttributeIgnoringPassThroughAttributesback to summary
private void writeURIAttributeIgnoringPassThroughAttributes(String name, Object value, String componentPropertyName, boolean isPassthrough) throws IOException