Top Description Fields Constructors Methods
com.thoughtworks.xstream.io.xml

public Class PrettyPrintWriter

extends AbstractXmlWriter
Class Inheritance
Known Direct Subclasses
com.thoughtworks.xstream.io.xml.CompactWriter
Imports
com.thoughtworks.xstream.core.util.FastStack, .QuickWriter, com.thoughtworks.xstream.io.StreamException, com.thoughtworks.xstream.io.naming.NameCoder, java.io.Writer

Deprecated

as a consequence of AbstractXmlWriter being deprecated. See corresponding docs for further information.

A simple writer that outputs XML in a pretty-printed indented stream.

By default, the chars
& < > " ' \r
are escaped and replaced with a suitable XML entity. To alter this behavior, override the writeText(com.thoughtworks.xstream.core.util.QuickWriter, String) and writeAttributeValue(com.thoughtworks.xstream.core.util.QuickWriter, String) methods.

The XML specification requires XML parsers to drop CR characters completely. This implementation will therefore use only a LF for line endings, never the platform encoding. You can overwrite the getNewLine() method for a different behavior.

Note

Depending on the XML version some characters cannot be written. Especially a 0 character is never valid in XML, neither directly nor as entity nor within CDATA. However, this writer works by default in a quirks mode, where it will write any character at least as character entity (even a null character). You may switch into XML_1_1 mode (which supports most characters) or XML_1_0 that does only support a very limited number of control characters. See XML specification for version 1.0 or 1.1. If a character is not supported, a StreamException is thrown. Select a proper parser implementation that respects the version in the XML header (the Xpp3 parser will also read character entities of normally invalid characters).

Authors
Joe Walnes, Jörg Schaible

Field Summary

Modifier and TypeField and Description
private static final char[]
private static final char[]
private static final char[]
private static final char[]
protected int
private final FastStack
private static final char[]
private final char[]
private static final char[]
private final int
private String
private static final char[]
private static final char[]
private boolean
private boolean
private boolean
private final QuickWriter
public static int
public static int
public static int

Constructor Summary

AccessConstructor and Description
private
PrettyPrintWriter(Writer writer, int mode, char[] lineIndenter, NameCoder nameCoder, String newLine)

public
PrettyPrintWriter(Writer writer, char[] lineIndenter, String newLine, XmlFriendlyReplacer replacer)

Deprecated As of 1.3
public
PrettyPrintWriter(Writer writer, int mode, char[] lineIndenter, NameCoder nameCoder)

public
PrettyPrintWriter(Writer writer, int mode, char[] lineIndenter, XmlFriendlyReplacer replacer)

public
PrettyPrintWriter(Writer writer, char[] lineIndenter, String newLine)

Deprecated As of 1.3
public
PrettyPrintWriter(Writer writer, int mode, char[] lineIndenter)

public
PrettyPrintWriter(Writer writer, char[] lineIndenter)

public
PrettyPrintWriter(Writer writer, String lineIndenter, String newLine)

Deprecated As of 1.3
public
PrettyPrintWriter(Writer writer, int mode, String lineIndenter)

public
PrettyPrintWriter(Writer writer, String lineIndenter)

public
PrettyPrintWriter(Writer writer, int mode, NameCoder nameCoder)

public
public
PrettyPrintWriter(Writer writer, NameCoder nameCoder)

public
public
PrettyPrintWriter(Writer writer, int mode)

public

Method Summary

Modifier and TypeMethod and Description
public void
public void
close()

Implements com.thoughtworks.xstream.io.HierarchicalStreamWriter.close.

Close the writer, if necessary.
public void
protected void
private void
public void
flush()

Implements com.thoughtworks.xstream.io.HierarchicalStreamWriter.flush.

Flush the writer, if necessary.
protected String

Returns:

the line terminator
getNewLine
()

Retrieve the line terminator.

public void
setValue(String text)

Implements com.thoughtworks.xstream.io.HierarchicalStreamWriter.setValue.

Write the value (text content) of the current node.
public void
public void
protected void
protected void
private void
writeText(String text, boolean isAttribute)

Inherited from com.thoughtworks.xstream.io.xml.AbstractXmlWriter:
escapeXmlName

Field Detail

AMPback to summary
private static final char[] AMP
APOSback to summary
private static final char[] APOS
CLOSEback to summary
private static final char[] CLOSE
CRback to summary
private static final char[] CR
depthback to summary
protected int depth
elementStackback to summary
private final FastStack elementStack
GTback to summary
private static final char[] GT
lineIndenterback to summary
private final char[] lineIndenter
LTback to summary
private static final char[] LT
modeback to summary
private final int mode
newLineback to summary
private String newLine
NULLback to summary
private static final char[] NULL
QUOTback to summary
private static final char[] QUOT
readyForNewLineback to summary
private boolean readyForNewLine
tagInProgressback to summary
private boolean tagInProgress
tagIsEmptyback to summary
private boolean tagIsEmpty
writerback to summary
private final QuickWriter writer
XML_1_0back to summary
public static int XML_1_0
XML_1_1back to summary
public static int XML_1_1
XML_QUIRKSback to summary
public static int XML_QUIRKS

