Top Description Inners Fields Constructors Methods
org.jdom2.output.support

public abstract Class AbstractFormattedWalker

extends Object
implements Walker
Class Inheritance
All Implemented Interfaces
org.jdom2.output.support.Walker
Known Direct Subclasses
org.jdom2.output.support.WalkerNORMALIZE, org.jdom2.output.support.WalkerTRIM, org.jdom2.output.support.WalkerTRIM_FULL_WHITE
Imports
java.util.Iterator, .List, .NoSuchElementException, org.jdom2.CDATA, .Content, org.jdom2.internal.ArrayCopy, org.jdom2.output.EscapeStrategy, .Format

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 and Inner Type Summary

Modifier and TypeClass and Description
protected class
AbstractFormattedWalker.MultiText

Collect together the items that constitute formatted Text-like content.

protected static enum
AbstractFormattedWalker.Trim

Indicate how text content should be added

Field Summary

Modifier and TypeField and Description
private final boolean
private final boolean
private static final CDATA
private final Iterator<? extends Content>
private static final Iterator<Content>
private final String
private final EscapeStrategy
private final FormatStack
private boolean
private final AbstractFormattedWalker.MultiText
private final StringBuilder
private Content[]
private boolean
private int
private boolean
private int
private Content[]
private int
private String[]
private Boolean
private AbstractFormattedWalker.MultiText
private final String
private Content
private AbstractFormattedWalker.MultiText

Constructor Summary

AccessConstructor and Description
public
AbstractFormattedWalker(final List<? extends Content>
the content to walk.
xx
,
final FormatStack
the current FormatStack
fstack
,
final boolean
Whether Text values should be escaped.
doescape
)

Create a Walker that preserves all content in its raw state.

Method Summary

Modifier and TypeMethod and Description
protected abstract void
analyzeMultiText(AbstractFormattedWalker.MultiText
the MultiText to append to.
mtext
,
int
The first Text-like content to add to the MultiText
offset
,
int
The number of Text-like content items to add.
len
)

Add the content at the specified indices to the provided MultiText.

private final AbstractFormattedWalker.MultiText

Returns:

The updated MultiText containing the correct sequence of Text-like content
buildMultiText
(final boolean first)

This method was changed in 2.0.5 It now is only called when building the content of the variable pendingmt This is important, because only pendingmt can be referenced when analyzing the MultiText content.

protected final Content

Returns:

the content at the index.
get
(final int
the index to get the content at.
index
)

Get the content at a position in the input content.

public final boolean
hasNext()

Implements org.jdom2.output.support.Walker.hasNext.

Behaves similarly to to a regular Iterator
public final boolean
isAllText()

Implements org.jdom2.output.support.Walker.isAllText.

If all the content in this walker is empty, or if whatever content is available is Text-like.
public final boolean
isAllWhitespace()

Implements org.jdom2.output.support.Walker.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.
public final boolean
isCDATA()

Implements org.jdom2.output.support.Walker.isCDATA.

If the previous next() method returned null, then this will indicate whether the current text() value is CDATA or regular Text.
private final boolean
public final Content
next()

Implements org.jdom2.output.support.Walker.next.

Similar to an Iterator, but null return values need special treatment.
private void
public final String
text()

Implements org.jdom2.output.support.Walker.text.

If the previous call to next() returned null, then this will return the required text to be processed.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

alltextback to summary
private final boolean alltext
allwhiteback to summary
private final boolean allwhite
CDATATOKENback to summary
private static final CDATA CDATATOKEN
contentback to summary
private final Iterator<? extends Content> content
EMPTYITback to summary
private static final Iterator<Content> EMPTYIT
endoflineback to summary
private final String endofline
escapeback to summary
private final EscapeStrategy escape
fstackback to summary
private final FormatStack fstack
hasnextback to summary
private boolean hasnext
holdingmtback to summary
private final AbstractFormattedWalker.MultiText holdingmt
mtbufferback to summary
private final StringBuilder mtbuffer
mtdataback to summary
private Content[] mtdata
mtgottextback to summary
private boolean mtgottext
mtposback to summary
private int mtpos
mtpostpadback to summary
private boolean mtpostpad
mtsizeback to summary
private int mtsize
mtsourceback to summary
private Content[] mtsource
mtsourcesizeback to summary
private int mtsourcesize
mttextback to summary
private String[] mttext
mtwasescapeback to summary
private Boolean mtwasescape
multitextback to summary
private AbstractFormattedWalker.MultiText multitext
newlineindentback to summary
private final String newlineindent
pendingback to summary
private Content pending
pendingmtback to summary
private AbstractFormattedWalker.MultiText pendingmt

