Class ResponseWriter
- java.lang.Object
- 
- java.io.Writer
- 
- jakarta.faces.context.ResponseWriter
 
 
- 
- All Implemented Interfaces:
- Closeable,- Flushable,- Appendable,- AutoCloseable
 - Direct Known Subclasses:
- ResponseWriterWrapper
 
 public abstract class ResponseWriter extends Writer ResponseWriter is an abstract class describing an adapter to an underlying output mechanism for character-based output. In addition to the low-level write()methods inherited fromjava.io.Writer, this class provides utility methods that are useful in producing elements and attributes for markup languages like HTML and XML.
- 
- 
Constructor SummaryConstructors Constructor Description ResponseWriter()
 - 
Method SummaryAll Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract ResponseWritercloneWithWriter(Writer writer)Create and return a new instance of thisResponseWriter, using the specifiedWriteras the output destination.voidendCDATA()Close an XMLCDATAblock.abstract voidendDocument()Write whatever text should end a response.abstract voidendElement(String name)Write the end of an element, after closing any open element created by a call tostartElement().abstract voidflush()Flush any ouput buffered by the output method to the underlying Writer or OutputStream.abstract StringgetCharacterEncoding()Return the character encoding (such as "ISO-8859-1") for thisResponseWriter.abstract StringgetContentType()Return the content type (such as "text/html") for thisResponseWriter.voidstartCDATA()Open an XMLCDATAblock.abstract voidstartDocument()Write whatever text should begin a response.abstract voidstartElement(String name, UIComponent component)Write the start of an element, up to and including the element name.abstract voidwriteAttribute(String name, Object value, String property)Write an attribute name and corresponding value, after converting that text to a String (if necessary), and after performing any escaping appropriate for the markup language being rendered.abstract voidwriteComment(Object comment)Write a comment containing the specified text, after converting that text to a String (if necessary), and after performing any escaping appropriate for the markup language being rendered.voidwriteDoctype(String doctype)Write a string containing the markup specific doctype.voidwritePreamble(String preamble)Write a string containing the markup specific preamble.abstract voidwriteText(char[] text, int off, int len)Write text from a character array, after any performing any escaping appropriate for the markup language being rendered.voidwriteText(Object text, UIComponent component, String property)Write an object, after converting it to a String (if necessary), and after performing any escaping appropriate for the markup language being rendered.abstract voidwriteText(Object text, String property)Write an object, after converting it to a String (if necessary), and after performing any escaping appropriate for the markup language being rendered.abstract voidwriteURIAttribute(String name, Object value, String property)Write a URI attribute name and corresponding value, after converting that text to a String (if necessary), and after performing any encoding or escaping appropriate to the markup language being rendered.
 
- 
- 
- 
Method Detail- 
getContentTypepublic abstract String getContentType() Return the content type (such as "text/html") for this ResponseWriter. Note: this must not include the "charset=" suffix.- Returns:
- the content type
 
 - 
getCharacterEncodingpublic abstract String getCharacterEncoding() Return the character encoding (such as "ISO-8859-1") for this ResponseWriter. Please see the IANA for a list of character encodings.- Returns:
- the character encoding
 
 - 
flushpublic abstract void flush() throws IOExceptionFlush any ouput buffered by the output method to the underlying Writer or OutputStream. This method will not flush the underlying Writer or OutputStream; it simply clears any values buffered by this ResponseWriter.- Specified by:
- flushin interface- Flushable
- Specified by:
- flushin class- Writer
- Throws:
- IOException
 
 - 
startDocumentpublic abstract void startDocument() throws IOExceptionWrite whatever text should begin a response. - Throws:
- IOException- if an input/output error occurs
 
 - 
endDocumentpublic abstract void endDocument() throws IOExceptionWrite whatever text should end a response. If there is an open element that has been created by a call to startElement(), that element will be closed first.- Throws:
- IOException- if an input/output error occurs
 
 - 
startElementpublic abstract void startElement(String name, UIComponent component) throws IOException Write the start of an element, up to and including the element name. Once this method has been called, clients can call the writeAttribute()orwriteURIAttribute()methods to add attributes and corresponding values. The starting element will be closed (that is, the trailing '>' character added) on any subsequent call tostartElement(),writeComment(),writeText(),endElement(),endDocument(),close(),flush(), orwrite().If the argument component's pass through attributes includes an attribute of the name given by the value of the symbolic constant Renderer.PASSTHROUGH_RENDERER_LOCALNAME_KEY, use that as the element name, instead of the value passed as the first parameter to this method. Care must be taken so that this value is not also rendered when any other pass through attributes on this component are rendered.- Parameters:
- name- Name of the element to be started
- component- The- UIComponent(if any) to which this element corresponds. This component is inspected for its pass through attributes as described in the standard HTML_BASIC- RenderKitspecification.
- Throws:
- IOException- if an input/output error occurs
- NullPointerException- if- nameis- null
 
 - 
endElementpublic abstract void endElement(String name) throws IOException Write the end of an element, after closing any open element created by a call to startElement(). Elements must be closed in the inverse order from which they were opened; it is an error to do otherwise.If the argument component's pass through attributes includes an attribute of the name given by the value of the symbolic constant Renderer.PASSTHROUGH_RENDERER_LOCALNAME_KEY, use that as the element name, instead of the value passed as the first parameter to this method.- Parameters:
- name- Name of the element to be ended
- Throws:
- IOException- if an input/output error occurs
- NullPointerException- if- nameis- null
 
 - 
