public class PrettyPrintWriter extends AbstractXmlWriter
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 and MX parsers will also read character entities of normally
invalid characters).
You may also switch to XML_1_0_REPLACEMENT or XML_1_1_REPLACEMENT mode, which will replace the invalid characters
with a U+FFFD replacement character.
Modifier and Type | Field and Description |
---|---|
protected int |
depth |
static int |
XML_1_0
XML 1.0 mode: Writes characters according XML 1.0 specification, throws
StreamException for invalid characters. |
static int |
XML_1_0_REPLACEMENT
XML 1.0 mode: Writes characters according XML 1.0 specification, writes character U+FFFFD as replacement for invalid ones.
|
static int |
XML_1_1
XML 1.1 mode: Writes characters according XML 1.1 specification, throws
StreamException for invalid characters. |
static int |
XML_1_1_REPLACEMENT
XML 1.1 mode: Writes characters according XML 1.1 specification, writes character U+FFFFD as replacement for invalid ones.
|
static int |
XML_QUIRKS
Quirks mode: Writes any character into data stream incl.
|
Constructor and Description |
---|
PrettyPrintWriter(java.io.Writer writer) |
PrettyPrintWriter(java.io.Writer writer,
char[] lineIndenter) |
PrettyPrintWriter(java.io.Writer writer,
char[] lineIndenter,
java.lang.String newLine)
Deprecated.
As of 1.3
|
PrettyPrintWriter(java.io.Writer writer,
char[] lineIndenter,
java.lang.String newLine,
XmlFriendlyReplacer replacer)
Deprecated.
As of 1.3
|
PrettyPrintWriter(java.io.Writer writer,
int mode) |
PrettyPrintWriter(java.io.Writer writer,
int mode,
char[] lineIndenter) |
PrettyPrintWriter(java.io.Writer writer,
int mode,
char[] lineIndenter,
NameCoder nameCoder) |
PrettyPrintWriter(java.io.Writer writer,
int mode,
char[] lineIndenter,
XmlFriendlyReplacer replacer)
Deprecated.
As of 1.4 use
PrettyPrintWriter(Writer, int, char[], NameCoder) instead |
PrettyPrintWriter(java.io.Writer writer,
int mode,
NameCoder nameCoder) |
PrettyPrintWriter(java.io.Writer writer,
int mode,
java.lang.String lineIndenter) |
PrettyPrintWriter(java.io.Writer writer,
int mode,
XmlFriendlyReplacer replacer)
Deprecated.
As of 1.4 use
PrettyPrintWriter(Writer, int, NameCoder) instead |
PrettyPrintWriter(java.io.Writer writer,
NameCoder nameCoder) |
PrettyPrintWriter(java.io.Writer writer,
java.lang.String lineIndenter) |
PrettyPrintWriter(java.io.Writer writer,
java.lang.String lineIndenter,
java.lang.String newLine)
Deprecated.
As of 1.3
|
PrettyPrintWriter(java.io.Writer writer,
XmlFriendlyReplacer replacer)
Deprecated.
As of 1.4 use
PrettyPrintWriter(Writer, NameCoder) instead. |
Modifier and Type | Method and Description |
---|---|
void |
addAttribute(java.lang.String key,
java.lang.String value) |
void |
close()
Close the writer, if necessary.
|
void |
endNode() |
protected void |
endOfLine() |
void |
flush()
Flush the writer, if necessary.
|
protected java.lang.String |
getNewLine()
Retrieve the line terminator.
|
void |
setValue(java.lang.String text)
Write the value (text content) of the current node.
|
void |
startNode(java.lang.String name) |
void |
startNode(java.lang.String name,
java.lang.Class clazz) |
protected void |
writeAttributeValue(com.thoughtworks.xstream.core.util.QuickWriter writer,
java.lang.String text) |
protected void |
writeText(com.thoughtworks.xstream.core.util.QuickWriter writer,
java.lang.String text) |
escapeXmlName
encodeAttribute, encodeNode, underlyingWriter
public static int XML_QUIRKS
public static int XML_1_0
StreamException
for invalid characters.public static int XML_1_1
StreamException
for invalid characters.public static int XML_1_0_REPLACEMENT
public static int XML_1_1_REPLACEMENT
protected int depth
public PrettyPrintWriter(java.io.Writer writer, char[] lineIndenter, java.lang.String newLine, XmlFriendlyReplacer replacer)
public PrettyPrintWriter(java.io.Writer writer, int mode, char[] lineIndenter, NameCoder nameCoder)
public PrettyPrintWriter(java.io.Writer writer, int mode, char[] lineIndenter, XmlFriendlyReplacer replacer)
PrettyPrintWriter(Writer, int, char[], NameCoder)
insteadpublic PrettyPrintWriter(java.io.Writer writer, char[] lineIndenter, java.lang.String newLine)
public PrettyPrintWriter(java.io.Writer writer, int mode, char[] lineIndenter)
public PrettyPrintWriter(java.io.Writer writer, char[] lineIndenter)
public PrettyPrintWriter(java.io.Writer writer, java.lang.String lineIndenter, java.lang.String newLine)
public PrettyPrintWriter(java.io.Writer writer, int mode, java.lang.String lineIndenter)
public PrettyPrintWriter(java.io.Writer writer, java.lang.String lineIndenter)
public PrettyPrintWriter(java.io.Writer writer, int mode, NameCoder nameCoder)
public PrettyPrintWriter(java.io.Writer writer, int mode, XmlFriendlyReplacer replacer)
PrettyPrintWriter(Writer, int, NameCoder)
insteadpublic PrettyPrintWriter(java.io.Writer writer, NameCoder nameCoder)
public PrettyPrintWriter(java.io.Writer writer, XmlFriendlyReplacer replacer)
PrettyPrintWriter(Writer, NameCoder)
instead.public PrettyPrintWriter(java.io.Writer writer, int mode)
public PrettyPrintWriter(java.io.Writer writer)
public void startNode(java.lang.String name)
public void startNode(java.lang.String name, java.lang.Class clazz)
AbstractWriter
startNode
in interface ExtendedHierarchicalStreamWriter
startNode
in class AbstractWriter
public void setValue(java.lang.String text)
HierarchicalStreamWriter
public void addAttribute(java.lang.String key, java.lang.String value)
protected void writeAttributeValue(com.thoughtworks.xstream.core.util.QuickWriter writer, java.lang.String text)
protected void writeText(com.thoughtworks.xstream.core.util.QuickWriter writer, java.lang.String text)
public void endNode()
protected void endOfLine()
public void flush()
HierarchicalStreamWriter
public void close()
HierarchicalStreamWriter
protected java.lang.String getNewLine()
Copyright © 2004–2024 XStream. All rights reserved.