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

public final Class FormatStack

extends Object
Class Inheritance
Imports
org.jdom2.internal.ArrayCopy, org.jdom2.output.EscapeStrategy, .Format, .Format.TextMode

FormatStack implements a mechanism where the formatting details can be changed mid-tree, but then get reverted when that tree segment is complete.

This class is intended as a working-class for in the various outputter implementations. It is only public so that people extending the Abstract*Processor classes can take advantage of its functionality.

The value this class adds is:

Author
Rolf Lear
Since
JDOM2

Field Summary

Modifier and TypeField and Description
private int
private final Format.TextMode
private int
private final String
encoding

The encoding format

private boolean[]
escapeOutput

escape Output logic - can be changed by

private final EscapeStrategy
escapeStrategy

entity escape logic

private final boolean
expandEmptyElements

Whether or not to expand empty elements to <tagName></tagName> - default is false

private boolean[]
ignoreTrAXEscapingPIs

Whether TrAX output escaping disabling/enabling PIs are ignored or processed - default is false

private final String
indent

The default indent is no spaces (as original document)

private String[]
levelEOL

The 'current' End-Of-Line

private String[]
levelEOLIndent

The padding to put between content items

private String[]
levelIndent

The 'current' accumulated indent

private final String
lineSeparator

New line separator

private Format.TextMode[]
mode

text handling mode

private final boolean
omitDeclaration

Whether or not to output the XML declaration - default is false

private final boolean
omitEncoding

Whether or not to output the encoding in the XML declaration - default is false

private final boolean
specifiedAttributesOnly

Whether or not to output 'specified' Attributes only

private String[]
termEOLIndent

The padding to put after the last item (typically one less indent)

Constructor Summary

AccessConstructor and Description
public
FormatStack(Format
the Format instance to seed the stack with.
format
)

Creates a new FormatStack seeded with the specified Format

Method Summary

Modifier and TypeMethod and Description
public Format.TextMode

Returns:

the TextMode that was originally set for this stack before any modifications.
getDefaultMode
()

public String

Returns:

the original Format#getEncoding()
getEncoding
()

public boolean

Returns:

the current depth's escapeOutput flag.
getEscapeOutput
()

The escapeOutput flag can be set or unset.

public EscapeStrategy
public String

Returns:

the original Format#getIndent(), may be null
getIndent
()

public String

Returns:

the current depth's End-Of-Line sequence, may be null
getLevelEOL
()

public String

Returns:

the current depth's accumulated/maintained indent, may be null
getLevelIndent
()

public String
public String

Returns:

the String EOL sequence followed by an indent. Null if it should be ignored
getPadBetween
()

Get the end-of-line indenting sequence for before the first item in an Element, as well as between subsequent items (but not after the last item)

public String

Returns:

the String EOL sequence followed by an indent. Null if it should be ignored
getPadLast
()

Get the end-of-line indenting sequence for after the last item in an Element

public Format.TextMode

Returns:

the current depth's Format#getTextMode()
getTextMode
()

public boolean
public boolean
public boolean
public boolean
public boolean

Returns:

true if only the specified Attributes should be output, false if those Attributes defaulted from the DTD or XML schema should be output too.
isSpecifiedAttributesOnly
()

Indicate whether only those Attributes specified in the XML should be output.

public void
pop()

Move back a level on the stack.

public void
push()

Create a new depth level on the stack.

private final void
resetReusableIndents()

If the indent strategy changes part way through a stack, we need to clear the previously calculated reusable 'lower' levels of the stack.

public void
setEscapeOutput(boolean
what to set the current level's escapeOutput flag to.
escape
)

The escapeOutput flag can be set or unset.

public void
setIgnoreTrAXEscapingPIs(boolean
the boolean value to set.
ignoreTrAXEscapingPIs
)

Set the current depth's Format#getIgnoreTrAXEscapingPIs()

public void
setLevelEOL(String
the new End-Of-Line sequence to set.
newline
)

Set the current depth's End-Of-Line sequence

public void
setLevelIndent(String
the indent to set.
indent
)

Override the current depth's accumulated line indent.

public void
setTextMode(Format.TextMode
the new mode to set.
mode
)

Change the current level's TextMode

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

capacityback to summary
private int capacity
defaultModeback to summary
private final Format.TextMode defaultMode
depthback to summary
private int depth
encodingback to summary
private final String encoding

The encoding format

escapeOutputback to summary
private boolean[] escapeOutput

escape Output logic - can be changed by

escapeStrategyback to summary
private final EscapeStrategy escapeStrategy

entity escape logic

expandEmptyElementsback to summary
private final boolean expandEmptyElements

Whether or not to expand empty elements to <tagName></tagName> - default is false

ignoreTrAXEscapingPIsback to summary
private boolean[] ignoreTrAXEscapingPIs

Whether TrAX output escaping disabling/enabling PIs are ignored or processed - default is false

indentback to summary
private final String indent

The default indent is no spaces (as original document)

levelEOLback to summary
private String[] levelEOL

The 'current' End-Of-Line