writeAttributepublic abstract void writeAttribute(String name, Object value, String property) throws IOException Write an attribute name and corresponding value, after converting that text to a String (if necessary), and after performing any escaping appropriate for the markup language being rendered. This method may only be called after a call to startElement(), and before the opened element has been closed.- Parameters:
- name- Attribute name to be added
- value- Attribute value to be added
- property- Name of the property or attribute (if any) of the- UIComponentassociated with the containing element, to which this generated attribute corresponds
- Throws:
- IllegalStateException- if this method is called when there is no currently open element
- IOException- if an input/output error occurs
- NullPointerException- if- nameis- null
 
 - 
writeURIAttributepublic abstract void writeURIAttribute(String name, Object value, String property) throws IOException Write a URI attribute name and corresponding value, after converting that text to a String (if necessary), and after performing any encoding or escaping appropriate to the markup language being rendered. When rendering in a WWW environment, the escaping conventions established in the W3C URI spec document <http://www.w3.org/Addressing/URL/uri-spec.html> must be followed. In particular, spaces ' ' must be encoded as %20 and not the plus character '+'. This method may only be called after a call to startElement(), and before the opened element has been closed.- Parameters:
- name- Attribute name to be added
- value- Attribute value to be added
- property- Name of the property or attribute (if any) of the- UIComponentassociated with the containing element, to which this generated attribute corresponds
- Throws:
- IllegalStateException- if this method is called when there is no currently open element
- IOException- if an input/output error occurs
- NullPointerException- if- nameis- null
 
 - 
startCDATApublic void startCDATA() throws IOExceptionOpen an XML CDATAblock. Note that XML does not allow nestedCDATAblocks, though this method does not enforce that constraint. The default implementation of this method takes no action when invoked.- Throws:
- IOException- if input/output error occures
 
 - 
endCDATApublic void endCDATA() throws IOExceptionClose an XML CDATAblock. The default implementation of this method takes no action when invoked.- Throws:
- IOException- if input/output error occures
 
 - 
writeCommentpublic abstract void writeComment(Object comment) throws IOException Write a comment containing the specified text, after converting that text to a String (if necessary), and after performing any escaping appropriate for the markup language being rendered. If there is an open element that has been created by a call to startElement(), that element will be closed first.- Parameters:
- comment- Text content of the comment
- Throws:
- IOException- if an input/output error occurs
- NullPointerException- if- commentis- null
 
 - 
writePreamblepublic void writePreamble(String preamble) throws IOException Write a string containing the markup specific preamble. No escaping is performed. The default implementation simply calls through to Writer.write(java.lang.String).The implementation makes no checks if this is the correct place in the response to have a preamble, nor does it prevent the preamble from being written more than once. - Parameters:
- preamble- Text content of the preamble
- Throws:
- IOException- if an input/output error occurs
- Since:
- 2.2
 
 - 
writeDoctypepublic void writeDoctype(String doctype) throws IOException Write a string containing the markup specific doctype. No escaping is performed. The default implementation simply calls through to Writer.write(java.lang.String).The implementation makes no checks if this is the correct place in the response to have a doctype, nor does it prevent the doctype from being written more than once. - Parameters:
- doctype- Text content of the doctype
- Throws:
- IOException- if an input/output error occurs
- Since:
- 2.2
 
 - 
writeTextpublic abstract void writeText(Object text, String property) throws IOException Write an object, after converting it to a String (if necessary), and after performing any escaping appropriate for the markup language being rendered. If there is an open element that has been created by a call to startElement(), that element will be closed first.- Parameters:
- text- Text to be written
- property- Name of the property or attribute (if any) of the- UIComponentassociated with the containing element, to which this generated text corresponds
- Throws:
- IOException- if an input/output error occurs
- NullPointerException- if- textis- null
 
 - 
writeTextpublic void writeText(Object text, UIComponent component, String property) throws IOException Write an object, after converting it to a String (if necessary), and after performing any escaping appropriate for the markup language being rendered. This method is equivalent to writeText(java.lang.Object,java.lang.String)but adds acomponentproperty to allow customResponseWriterimplementations to associate a component with an arbitrary portion of text.The default implementation simply ignores the componentargument and calls through towriteText(java.lang.Object,java.lang.String)- Parameters:
- text- Text to be written
- component- The- UIComponent(if any) to which this element corresponds
- property- Name of the property or attribute (if any) of the- UIComponentassociated with the containing element, to which this generated text corresponds
- Throws:
- IOException- if an input/output error occurs
- NullPointerException- if- textis- null
- Since:
- 1.2
 
 - 
writeTextpublic abstract void writeText(char[] text, int off, int len) throws IOExceptionWrite text from a character array, after any performing any escaping appropriate for the markup language being rendered. If there is an open element that has been created by a call to startElement(), that element will be closed first.- 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- textis- null
 
 - 
cloneWithWriterpublic abstract ResponseWriter cloneWithWriter(Writer writer) Create and return a new instance of this ResponseWriter, using the specifiedWriteras the output destination.- Parameters:
- writer- The- Writerthat is the output destination
- Returns:
- the new ResponseWriter
 
 
- 
 
-