Class HTMLWriter

java.lang.Object
com.sun.javatest.util.HTMLWriter
Direct Known Subclasses:
HTMLWriterEx

public class HTMLWriter extends Object
A class to facilitate writing HTML via a stream.
  • Field Details

  • Constructor Details

    • HTMLWriter

      public HTMLWriter(Writer out) throws IOException
      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

      public HTMLWriter(Writer out, String docType) throws IOException
      Create an HTMLWriter object, using a specified doctype header.
      Parameters:
      out - a Writer to which to write the generated HTML
      docType - 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

      public HTMLWriter(Writer out, I18NResourceBundle i18n) throws IOException
      Create an HTMLWriter object, using a specified bundle for l0calizing messages.
      Parameters:
      out - a Writer to which to write the generated HTML
      i18n - a resource bundle to use to localize messages
      Throws:
      IOException - if there is a problem writing to the underlying stream
    • HTMLWriter

      public HTMLWriter(Writer out, String docType, I18NResourceBundle i18n) throws IOException
      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 HTML
      docType - a string containing a doctype header for the HTML to be generated
      i18n - a resource bundle to use to localize messages
      Throws:
      IOException - if there is a problem writing to the underlying stream
  • Method Details

    • 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 IOException
      Flush the stream, and the underlying output stream.
      Throws:
      IOException - if there is a problem writing to the underlying stream
    • close

      public void close() throws IOException
      Close the stream, and the underlying output stream.
      Throws:
      IOException - if there is a problem closing the underlying stream
    • newLine

      public void newLine() throws IOException
      Write a newline to the underlying output stream.
      Throws:
      IOException - if there is a problem writing to the underlying stream
    • startTag

      public void startTag(String tag) throws IOException
      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

      public void endTag(String tag) throws IOException
      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

      public void endEmptyTag(String tag) throws IOException
      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

      public void writeAttr(String name, String value) throws IOException
      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 written
      value - 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 writteAttr
      IOException - if there is a problem writing to the underlying stream
    • writeLangAttr

      public void writeLangAttr() throws IOException
      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

      public void writeAttr(String name, int value) throws IOException
      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 written
      value - 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 writteAttr
      IOException - if there is a problem writing to the underlying stream
    • writeLine

      public void writeLine(String text) throws IOException
      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

      public void writeRaw(String text) throws IOException
      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

      public void write(String text) throws IOException
      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

      public void writeEntity(String entity) throws IOException
      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

      public void writeImage(String imagePath) throws IOException
      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

      public void writeImage(URL imageURL) throws IOException
      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

      public void writeLink(String anchor, String body) throws IOException
      Write a hypertext link.
      Parameters:
      anchor - the target for the link
      body - the body text for the link
      Throws:
      IOException - if there is a problem closing the underlying stream
    • writeLink

      public void writeLink(File file, String body) throws IOException
      Write a hypertext link.
      Parameters:
      file - the target for the link
      body - the body text for the link
      Throws:
      IOException - if there is a problem closing the underlying stream
    • getCanonicalURIPath

      public String getCanonicalURIPath(File file) throws IOException
      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

      public void writeLink(File file) throws IOException
      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

      public void writeLink(URL url, String body) throws IOException
      Write a hypertext link.
      Parameters:
      url - the target for the link
      body - the body text for the link
      Throws:
      IOException - if there is a problem closing the underlying stream
    • writeLinkDestination

      public void writeLinkDestination(String anchor, String body) throws IOException
      Write the destination marker for a hypertext link.
      Parameters:
      anchor - the destination marker for hypertext links
      body - the body text for the marker
      Throws:
      IOException - if there is a problem closing the underlying stream
    • writeParam

      public void writeParam(String name, String value) throws IOException
      Write a parameter tag.
      Parameters:
      name - the name of the parameter
      value - the value of the parameter
      Throws:
      IOException - if there is a problem closing the underlying stream
    • writeStyleAttr

      public void writeStyleAttr(String value) throws IOException
      Write a style attribute.
      Parameters:
      value - the value for the style attribute
      Throws:
      IOException - if there is a problem closing the underlying stream
    • write

      public void write(I18NResourceBundle i18n, String key) throws IOException
      Write a localized message, using a specified resource bundle.
      Parameters:
      i18n - the resource bundle used to localize the message
      key - the key for the message to be localized
      Throws:
      IOException - if there is a problem closing the underlying stream
    • write

      public void write(I18NResourceBundle i18n, String key, Object arg) throws IOException
      Write a localized message, using a specified resource bundle.
      Parameters:
      i18n - the resource bundle used to localize the message
      key - the key for the message to be localized
      arg - an argument to be formatted into the localized message
      Throws:
      IOException - if there is a problem closing the underlying stream
    • write

      public void write(I18NResourceBundle i18n, String key, Object... args) throws IOException
      Write a localized message, using a specified resource bundle.
      Parameters:
      i18n - the resource bundle used to localize the message
      key - the key for the message to be localized
      args - arguments to be formatted into the localized message
      Throws:
      IOException - if there is a problem closing the underlying stream
    • writeI18N

      public void writeI18N(String key) throws IOException
      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

      public void writeI18N(String key, Object arg) throws IOException
      Write a localized message, using the default resource bundle.
      Parameters:
      key - the key for the message to be localized
      arg - an argument to be formatted into the localized message
      Throws:
      IOException - if there is a problem closing the underlying stream
    • writeI18N

      public void writeI18N(String key, Object... args) throws IOException
      Write a localized message, using the default resource bundle.
      Parameters:
      key - the key for the message to be localized
      args - arguments to be formatted into the localized message
      Throws:
      IOException - if there is a problem closing the underlying stream
    • closePrevTag

      protected boolean closePrevTag() throws IOException
      Throws:
      IOException