Class AbstractDOMOutputProcessor

java.lang.Object
org.jdom2.output.support.AbstractOutputProcessor
org.jdom2.output.support.AbstractDOMOutputProcessor
All Implemented Interfaces:
DOMOutputProcessor

public abstract class AbstractDOMOutputProcessor extends AbstractOutputProcessor implements DOMOutputProcessor
This class provides a concrete implementation of DOMOutputProcessor for supporting the DOMOutputter.

Overview

This class is marked abstract even though all methods are fully implemented. The process*(...) methods are public because they match the DOMOutputProcessor interface but the remaining methods are all protected.

People who want to create a custom DOMOutputProcessor for DOMOutputter are able to extend this class and modify any functionality they want. Before sub-classing this you should first check to see if the Format class can get you the results you want.

Subclasses of this should have reentrant methods. This is easiest to accomplish simply by not allowing any instance fields. If your sub-class has an instance field/variable, then it's probably broken.

The Stacks

One significant feature of this implementation is that it creates and maintains both a NamespaceStack and FormatStack that are managed in the printElement(FormatStack, NamespaceStack, org.w3c.dom.Document, Element) method. The stacks are pushed and popped in that method only. They significantly improve the performance and readability of the code.

The NamespaceStack is only sent through to the printElement(FormatStack, NamespaceStack, org.w3c.dom.Document, Element) and printContent(FormatStack, NamespaceStack, org.w3c.dom.Document, org.w3c.dom.Node, Walker) methods, but the FormatStack is pushed through to all print* Methods.

Content Processing

This class delegates the formatting of the content to the Walker classes and you can create your own custom walker by overriding the AbstractOutputProcessor.buildWalker(FormatStack, List, boolean) method.

