Class Dom4JXMLOutput

  • All Implemented Interfaces:
    XMLOutput

    public class Dom4JXMLOutput
    extends java.lang.Object
    implements XMLOutput
    XMLOutput class to build all or part of a dom4j tree.
    Author:
    David Hovemeyer
    See Also:
    XMLOutput
    • Constructor Summary

      Constructors 
      Constructor Description
      Dom4JXMLOutput​(org.dom4j.Branch topLevel)
      Constructor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addAttribute​(java.lang.String name, java.lang.String value)
      Add an attribute to a started tag.
      void beginDocument()
      Begin the XML document.
      void closeTag​(java.lang.String tagName)
      Close tag with given name.
      void finish()
      Finish writing XML output, closing any underlying resources (such as output streams).
      void openCloseTag​(java.lang.String tagName)
      Open and close tag with given name.
      void openCloseTag​(java.lang.String tagName, XMLAttributeList attributeList)
      Open and close tag with given name and given attributes.
      void openTag​(java.lang.String tagName)
      Open a tag with given name.
      void openTag​(java.lang.String tagName, XMLAttributeList attributeList)
      Open a tag with given name and given attributes.
      void startTag​(java.lang.String tagName)
      Start a tag, with the intention of adding attributes.
      void stopTag​(boolean close)
      End a started tag.
      void write​(XMLWriteable obj)
      Add given object to the tree.
      void writeCDATA​(java.lang.String cdata)
      Write a CDATA section to the XML document.
      void writeCollection​(java.util.Collection<? extends XMLWriteable> collection)
      Add a Collection of XMLWriteable objects to the tree.
      void writeElementList​(java.lang.String tagName, java.util.Collection<java.lang.String> listValues)
      Add a list of Strings to document as elements with given tag name to the tree.
      void writeText​(java.lang.String text)
      Write text to the XML document.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Dom4JXMLOutput

        public Dom4JXMLOutput​(org.dom4j.Branch topLevel)
        Constructor.
        Parameters:
        topLevel - the Document or Element that is the root of the tree to be built
    • Method Detail

      • beginDocument

        public void beginDocument()
        Description copied from interface: XMLOutput
        Begin the XML document.
        Specified by:
        beginDocument in interface XMLOutput
      • openTag

        public void openTag​(java.lang.String tagName)
        Description copied from interface: XMLOutput
        Open a tag with given name.
        Specified by:
        openTag in interface XMLOutput
        Parameters:
        tagName - the tag name
      • openTag

        public void openTag​(java.lang.String tagName,
                            XMLAttributeList attributeList)
        Description copied from interface: XMLOutput
        Open a tag with given name and given attributes.
        Specified by:
        openTag in interface XMLOutput
        Parameters:
        tagName - the tag name
        attributeList - the attributes
      • openCloseTag

        public void openCloseTag​(java.lang.String tagName)
        Description copied from interface: XMLOutput
        Open and close tag with given name.
        Specified by:
        openCloseTag in interface XMLOutput
        Parameters:
        tagName - the tag name
      • openCloseTag

        public void openCloseTag​(java.lang.String tagName,
                                 XMLAttributeList attributeList)
        Description copied from interface: XMLOutput
        Open and close tag with given name and given attributes.
        Specified by:
        openCloseTag in interface XMLOutput
        Parameters:
        tagName - the tag name
        attributeList - the attributes
      • startTag

        public void startTag​(java.lang.String tagName)
        Description copied from interface: XMLOutput
        Start a tag, with the intention of adding attributes. Must be followed by stopTag after zero or more addAttribute calls.
        Specified by:
        startTag in interface XMLOutput
        Parameters:
        tagName - the tag name
      • addAttribute

        public void addAttribute​(java.lang.String name,
                                 java.lang.String value)
        Description copied from interface: XMLOutput
        Add an attribute to a started tag. Must follow a call to startTag.
        Specified by:
        addAttribute in interface XMLOutput
        Parameters:
        name - the attribute name.
        value - the attribute value, unescaped.
      • stopTag

        public void stopTag​(boolean close)
        Description copied from interface: XMLOutput
        End a started tag. Must follow a call to startTag.
        Specified by:
        stopTag in interface XMLOutput
        Parameters:
        close - true if the element has no content.
      • closeTag

        public void closeTag​(java.lang.String tagName)
        Description copied from interface: XMLOutput
        Close tag with given name.
        Specified by:
        closeTag in interface XMLOutput
        Parameters:
        tagName - the tag name
      • writeText

        public void writeText​(java.lang.String text)
        Description copied from interface: XMLOutput
        Write text to the XML document. XML metacharacters are automatically escaped.
        Specified by:
        writeText in interface XMLOutput
        Parameters:
        text - the text to write
      • writeCDATA

        public void writeCDATA​(java.lang.String cdata)
        Description copied from interface: XMLOutput
        Write a CDATA section to the XML document. The characters are not escaped in any way.
        Specified by:
        writeCDATA in interface XMLOutput
        Parameters:
        cdata - the character data to write
      • writeElementList

        public void writeElementList​(java.lang.String tagName,
                                     java.util.Collection<java.lang.String> listValues)
        Add a list of Strings to document as elements with given tag name to the tree.
        Parameters:
        tagName - the tag name
        listValues - Collection of String values to add
      • write

        public void write​(XMLWriteable obj)
        Add given object to the tree.
        Parameters:
        obj - the object
      • writeCollection

        public void writeCollection​(java.util.Collection<? extends XMLWriteable> collection)
        Add a Collection of XMLWriteable objects to the tree.
        Parameters:
        collection - Collection of XMLWriteable objects
      • finish

        public void finish()
        Description copied from interface: XMLOutput
        Finish writing XML output, closing any underlying resources (such as output streams). A call to this method should always be made, even if one of the XML-generation methods throws an exception. Therefore, a call to this method should be performed in a finally block.
        Specified by:
        finish in interface XMLOutput