levelEOLIndentback to summary
private String[] levelEOLIndent

The padding to put between content items

levelIndentback to summary
private String[] levelIndent

The 'current' accumulated indent

lineSeparatorback to summary
private final String lineSeparator

New line separator

modeback to summary
private Format.TextMode[] mode

text handling mode

omitDeclarationback to summary
private final boolean omitDeclaration

Whether or not to output the XML declaration - default is false

omitEncodingback to summary
private final boolean omitEncoding

Whether or not to output the encoding in the XML declaration - default is false

specifiedAttributesOnlyback to summary
private final boolean specifiedAttributesOnly

Whether or not to output 'specified' Attributes only

termEOLIndentback to summary
private String[] termEOLIndent

The padding to put after the last item (typically one less indent)

Constructor Detail

FormatStackback to summary
public FormatStack(Format format)

Creates a new FormatStack seeded with the specified Format

Parameters
format:Format

the Format instance to seed the stack with.

Method Detail

getDefaultModeback to summary
public Format.TextMode getDefaultMode()
Returns:Format.TextMode

the TextMode that was originally set for this stack before any modifications.

getEncodingback to summary
public String getEncoding()
Returns:String

the original Format#getEncoding()

getEscapeOutputback to summary
public boolean getEscapeOutput()

The escapeOutput flag can be set or unset. When set, Element text and Attribute values are 'escaped' so that the output is valid XML. When unset, the Element text and Attribute values are not escaped.

Returns:boolean

the current depth's escapeOutput flag.

getEscapeStrategyback to summary
public EscapeStrategy getEscapeStrategy()
Returns:EscapeStrategy

the original Format#getEscapeStrategy()

getIndentback to summary
public String getIndent()
Returns:String

the original Format#getIndent(), may be null

getLevelEOLback to summary
public String getLevelEOL()
Returns:String

the current depth's End-Of-Line sequence, may be null

getLevelIndentback to summary
public String getLevelIndent()
Returns:String

the current depth's accumulated/maintained indent, may be null

getLineSeparatorback to summary
public String getLineSeparator()
Returns:String

the original Format#getLineSeparator()

getPadBetweenback to summary
public String getPadBetween()

Get the end-of-line indenting sequence for before the first item in an Element, as well as between subsequent items (but not after the last item)

Returns:String

the String EOL sequence followed by an indent. Null if it should be ignored

getPadLastback to summary
public String getPadLast()

Get the end-of-line indenting sequence for after the last item in an Element

Returns:String

the String EOL sequence followed by an indent. Null if it should be ignored

getTextModeback to summary
public Format.TextMode getTextMode()
Returns:Format.TextMode

the current depth's Format#getTextMode()

isExpandEmptyElementsback to summary
public boolean isExpandEmptyElements()
Returns:boolean

the original Format#getExpandEmptyElements()

isIgnoreTrAXEscapingPIsback to summary
public boolean isIgnoreTrAXEscapingPIs()
Returns:boolean

the current depth's Format#getIgnoreTrAXEscapingPIs()

isOmitDeclarationback to summary
public boolean isOmitDeclaration()
Returns:boolean

the original Format#getOmitDeclaration()

isOmitEncodingback to summary
public boolean isOmitEncoding()
Returns:boolean

the original Format#getOmitEncoding()

isSpecifiedAttributesOnlyback to summary
public boolean isSpecifiedAttributesOnly()

Indicate whether only those Attributes specified in the XML should be output.

Returns:boolean

true if only the specified Attributes should be output, false if those Attributes defaulted from the DTD or XML schema should be output too.

popback to summary
public void pop()

Move back a level on the stack.

pushback to summary
public void push()

Create a new depth level on the stack. The previous level's details are copied to this level, and the accumulated indent (if any) is indented further.

resetReusableIndentsback to summary
private final void resetReusableIndents()

If the indent strategy changes part way through a stack, we need to clear the previously calculated reusable 'lower' levels of the stack.

setEscapeOutputback to summary
public void setEscapeOutput(boolean escape)

The escapeOutput flag can be set or unset. When set, Element text and Attribute values are 'escaped' so that the output is valid XML. When unset, the Element text and Attribute values are not escaped.

Parameters
escape:boolean

what to set the current level's escapeOutput flag to.

setIgnoreTrAXEscapingPIsback to summary
public void setIgnoreTrAXEscapingPIs(boolean ignoreTrAXEscapingPIs)

Set the current depth's Format#getIgnoreTrAXEscapingPIs()

Parameters
ignoreTrAXEscapingPIs:boolean

the boolean value to set.

setLevelEOLback to summary
public void setLevelEOL(String newline)

Set the current depth's End-Of-Line sequence

Parameters
newline:String

the new End-Of-Line sequence to set.

setLevelIndentback to summary
public void setLevelIndent(String indent)

Override the current depth's accumulated line indent.

Parameters
indent:String

the indent to set.

setTextModeback to summary
public void setTextMode(Format.TextMode mode)

Change the current level's TextMode

Parameters
mode:Format.TextMode

the new mode to set.