Package org.simpleframework.xml.stream
Class Indenter
java.lang.Object
org.simpleframework.xml.stream.Indenter
The
Indenter
is used create indent strings using the
stack paradigm. This allows XML documents to be generated by
pushing and popping indents onto the stack. This indenter caches
all indent strings created so that when the same position on the
stack is encountered the indent can be acquired quickly.
The indents created by this are all prefixed with the line feed character, which allows XML tags to span exclusive lines. If the indent size specified is zero or less then no spaces, or line feed will be added to the generated indent string.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
TheCache
object is used create an indexable list which allows the indenter to quickly acquire an indent using a stack position. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Indenter.Cache
Provides a quick string cache that caches using by index.private int
Represents the current number of spaces in the indent text.private int
Number of spaces that is used for each of the indents.private int
Represents the index within the cache to get the indent. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate String
create()
This is used to create an indent which can later be pushed on to the stack.private String
indent
(int index) This is used to acquire the indent at the specified index.pop()
This is used to pop an indent from the cache.push()
This is used to push an indent on to the cache.top()
This returns the current indent for this indenter.
-
Field Details
-
cache
Provides a quick string cache that caches using by index. -
indent
private int indentNumber of spaces that is used for each of the indents. -
count
private int countRepresents the current number of spaces in the indent text. -
index
private int indexRepresents the index within the cache to get the indent.
-
-
Constructor Details
-
Indenter
public Indenter()Constructor for theIndenter
object. This will create an indent that uses three spaces for each indent that is pushed on to the stack. This also uses a default cache size of sixteen, which should be sufficient for most files. -
Indenter
Constructor for theIndenter
object. This will create an indent that uses the specified number of spaces to create each entry pushed on to the stack. This uses a cache size of sixteen, which should be sufficient for most files.- Parameters:
format
- determines the number of spaces per indent
-
Indenter
Constructor for theIndenter
object. This will create an indent that uses the specified number of spaces to create each entry pushed on to the stack. This uses a cache of the specified size, which is used to optimize the object.- Parameters:
format
- determines the number of spaces per indentsize
- this is the initial size of the indent cache
-
-
Method Details
-
top
This returns the current indent for this indenter. This should be used to write elements or comments that should be at the same indentation level as the XML element that will follow.- Returns:
- this returns the current indentation level for this
-
push
This is used to push an indent on to the cache. The first indent created by this is an empty string, this is because an indent is not required for the start of an XML file. If there are multiple roots written to the same writer then the start and end tags of a root element will exist on the same line.- Returns:
- this is used to push an indent on to the stack
-
pop
This is used to pop an indent from the cache. This reduces the length of the current indent and is typically used when an end tag is added to an XML document. If the number of pop requests exceeds the number of push requests then an empty string is returned from this method.- Returns:
- this is used to pop an indent from the stack
-
indent
This is used to acquire the indent at the specified index. If the indent does not exist at the specified index then on is created using the current value of the indent. The very first indent taken from this will be an empty string value.- Parameters:
index
- this is the index to acquire the indent from- Returns:
- this returns the indent from the specified index
-
create
This is used to create an indent which can later be pushed on to the stack. If the number of spaces to be added is zero then this will return a single character string with a line feed.- Returns:
- this will create an indent to be added to the stack
-