Since:
JDOM2
Author:
Rolf Lear
See Also:
  • Constructor Details

    • AbstractDOMOutputProcessor

      public AbstractDOMOutputProcessor()
  • Method Details

    • process

      public Document process(Document basedoc, Format format, Document doc)
      Description copied from interface: DOMOutputProcessor
      This will convert the Document to the given DOM Document.

      Specified by:
      process in interface DOMOutputProcessor
      Parameters:
      basedoc - The DOM document to use for the conversion
      format - Format instance specifying output style
      doc - Document to format.
      Returns:
      The same DOM Document as the input document, but with the JDOM content converted and added.
    • process

      public Element process(Document basedoc, Format format, Element element)
      Description copied from interface: DOMOutputProcessor
      This will convert the Element using the given DOM Document to create the resulting DOM Element.
      Specified by:
      process in interface DOMOutputProcessor
      Parameters:
      basedoc - The DOM document to use for the conversion
      format - Format instance specifying output style
      element - Element to format.
      Returns:
      The input JDOM Element converted to a DOM Element
    • process

      public List<Node> process(Document basedoc, Format format, List<? extends Content> list)
      Description copied from interface: DOMOutputProcessor
      This will convert the list of JDOM Content using the given DOM Document to create the resulting list of DOM Nodes.
      Specified by:
      process in interface DOMOutputProcessor
      Parameters:
      basedoc - The DOM document to use for the conversion
      format - Format instance specifying output style
      list - JDOM Content to convert.
      Returns:
      The input JDOM Content List converted to a List of DOM Nodes
    • process

      public CDATASection process(Document basedoc, Format format, CDATA cdata)
      Description copied from interface: DOMOutputProcessor
      This will convert the CDATA using the given DOM Document to create the resulting DOM CDATASection.
      Specified by:
      process in interface DOMOutputProcessor
      Parameters:
      basedoc - The DOM document to use for the conversion
      format - Format instance specifying output style
      cdata - CDATA to format.
      Returns:
      The input JDOM CDATA converted to a DOM CDATASection
    • process

      public Text process(Document basedoc, Format format, Text text)
      Description copied from interface: DOMOutputProcessor
      This will convert the Text using the given DOM Document to create the resulting DOM Text.
      Specified by:
      process in interface DOMOutputProcessor
      Parameters:
      basedoc - The DOM document to use for the conversion
      format - Format instance specifying output style
      text - Text to format.
      Returns:
      The input JDOM Text converted to a DOM Text
    • process

      public Comment process(Document basedoc, Format format, Comment comment)
      Description copied from interface: DOMOutputProcessor
      This will convert the Comment using the given DOM Document to create the resulting DOM Comment.
      Specified by:
      process in interface DOMOutputProcessor
      Parameters:
      basedoc - The DOM document to use for the conversion
      format - Format instance specifying output style
      comment - Comment to format.
      Returns:
      The input JDOM Comment converted to a DOM Comment
    • process

      public ProcessingInstruction process(Document basedoc, Format format, ProcessingInstruction pi)
      Description copied from interface: DOMOutputProcessor
      This will convert the ProcessingInstruction using the given DOM Document to create the resulting DOM ProcessingInstruction.
      Specified by:
      process in interface DOMOutputProcessor
      Parameters:
      basedoc - The DOM document to use for the conversion
      format - Format instance specifying output style
      pi - ProcessingInstruction to format.
      Returns:
      The input JDOM ProcessingInstruction converted to a DOM ProcessingInstruction
    • process

      public EntityReference process(Document basedoc, Format format, EntityRef entity)
      Description copied from interface: DOMOutputProcessor
      This will convert the EntityRef using the given DOM Document to create the resulting DOM EntityReference.
      Specified by:
      process in interface DOMOutputProcessor
      Parameters:
      basedoc - The DOM document to use for the conversion
      format - Format instance specifying output style
      entity - EntityRef to format.
      Returns:
      The input JDOM EntityRef converted to a DOM EntityReference
    • process

      public Attr process(Document basedoc, Format format, Attribute attribute)
      Description copied from interface: DOMOutputProcessor
      This will convert the Attribute using the given DOM Document to create the resulting DOM Attr.
      Specified by:
      process in interface DOMOutputProcessor
      Parameters:
      basedoc - The DOM document to use for the conversion
      format - Format instance specifying output style
      attribute - Attribute to format.
      Returns:
      The input JDOM Attribute converted to a DOM Attr
    • printDocument

      protected Document printDocument(FormatStack fstack, NamespaceStack nstack, Document basedoc, Document doc)
      This will handle printing of a Document.
      Parameters:
      fstack - the FormatStack
      nstack - the NamespaceStack
      basedoc - The org.w3c.dom.Document for creating DOM Nodes
      doc - Document to write.
      Returns:
      The input JDOM document converted to a DOM document.
    • printProcessingInstruction

      protected ProcessingInstruction printProcessingInstruction(FormatStack fstack, Document basedoc, ProcessingInstruction pi)
      This will handle printing of a ProcessingInstruction.
      Parameters:
      fstack - the FormatStack
      basedoc - The org.w3c.dom.Document for creating DOM Nodes
      pi - ProcessingInstruction to write.
      Returns:
      The input JDOM ProcessingInstruction converted to a DOM ProcessingInstruction.
    • printComment

      protected Comment printComment(FormatStack fstack, Document basedoc, Comment comment)
      This will handle printing of a Comment.
      Parameters:
      fstack - the FormatStack
      basedoc - The org.w3c.dom.Document for creating DOM Nodes
      comment - Comment to write.
      Returns:
      The input JDOM Comment converted to a DOM Comment
    • printEntityRef

      protected EntityReference printEntityRef(FormatStack fstack, Document basedoc, EntityRef entity)
      This will handle printing of an EntityRef.
      Parameters:
      fstack - the FormatStack
      basedoc - The org.w3c.dom.Document for creating DOM Nodes
      entity - EntotyRef to write.
      Returns:
      The input JDOM EntityRef converted to a DOM EntityReference
    • printCDATA

      protected CDATASection printCDATA(FormatStack fstack, Document basedoc, CDATA cdata)
      This will handle printing of a CDATA.
      Parameters:
      fstack - the FormatStack
      basedoc - The org.w3c.dom.Document for creating DOM Nodes
      cdata - CDATA to write.
      Returns:
      The input JDOM CDATA converted to a DOM CDATASection
    • printText

      protected Text printText(FormatStack fstack, Document basedoc, Text text)
      This will handle printing of a Text.
      Parameters:
      fstack - the FormatStack
      basedoc - The org.w3c.dom.Document for creating DOM Nodes
      text - Text to write.
      Returns:
      The input JDOM Text converted to a DOM Text
    • printAttribute

      protected Attr printAttribute(FormatStack fstack, Document basedoc, Attribute attribute)
      This will handle printing of a Attribute.
      Parameters:
      fstack - the FormatStack
      basedoc - The org.w3c.dom.Document for creating DOM Nodes
      attribute - Attribute to write.
      Returns:
      The input JDOM Attribute converted to a DOM Attr
    • printElement

      protected Element printElement(FormatStack fstack, NamespaceStack nstack, Document basedoc, Element element)
      This will handle printing of an Element.

      This method arranges for outputting the Element infrastructure including Namespace Declarations and Attributes.

      The actual formatting of the content is managed by the Walker created for the Element's content.

      Parameters:
      fstack - the FormatStack
      nstack - the NamespaceStack
      basedoc - The org.w3c.dom.Document for creating DOM Nodes
      element - Element to write.
      Returns:
      The input JDOM Element converted to a DOM Element
    • printContent

      protected void printContent(FormatStack fstack, NamespaceStack nstack, Document basedoc, Node target, Walker walker)
      This will handle printing of a List of Content. Uses the Walker to ensure formatting.
      Parameters:
      fstack - the FormatStack
      nstack - the NamespaceStack
      basedoc - The org.w3c.dom.Document for creating DOM Nodes
      target - the DOM node this content should be appended to.
      walker - List of Content to write.
    • helperContentDispatcher

      protected Node helperContentDispatcher(FormatStack fstack, NamespaceStack nstack, Document basedoc, Content content)
      This method contains code which is reused in a number of places. It simply determines what content is passed in, and dispatches it to the correct print* method.
      Parameters:
      fstack - The current FormatStack
      nstack - the NamespaceStack
      basedoc - The org.w3c.dom.Document for creating DOM Nodes
      content - The content to dispatch
      Returns:
      the input JDOM Content converted to a DOM Node.