ResponseWriter (Java EE 5)

Java EE API


javax.faces.context Class ResponseWriter

java.lang.Object
  extended by java.io.Writer
      extended by javax.faces.context.ResponseWriter
All Implemented Interfaces:
Closeable, Flushable, Appendable
Direct Known Subclasses:
ResponseWriterWrapper

public abstract class ResponseWriter
extends Writer

Extends: java.io.Writer

ResponseWriter 是一个抽象类,该类描述基于字符输出的底层输出机制的适配器。除了从 java.io.Writer 继承的低级别 write() 方法之外,此类还提供一些实用程序方法,这些方法在生成标记语言(如 HTML 和 XML)的元素和属性方面非常有用。

英文文档:

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 from java.io.Writer, this class provides utility methods that are useful in producing elements and attributes for markup languages like HTML and XML.


Field Summary
 
Fields inherited from class java.io.Writer
 
Constructor Summary
 
Method Summary
abstract  ResponseWriter
abstract  void
abstract  void
abstract  void
abstract  String
abstract  String
abstract  void
abstract  void
abstract  void
abstract  void
abstract  void
abstract  void
 void
abstract  void
 
Methods inherited from class java.io.Writer
 
Methods inherited from class java.lang.Object
 

Constructor Detail

public ResponseWriter()
英文文档:

ResponseWriter

public ResponseWriter()
Method Detail

abstract public String getContentType()

返回此 ResponseWriter 的内容类型(如 "text/html")。注:这不得包括 "charset=" 后缀。

英文文档:

getContentType

public abstract String getContentType()

Return the content type (such as "text/html") for this ResponseWriter. Note: this must not include the "charset=" suffix.


abstract public String getCharacterEncoding()

返回此 ResponseWriter 的字符编码(如 "ISO-8859-1")。有关字符编码的列表,请参见 the IANA

英文文档:

getCharacterEncoding

public 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.


abstract public void flush() throws java.io.IOException

将由输出方法缓冲的任何输出刷新到底层 Writer 或 OutputStream。此方法将不刷新底层 Writer 或 OutputStream;它只清除由此 ResponseWriter 缓冲的任何值。

英文文档:

flush

public abstract void flush()
                    throws IOException

Flush 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:
flush in interface Flushable
Specified by:
flush in class Writer
Throws:
IOException

abstract public void startDocument() throws java.io.IOException

无论写入什么文本都应开始响应。

Throwsjava.io.IOException: 如果发生输入/输出错误
英文文档:

startDocument

public abstract void startDocument()
                            throws IOException

Write whatever text should begin a response.

Throws:
IOException - if an input/output error occurs

abstract public void endDocument() throws java.io.IOException

无论写入什么文本都应结束响应。如果存在调用 startElement() 创建的公开元素,则将首先关闭该元素。

Throwsjava.io.IOException: 如果发生输入/输出错误
英文文档:

endDocument

public abstract void endDocument()
                          throws IOException

Write 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

abstract public void startElement(String name, UIComponent component) throws java.io.IOException

写入元素的开头部分,直到包含元素名称。调用此方法后,客户端便可以调用 writeAttribute()writeURIAttribute() 方法添加属性和相应的值。后续所有对 startElement()writeComment()writeText()endElement()endDocument()close()flush()write() 的调用将关闭开始元素(即,在结尾添加 ">" 字符)。

name 将开始的元素名称
component 此元素对应的 UIComponent(如果有)
Throwsjava.io.IOException: 如果发生输入/输出错误
ThrowsNullPointerException: 如果 namenull
英文文档:

startElement

public 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() or writeURIAttribute() methods to add attributes and corresponding values. The starting element will be closed (that is, the trailing '>' character added) on any subsequent call to startElement(), writeComment(), writeText(), endElement(), endDocument(), close(), flush(), or write().

Parameters:
name - Name of the element to be started
component - The UIComponent (if any) to which this element corresponds
Throws:
IOException - if an input/output error occurs
NullPointerException - if name is null

abstract public void endElement(String name) throws java.io.IOException

关闭通过调用 startElement() 创建的任何开放元素之后,写入元素的结尾。必须按照与打开顺序相反的顺序关闭元素;否则会出现错误。

name 将结束的元素的名称。
Throwsjava.io.IOException: 如果发生输入/输出错误
ThrowsNullPointerException: 如果 namenull
英文文档:

endElement

public 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.

Parameters:
name - Name of the element to be ended
Throws:
IOException - if an input/output error occurs
NullPointerException - if name is null

abstract public void writeAttribute(String name, Object value, String property) throws java.io.IOException

在将该文本转换为 String(如果必要)并执行与呈现的标记语言相应的任何转义之后,写入属性名称和相应的值。此方法只能在调用 startElement() 之后、关闭开放的元素之前调用。

