JavaTM 2 Platform
Standard Ed. 6

javax.swing.text.html
类 HTMLWriter

java.lang.Object
  继承者 javax.swing.text.AbstractWriter
      继承者 javax.swing.text.html.HTMLWriter

public class HTMLWriter
extends AbstractWriter

这是用于 HTMLDocuments 的 writer。


字段摘要
 
从类 javax.swing.text.AbstractWriter 继承的字段
NEWLINE
 
构造方法摘要
HTMLWriter(Writer w, HTMLDocument doc)
          创建新的 HTMLWriter。
HTMLWriter(Writer w, HTMLDocument doc, int pos, int len)
          创建新的 HTMLWriter。
 
方法摘要
protected  void closeOutUnwantedEmbeddedTags(AttributeSet attr)
          搜索属性集和存储在标记向量中的每个标记。
protected  void comment(Element elem)
          写出注释。
protected  void emptyTag(Element elem)
          写出所有空元素(没有对应结束标记的所有标记)。
protected  void endTag(Element elem)
          写出元素的结束标记。
protected  boolean isBlockTag(AttributeSet attr)
          确定与该元素关联的 HTML.Tag 是否为块标记。
protected  boolean matchNameAttribute(AttributeSet attr, HTML.Tag tag)
          如果 StyleConstants.NameAttribute 与作为参数传入的标记相同,则返回 true。
protected  void output(char[] chars, int start, int length)
          重写此方法来映射任何字符实体,例如 < 映射到 <。
protected  void selectContent(AttributeSet attr)
          写出 SELECT 表单元素的内容。
protected  void startTag(Element elem)
          写出元素的开始标记。
protected  boolean synthesizedElement(Element elem)
          如果元素是合成元素,则返回 true。
protected  void text(Element elem)
          写出文本。
protected  void textAreaContent(AttributeSet attr)
          写出 TEXTAREA 表单元素中所包含的文本。
 void write()
          对 Element 树进行迭代并控制所有标记及其属性的写出。
protected  void writeAttributes(AttributeSet attr)
          写出属性集。
protected  void writeEmbeddedTags(AttributeSet attr)
          搜索 AttributeSet 中的嵌入式标记并写出它们。
protected  void writeLineSeparator()
          写出行分隔符。
protected  void writeOption(Option option)
          写出 Option 表单元素的内容。
 
从类 javax.swing.text.AbstractWriter 继承的方法
decrIndent, getCanWrapLines, getCurrentLineLength, getDocument, getElementIterator, getEndOffset, getIndentLevel, getIndentSpace, getLineLength, getLineSeparator, getStartOffset, getText, getWriter, incrIndent, indent, inRange, isLineEmpty, setCanWrapLines, setCurrentLineLength, setIndentSpace, setLineLength, setLineSeparator, write, write, write
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

构造方法详细信息

HTMLWriter

public HTMLWriter(Writer w,
                  HTMLDocument doc)
创建新的 HTMLWriter。

参数:
w - Writer
doc - HTMLDocument

HTMLWriter

public HTMLWriter(Writer w,
                  HTMLDocument doc,
                  int pos,
                  int len)
创建新的 HTMLWriter。

参数:
w - Writer
doc - HTMLDocument
pos - 文档位置,从此位置获取内容
len - 写出量
方法详细信息

write

public void write()
           throws IOException,
                  BadLocationException
对 Element 树进行迭代并控制所有标记及其属性的写出。

指定者:
AbstractWriter 中的 write
抛出:
IOException - 如果发生任何 I/O 错误
BadLocationException - 如果 pos 表示文档中的无效位置。

writeAttributes

protected void writeAttributes(AttributeSet attr)
                        throws IOException
写出属性集。忽略带有类型 HTML.Tag 键的所有属性,带有类型 StyleConstants 键的所有属性,以及带有类型 HTML.Attribute.ENDTAG 键的所有属性。

覆盖:
AbstractWriter 中的 writeAttributes
参数:
attr - AttributeSet
抛出:
IOException - 如果发生任何 I/O 错误

emptyTag

protected void emptyTag(Element elem)
                 throws BadLocationException,
                        IOException
写出所有空元素(没有对应结束标记的所有标记)。

