Class AbstractFormattedWalker

java.lang.Object
org.jdom2.output.support.AbstractFormattedWalker
All Implemented Interfaces:
Walker
Direct Known Subclasses:
WalkerNORMALIZE, WalkerTRIM, WalkerTRIM_FULL_WHITE

public abstract class AbstractFormattedWalker extends Object implements Walker
This Walker implementation walks a list of Content in a Formatted form of some sort.

The JDOM content can be loosely categorised in to 'Text-like' content (consisting of Text, CDATA, and EntityRef), and everything else. This distinction is significant for for this class and its sub-classes.

There will be text manipulation, and some (but not necessarily all) Text-like content will be returned as text() instead of next().

The trick in this class is that it deals with the regular content, and delegates the Text-like content to the sub-classes.

Subclasses are tasked with analysing chunks of Text-like content in the analyzeMultiText(MultiText, int, int) method. The subclasses are responsible for adding the relevant text content to the suppliedMultiText instance in such a way as to result in the correct format.

The Subclass needs to concern itself with only the text portion because this abstract class will ensure the Text-like content is appropriately indented.

Author:
Rolf Lear
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    protected final class 
    Collect together the items that constitute formatted Text-like content.
    protected static enum 
    Indicate how text content should be added
  • Constructor Summary

    Constructors
    Constructor
    Description
    AbstractFormattedWalker(List<? extends Content> xx, FormatStack fstack, boolean doescape)
    Create a Walker that preserves all content in its raw state.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected abstract void
    Add the content at the specified indices to the provided MultiText.
    protected final Content
    get(int index)
    Get the content at a position in the input content.
    final boolean
    Behaves similarly to to a regular Iterator
    final boolean
    If all the content in this walker is empty, or if whatever content is available is Text-like.
    final boolean
    If all the content is Text-like (Walker.isAllText() returns true), and additionally that any content is either Text or CDATA, and that the values of these Text/CDATA members are all XML Whitespace.
    final boolean
    If the previous next() method returned null, then this will indicate whether the current text() value is CDATA or regular Text.
    final Content
    Similar to an Iterator, but null return values need special treatment.
    final String
    If the previous call to next() returned null, then this will return the required text to be processed.

    Methods inherited from class java.lang.Object

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

    • AbstractFormattedWalker

      public AbstractFormattedWalker(List<? extends Content> xx, FormatStack fstack, boolean doescape)
      Create a Walker that preserves all content in its raw state.
      Parameters:
      xx - the content to walk.
      fstack - the current FormatStack
      doescape - Whether Text values should be escaped.
  • Method Details

    • next

      public final Content next()
      Description copied from interface: Walker
      Similar to an Iterator, but null return values need special treatment.
      Specified by:
      next in interface Walker
      Returns:
      the next content to be processed, perhaps null if the next content is re-formatted text of some sort (Text / CDATA).
    • analyzeMultiText

      protected abstract void analyzeMultiText(AbstractFormattedWalker.MultiText mtext, int offset, int len)
      Add the content at the specified indices to the provided MultiText.
      Parameters:
      mtext - the MultiText to append to.
      offset - The first Text-like content to add to the MultiText
      len - The number of Text-like content items to add.
    • get

      protected final Content get(int index)
      Get the content at a position in the input content. Useful for subclasses in their analyzeMultiText(MultiText, int, int) calls.
      Parameters:
      index - the index to get the content at.
      Returns:
      the content at the index.
    • isAllText

      public final boolean isAllText()
      Description copied from interface: Walker
      If all the content in this walker is empty, or if whatever content is available is Text-like.

      Text-like content is considered to be Text, CDATA, EntityRef, or any (potentially mixed) sequence of these types, but no other types.

      Specified by:
      isAllText in interface Walker
      Returns:
      true if there is no content, or all content is Text
    • hasNext

      public final boolean hasNext()
      Description copied from interface: Walker
      Behaves similarly to to a regular Iterator
      Specified by:
      hasNext in interface Walker
      Returns:
      true if there is more content to be processed
    • text

      public final String text()
      Description copied from interface: Walker
      If the previous call to next() returned null, then this will return the required text to be processed. Check to see whether this text is CDATA by calling the isCDATA() method.
      Specified by:
      text in interface Walker
      Returns:
      The current text value (null if the previous invocation of next() returned a non-null value).
    • isCDATA

      public final boolean isCDATA()
      Description copied from interface: Walker
      If the previous next() method returned null, then this will indicate whether the current text() value is CDATA or regular Text.
      Specified by:
      isCDATA in interface Walker
      Returns:
      true if the current text() is valid, and is CDATA.
    • isAllWhitespace

      public final boolean isAllWhitespace()
      Description copied from interface: Walker
      If all the content is Text-like (Walker.isAllText() returns true), and additionally that any content is either Text or CDATA, and that the values of these Text/CDATA members are all XML Whitespace.
      Specified by:
      isAllWhitespace in interface Walker
      Returns:
      true