Class SaxAuthor

java.lang.Object
eu.bandm.tools.util.xml.SaxAuthor

public class SaxAuthor extends Object
Facade for conveniently creating sequences of SAX events, more likely to be well-formed.

For this, a stack is maintained of the currently open elements, and closing tags are checked for the correct sequence.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Attributes
    evident
    protected ContentHandler
    Target of the generated Sax events.
    protected Deque<String>
    Protocol of currently open elements.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Create a new instance with the given content handler as the target of all generated sax events.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    CHARS(String text)
    Output a SAX event representing the character data.
    void
    CLOP(String... tags)
    "*CL*ose and re-*OP*en" = close and Close the elements with the given tags, one after the other, and then open them again, backwards.
    void
    Close the current top-level element = the latest opened element.
    void
    CLOSE(int i)
    Close the current top-level n elements = the latest opened n elements.
    void
    Close one element with the given tags, check whether it is really currently open.
    void
    CLOSE_S(String... tags)
    Close the elements with the given tags, one after the other, and check whether they are really currently open.
    void
    Output two SAX event which correspond to an empty element with the given tag- Output one open event immediately folloed by a close.
    void
    EMPTY(String tag, String... pairs)
    Output two SAX events which correspond to an empty element.
    void
    OPEN(String tag)
    Execute a "start element" sax call on the receiver, with empty attributes, and memoize the element as open.
    void
    OPEN(String tag, String... pairs)
    Perform a "start element" sax call with the tag and the collected attribute/value pairs as attribute, and memorize the element as open.
    void
    OPEN(String tag, Attributes atts)
    Execute a "start element" sax call on the receiver, and memorize the element as open.
    void
    OPEN_S(String... tags)
    Execute a sequence of "start element" sax calls on the given tag sequence, and memorize all these elements as open.
    void
    SIMPLE(String tag, String text)
    Output three SAX event which correspond to a element with plain character data.
    void
    SIMPLE(String tag, String text, String... pairs)
    Output three SAX event which correspond to a element with plain character data.
    void
    Output a SAX event representing threw whitespace characters- data.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • sax

      protected ContentHandler sax
      Target of the generated Sax events.
    • stack

      protected Deque<String> stack
      Protocol of currently open elements.
    • EMPTY_ATTRIBUTES

      public static final Attributes EMPTY_ATTRIBUTES
      evident
  • Constructor Details

    • SaxAuthor

      public SaxAuthor(ContentHandler sax0)
      Create a new instance with the given content handler as the target of all generated sax events.
  • Method Details

    • OPEN

      public void OPEN(String tag, Attributes atts)
      Execute a "start element" sax call on the receiver, and memorize the element as open.
      Throws:
      IllegalStateException - if a SAXException is encountered
    • OPEN

      public void OPEN(String tag)
      Execute a "start element" sax call on the receiver, with empty attributes, and memoize the element as open.
      Throws:
      IllegalStateException - if a SAXException is encountered
    • OPEN_S

      public void OPEN_S(String... tags)
      Execute a sequence of "start element" sax calls on the given tag sequence, and memorize all these elements as open.
      Throws:
      IllegalStateException - if a SAXException is encountered
    • OPEN

      public void OPEN(String tag, String... pairs)
      Perform a "start element" sax call with the tag and the collected attribute/value pairs as attribute, and memorize the element as open.
      Throws:
      IllegalStateException - if a SAXException is encountered
    • CLOSE_S

      public void CLOSE_S(String... tags)
      Close the elements with the given tags, one after the other, and check whether they are really currently open.
      Throws:
      IllegalStateException - if the tag does not match to the current protocol of opened elements, or when a SAXException is encountered during write.
    • CLOP

      public void CLOP(String... tags)
      "*CL*ose and re-*OP*en" = close and Close the elements with the given tags, one after the other, and then open them again, backwards. Check whether they are really currently open.
      Throws:
      IllegalStateException - if the tag does not match to the current protocol of opened elements, or when a SAXException is encountered during write.
    • CLOSE

      public void CLOSE(String tag)
      Close one element with the given tags, check whether it is really currently open.
      Throws:
      IllegalStateException - if the tag does not match to the current protocol of opened elements, or when a SAXException is encountered during write.
    • CLOSE

      public void CLOSE()
      Close the current top-level element = the latest opened element.
      Throws:
      IllegalStateException - if no element is open, or when a SAXException is encountered during write.
    • CLOSE

      public void CLOSE(int i)
      Close the current top-level n elements = the latest opened n elements.
      Parameters:
      i - number of elements to close.
      Throws:
      IllegalStateException - if not enough elements are open, or when a SAXException is encountered during write.
    • CHARS

      public void CHARS(String text)
      Output a SAX event representing the character data.
      Throws:
      IllegalStateException - if a SAXException is encountered during write.
    • SPACE

      public void SPACE()
      Output a SAX event representing threw whitespace characters- data.
      Throws:
      IllegalStateException - if a SAXException is encountered during write.
    • SIMPLE

      public void SIMPLE(String tag, String text)
      Output three SAX event which correspond to a element with plain character data. Output a SAX event starting an element with the given tag, then output the character data, then close the element immediately.
      Throws:
      IllegalStateException - if a SAXException is encountered during write.
    • SIMPLE

      public void SIMPLE(String tag, String text, String... pairs)
      Output three SAX event which correspond to a element with plain character data. Output a SAX event starting an element with the given tag and the key/value pairs as attributes, then output the character data, then close the element immediately.
      Parameters:
      text - the character data
      pairs - of attribute names (qnames, if namespace mode) and values
      Throws:
      IllegalStateException - if a SAXException is encountered during write.
    • EMPTY

      public void EMPTY(String tag)
      Output two SAX event which correspond to an empty element with the given tag- Output one open event immediately folloed by a close.
      Throws:
      IllegalStateException - if a SAXException is encountered during write.
    • EMPTY

      public void EMPTY(String tag, String... pairs)
      Output two SAX events which correspond to an empty element. Output one open event immediately followed by a close, with the given tag and the key/value pairs as attribute values.