Class HTMLWriter
java.lang.Object
javax.swing.text.AbstractWriter
javax.swing.text.html.HTMLWriter
This is a writer for HTMLDocuments.
-
Field Summary
Fields declared in class AbstractWriter
NEWLINE
Modifier and TypeFieldDescriptionprotected static final char
How the text packages models newlines. -
Constructor Summary
ConstructorsConstructorDescriptionHTMLWriter
(Writer w, HTMLDocument doc) Creates a new HTMLWriter.HTMLWriter
(Writer w, HTMLDocument doc, int pos, int len) Creates a new HTMLWriter. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Searches the attribute set and for each tag that is stored in the tag vector.protected void
Writes out comments.protected void
Writes out all empty elements (all tags that have no corresponding end tag).protected void
Writes out an end tag for the element.protected boolean
isBlockTag
(AttributeSet attr) Determines if the HTML.Tag associated with the element is a block tag.protected boolean
matchNameAttribute
(AttributeSet attr, HTML.Tag tag) Returns true if the StyleConstants.NameAttribute is equal to the tag that is passed in as a parameter.protected void
output
(char[] chars, int start, int length) This method is overridden to map any character entities, such as < to <.protected void
selectContent
(AttributeSet attr) Writes out the content of the SELECT form element.protected void
Writes out a start tag for the element.protected boolean
synthesizedElement
(Element elem) Returnstrue
if the element is a synthesized element.protected void
Writes out text.protected void
textAreaContent
(AttributeSet attr) Writes out text that is contained in a TEXTAREA form element.void
write()
Iterates over the Element tree and controls the writing out of all the tags and its attributes.protected void
writeAttributes
(AttributeSet attr) Writes out the attribute set.protected void
Searches for embedded tags in the AttributeSet and writes them out.protected void
Writes the line separator.protected void
writeOption
(Option option) Writes out the content of the Option form element.Methods declared in class 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
Modifier and TypeMethodDescriptionprotected void
Decrements the indent level.protected boolean
Returns whether or not the lines can be wrapped.protected int
Returns the current line length.protected Document
Fetches the document.protected ElementIterator
Fetches the ElementIterator.int
Returns the last offset to be output.protected int
Returns the current indentation level.protected int
Returns the amount of space to indent.protected int
Returns the maximum line length.Returns the string used to represent newlines.int
Returns the first offset to be output.protected String
Returns the text associated with the element.protected Writer
Returns the Writer that is used to output the content.protected void
Increments the indent level.protected void
indent()
Does indentation.protected boolean
This method determines whether the current element is in the range specified.protected boolean
Returns true if the current line should be considered empty.protected void
setCanWrapLines
(boolean newValue) Sets whether or not lines can be wrapped.protected void
setCurrentLineLength
(int length) Sets the current line length.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.void
setLineSeparator
(String value) Sets the String used to represent newlines.protected void
write
(char ch) Writes out a character.protected void
write
(char[] chars, int startIndex, int length) All write methods call into this one.protected void
Writes out a string.Methods declared in class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Modifier and TypeMethodDescriptionprotected Object
clone()
Creates and returns a copy of this object.boolean
Indicates whether some other object is "equal to" this one.protected void
finalize()
Deprecated, for removal: This API element is subject to removal in a future version.Finalization is deprecated and subject to removal in a future release.final Class
<?> getClass()
Returns the runtime class of thisObject
.int
hashCode()
Returns a hash code value for this object.final void
notify()
Wakes up a single thread that is waiting on this object's monitor.final void
Wakes up all threads that are waiting on this object's monitor.toString()
Returns a string representation of the object.final void
wait()
Causes the current thread to wait until it is awakened, typically by being notified or interrupted.final void
wait
(long timeoutMillis) Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.final void
wait
(long timeoutMillis, int nanos) Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.
-
Constructor Details
-
HTMLWriter
Creates a new HTMLWriter.- Parameters:
w
- a Writerdoc
- an HTMLDocument
-
HTMLWriter
Creates a new HTMLWriter.- Parameters:
w
- a Writerdoc
- an HTMLDocumentpos
- the document location from which to fetch the contentlen
- the amount to write out
-
-
Method Details
-
write
Iterates over the Element tree and controls the writing out of all the tags and its attributes.- Specified by:
write
in classAbstractWriter
- Throws:
IOException
- on any I/O errorBadLocationException
- if pos represents an invalid location within the document.
-
writeAttributes
Writes out the attribute set. Ignores all attributes with a key of type HTML.Tag, attributes with a key of type StyleConstants, and attributes with a key of type HTML.Attribute.ENDTAG.- Overrides:
writeAttributes
in classAbstractWriter
- Parameters:
attr
- an AttributeSet- Throws:
IOException
- on any I/O error
-
emptyTag
Writes out all empty elements (all tags that have no corresponding end tag).- Parameters:
elem
- an Element- Throws:
IOException
- on any I/O errorBadLocationException
- if pos represents an invalid location within the document.
-
isBlockTag
Determines if the HTML.Tag associated with the element is a block tag.- Parameters:
attr
- an AttributeSet- Returns:
- true if tag is block tag, false otherwise.
-
startTag
Writes out a start tag for the element. Ignores all synthesized elements.- Parameters:
elem
- an Element- Throws:
IOException
- on any I/O errorBadLocationException
- if pos represents an invalid location within the document.
-
textAreaContent
Writes out text that is contained in a TEXTAREA form element.- Parameters:
attr
- an AttributeSet- Throws:
IOException
- on any I/O errorBadLocationException
- if pos represents an invalid location within the document.
-
text
Writes out text. If a range is specified when the constructor is invoked, then only the appropriate range of text is written out.- Overrides:
text
in classAbstractWriter
- Parameters:
elem
- an Element- Throws:
IOException
- on any I/O errorBadLocationException
- if pos represents an invalid location within the document.
-
selectContent
Writes out the content of the SELECT form element.- Parameters:
attr
- the AttributeSet associated with the form element- Throws:
IOException
- on any I/O error
-
writeOption
Writes out the content of the Option form element.- Parameters:
option
- an Option- Throws:
IOException
- on any I/O error
-
endTag
Writes out an end tag for the element.- Parameters:
elem
- an Element- Throws:
IOException
- on any I/O error
-
comment
Writes out comments.- Parameters:
elem
- an Element- Throws:
IOException
- on any I/O errorBadLocationException
- if pos represents an invalid location within the document.
-
synthesizedElement
Returnstrue
if the element is a synthesized element. Currently we are only testing for the p-implied tag.- Parameters:
elem
- an element- Returns:
true
if the element is a synthesized element.
-
matchNameAttribute
Returns true if the StyleConstants.NameAttribute is equal to the tag that is passed in as a parameter.- Parameters:
attr
- a set of attributestag
- an HTML tag- Returns:
true
if the StyleConstants.NameAttribute is equal to the tag that is passed in as a parameter.
-
writeEmbeddedTags
Searches for embedded tags in the AttributeSet and writes them out. It also stores these tags in a vector so that when appropriate the corresponding end tags can be written out.- Parameters:
attr
- a set of attributes- Throws:
IOException
- on any I/O error
-
closeOutUnwantedEmbeddedTags
Searches the attribute set and for each tag that is stored in the tag vector. If the tag is not found, then the tag is removed from the vector and a corresponding end tag is written out.- Parameters:
attr
- a set of attributes- Throws:
IOException
- on any I/O error
-
writeLineSeparator
Writes the line separator. This is overridden to make sure we don't replace the newline content in case it is outside normal ascii.- Overrides:
writeLineSeparator
in classAbstractWriter
- Throws:
IOException
- on any I/O error- Since:
- 1.3
-
output
This method is overridden to map any character entities, such as < to <.super.output
will be invoked to write the content.- Overrides:
output
in classAbstractWriter
- Parameters:
chars
- characters to outputstart
- starting indexlength
- length of output- Throws:
IOException
- on any I/O error- Since:
- 1.3
-