Interface Walker

All Known Implementing Classes:
AbstractFormattedWalker, WalkerNORMALIZE, WalkerPRESERVE, WalkerTRIM, WalkerTRIM_FULL_WHITE

public interface Walker
A model for walking the (potentially formatted) content of an Element.

Implementations of this class restructure the content to a particular format and expose the restructured content in this 'Walker' which is a loose equivalent to an iterator.

The next() method will return a Content instance (perhaps null) if there is more content. If the returned content is null, then there will be some formatted characters available in the text() method. These characters may need to be represented as CDATA (check the isCDATA() method).

Not all CDATA and Text nodes need to be reformatted, and as a result they may be returned as their original CDATA or Text instances instead of using the formatted text() / isCDATA() mechanism.

The 'Rules' for the walkers are that no padding is done before the first content step, and no padding is done after the last content step (but the first/last content items may be trimmed to the correct format). Any required padding will be done in plain text (not CDATA) content. Consecutive CDATA sections may be separated by whitespace text for example.

Author:
Rolf Lear
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Behaves similarly to to a regular Iterator
    boolean
    If all the content in this walker is empty, or if whatever content is available is Text-like.
    boolean
    If all the content is Text-like (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.
    boolean
    If the previous next() method returned null, then this will indicate whether the current text() value is CDATA or regular Text.
    Similar to an Iterator, but null return values need special treatment.
    If the previous call to next() returned null, then this will return the required text to be processed.
  • Method Details

    • isAllText

      boolean isAllText()
      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.

      Returns:
      true if there is no content, or all content is Text
    • isAllWhitespace

      boolean isAllWhitespace()
      If all the content is Text-like (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.
      Returns:
      true
    • hasNext

      boolean hasNext()
      Behaves similarly to to a regular Iterator
      Returns:
      true if there is more content to be processed
    • next

      Content next()
      Similar to an Iterator, but null return values need special treatment.
      Returns:
      the next content to be processed, perhaps null if the next content is re-formatted text of some sort (Text / CDATA).
      Throws:
      NoSuchElementException - if there is no further content.
    • text

      String text()
      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.
      Returns:
      The current text value (null if the previous invocation of next() returned a non-null value).
      Throws:
      IllegalStateException - if there was not previous call to next()
    • isCDATA

      boolean isCDATA()
      If the previous next() method returned null, then this will indicate whether the current text() value is CDATA or regular Text.
      Returns:
      true if the current text() is valid, and is CDATA.
      Throws:
      IllegalStateException - if there was not previous call to next()