Package com.sun.javatest.util
Class HTMLWriter
- java.lang.Object
-
- com.sun.javatest.util.HTMLWriter
-
- Direct Known Subclasses:
HTMLWriterEx
public class HTMLWriter extends java.lang.ObjectA class to facilitate writing HTML via a stream.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringAThe HTML "a" tag.static java.lang.StringALIGNThe HTML "align" attribute.static java.lang.StringBThe HTML "b" tag.static java.lang.StringBODYThe HTML "body" tag.static java.lang.StringBORDERThe HTML "border" attribute.static java.lang.StringBRThe HTML "br" tag.static java.lang.StringCLASSIDThe HTML "classid" attribute.static java.lang.StringCODEThe HTML "code" tag.static java.lang.StringCOLThe HTML "col" attribute value.static java.lang.StringCOLORThe HTML "color" attribute.static java.lang.StringFONTThe HTML "font" tag.static java.lang.StringH1The HTML "h1" tag.static java.lang.StringH2The HTML "h2" tag.static java.lang.StringH3The HTML "h3" tag.static java.lang.StringH4The HTML "h4" tag.static java.lang.StringHEADThe HTML "head" tag.static java.lang.StringHRThe HTML "hr" tag.static java.lang.StringHREFThe HTML "href" attribute.static java.lang.StringHTMLThe HTML "html" tag.static java.lang.StringIThe HTML "i" tag.static java.lang.StringIDThe HTML "id" attribute.static java.lang.StringIMAGEThe HTML "image" tag.static java.lang.StringLEFTThe HTML "left" attribute value.static java.lang.StringLIThe HTML "li" tag.static java.lang.StringLINKThe HTML "link" tag.static java.lang.StringNAMEThe HTML "name" attribute.static java.lang.StringOBJECTThe HTML "object" tag.static java.lang.StringPThe HTML "param" tag.static java.lang.StringPARAMThe HTML "p" tag.static java.lang.StringRELThe HTML "rel" attribute value.static java.lang.StringRIGHTThe HTML "right" attribute value.static java.lang.StringROWThe HTML "row" attribute value.static java.lang.StringSCOPEThe HTML "scope" attribute.static java.lang.StringSMALLThe HTML "small" tag.static java.lang.StringSRCThe HTML "src" attribute.static java.lang.StringSTYLEThe HTML "style" attribute.static java.lang.StringSUMMARYThe HTML "summary" attribute.static java.lang.StringTABLEThe HTML "table" tag.static java.lang.StringTDThe HTML "td" tag.static java.lang.StringTEXT_LEFTstatic java.lang.StringTEXT_RIGHTstatic java.lang.StringTHThe HTML "th" tag.static java.lang.StringTITLEThe HTML "title"attribute.static java.lang.StringTOPThe HTML "top" attribute value.static java.lang.StringTRThe HTML "tr" tag.static java.lang.StringTYPEThe HTML "type" attribute.static java.lang.StringULThe HTML "ul" tag.static java.lang.StringVALIGNThe HTML "valign" attribute.static java.lang.StringVALUEThe HTML "value" attribute.
-
Constructor Summary
Constructors Constructor Description HTMLWriter(java.io.Writer out)Create an HTMLWriter object, using a default doctype for HTML 3.2.HTMLWriter(java.io.Writer out, I18NResourceBundle i18n)Create an HTMLWriter object, using a specified bundle for l0calizing messages.HTMLWriter(java.io.Writer out, java.lang.String docType)Create an HTMLWriter object, using a specified doctype header.HTMLWriter(java.io.Writer out, java.lang.String docType, I18NResourceBundle i18n)Create an HTMLWriter object, using a specified doctype header and using a specified bundle for localizing messages.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Close the stream, and the underlying output stream.protected booleanclosePrevTag()voidendEmptyTag(java.lang.String tag)Finish an empty element tag, such as a META, BASE or LINK tag.voidendTag(java.lang.String tag)Finish an HTML tag.voidflush()Flush the stream, and the underlying output stream.java.lang.StringgetCanonicalURIPath(java.io.File file)Returns URI path to the specified absolute file.voidnewLine()Write a newline to the underlying output stream.voidsetI18NResourceBundle(I18NResourceBundle i18n)Set the resource bundle to be used for localizing messages.voidstartTag(java.lang.String tag)Start an HTML tag.voidwrite(I18NResourceBundle i18n, java.lang.String key)Write a localized message, using a specified resource bundle.voidwrite(I18NResourceBundle i18n, java.lang.String key, java.lang.Object arg)Write a localized message, using a specified resource bundle.voidwrite(I18NResourceBundle i18n, java.lang.String key, java.lang.Object... args)Write a localized message, using a specified resource bundle.voidwrite(java.lang.String text)Write body text, escaping it as necessary.voidwriteAttr(java.lang.String name, int value)Write an attribute for a tag.voidwriteAttr(java.lang.String name, java.lang.String value)Write an attribute for a tag.voidwriteEntity(java.lang.String entity)Write a basic HTML entity, such as or { .voidwriteI18N(java.lang.String key)Write a localized message, using the default resource bundle.voidwriteI18N(java.lang.String key, java.lang.Object arg)Write a localized message, using the default resource bundle.voidwriteI18N(java.lang.String key, java.lang.Object... args)Write a localized message, using the default resource bundle.voidwriteImage(java.lang.String imagePath)Write an image tag, using a specified path for the image source attribute.voidwriteImage(java.net.URL imageURL)Write an image tag, using a specified path for the image source attribute.voidwriteLangAttr()Writes value of 'lang' attribute that is defined in resource bundle.voidwriteLine(java.lang.String text)Write a line of text, followed by a newline.voidwriteLink(java.io.File file)Write a hypertext link.voidwriteLink(java.io.File file, java.lang.String body)Write a hypertext link.voidwriteLink(java.lang.String anchor, java.lang.String body)Write a hypertext link.voidwriteLink(java.net.URL url, java.lang.String body)Write a hypertext link.voidwriteLinkDestination(java.lang.String anchor, java.lang.String body)Write the destination marker for a hypertext link.voidwriteParam(java.lang.String name, java.lang.String value)Write a parameter tag.voidwriteRaw(java.lang.String text)Write body text, escaping it as necessary.voidwriteStyleAttr(java.lang.String value)Write a style attribute.
-
-
-
Field Detail
-
A
public static final java.lang.String A
The HTML "a" tag.- See Also:
- Constant Field Values
-
ALIGN
public static final java.lang.String ALIGN
The HTML "align" attribute.- See Also:
- Constant Field Values
-
B
public static final java.lang.String B
The HTML "b" tag.- See Also:
- Constant Field Values
-
BODY
public static final java.lang.String BODY
The HTML "body" tag.- See Also:
- Constant Field Values
-
BORDER
public static final java.lang.String BORDER
The HTML "border" attribute.- See Also:
- Constant Field Values
-
BR
public static final java.lang.String BR
The HTML "br" tag.- See Also:
- Constant Field Values
-
CLASSID
public static final java.lang.String CLASSID
The HTML "classid" attribute.- See Also:
- Constant Field Values
-
CODE
public static final java.lang.String CODE
The HTML "code" tag.- See Also:
- Constant Field Values
-
COLOR
public static final java.lang.String COLOR
The HTML "color" attribute.- See Also:
- Constant Field Values
-
COL
public static final java.lang.String COL
The HTML "col" attribute value.- See Also:
- Constant Field Values
-
FONT
public static final java.lang.String FONT
The HTML "font" tag.- See Also:
- Constant Field Values
-
H1
public static final java.lang.String H1
The HTML "h1" tag.- See Also:
- Constant Field Values
-
H2
public static final java.lang.String H2
The HTML "h2" tag.- See Also:
- Constant Field Values
-
H3
public static final java.lang.String H3
The HTML "h3" tag.- See Also:
- Constant Field Values
-
H4
public static final java.lang.String H4
The HTML "h4" tag.- See Also:
- Constant Field Values
-
HEAD
public static final java.lang.String HEAD
The HTML "head" tag.- See Also:
- Constant Field Values
-
HREF
public static final java.lang.String HREF
The HTML "href" attribute.- See Also:
- Constant Field Values
-
HTML
public static final java.lang.String HTML
The HTML "html" tag.- See Also:
- Constant Field Values
-
HR
public static final java.lang.String HR
The HTML "hr" tag.- See Also:
- Constant Field Values
-
I
public static final java.lang.String I
The HTML "i" tag.- See Also:
- Constant Field Values
-
IMAGE
public static final java.lang.String IMAGE
The HTML "image" tag.- See Also:
- Constant Field Values
-
LEFT
public static final java.lang.String LEFT
The HTML "left" attribute value.- See Also:
- Constant Field Values
-
TEXT_LEFT
public static final java.lang.String TEXT_LEFT
- See Also:
- Constant Field Values
-
LI
public static final java.lang.String LI
The HTML "li" tag.- See Also:
- Constant Field Values
-
LINK
public static final java.lang.String LINK
The HTML "link" tag.- See Also:
- Constant Field Values
-
NAME
public static final java.lang.String NAME
The HTML "name" attribute.- See Also:
- Constant Field Values
-
ID
public static final java.lang.String ID
The HTML "id" attribute.- See Also:
- Constant Field Values
-
OBJECT
public static final java.lang.String OBJECT
The HTML "object" tag.- See Also:
- Constant Field Values
-
PARAM
public static final java.lang.String PARAM
The HTML "p" tag.- See Also:
- Constant Field Values
-
P
public static final java.lang.String P
The HTML "param" tag.- See Also:
- Constant Field Values
-
REL
public static final java.lang.String REL
The HTML "rel" attribute value.- See Also:
- Constant Field Values
-
RIGHT
public static final java.lang.String RIGHT
The HTML "right" attribute value.- See Also:
- Constant Field Values
-
TEXT_RIGHT
public static final java.lang.String TEXT_RIGHT
- See Also:
- Constant Field Values
-
ROW
public static final java.lang.String ROW
The HTML "row" attribute value.- See Also:
- Constant Field Values
-
SMALL
public static final java.lang.String SMALL
The HTML "small" tag.- See Also:
- Constant Field Values
-
SRC
public static final java.lang.String SRC
The HTML "src" attribute.- See Also:
- Constant Field Values
-
SCOPE
public static final java.lang.String SCOPE
The HTML "scope" attribute.- See Also:
- Constant Field Values
-
STYLE
public static final java.lang.String STYLE
The HTML "style" attribute.- See Also:
- Constant Field Values
-
SUMMARY
public static final java.lang.String SUMMARY
The HTML "summary" attribute.- See Also:
- Constant Field Values
-
TABLE
public static final java.lang.String TABLE
The HTML "table" tag.- See Also:
- Constant Field Values
-
TD
public static final java.lang.String TD
The HTML "td" tag.- See Also:
- Constant Field Values
-
TITLE
public static final java.lang.String TITLE
The HTML "title"attribute.- See Also:
- Constant Field Values
-
TH
public static final java.lang.String TH
The HTML "th" tag.- See Also:
- Constant Field Values
-
TOP
public static final java.lang.String TOP
The HTML "top" attribute value.- See Also:
- Constant Field Values
-
TR
public static final java.lang.String TR
The HTML "tr" tag.- See Also:
- Constant Field Values
-
TYPE
public static final java.lang.String TYPE
The HTML "type" attribute.- See Also:
- Constant Field Values
-
UL
public static final java.lang.String UL
The HTML "ul" tag.- See Also:
- Constant Field Values
-
VALIGN
public static final java.lang.String VALIGN
The HTML "valign" attribute.- See Also:
- Constant Field Values
-
VALUE
public static final java.lang.String VALUE
The HTML "value" attribute.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
HTMLWriter
public HTMLWriter(java.io.Writer out) throws java.io.IOExceptionCreate an HTMLWriter object, using a default doctype for HTML 3.2.- Parameters:
out- a Writer to which to write the generated HTML- Throws:
java.io.IOException- if there is a problem writing to the underlying stream
-
HTMLWriter
public HTMLWriter(java.io.Writer out, java.lang.String docType) throws java.io.IOExceptionCreate 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:
java.io.IOException- if there is a problem writing to the underlying stream
-
HTMLWriter
public HTMLWriter(java.io.Writer out, I18NResourceBundle i18n) throws java.io.IOExceptionCreate 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:
java.io.IOException- if there is a problem writing to the underlying stream
-
HTMLWriter
public HTMLWriter(java.io.Writer out, java.lang.String docType, I18NResourceBundle i18n) throws java.io.IOExceptionCreate 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:
java.io.IOException- if there is a problem writing to the underlying stream
-
-
Method Detail
-
setI18NResourceBundle
public void setI18NResourceBundle(I18NResourceBundle i18n)
Set the resource bundle to be used for localizing messages.- Parameters:
i18n- the resource bundle to be used for localizing messages
-
flush
public void flush() throws java.io.IOExceptionFlush the stream, and the underlying output stream.- Throws:
java.io.IOException- if there is a problem writing to the underlying stream
-
close
public void close() throws java.io.IOExceptionClose the stream, and the underlying output stream.- Throws:
java.io.IOException- if there is a problem closing the underlying stream
-
newLine
public void newLine() throws java.io.IOExceptionWrite a newline to the underlying output stream.- Throws:
java.io.IOException- if there is a problem writing to the underlying stream
-
startTag
public void startTag(java.lang.String tag) throws java.io.IOExceptionStart 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:
java.io.IOException- if there is a problem writing to the underlying stream- See Also:
writeAttr(java.lang.String, java.lang.String),write(java.lang.String),endTag(java.lang.String)
-
endTag
public void endTag(java.lang.String tag) throws java.io.IOExceptionFinish 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:
java.io.IOException- if there is a problem writing to the underlying stream
-
endEmptyTag
public void endEmptyTag(java.lang.String tag) throws java.io.IOExceptionFinish 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:
java.lang.IllegalStateException- if this call does not follow startTag (stream is not currently inside a tag)java.io.IOException- if there is a problem writing to the underlying stream
-
writeAttr
public void writeAttr(java.lang.String name, java.lang.String value) throws java.io.IOExceptionWrite 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:
java.lang.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 writteAttrjava.io.IOException- if there is a problem writing to the underlying stream
-
writeLangAttr
public void writeLangAttr() throws java.io.IOExceptionWrites 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:
java.io.IOException- if there is a problem writing to the underlying stream
-
writeAttr
public void writeAttr(java.lang.String name, int value) throws java.io.IOExceptionWrite 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:
java.lang.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 writteAttrjava.io.IOException- if there is a problem writing to the underlying stream
-
writeLine
public void writeLine(java.lang.String text) throws java.io.IOExceptionWrite a line of text, followed by a newline. The text will be escaped as necessary.- Parameters:
text- the text to be written.- Throws:
java.io.IOException- if there is a problem closing the underlying stream
-
writeRaw
public void writeRaw(java.lang.String text) throws java.io.IOExceptionWrite 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:
java.io.IOException- if there is a problem writing to the underlying stream
-
write
public void write(java.lang.String text) throws java.io.IOExceptionWrite 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:
java.io.IOException- if there is a problem writing to the underlying stream
-
writeEntity
public void writeEntity(java.lang.String entity) throws java.io.IOExceptionWrite a basic HTML entity, such as or { .- Parameters:
entity- the entity to write- Throws:
java.io.IOException- if there is a problem writing to the underlying stream
-
writeImage
public void writeImage(java.lang.String imagePath) throws java.io.IOExceptionWrite an image tag, using a specified path for the image source attribute.- Parameters:
imagePath- the path for the image source- Throws:
java.io.IOException- if there is a problem closing the underlying stream
-
writeImage
public void writeImage(java.net.URL imageURL) throws java.io.IOExceptionWrite an image tag, using a specified path for the image source attribute.- Parameters:
imageURL- the url for the image source- Throws:
java.io.IOException- if there is a problem closing the underlying stream
-
writeLink
public void writeLink(java.lang.String anchor, java.lang.String body) throws java.io.IOExceptionWrite a hypertext link.- Parameters:
anchor- the target for the linkbody- the body text for the link- Throws:
java.io.IOException- if there is a problem closing the underlying stream
-
writeLink
public void writeLink(java.io.File file, java.lang.String body) throws java.io.IOExceptionWrite a hypertext link.- Parameters:
file- the target for the linkbody- the body text for the link- Throws:
java.io.IOException- if there is a problem closing the underlying stream
-
getCanonicalURIPath
public java.lang.String getCanonicalURIPath(java.io.File file) throws java.io.IOExceptionReturns URI path to the specified absolute file.- Parameters:
file- to get URI path- Returns:
- URI path for the file
- Throws:
java.io.IOException- if there is a problem to encode path symbol
-
writeLink
public void writeLink(java.io.File file) throws java.io.IOExceptionWrite a hypertext link.- Parameters:
file- the target and body for the link- Throws:
java.io.IOException- if there is a problem closing the underlying stream
-
writeLink
public void writeLink(java.net.URL url, java.lang.String body) throws java.io.IOExceptionWrite a hypertext link.- Parameters:
url- the target for the linkbody- the body text for the link- Throws:
java.io.IOException- if there is a problem closing the underlying stream
-
writeLinkDestination
public void writeLinkDestination(java.lang.String anchor, java.lang.String body) throws java.io.IOExceptionWrite the destination marker for a hypertext link.- Parameters:
anchor- the destination marker for hypertext linksbody- the body text for the marker- Throws:
java.io.IOException- if there is a problem closing the underlying stream
-
writeParam
public void writeParam(java.lang.String name, java.lang.String value) throws java.io.IOExceptionWrite a parameter tag.- Parameters:
name- the name of the parametervalue- the value of the parameter- Throws:
java.io.IOException- if there is a problem closing the underlying stream
-
writeStyleAttr
public void writeStyleAttr(java.lang.String value) throws java.io.IOExceptionWrite a style attribute.- Parameters:
value- the value for the style attribute- Throws:
java.io.IOException- if there is a problem closing the underlying stream
-
write
public void write(I18NResourceBundle i18n, java.lang.String key) throws java.io.IOException
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:
java.io.IOException- if there is a problem closing the underlying stream
-
write
public void write(I18NResourceBundle i18n, java.lang.String key, java.lang.Object arg) throws java.io.IOException
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:
java.io.IOException- if there is a problem closing the underlying stream
-
write
public void write(I18NResourceBundle i18n, java.lang.String key, java.lang.Object... args) throws java.io.IOException
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:
java.io.IOException- if there is a problem closing the underlying stream
-
writeI18N
public void writeI18N(java.lang.String key) throws java.io.IOExceptionWrite a localized message, using the default resource bundle.- Parameters:
key- the key for the message to be localized- Throws:
java.io.IOException- if there is a problem closing the underlying stream
-
writeI18N
public void writeI18N(java.lang.String key, java.lang.Object arg) throws java.io.IOExceptionWrite 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:
java.io.IOException- if there is a problem closing the underlying stream
-
writeI18N
public void writeI18N(java.lang.String key, java.lang.Object... args) throws java.io.IOExceptionWrite 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:
java.io.IOException- if there is a problem closing the underlying stream
-
closePrevTag
protected boolean closePrevTag() throws java.io.IOException- Throws:
java.io.IOException
-
-