Class XMLWriter

java.lang.Object
com.sun.javatest.util.XMLWriter

public class XMLWriter extends Object
A class to facilitate writing XML via a stream.
  • Constructor Details

    • XMLWriter

      public XMLWriter(Writer out) throws IOException
      Create an XMLWriter object, using a default header.
      Parameters:
      out - a Writer to which to write the generated XML
      Throws:
      IOException - if there is a problem writing to the underlying stream
    • XMLWriter

      public XMLWriter(Writer out, String docType) throws IOException
      Create an XMLWriter object, using a specified doctype header.
      Parameters:
      out - a Writer to which to write the generated XML
      docType - a string containing a doctype header for the XML to be generated
      Throws:
      IOException - if there is a problem writing to the underlying stream
    • XMLWriter

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

      public XMLWriter(Writer out, String docType, I18NResourceBundle i18n) throws IOException
      Create an XMLWriter object, using a specified doctype header and using a specified bundle for localizing messages.
      Parameters:
      out - a Writer to which to write the generated XML
      docType - a string containing a doctype header for the XML 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 closing the underlying stream
    • startTag

      public void startTag(String tag) throws IOException
      Start an XML 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 closing the underlying stream
      See Also:
    • endTag

      public void endTag(String tag) throws IOException
      Finish an XML 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 closing 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 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 closing 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
    • writeDate

      public void writeDate(long millis) throws IOException
      Write a formatted date.
      Parameters:
      millis - date represented in milliseconds
      Throws:
      IOException - if a exception occurs during writing
      See Also:
    • writeDate

      public void writeDate(String tag, long millis) throws IOException
      Write a formatted date surrounded by a markup tag.
      Parameters:
      tag - tag to open and close before and after the date is inserted
      millis - date represented in milliseconds
      Throws:
      IOException - if a exception occurs during writing
      See Also:
    • writeDate

      public void writeDate(Date date) throws IOException
      Write a formatted date.
      Parameters:
      date - the date to print
      Throws:
      IOException - if a exception occurs during writing
    • writeDate

      public void writeDate(String tag, Date date) throws IOException
      Write a formatted date surrounded by a markup tag.
      Parameters:
      tag - tag to open and close before and after the date is inserted
      date - the date to print
      Throws:
      IOException - if a exception occurs during writing
      See Also:
    • 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.
      Parameters:
      text - the text to be written
      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