Constructor Detail

AbstractFormattedWalkerback to summary
public AbstractFormattedWalker(final List<? extends Content> xx, final FormatStack fstack, final boolean doescape)

Create a Walker that preserves all content in its raw state.

Parameters
xx:List<? extends Content>

the content to walk.

fstack:FormatStack

the current FormatStack

doescape:boolean

Whether Text values should be escaped.

Method Detail

analyzeMultiTextback to summary
protected abstract void analyzeMultiText(AbstractFormattedWalker.MultiText mtext, int offset, int len)

Add the content at the specified indices to the provided MultiText.

Parameters
mtext:AbstractFormattedWalker.MultiText

the MultiText to append to.

offset:int

The first Text-like content to add to the MultiText

len:int

The number of Text-like content items to add.

buildMultiTextback to summary
private final AbstractFormattedWalker.MultiText buildMultiText(final boolean first)

This method was changed in 2.0.5 It now is only called when building the content of the variable pendingmt This is important, because only pendingmt can be referenced when analyzing the MultiText content.

Returns:AbstractFormattedWalker.MultiText

The updated MultiText containing the correct sequence of Text-like content

getback to summary
protected final Content get(final int index)

Get the content at a position in the input content. Useful for subclasses in their analyzeMultiText(MultiText, int, int) calls.

Parameters
index:int

the index to get the content at.

Returns:Content

the content at the index.

hasNextback to summary
public final boolean hasNext()

Implements org.jdom2.output.support.Walker.hasNext.

Doc from org.jdom2.output.support.Walker.hasNext.

Behaves similarly to to a regular Iterator

Returns:boolean

true if there is more content to be processed

Annotations
@Override
isAllTextback to summary
public final boolean isAllText()

Implements org.jdom2.output.support.Walker.isAllText.

Doc from org.jdom2.output.support.Walker.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:boolean

true if there is no content, or all content is Text

Annotations
@Override
isAllWhitespaceback to summary
public final boolean isAllWhitespace()

Implements org.jdom2.output.support.Walker.isAllWhitespace.

Doc from org.jdom2.output.support.Walker.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:boolean

true

Annotations
@Override
isCDATAback to summary
public final boolean isCDATA()

Implements org.jdom2.output.support.Walker.isCDATA.

Doc from org.jdom2.output.support.Walker.isCDATA.

If the previous next() method returned null, then this will indicate whether the current text() value is CDATA or regular Text.

Returns:boolean

true if the current text() is valid, and is CDATA.

Annotations
@Override
isTextLikeback to summary
private final boolean isTextLike(final Content c)
nextback to summary
public final Content next()

Implements org.jdom2.output.support.Walker.next.

Doc from org.jdom2.output.support.Walker.next.

Similar to an Iterator, but null return values need special treatment.

Returns:Content

the next content to be processed, perhaps null if the next content is re-formatted text of some sort (Text / CDATA).

Annotations
@Override
resetMultiTextback to summary
private void resetMultiText()
textback to summary
public final String text()

Implements org.jdom2.output.support.Walker.text.

Doc from org.jdom2.output.support.Walker.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:String

The current text value (null if the previous invocation of next() returned a non-null value).

Annotations
@Override
org.jdom2.output.support back to summary

protected final Class AbstractFormattedWalker.MultiText

extends Object
Class Inheritance

Collect together the items that constitute formatted Text-like content.
Author
Rolf Lear

Constructor Summary

AccessConstructor and Description
private
MultiText()

This is private so only this abstract class can create instances.

Method Summary