Constructor Detail

PrettyPrintWriterback to summary
private PrettyPrintWriter(Writer writer, int mode, char[] lineIndenter, NameCoder nameCoder, String newLine)
PrettyPrintWriterback to summary
public PrettyPrintWriter(Writer writer, char[] lineIndenter, String newLine, XmlFriendlyReplacer replacer)

Deprecated

As of 1.3

Since
1.2
PrettyPrintWriterback to summary
public PrettyPrintWriter(Writer writer, int mode, char[] lineIndenter, NameCoder nameCoder)
Since
1.4
PrettyPrintWriterback to summary
public PrettyPrintWriter(Writer writer, int mode, char[] lineIndenter, XmlFriendlyReplacer replacer)
Since
1.3
PrettyPrintWriterback to summary
public PrettyPrintWriter(Writer writer, char[] lineIndenter, String newLine)

Deprecated

As of 1.3

PrettyPrintWriterback to summary
public PrettyPrintWriter(Writer writer, int mode, char[] lineIndenter)
Since
1.3
PrettyPrintWriterback to summary
public PrettyPrintWriter(Writer writer, char[] lineIndenter)
PrettyPrintWriterback to summary
public PrettyPrintWriter(Writer writer, String lineIndenter, String newLine)

Deprecated

As of 1.3

PrettyPrintWriterback to summary
public PrettyPrintWriter(Writer writer, int mode, String lineIndenter)
Since
1.3
PrettyPrintWriterback to summary
public PrettyPrintWriter(Writer writer, String lineIndenter)
PrettyPrintWriterback to summary
public PrettyPrintWriter(Writer writer, int mode, NameCoder nameCoder)
Since
1.4
PrettyPrintWriterback to summary
public PrettyPrintWriter(Writer writer, int mode, XmlFriendlyReplacer replacer)
Since
1.3
PrettyPrintWriterback to summary
public PrettyPrintWriter(Writer writer, NameCoder nameCoder)
Since
1.4
PrettyPrintWriterback to summary
public PrettyPrintWriter(Writer writer, XmlFriendlyReplacer replacer)
PrettyPrintWriterback to summary
public PrettyPrintWriter(Writer writer, int mode)
Since
1.3
PrettyPrintWriterback to summary
public PrettyPrintWriter(Writer writer)

Method Detail

addAttributeback to summary
public void addAttribute(String key, String value)

Implements com.thoughtworks.xstream.io.HierarchicalStreamWriter.addAttribute.

closeback to summary
public void close()

Implements com.thoughtworks.xstream.io.HierarchicalStreamWriter.close.

Doc from com.thoughtworks.xstream.io.HierarchicalStreamWriter.close.

Close the writer, if necessary.

endNodeback to summary
public void endNode()

Implements com.thoughtworks.xstream.io.HierarchicalStreamWriter.endNode.

endOfLineback to summary
protected void endOfLine()
finishTagback to summary
private void finishTag()
flushback to summary
public void flush()

Implements com.thoughtworks.xstream.io.HierarchicalStreamWriter.flush.

Doc from com.thoughtworks.xstream.io.HierarchicalStreamWriter.flush.

Flush the writer, if necessary.

getNewLineback to summary
protected String getNewLine()

Retrieve the line terminator. This method returns always a line feed, since according the XML specification any parser must ignore a carriage return. Overload this method, if you need different behavior.

Returns:String

the line terminator

Since
1.3
setValueback to summary
public void setValue(String text)

Implements com.thoughtworks.xstream.io.HierarchicalStreamWriter.setValue.

Doc from com.thoughtworks.xstream.io.HierarchicalStreamWriter.setValue.

Write the value (text content) of the current node.

startNodeback to summary
public void startNode(String name)

Implements com.thoughtworks.xstream.io.HierarchicalStreamWriter.startNode.

startNodeback to summary
public void startNode(String name, Class<T> clazz)

Overrides com.thoughtworks.xstream.io.AbstractWriter.startNode.

Implements com.thoughtworks.xstream.io.ExtendedHierarchicalStreamWriter.startNode.

writeAttributeValueback to summary
protected void writeAttributeValue(QuickWriter writer, String text)
writeTextback to summary
protected void writeText(QuickWriter writer, String text)
writeTextback to summary
private void writeText(String text, boolean isAttribute)