name 要添加的属性名称
value 要添加的属性值
property 与包含元素(对应于生成的属性)关联的 UIComponent 的属性(如果有)名称
ThrowsIllegalStateException: 如果在当前没有打开的元素时调用此方法
Throwsjava.io.IOException: 如果发生输入/输出错误
ThrowsNullPointerException: 如果 namenull
英文文档:

writeAttribute

public 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 UIComponent associated 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 name is null

abstract public void writeURIAttribute(String name, Object value, String property) throws java.io.IOException

在将该文本转换为 String(如果必要)并执行与呈现的标记语言相应的任何编码之后,写入 URI 属性名称和相应的值。此方法只能在调用 startElement() 之后、关闭开放的元素之前调用。

name 要添加的属性名称
value 要添加的属性值
property 与包含元素(对应于生成的属性)关联的 UIComponent 的属性(如果有)名称
ThrowsIllegalStateException: 如果在当前没有打开的元素时调用此方法
Throwsjava.io.IOException: 如果发生输入/输出错误
ThrowsNullPointerException: 如果 namenull
英文文档:

writeURIAttribute

public 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 appropriate to 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 UIComponent associated 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 name is null

abstract public void writeComment(Object comment) throws java.io.IOException

在将该文本转换为 String(如果必要)并执行与呈现的标记语言相应的任何转义之后,写入包含指定文本的注释。如果存在调用 startElement() 创建的公开元素,则将首先关闭该元素。

comment 注释的文本内容
Throwsjava.io.IOException: 如果发生输入/输出错误
ThrowsNullPointerException: 如果 commentnull
英文文档:

writeComment

public 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 comment is null

abstract public void writeText(Object text, String property) throws java.io.IOException

在转换为 String(如果必要),并执行与呈现的标记语言相应的转义之后,写入对象。如果存在调用 startElement() 创建的公开元素,则将首先关闭该元素。

text 要写入的文本
property 与包含元素(对应于生成的文本)关联的 UIComponent 的属性(如果有)名称
Throwsjava.io.IOException: 如果发生输入/输出错误
ThrowsNullPointerException: 如果 textnull
英文文档:

writeText

public 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 UIComponent associated with the containing element, to which this generated text corresponds
Throws:
IOException - if an input/output error occurs
NullPointerException - if text is null

public void writeText(Object text, UIComponent component, String property) throws java.io.IOException

在转换为 String(如果必要),并执行与呈现的标记语言相应的转义之后,写入对象。该方法等效于 #writeText(java.lang.Object,java.lang.String),但添加了一个 component 属性,以允许自定义的 ResponseWriter 实现将组件与文本的任意部分关联。

默认的实现忽略 component 参数并接通 #writeText(java.lang.Object,java.lang.String)

text 要写入的文本
component 此元素对应的 UIComponent(如果有)
property 与包含元素(对应于生成的文本)关联的 UIComponent 的属性(如果有)名称
Throwsjava.io.IOException: 如果发生输入/输出错误
ThrowsNullPointerException: 如果 textnull
since1.2
英文文档:

writeText

public 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 a component property to allow custom ResponseWriter implementations to associate a component with an arbitrary portion of text.

The default implementation simply ignores the component argument and calls through to writeText(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 UIComponent associated with the containing element, to which this generated text corresponds
Throws:
IOException - if an input/output error occurs
NullPointerException - if text is null
Since:
1.2

abstract public void writeText(char[] text, int off, int len) throws java.io.IOException

执行呈现的标记语言相应的任何转义之后,从字符数组中写入文本。如果存在调用 startElement() 创建的公开元素,则将首先关闭该元素。

text 要写入的文本
off 起始偏移量(相对于 0)
len 要写入字符的数量
ThrowsIndexOutOfBoundsException: 如果计算的开始或结束位置位于字符数组的边界之外
Throwsjava.io.IOException: 如果发生输入/输出错误
ThrowsNullPointerException: 如果 textnull
英文文档:

writeText

public abstract void writeText(char[] text,
                               int off,
                               int len)
                        throws IOException

Write 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 text is null

abstract public ResponseWriter cloneWithWriter(java.io.Writer writer)

使用指定的 Writer 作为输出目标,创建并返回此 ResponseWriter 的一个新实例。

writer 作为输出目标的 Writer
英文文档:

cloneWithWriter

public abstract ResponseWriter cloneWithWriter(Writer writer)

Create and return a new instance of this ResponseWriter, using the specified Writer as the output destination.

Parameters:
writer - The Writer that is the output destination


Submit a bug or feature

Copyright 2007 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.

一看就知道只有菜鸟才干这么无知的事啦。

PS : 未经我党受权你也可自由散发此文档。 如有任何错误请自行修正;若因此而造成任何损失请直接找人民主席,请勿与本人联系。谢谢!