Modifier and TypeMethod and Description
public void
appendCDATA(final AbstractFormattedWalker.Trim
How to prepare the CDATA content
trim
,
final String
The actual CDATA content.
text
)

Append some text to the text-like sequence that will be treated as CDATA.

public void
appendRaw(final Content
the content to add.
c
)

Add some JDOM Content (typically an EntityRef) that will be treated as part of the Text-like sequence.

public void
appendText(final AbstractFormattedWalker.Trim
How to prepare the Text content
trim
,
final String
The actual Text content.
text
)

Append some text to the text-like sequence that will be treated as plain XML text (PCDATA).

private void
closeText()

Handle the case where we have been accumulating true text content, and the next item is not more text.

public void
done()

Indicate that there is no further content to be added to the text-like sequence.

private void
ensurespace()

Ensure we have space for at least one more text-like item.

private String
escapeCDATA(final String text)

private String
escapeText(final String text)

private void
forceAppend(final String text)

Simple method that ensures the text is processed, regardless of content, and is never escaped.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

MultiTextback to summary
private MultiText()

This is private so only this abstract class can create instances.

Method Detail

appendCDATAback to summary
public void appendCDATA(final AbstractFormattedWalker.Trim trim, final String text)

Append some text to the text-like sequence that will be treated as CDATA.

Parameters
trim:AbstractFormattedWalker.Trim

How to prepare the CDATA content

text:String

The actual CDATA content.

appendRawback to summary
public void appendRaw(final Content c)

Add some JDOM Content (typically an EntityRef) that will be treated as part of the Text-like sequence.

Parameters
c:Content

the content to add.

appendTextback to summary
public void appendText(final AbstractFormattedWalker.Trim trim, final String text)

Append some text to the text-like sequence that will be treated as plain XML text (PCDATA). If the last content added to this text-like sequence then this new text will be appended directly to the previous text.

Parameters
trim:AbstractFormattedWalker.Trim

How to prepare the Text content

text:String

The actual Text content.

closeTextback to summary
private void closeText()

Handle the case where we have been accumulating true text content, and the next item is not more text.

doneback to summary
public void done()

Indicate that there is no further content to be added to the text-like sequence.

ensurespaceback to summary
private void ensurespace()

Ensure we have space for at least one more text-like item.

escapeCDATAback to summary
private String escapeCDATA(final String text)
escapeTextback to summary
private String escapeText(final String text)
forceAppendback to summary
private void forceAppend(final String text)

Simple method that ensures the text is processed, regardless of content, and is never escaped.

org.jdom2.output.support back to summary

protected final Enum AbstractFormattedWalker.Trim

extends Enum<AbstractFormattedWalker.Trim>
Class Inheritance

Indicate how text content should be added
Author
Rolf Lear

Field Summary

Modifier and TypeField and Description
public static final AbstractFormattedWalker.Trim
BOTH

Both Trim

public static final AbstractFormattedWalker.Trim
COMPACT

Trim Both and replace all internal whitespace with a single space

public static final AbstractFormattedWalker.Trim
LEFT

Left Trim

public static final AbstractFormattedWalker.Trim
NONE

No Trimming at all

public static final AbstractFormattedWalker.Trim
RIGHT

Right Trim

Constructor Summary

AccessConstructor and Description
private
Trim()

Method Summary

Modifier and TypeMethod and Description
public static AbstractFormattedWalker.Trim
public static AbstractFormattedWalker.Trim[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

BOTHback to summary
public static final AbstractFormattedWalker.Trim BOTH

Both Trim

COMPACTback to summary
public static final AbstractFormattedWalker.Trim COMPACT

Trim Both and replace all internal whitespace with a single space

LEFTback to summary
public static final AbstractFormattedWalker.Trim LEFT

Left Trim

NONEback to summary
public static final AbstractFormattedWalker.Trim NONE

No Trimming at all

RIGHTback to summary
public static final AbstractFormattedWalker.Trim RIGHT

Right Trim

Constructor Detail

Trimback to summary
private Trim()

Method Detail

valueOfback to summary
public static AbstractFormattedWalker.Trim valueOf(String name)
valuesback to summary
public static AbstractFormattedWalker.Trim[] values()