public class XMLEncoder extends Object
A helper class to encode objects to XML.
Usage:
XMLEncoder encoder = new XMLEncoder(writer);
encoder
.start("tag").attribute("name", "tag_name_attribute")
.start("nested_tag").attribute("name", "nested_tag_name).cdata("tag text element").end()
.end();
Modifier and Type | Field and Description |
---|---|
protected boolean |
cdata |
protected int |
currentTagLevel |
protected String |
indent |
protected boolean |
indentLine |
protected int |
indentTimes |
protected int |
lastTagLevel |
protected Deque<String> |
openTags |
protected PrintWriter |
out |
protected String |
projectVersion |
protected boolean |
tagOpened |
Constructor and Description |
---|
XMLEncoder(PrintWriter out) |
XMLEncoder(PrintWriter out,
String indent) |
XMLEncoder(PrintWriter out,
String indent,
String projectVersion) |
Modifier and Type | Method and Description |
---|---|
XMLEncoder |
attribute(String name,
boolean value) |
XMLEncoder |
attribute(String name,
int value) |
XMLEncoder |
attribute(String name,
String value) |
XMLEncoder |
attribute(String name,
String value,
boolean newLine) |
XMLEncoder |
cdata(String data) |
XMLEncoder |
cdata(String data,
boolean escape) |
XMLEncoder |
end()
This method will track presence of nested tags and print closure accordingly
|
XMLEncoder |
indent(int i) |
XMLEncoder |
nested(Collection<? extends XMLSerializable> collection,
ConfigurationNodeVisitor delegate) |
XMLEncoder |
nested(Map<?,? extends XMLSerializable> map,
ConfigurationNodeVisitor delegate) |
XMLEncoder |
nested(XMLSerializable object,
ConfigurationNodeVisitor delegate) |
XMLEncoder |
print(String text) |
XMLEncoder |
println() |
XMLEncoder |
println(String text) |
XMLEncoder |
projectVersion()
Inserts an optional project version attribute in the output.
|
XMLEncoder |
property(String name,
boolean b)
Prints a common XML element - property with name and value.
|
XMLEncoder |
property(String name,
int i)
Prints a common XML element - property with name and value.
|
XMLEncoder |
property(String name,
String value)
Prints a common XML element - property with name and value.
|
XMLEncoder |
simpleTag(String tag,
String value)
Prints common XML element - tag with name and text value (<tag>value</tag>)
If value is empty, nothing will be printed.
|
XMLEncoder |
start(String tag) |
protected String projectVersion
protected String indent
protected PrintWriter out
protected boolean indentLine
protected int indentTimes
protected boolean tagOpened
protected boolean cdata
protected int currentTagLevel
protected int lastTagLevel
public XMLEncoder(PrintWriter out)
public XMLEncoder(PrintWriter out, String indent)
public XMLEncoder(PrintWriter out, String indent, String projectVersion)
public XMLEncoder indent(int i)
public XMLEncoder print(String text)
public XMLEncoder println(String text)
public XMLEncoder println()
public XMLEncoder start(String tag)
tag
- to startpublic XMLEncoder end()
public XMLEncoder attribute(String name, String value)
name
- of the attributevalue
- of the attributepublic XMLEncoder attribute(String name, String value, boolean newLine)
name
- of the attributevalue
- of the attributenewLine
- should this attribute be printed on new linepublic XMLEncoder attribute(String name, boolean value)
name
- of the attributevalue
- of the attributepublic XMLEncoder attribute(String name, int value)
name
- of the attributevalue
- of the attributepublic XMLEncoder cdata(String data)
data
- char datapublic XMLEncoder cdata(String data, boolean escape)
data
- char dataescape
- does this data need to be enclosed into <![CDATA[ ... ]]>public XMLEncoder nested(XMLSerializable object, ConfigurationNodeVisitor delegate)
object
- nested object to serializedelegate
- visitorpublic XMLEncoder nested(Collection<? extends XMLSerializable> collection, ConfigurationNodeVisitor delegate)
collection
- of nested objectsdelegate
- visitorpublic XMLEncoder nested(Map<?,? extends XMLSerializable> map, ConfigurationNodeVisitor delegate)
map
- of nested objectsdelegate
- visitorpublic XMLEncoder property(String name, String value)
public XMLEncoder property(String name, boolean b)
public XMLEncoder property(String name, int i)
public XMLEncoder simpleTag(String tag, String value)
public XMLEncoder projectVersion()
Copyright © 2001–2019 Apache Cayenne. All rights reserved.