public class HtmlResponseWriter
extends javax.faces.context.ResponseWriter
HtmlResponseWriter is an Html specific implementation
of the ResponseWriter
abstract class.
Kudos to Adam Winer (Oracle) for much of this code.
Modifier and Type | Field and Description |
---|---|
private FastStringWriter |
attributesBuffer |
private static java.lang.String |
BREAKCDATA |
private char[] |
buffer |
(package private) static java.util.regex.Pattern |
CDATA_END_SLASH_SLASH |
(package private) static java.util.regex.Pattern |
CDATA_END_SLASH_STAR |
(package private) static java.util.regex.Pattern |
CDATA_START_SLASH_SLASH |
(package private) static java.util.regex.Pattern |
CDATA_START_SLASH_STAR |
private char[] |
cdataBuffer |
private int |
cdataBufferLength |
private static int |
cdataBufferSize |
private char[] |
cdataTextBuffer |
private static int |
cdataTextBufferSize |
private char[] |
charHolder |
private static int |
CLOSEBRACKET |
private boolean |
closeStart |
private java.lang.String |
contentType |
private WebConfiguration.DisableUnicodeEscaping |
disableUnicodeEscaping |
private boolean |
dontEscape |
private java.util.LinkedList<java.lang.String> |
elementNames |
private java.lang.String |
encoding |
private static char[] |
ESCAPEDEND |
private static char[] |
ESCAPEDLT |
private static char[] |
ESCAPEDSINGLEBRACKET |
private static char[] |
ESCAPEDSTART |
private boolean |
escapeIso |
private boolean |
escapeUnicode |
private boolean |
isCdata |
private boolean |
isPartial |
private boolean |
isScript |
private java.lang.Boolean |
isScriptHidingEnabled |
private java.lang.Boolean |
isScriptInAttributeValueEnabled |
private boolean |
isStyle |
private boolean |
isXhtml |
private static int |
LT |
private java.io.Writer |
origWriter |
private java.util.Map<java.lang.String,java.lang.Object> |
passthroughAttributes |
private FastStringWriter |
scriptBuffer |
private boolean |
scriptOrStyleSrc |
private char[] |
textBuffer |
private boolean |
withinScript |
private boolean |
withinStyle |
private java.io.Writer |
writer |
private boolean |
writingCdata |
Constructor and Description |
---|
HtmlResponseWriter(java.io.Writer writer,
java.lang.String contentType,
java.lang.String encoding)
Constructor sets the
ResponseWriter and
encoding, and enables script hiding by default. |
HtmlResponseWriter(java.io.Writer writer,
java.lang.String contentType,
java.lang.String encoding,
java.lang.Boolean isScriptHidingEnabled,
java.lang.Boolean isScriptInAttributeValueEnabled,
WebConfiguration.DisableUnicodeEscaping disableUnicodeEscaping,
boolean isPartial)
Constructor sets the
ResponseWriter and
encoding. |
Modifier and Type | Method and Description |
---|---|
private void |
appendBuffer(char c) |
private void |
appendBuffer(char[] cbuf) |
javax.faces.context.ResponseWriter |
cloneWithWriter(java.io.Writer writer)
Create a new instance of this
ResponseWriter using
a different Writer . |
void |
close()
Methods From
java.io.Writer |
private void |
closeStartIfNecessary()
This method automatically closes a previous element (if not
already closed).
|
private void |
considerPassThroughAttributes(java.util.Map<java.lang.String,java.lang.Object> toCopy) |
private boolean |
containsPassThroughAttribute(java.lang.String attrName) |
void |
endCDATA()
Closes the CDATA block.
|
void |
endDocument()
Output the text for the end of a document.
|
void |
endElement(java.lang.String name)
Write the end of an element.
|
private void |
ensureTextBufferCapacity(java.lang.String source) |
void |
flush()
Flush any buffered output to the contained writer.
|
private void |
flushAttributes() |
private void |
flushBuffer() |
private java.lang.String |
getAttributeValue(javax.faces.context.FacesContext context,
java.lang.Object valObj) |
java.lang.String |
getCharacterEncoding() |
java.lang.String |
getContentType() |
private java.lang.String |
getElementName(java.lang.String name) |
private WebConfiguration |
getWebConfiguration(WebConfiguration webConfig) |
private boolean |
isScriptOrStyle() |
private boolean |
isScriptOrStyle(java.lang.String name) |
private java.lang.String |
popElementName(java.lang.String original) |
private java.lang.String |
pushElementName(java.lang.String original) |
void |
startCDATA()
Starts a CDATA block.
|
void |
startDocument()
Write the text that should begin a response.
|
void |
startElement(java.lang.String name,
javax.faces.component.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 |
write(java.lang.String str) |
void |
write(java.lang.String str,
int off,
int len) |
void |
writeAttribute(java.lang.String name,
java.lang.Object value,
java.lang.String componentPropertyName)
Write a properly escaped attribute name and the corresponding
value.
|
void |
writeComment(java.lang.Object comment)
Write a comment string containing the specified text.
|
private void |
writeEscaped(char[] cbuf,
int offset,
int length) |
void |
writeText(char 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. |
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 |
writeText(java.lang.Object text,
java.lang.String componentPropertyName)
Write a properly escaped object.
|
void |
writeURIAttribute(java.lang.String name,
java.lang.Object value,
java.lang.String componentPropertyName)
Write a properly encoded URI attribute name and the corresponding
value.
|
private void |
writeURIAttributeIgnoringPassThroughAttributes(java.lang.String name,
java.lang.Object value,
java.lang.String componentPropertyName,
boolean isPassthrough) |
private java.lang.String contentType
private java.lang.String encoding
private java.io.Writer writer
private boolean closeStart
private WebConfiguration.DisableUnicodeEscaping disableUnicodeEscaping
private boolean escapeUnicode
private boolean escapeIso
private boolean dontEscape
private boolean writingCdata
private boolean isCdata
private boolean isScript
private boolean isStyle
private boolean withinScript
private boolean withinStyle
private boolean scriptOrStyleSrc
private boolean isPartial
private boolean isXhtml
private java.io.Writer origWriter
private FastStringWriter scriptBuffer
private FastStringWriter attributesBuffer
private java.lang.Boolean isScriptHidingEnabled
private java.lang.Boolean isScriptInAttributeValueEnabled
private char[] buffer
private static final int cdataBufferSize
private char[] cdataBuffer
private int cdataBufferLength
private static final int cdataTextBufferSize
private char[] cdataTextBuffer
private java.util.Map<java.lang.String,java.lang.Object> passthroughAttributes
private char[] textBuffer
private char[] charHolder
private java.util.LinkedList<java.lang.String> elementNames
private static final java.lang.String BREAKCDATA
private static final char[] ESCAPEDSINGLEBRACKET
private static final char[] ESCAPEDLT
private static final char[] ESCAPEDSTART
private static final char[] ESCAPEDEND
private static final int CLOSEBRACKET
private static final int LT
static final java.util.regex.Pattern CDATA_START_SLASH_SLASH
static final java.util.regex.Pattern CDATA_END_SLASH_SLASH
static final java.util.regex.Pattern CDATA_START_SLASH_STAR
static final java.util.regex.Pattern CDATA_END_SLASH_STAR
public HtmlResponseWriter(java.io.Writer writer, java.lang.String contentType, java.lang.String encoding) throws javax.faces.FacesException
ResponseWriter
and
encoding, and enables script hiding by default.writer
- the ResponseWriter
contentType
- the content type.encoding
- the character encoding.javax.faces.FacesException
- the encoding is not recognized.public HtmlResponseWriter(java.io.Writer writer, java.lang.String contentType, java.lang.String encoding, java.lang.Boolean isScriptHidingEnabled, java.lang.Boolean isScriptInAttributeValueEnabled, WebConfiguration.DisableUnicodeEscaping disableUnicodeEscaping, boolean isPartial) throws javax.faces.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
writer
- the ResponseWriter
contentType
- the content type.encoding
- the character encoding.javax.faces.FacesException
- the encoding is not recognized.private WebConfiguration getWebConfiguration(WebConfiguration webConfig)
public void close() throws java.io.IOException
java.io.Writer
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in class java.io.Writer
java.io.IOException
public void flush() throws java.io.IOException
flush
in interface java.io.Flushable
flush
in class javax.faces.context.ResponseWriter
java.io.IOException
- if an input/output error occurs.public java.lang.String getContentType()
getContentType
in class javax.faces.context.ResponseWriter
public javax.faces.context.ResponseWriter cloneWithWriter(java.io.Writer writer)
Create a new instance of this ResponseWriter
using
a different Writer
.
cloneWithWriter
in class javax.faces.context.ResponseWriter
writer
- The Writer
that will be used to create
another ResponseWriter
.public void endDocument() throws java.io.IOException
endDocument
in class javax.faces.context.ResponseWriter
java.io.IOException
public void endElement(java.lang.String name) throws java.io.IOException
Write the end of an element. This method will first
close any open element created by a call to
startElement()
.
endElement
in class javax.faces.context.ResponseWriter
name
- Name of the element to be endedjava.io.IOException
- if an input/output error occursjava.lang.NullPointerException
- if name
is null
public java.lang.String getCharacterEncoding()
getCharacterEncoding
in class javax.faces.context.ResponseWriter
public void startDocument() throws java.io.IOException
Write the text that should begin a response.
startDocument
in class javax.faces.context.ResponseWriter
java.io.IOException
- if an input/output error occurspublic void startElement(java.lang.String name, javax.faces.component.UIComponent componentForElement) throws java.io.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.
startElement
in class javax.faces.context.ResponseWriter
name
- Name of the starting elementcomponentForElement
- The UIComponent instance that applies to this
element. This argument may be null
.java.io.IOException
- if an input/output error occursjava.lang.NullPointerException
- if name
is null
public void startCDATA() throws java.io.IOException
startCDATA
in class javax.faces.context.ResponseWriter
java.io.IOException
- on a read/write errorjava.lang.IllegalStateException
- If startCDATA is called a second time before endCDATA.public void endCDATA() throws java.io.IOException
endCDATA
in class javax.faces.context.ResponseWriter
java.io.IOException
public void write(char[] cbuf) throws java.io.IOException
write
in class java.io.Writer
java.io.IOException
public void write(int c) throws java.io.IOException
write
in class java.io.Writer
java.io.IOException
public void write(java.lang.String str) throws java.io.IOException
write
in class java.io.Writer
java.io.IOException
public void write(char[] cbuf, int off, int len) throws java.io.IOException
write
in class java.io.Writer
java.io.IOException
public void write(java.lang.String str, int off, int len) throws java.io.IOException
write
in class java.io.Writer
java.io.IOException
public void writeAttribute(java.lang.String name, java.lang.Object value, java.lang.String componentPropertyName) throws java.io.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.
writeAttribute
in class javax.faces.context.ResponseWriter
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 be
null
.java.lang.IllegalStateException
- if this method is called when there
is no currently open elementjava.io.IOException
- if an input/output error occursjava.lang.NullPointerException
- if name
is null
public void writeComment(java.lang.Object comment) throws java.io.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.
writeComment
in class javax.faces.context.ResponseWriter
comment
- Text content of the commentjava.io.IOException
- if an input/output error occursjava.lang.NullPointerException
- if comment
is null
public void writeText(char text) throws java.io.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.
text
- Text to be writtenjava.io.IOException
- if an input/output error occurspublic void writeText(char[] text) throws java.io.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.
text
- Text to be writtenjava.io.IOException
- if an input/output error occursjava.lang.NullPointerException
- if text
is null
public void writeText(java.lang.Object text, java.lang.String componentPropertyName) throws java.io.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.
writeText
in class javax.faces.context.ResponseWriter
text
- Text to be writtencomponentPropertyName
- The name of the component property to
which this text argument applies. This argument may be null
.java.io.IOException
- if an input/output error occursjava.lang.NullPointerException
- if text
is null
public void writeText(char[] text, int off, int len) throws java.io.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.
writeText
in class javax.faces.context.ResponseWriter
text
- Text to be writtenoff
- Starting offset (zero-relative)len
- Number of characters to be writtenjava.lang.IndexOutOfBoundsException
- if the calculated starting or
ending position is outside the bounds of the character arrayjava.io.IOException
- if an input/output error occursjava.lang.NullPointerException
- if text
is null
public void writeURIAttribute(java.lang.String name, java.lang.Object value, java.lang.String componentPropertyName) throws java.io.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.
writeURIAttribute
in class javax.faces.context.ResponseWriter
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 be
null
.java.lang.IllegalStateException
- if this method is called when there
is no currently open elementjava.io.IOException
- if an input/output error occursjava.lang.NullPointerException
- if name
or
value
is null
private void writeURIAttributeIgnoringPassThroughAttributes(java.lang.String name, java.lang.Object value, java.lang.String componentPropertyName, boolean isPassthrough) throws java.io.IOException
java.io.IOException
private void ensureTextBufferCapacity(java.lang.String source)
private void closeStartIfNecessary() throws java.io.IOException
java.io.IOException
- if an error occurs writingprivate void considerPassThroughAttributes(java.util.Map<java.lang.String,java.lang.Object> toCopy)
private boolean containsPassThroughAttribute(java.lang.String attrName)
private void flushAttributes() throws java.io.IOException
java.io.IOException
private java.lang.String getAttributeValue(javax.faces.context.FacesContext context, java.lang.Object valObj)
private java.lang.String pushElementName(java.lang.String original)
private java.lang.String popElementName(java.lang.String original)
private java.lang.String getElementName(java.lang.String name)
private boolean isScriptOrStyle(java.lang.String name)
private boolean isScriptOrStyle()
private void writeEscaped(char[] cbuf, int offset, int length) throws java.io.IOException
java.io.IOException
private void appendBuffer(char[] cbuf) throws java.io.IOException
java.io.IOException
private void appendBuffer(char c) throws java.io.IOException
java.io.IOException
private void flushBuffer() throws java.io.IOException
java.io.IOException
Copyright © 2002-2013 Oracle America, Inc. All Rights Reserved.