com.thoughtworks.xstream.io.xml
Class PrettyPrintWriter

java.lang.Object
  extended by com.thoughtworks.xstream.io.AbstractWriter
      extended by com.thoughtworks.xstream.io.xml.AbstractXmlWriter
          extended by com.thoughtworks.xstream.io.xml.PrettyPrintWriter
All Implemented Interfaces:
ExtendedHierarchicalStreamWriter, HierarchicalStreamWriter, XmlFriendlyWriter
Direct Known Subclasses:
CompactWriter

public class PrettyPrintWriter
extends AbstractXmlWriter

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 the writeText(com.thoughtworks.xstream.core.util.QuickWriter, String) and writeAttributeValue(com.thoughtworks.xstream.core.util.QuickWriter, String) methods.

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).

Author:
Joe Walnes, Jörg Schaible

Field Summary
protected  int depth
           
static int XML_1_0
           
static int XML_1_1
           
static int XML_QUIRKS
           
 
Constructor Summary
PrettyPrintWriter(Writer writer)
           
PrettyPrintWriter(Writer writer, char[] lineIndenter)
           
PrettyPrintWriter(Writer writer, char[] lineIndenter, String newLine)
          Deprecated. As of 1.3
PrettyPrintWriter(Writer writer, char[] lineIndenter, String newLine, XmlFriendlyReplacer replacer)
          Deprecated. As of 1.3
PrettyPrintWriter(Writer writer, int mode)
           
PrettyPrintWriter(Writer writer, int mode, char[] lineIndenter)
           
PrettyPrintWriter(Writer writer, int mode, char[] lineIndenter, NameCoder nameCoder)
           
PrettyPrintWriter(Writer writer, int mode, char[] lineIndenter, XmlFriendlyReplacer replacer)
          Deprecated. As of 1.4 use PrettyPrintWriter(Writer, int, char[], NameCoder) instead
PrettyPrintWriter(Writer writer, int mode, NameCoder nameCoder)
           
PrettyPrintWriter(Writer writer, int mode, String lineIndenter)
           
PrettyPrintWriter(Writer writer, int mode, XmlFriendlyReplacer replacer)
          Deprecated. As of 1.4 use PrettyPrintWriter(Writer, int, NameCoder) instead
PrettyPrintWriter(Writer writer, NameCoder nameCoder)
           
PrettyPrintWriter(Writer writer, String lineIndenter)
           
PrettyPrintWriter(Writer writer, String lineIndenter, String newLine)
          Deprecated. As of 1.3
PrettyPrintWriter(Writer writer, XmlFriendlyReplacer replacer)
          Deprecated. As of 1.4 use PrettyPrintWriter(Writer, NameCoder) instead.
 
Method Summary
 void addAttribute(String key, String value)
           
 void close()
          Close the writer, if necessary.
 void endNode()
           
protected  void endOfLine()
           
 void flush()
          Flush the writer, if necessary.
protected  String getNewLine()
           
 void setValue(String text)
          Write the value (text content) of the current node.
 void startNode(String name)
           
 void startNode(String name, Class clazz)
          
protected  void writeAttributeValue(com.thoughtworks.xstream.core.util.QuickWriter writer, String text)
           
protected  void writeText(com.thoughtworks.xstream.core.util.QuickWriter writer, String text)
           
 
Methods inherited from class com.thoughtworks.xstream.io.xml.AbstractXmlWriter
escapeXmlName
 
Methods inherited from class com.thoughtworks.xstream.io.AbstractWriter
encodeAttribute, encodeNode, underlyingWriter
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

XML_QUIRKS

public static int XML_QUIRKS

XML_1_0

public static int XML_1_0

XML_1_1

public static int XML_1_1

depth

protected int depth
Constructor Detail

PrettyPrintWriter

public PrettyPrintWriter(Writer writer,
                         char[] lineIndenter,
                         String newLine,
                         XmlFriendlyReplacer replacer)
Deprecated. As of 1.3

Since:
1.2

PrettyPrintWriter

public PrettyPrintWriter(Writer writer,
                         int mode,
                         char[] lineIndenter,
                         NameCoder nameCoder)
Since:
1.4

PrettyPrintWriter

public PrettyPrintWriter(Writer writer,
                         int mode,
                         char[] lineIndenter,
                         XmlFriendlyReplacer replacer)
Deprecated. As of 1.4 use PrettyPrintWriter(Writer, int, char[], NameCoder) instead

Since:
1.3

PrettyPrintWriter

public PrettyPrintWriter(Writer writer,
                         char[] lineIndenter,
                         String newLine)
Deprecated. As of 1.3


PrettyPrintWriter

public PrettyPrintWriter(Writer writer,
                         int mode,
                         char[] lineIndenter)
Since:
1.3

PrettyPrintWriter

public PrettyPrintWriter(Writer writer,
                         char[] lineIndenter)

PrettyPrintWriter

public PrettyPrintWriter(Writer writer,
                         String lineIndenter,
                         String newLine)
Deprecated. As of 1.3


PrettyPrintWriter

public PrettyPrintWriter(Writer writer,
                         int mode,
                         String lineIndenter)
Since:
1.3

PrettyPrintWriter

public PrettyPrintWriter(Writer writer,
                         String lineIndenter)

PrettyPrintWriter

public PrettyPrintWriter(Writer writer,
                         int mode,
                         NameCoder nameCoder)
Since:
1.4

PrettyPrintWriter

public PrettyPrintWriter(Writer writer,
                         int mode,
                         XmlFriendlyReplacer replacer)
Deprecated. As of 1.4 use PrettyPrintWriter(Writer, int, NameCoder) instead

Since:
1.3

PrettyPrintWriter

public PrettyPrintWriter(Writer writer,
                         NameCoder nameCoder)
Since:
1.4

PrettyPrintWriter

public PrettyPrintWriter(Writer writer,
                         XmlFriendlyReplacer replacer)
Deprecated. As of 1.4 use PrettyPrintWriter(Writer, NameCoder) instead.


PrettyPrintWriter

public PrettyPrintWriter(Writer writer,
                         int mode)
Since:
1.3

PrettyPrintWriter

public PrettyPrintWriter(Writer writer)
Method Detail

startNode

public void startNode(String name)

startNode

public void startNode(String name,
                      Class clazz)
Description copied from class: AbstractWriter

Specified by:
startNode in interface ExtendedHierarchicalStreamWriter
Overrides:
startNode in class AbstractWriter

setValue

public void setValue(String text)
Description copied from interface: HierarchicalStreamWriter
Write the value (text content) of the current node.


addAttribute

public void addAttribute(String key,
                         String value)

writeAttributeValue

protected void writeAttributeValue(com.thoughtworks.xstream.core.util.QuickWriter writer,
                                   String text)

writeText

protected void writeText(com.thoughtworks.xstream.core.util.QuickWriter writer,
                         String text)

endNode

public void endNode()

endOfLine

protected void endOfLine()

flush

public void flush()
Description copied from interface: HierarchicalStreamWriter
Flush the writer, if necessary.


close

public void close()
Description copied from interface: HierarchicalStreamWriter
Close the writer, if necessary.


getNewLine

protected String getNewLine()


Copyright © 2004-2014 XStream. All Rights Reserved.