参数:
elem - Element
抛出:
IOException - 如果发生任何 I/O 错误
BadLocationException - 如果 pos 表示文档中的无效位置。

isBlockTag

protected boolean isBlockTag(AttributeSet attr)
确定与该元素关联的 HTML.Tag 是否为块标记。

参数:
attr - AttributeSet
返回:
如果标记是块标记,则返回 true;否则返回 false。

startTag

protected void startTag(Element elem)
                 throws IOException,
                        BadLocationException
写出元素的开始标记。忽略所有的合成元素。

参数:
elem - Element
抛出:
IOException - 如果发生任何 I/O 错误
BadLocationException

textAreaContent

protected void textAreaContent(AttributeSet attr)
                        throws BadLocationException,
                               IOException
写出 TEXTAREA 表单元素中所包含的文本。

参数:
attr - AttributeSet
抛出:
IOException - 如果发生任何 I/O 错误
BadLocationException - 如果 pos 表示文档中的无效位置。

text

protected void text(Element elem)
             throws BadLocationException,
                    IOException
写出文本。如果调用构造方法时指定了范围,则只写出相应范围内的文本。

覆盖:
AbstractWriter 中的 text
参数:
elem - Element
抛出:
IOException - 如果发生任何 I/O 错误
BadLocationException - 如果 pos 表示文档中的无效位置。

selectContent

protected void selectContent(AttributeSet attr)
                      throws IOException
写出 SELECT 表单元素的内容。

参数:
attr - 与表单元素关联的 AttributeSet
抛出:
IOException - 如果发生任何 I/O 错误

writeOption

protected void writeOption(Option option)
                    throws IOException
写出 Option 表单元素的内容。

参数:
option - Option
抛出:
IOException - 如果发生任何 I/O 错误

endTag

protected void endTag(Element elem)
               throws IOException
写出元素的结束标记。

参数:
elem - Element
抛出:
IOException - 如果发生任何 I/O 错误

comment

protected void comment(Element elem)
                throws BadLocationException,
                       IOException
写出注释。

参数:
elem - Element
抛出:
IOException - 如果发生任何 I/O 错误
BadLocationException - 如果 pos 表示文档中的无效位置。

synthesizedElement

protected boolean synthesizedElement(Element elem)
如果元素是合成元素,则返回 true。目前我们只测试了 p 暗指的标记。


matchNameAttribute

protected boolean matchNameAttribute(AttributeSet attr,
                                     HTML.Tag tag)
如果 StyleConstants.NameAttribute 与作为参数传入的标记相同,则返回 true。


writeEmbeddedTags

protected void writeEmbeddedTags(AttributeSet attr)
                          throws IOException
搜索 AttributeSet 中的嵌入式标记并写出它们。它还将这些标记存储在一个向量中,以便在适当的时候能够写出对应的结束标记。

抛出:
IOException - 如果发生任何 I/O 错误

closeOutUnwantedEmbeddedTags

protected void closeOutUnwantedEmbeddedTags(AttributeSet attr)
                                     throws IOException
搜索属性集和存储在标记向量中的每个标记。如果未找到标记,则从向量中移除标记并写出对应的结束标记。

抛出:
IOException - 如果发生任何 I/O 错误

writeLineSeparator

protected void writeLineSeparator()
                           throws IOException
写出行分隔符。当它不是标准的 ascii 时,我们重写它以确保不替换新行内容。

覆盖:
AbstractWriter 中的 writeLineSeparator
抛出:
IOException
从以下版本开始:
1.3

output

protected void output(char[] chars,
                      int start,
                      int length)
               throws IOException
重写此方法来映射任何字符实体,例如 < 映射到 <。调用 super.output 可写出内容。

覆盖:
AbstractWriter 中的 output
抛出:
IOException
从以下版本开始:
1.3

JavaTM 2 Platform
Standard Ed. 6

提交错误或意见
有关更多的 API 参考资料和开发人员文档,请参阅 Java 2 SDK SE 开发人员文档。该文档包含更详细的、面向开发人员的描述,以及总体概述、术语定义、使用技巧和工作代码示例。

版权所有 2004 Sun Microsystems, Inc. 保留所有权利。 请遵守许可证条款。另请参阅文档重新分发政策