Package com.sun.javatest.util
Class HTMLWriter
java.lang.Object
com.sun.javatest.util.HTMLWriter
- Direct Known Subclasses:
HTMLWriterEx
A class to facilitate writing HTML via a stream.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
The HTML "a" tag.static final String
The HTML "align" attribute.static final String
The HTML "b" tag.static final String
The HTML "body" tag.static final String
The HTML "border" attribute.static final String
The HTML "br" tag.static final String
The HTML "classid" attribute.static final String
The HTML "code" tag.static final String
The HTML "col" attribute value.static final String
The HTML "color" attribute.static final String
The HTML "font" tag.static final String
The HTML "h1" tag.static final String
The HTML "h2" tag.static final String
The HTML "h3" tag.static final String
The HTML "h4" tag.static final String
The HTML "head" tag.static final String
The HTML "hr" tag.static final String
The HTML "href" attribute.static final String
The HTML "html" tag.static final String
The HTML "i" tag.static final String
The HTML "id" attribute.static final String
The HTML "image" tag.static final String
The HTML "left" attribute value.static final String
The HTML "li" tag.static final String
The HTML "link" tag.static final String
The HTML "name" attribute.static final String
The HTML "object" tag.static final String
The HTML "param" tag.static final String
The HTML "p" tag.static final String
The HTML "rel" attribute value.static final String
The HTML "right" attribute value.static final String
The HTML "row" attribute value.static final String
The HTML "scope" attribute.static final String
The HTML "small" tag.static final String
The HTML "src" attribute.static final String
The HTML "style" attribute.static final String
The HTML "summary" attribute.static final String
The HTML "table" tag.static final String
The HTML "td" tag.static final String
static final String
static final String
The HTML "th" tag.static final String
The HTML "title"attribute.static final String
The HTML "top" attribute value.static final String
The HTML "tr" tag.static final String
The HTML "type" attribute.static final String
The HTML "ul" tag.static final String
The HTML "valign" attribute.static final String
The HTML "value" attribute. -
Constructor Summary
ConstructorsConstructorDescriptionHTMLWriter
(Writer out) Create an HTMLWriter object, using a default doctype for HTML 3.2.HTMLWriter
(Writer out, I18NResourceBundle i18n) Create an HTMLWriter object, using a specified bundle for l0calizing messages.HTMLWriter
(Writer out, String docType) Create an HTMLWriter object, using a specified doctype header.HTMLWriter
(Writer out, String docType, I18NResourceBundle i18n) Create an HTMLWriter object, using a specified doctype header and using a specified bundle for localizing messages. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Close the stream, and the underlying output stream.protected boolean
void
endEmptyTag
(String tag) Finish an empty element tag, such as a META, BASE or LINK tag.void
Finish an HTML tag.void
flush()
Flush the stream, and the underlying output stream.getCanonicalURIPath
(File file) Returns URI path to the specified absolute file.void
newLine()
Write a newline to the underlying output stream.void
Set the resource bundle to be used for localizing messages.void
Start an HTML tag.void
write
(I18NResourceBundle i18n, String key) Write a localized message, using a specified resource bundle.void
write
(I18NResourceBundle i18n, String key, Object arg) Write a localized message, using a specified resource bundle.void
write
(I18NResourceBundle i18n, String key, Object... args) Write a localized message, using a specified resource bundle.void
Write body text, escaping it as necessary.void
Write an attribute for a tag.void
Write an attribute for a tag.void
writeEntity
(String entity) Write a basic HTML entity, such as or { .void
Write a localized message, using the default resource bundle.void
Write a localized message, using the default resource bundle.void
Write a localized message, using the default resource bundle.void
writeImage
(String imagePath) Write an image tag, using a specified path for the image source attribute.void
writeImage
(URL imageURL) Write an image tag, using a specified path for the image source attribute.void
Writes value of 'lang' attribute that is defined in resource bundle.void
Write a line of text, followed by a newline.void
Write a hypertext link.void
Write a hypertext link.void
Write a hypertext link.void
Write a hypertext link.void
writeLinkDestination
(String anchor, String body) Write the destination marker for a hypertext link.void
writeParam
(String name, String value) Write a parameter tag.void
Write body text, escaping it as necessary.void
writeStyleAttr
(String value) Write a style attribute.
-
Field Details
-
A
The HTML "a" tag.- See Also:
-
ALIGN
The HTML "align" attribute.- See Also:
-
B
The HTML "b" tag.- See Also:
-
BODY
The HTML "body" tag.- See Also:
-
BORDER
The HTML "border" attribute.- See Also:
-
BR
The HTML "br" tag.- See Also:
-
CLASSID
The HTML "classid" attribute.- See Also:
-
CODE
The HTML "code" tag.- See Also:
-
COLOR
The HTML "color" attribute.- See Also:
-
COL
The HTML "col" attribute value.- See Also:
-
FONT
The HTML "font" tag.- See Also:
-
H1
The HTML "h1" tag.- See Also:
-
H2
The HTML "h2" tag.- See Also:
-
H3
The HTML "h3" tag.- See Also:
-
H4
The HTML "h4" tag.- See Also:
-
HEAD
The HTML "head" tag.- See Also:
-
HREF
The HTML "href" attribute.- See Also:
-
HTML
The HTML "html" tag.- See Also:
-
HR
The HTML "hr" tag.- See Also:
-
I
The HTML "i" tag.- See Also:
-
IMAGE
The HTML "image" tag.- See Also:
-
LEFT
The HTML "left" attribute value.- See Also:
-
TEXT_LEFT
- See Also:
-
LI
The HTML "li" tag.- See Also:
-
LINK
The HTML "link" tag.- See Also:
-
NAME
The HTML "name" attribute.- See Also:
-
ID
The HTML "id" attribute.- See Also:
-
OBJECT
The HTML "object" tag.- See Also:
-
PARAM
The HTML "p" tag.- See Also:
-
P
The HTML "param" tag.- See Also:
-
REL
The HTML "rel" attribute value.- See Also:
-
RIGHT
The HTML "right" attribute value.- See Also:
-
TEXT_RIGHT
- See Also:
-
ROW
The HTML "row" attribute value.- See Also:
-
SMALL
The HTML "small" tag.- See Also:
-
SRC
The HTML "src" attribute.- See Also:
-
SCOPE
The HTML "scope" attribute.- See Also:
-
STYLE
The HTML "style" attribute.- See Also:
-
SUMMARY
The HTML "summary" attribute.- See Also:
-
TABLE
The HTML "table" tag.- See Also:
-
TD
The HTML "td" tag.- See Also:
-
TITLE
The HTML "title"attribute.- See Also:
-
TH
The HTML "th" tag.- See Also:
-
TOP
The HTML "top" attribute value.- See Also:
-
TR
The HTML "tr" tag.- See Also:
-
TYPE
The HTML "type" attribute.- See Also:
-
UL
The HTML "ul" tag.- See Also:
-
VALIGN
The HTML "valign" attribute.- See Also:
-
VALUE
The HTML "value" attribute.- See Also:
-
-
Constructor Details
-
HTMLWriter
Create an HTMLWriter object, using a default doctype for HTML 3.2.- Parameters:
out
- a Writer to which to write the generated HTML- Throws:
IOException
- if there is a problem writing to the underlying stream
-
HTMLWriter
Create an HTMLWriter object, using a specified doctype header.- Parameters:
out
- a Writer to which to write the generated HTMLdocType
- a string containing a doctype header for the HTML to be generated- Throws:
IOException
- if there is a problem writing to the underlying stream
-
HTMLWriter
Create an HTMLWriter object, using a specified bundle for l0calizing messages.- Parameters:
out
- a Writer to which to write the generated HTMLi18n
- a resource bundle to use to localize messages- Throws:
IOException
- if there is a problem writing to the underlying stream
-
HTMLWriter
Create an HTMLWriter object, using a specified doctype header and using a specified bundle for localizing messages.- Parameters:
out
- a Writer to which to write the generated HTMLdocType
- a string containing a doctype header for the HTML to be generatedi18n
- a resource bundle to use to localize messages- Throws:
IOException
- if there is a problem writing to the underlying stream
-
-
Method Details
-
setI18NResourceBundle
Set the resource bundle to be used for localizing messages.- Parameters:
i18n
- the resource bundle to be used for localizing messages
-
flush
Flush the stream, and the underlying output stream.- Throws:
IOException
- if there is a problem writing to the underlying stream
-
close
Close the stream, and the underlying output stream.- Throws:
IOException
- if there is a problem closing the underlying stream
-
newLine
Write a newline to the underlying output stream.- Throws:
IOException
- if there is a problem writing to the underlying stream
-
startTag
Start an HTML tag. If a prior tag has been started, it will be closed first. Once a tag has been opened, attributes for the tag may be written out, followed by body content before finally ending the tag.- Parameters:
tag
- the tag to be started- Throws:
IOException
- if there is a problem writing to the underlying stream- See Also:
-
endTag
Finish an HTML tag. It is expected that a call to endTag will match a corresponding earlier call to startTag, but there is no formal check for this.- Parameters:
tag
- the tag to be closed.- Throws:
IOException
- if there is a problem writing to the underlying stream
-
endEmptyTag
Finish an empty element tag, such as a META, BASE or LINK tag. This is expected to correspond with a startTag.- Parameters:
tag
- the tag which is being closed. this is only useful for validation, it is not written out- Throws:
IllegalStateException
- if this call does not follow startTag (stream is not currently inside a tag)IOException
- if there is a problem writing to the underlying stream
-
writeAttr
Write an attribute for a tag. A tag must previously have been started. All tag attributes must be written before any body text is written. The value will be quoted. No check is made that the attribute is valid for the current tag.- Parameters:
name
- the name of the attribute to be writtenvalue
- the value of the attribute to be written- Throws:
IllegalStateException
- if the stream is not in a state to write attributes -- e.g. if this call does not follow startTag or other calls of writteAttrIOException
- if there is a problem writing to the underlying stream
-
writeLangAttr
Writes value of 'lang' attribute that is defined in resource bundle. This method is expected to be called after opening (starting) the root HTML tag.- Throws:
IOException
- if there is a problem writing to the underlying stream
-
writeAttr
Write an attribute for a tag. A tag must previously have been started. All tag attributes must be written before any body text is written. The value will be quoted if necessary when writing it to the underlying stream. No check is made that the attribute is valid for the current tag.- Parameters:
name
- the name of the attribute to be writtenvalue
- the value of the attribute to be written- Throws:
IllegalStateException
- if the stream is not in a state to write attributes -- e.g. if this call does not follow startTag or other calls of writteAttrIOException
- if there is a problem writing to the underlying stream
-
writeLine
Write a line of text, followed by a newline. The text will be escaped as necessary.- Parameters:
text
- the text to be written.- Throws:
IOException
- if there is a problem closing the underlying stream
-
writeRaw
Write body text, escaping it as necessary. If this call follows a call of startTag, the open tag will be closed -- meaning that no more attributes can be written until another tag is started. If the text value is null, the current tag will still be closed, but no other text will be written.- Parameters:
text
- the text to be written, may be null or zero length.- Throws:
IOException
- if there is a problem writing to the underlying stream
-
write
Write body text, escaping it as necessary. If this call follows a call of startTag, the open tag will be closed -- meaning that no more attributes can be written until another tag is started. If the text value is null, the current tag will still be closed, but no other text will be written.- Parameters:
text
- the text to be written, may be null or zero length.- Throws:
IOException
- if there is a problem writing to the underlying stream
-
writeEntity
Write a basic HTML entity, such as or { .- Parameters:
entity
- the entity to write- Throws:
IOException
- if there is a problem writing to the underlying stream
-
writeImage
Write an image tag, using a specified path for the image source attribute.- Parameters:
imagePath
- the path for the image source- Throws:
IOException
- if there is a problem closing the underlying stream
-
writeImage
Write an image tag, using a specified path for the image source attribute.- Parameters:
imageURL
- the url for the image source- Throws:
IOException
- if there is a problem closing the underlying stream
-
writeLink
Write a hypertext link.- Parameters:
anchor
- the target for the linkbody
- the body text for the link- Throws:
IOException
- if there is a problem closing the underlying stream
-
writeLink
Write a hypertext link.- Parameters:
file
- the target for the linkbody
- the body text for the link- Throws:
IOException
- if there is a problem closing the underlying stream
-
getCanonicalURIPath
Returns URI path to the specified absolute file.- Parameters:
file
- to get URI path- Returns:
- URI path for the file
- Throws:
IOException
- if there is a problem to encode path symbol
-
writeLink
Write a hypertext link.- Parameters:
file
- the target and body for the link- Throws:
IOException
- if there is a problem closing the underlying stream
-
writeLink
Write a hypertext link.- Parameters:
url
- the target for the linkbody
- the body text for the link- Throws:
IOException
- if there is a problem closing the underlying stream
-
writeLinkDestination
Write the destination marker for a hypertext link.- Parameters:
anchor
- the destination marker for hypertext linksbody
- the body text for the marker- Throws:
IOException
- if there is a problem closing the underlying stream
-
writeParam
Write a parameter tag.- Parameters:
name
- the name of the parametervalue
- the value of the parameter- Throws:
IOException
- if there is a problem closing the underlying stream
-
writeStyleAttr
Write a style attribute.- Parameters:
value
- the value for the style attribute- Throws:
IOException
- if there is a problem closing the underlying stream
-
write
Write a localized message, using a specified resource bundle.- Parameters:
i18n
- the resource bundle used to localize the messagekey
- the key for the message to be localized- Throws:
IOException
- if there is a problem closing the underlying stream
-
write
Write a localized message, using a specified resource bundle.- Parameters:
i18n
- the resource bundle used to localize the messagekey
- the key for the message to be localizedarg
- an argument to be formatted into the localized message- Throws:
IOException
- if there is a problem closing the underlying stream
-
write
Write a localized message, using a specified resource bundle.- Parameters:
i18n
- the resource bundle used to localize the messagekey
- the key for the message to be localizedargs
- arguments to be formatted into the localized message- Throws:
IOException
- if there is a problem closing the underlying stream
-
writeI18N
Write a localized message, using the default resource bundle.- Parameters:
key
- the key for the message to be localized- Throws:
IOException
- if there is a problem closing the underlying stream
-
writeI18N
Write a localized message, using the default resource bundle.- Parameters:
key
- the key for the message to be localizedarg
- an argument to be formatted into the localized message- Throws:
IOException
- if there is a problem closing the underlying stream
-
writeI18N
Write a localized message, using the default resource bundle.- Parameters:
key
- the key for the message to be localizedargs
- arguments to be formatted into the localized message- Throws:
IOException
- if there is a problem closing the underlying stream
-
closePrevTag
- Throws:
IOException
-