站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > JDK 5 Documentation v1.2.2, Java 2 SDK 英文文档

Java(TM) 2 Platform, Standard Edition, v1.2.2 API Specification: Class AbstractWriter - JDK 5 Documentation v1.2.2, Java 2 SDK 英文文档

JavaTM 2 Platform
Standard Edition

javax.swing.text
Class AbstractWriter

java.lang.Object
  |
  +--javax.swing.text.AbstractWriter
Direct Known Subclasses:
HTMLWriter, MinimalHTMLWriter

public abstract class AbstractWriter
extends Object

AbstractWriter is an abstract class that actually does the work of writing out the element tree including the attributes. In terms of how much is written out per line, the writer defaults to 100. But this value can be set by subclasses.


Field Summary
protected static char NEWLINE
           
 
Constructor Summary
protected AbstractWriter(Writer w, Document doc)
          Creates a new AbstractWriter.
protected AbstractWriter(Writer w, Document doc, int pos, int len)
          Creates a new AbstractWriter.
protected AbstractWriter(Writer w, Element root)
          Creates a new AbstractWriter.
protected AbstractWriter(Writer w, Element root, int pos, int len)
          Creates a new AbstractWriter.
 
Method Summary
protected  void decrIndent()
          Decrements the indent level.
protected  Document getDocument()
          Fetches the document.
protected  ElementIterator getElementIterator()
          Fetches the ElementIterator.
protected  String getText(Element elem)
          Returns the text associated with the element.
protected  void incrIndent()
          Increments the indent level.
protected  void indent()
          Does indentation.
protected  boolean inRange(Element next)
          This method determines whether the current element is in the range specified.
protected  void setIndentSpace(int space)
          Enables subclasses to specify how many spaces an indent maps to.
protected  void setLineLength(int l)
          Enables subclasses to set the number of characters they want written per line.
protected  void text(Element elem)
          Writes out text.
protected abstract  void write()
          This abstract method needs to be implemented by subclasses.
protected  void write(char ch)
          Writes out a character.
protected  void write(String str)
          Writes out a string.
protected  void writeAttributes(AttributeSet attr)
          Writes out the set of attributes as " =" pairs.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NEWLINE

protected static final char NEWLINE
Constructor Detail

AbstractWriter

protected AbstractWriter(Writer w,
                         Document doc)
Creates a new AbstractWriter. Initializes the ElementIterator with the default root of the document.
Parameters:
a - Writer.
a - Document

AbstractWriter

protected AbstractWriter(Writer w,
                         Document doc,
                         int pos,
                         int len)
Creates a new AbstractWriter. Initializes the ElementIterator with the element passed in.
Parameters:
a - Writer
an - Element
pos - The location in the document to fetch the content.
len - The amount to write out.

AbstractWriter

protected AbstractWriter(Writer w,
                         Element root)
Creates a new AbstractWriter. Initializes the ElementIterator with the element passed in.
Parameters:
a - Writer
an - Element

AbstractWriter

protected AbstractWriter(Writer w,
                         Element root,
                         int pos,
                         int len)
Creates a new AbstractWriter. Initializes the ElementIterator with the element passed in.
Parameters:
a - Writer
an - Element
pos - The location in the document to fetch the content.
len - The amount to write out.
Method Detail

getElementIterator

protected ElementIterator getElementIterator()
Fetches the ElementIterator.
Returns:
the ElementIterator.

getDocument

protected Document getDocument()
Fetches the document.
Returns:
the Document.

inRange

protected boolean inRange(Element next)
This method determines whether the current element is in the range specified. When no range is specified, the range is initialized to be the entire document. inRange() returns true if the range specified intersects with the element's range.
Parameters:
an - Element.
Returns:
boolean that indicates whether the element is in the range.

write

protected abstract void write()
                       throws IOException,
                              BadLocationException
This abstract method needs to be implemented by subclasses. Its responsibility is to iterate over the elements and use the write() methods to generate output in the desired format.

getText

protected String getText(Element elem)
                  throws BadLocationException
Returns the text associated with the element. The assumption here is that the element is a leaf element. Throws a BadLocationException when encountered.
Parameters:
an - Element.
Throws:
BadLocationException - if pos represents an invalid location within the document.

text

protected void text(Element elem)
             throws BadLocationException,
                    IOException
Writes out text. If a range is specified when the constructor is invoked, then only the appropriate range of text is written out.
Parameters:
an - Element.
Throws:
IOException - on any I/O error
BadLocationException - if pos represents an invalid location within the document.

setLineLength

protected void setLineLength(int l)
Enables subclasses to set the number of characters they want written per line. The default is 100.
Parameters:
the - maximum line length.

setIndentSpace

protected void setIndentSpace(int space)
Enables subclasses to specify how many spaces an indent maps to. When indentation takes place, the indent level is multiplied by this mapping. The default is 2.
Parameters:
an - int representing the space to indent mapping.

incrIndent

protected void incrIndent()
Increments the indent level.

decrIndent

protected void decrIndent()
Decrements the indent level.

indent

protected void indent()
               throws IOException
Does indentation. The number of spaces written out is indent level times the space to map mapping.
Throws:
IOException - on any I/O error

write

protected void write(char ch)
              throws IOException
Writes out a character. If the character is a newline then it resets the current length to 0. If the current length equals the maximum line length, then a newline is outputed and the current length is reset to 0.
Parameters:
a - char.
Throws:
IOException - on any I/O error

write

protected void write(String str)
              throws IOException
Writes out a string. If writing out the string on the current line results in the maximum line length being exceeded, it then attempts to write this line out on the next line. However if the length of the string itself exceeds the maximum line length, it then recursively calls this method on the substring from 0 to max line length, and then again from max line length+1 to the end of the string -- inserting new lines where necessary.
Parameters:
a - String.
Throws:
IOException - on any I/O error

writeAttributes

protected void writeAttributes(AttributeSet attr)
                        throws IOException
Writes out the set of attributes as " =" pairs. It throws an IOException when encountered.
Parameters:
an - AttributeSet.
Throws:
IOException - on any I/O error

JavaTM 2 Platform
Standard Edition

Submit a bug or feature
Java, Java 2D, and JDBC are a trademarks or registered trademarks of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-1999 Sun Microsystems, Inc. 901 San Antonio Road,
Palo Alto, California, 94303, U.S.A. All Rights Reserved.