Package org.apache.cayenne.util
Class XMLEncoder
java.lang.Object
org.apache.cayenne.util.XMLEncoder
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();
- Since:
- 1.1, 4.1 API is greatly reworked to be more usable
-
Field Summary
Fields Modifier and Type Field Description protected booleancdataprotected intcurrentTagLevelprotected Stringindentprotected booleanindentLineprotected intindentTimesprotected intlastTagLevelprotected Deque<String>openTagsprotected PrintWriteroutprotected StringprojectVersionprotected booleantagOpened -
Constructor Summary
Constructors Constructor Description XMLEncoder(PrintWriter out)XMLEncoder(PrintWriter out, String indent)XMLEncoder(PrintWriter out, String indent, String projectVersion) -
Method Summary
Modifier and Type Method Description XMLEncoderattribute(String name, boolean value)XMLEncoderattribute(String name, int value)XMLEncoderattribute(String name, String value)XMLEncoderattribute(String name, String value, boolean newLine)XMLEncodercdata(String data)XMLEncodercdata(String data, boolean escape)XMLEncoderend()This method will track presence of nested tags and print closure accordinglyXMLEncoderindent(int i)XMLEncodernested(Collection<? extends XMLSerializable> collection, ConfigurationNodeVisitor delegate)XMLEncodernested(Map<?,? extends XMLSerializable> map, ConfigurationNodeVisitor delegate)XMLEncodernested(XMLSerializable object, ConfigurationNodeVisitor delegate)XMLEncoderprint(String text)XMLEncoderprintln()XMLEncoderprintln(String text)XMLEncoderprojectVersion()Inserts an optional project version attribute in the output.XMLEncoderproperty(String name, boolean b)Prints a common XML element - property with name and value.XMLEncoderproperty(String name, int i)Prints a common XML element - property with name and value.XMLEncoderproperty(String name, String value)Prints a common XML element - property with name and value.XMLEncodersimpleTag(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.XMLEncoderstart(String tag)
-
Field Details
-
projectVersion
-
indent
-
out
-
indentLine
protected boolean indentLine -
indentTimes
protected int indentTimes -
tagOpened
protected boolean tagOpened -
cdata
protected boolean cdata -
currentTagLevel
protected int currentTagLevel -
lastTagLevel
protected int lastTagLevel -
openTags
-
-
Constructor Details
-
XMLEncoder
-
XMLEncoder
-
XMLEncoder
- Since:
- 3.1
-
-
Method Details
-
indent
-
print
-
println
-
println
- Since:
- 3.1
-
start
- Parameters:
tag- to start- Returns:
- this
- Since:
- 4.1
-
end
This method will track presence of nested tags and print closure accordingly- Returns:
- this
- Since:
- 4.1
-
attribute
- Parameters:
name- of the attributevalue- of the attribute- Returns:
- this
- Since:
- 4.1
-
attribute
- Parameters:
name- of the attributevalue- of the attributenewLine- should this attribute be printed on new line- Returns:
- this
- Since:
- 4.1
-
attribute
- Parameters:
name- of the attributevalue- of the attribute- Returns:
- this
- Since:
- 4.1
-
attribute
- Parameters:
name- of the attributevalue- of the attribute- Returns:
- this
- Since:
- 4.1
-
cdata
- Parameters:
data- char data- Returns:
- this
- Since:
- 4.1
-
cdata
- Parameters:
data- char dataescape- does this data need to be enclosed into <![CDATA[ ... ]]>- Returns:
- this
- Since:
- 4.1
-
nested
- Parameters:
object- nested object to serializedelegate- visitor- Returns:
- this
- Since:
- 4.1
-
nested
public XMLEncoder nested(Collection<? extends XMLSerializable> collection, ConfigurationNodeVisitor delegate)- Parameters:
collection- of nested objectsdelegate- visitor- Returns:
- this
- Since:
- 4.1
-
nested
- Parameters:
map- of nested objectsdelegate- visitor- Returns:
- this
- Since:
- 4.1
-
property
Prints a common XML element - property with name and value.- Since:
- 4.1
-
property
Prints a common XML element - property with name and value.- Since:
- 4.1
-
property
Prints a common XML element - property with name and value.- Since:
- 4.1
-
simpleTag
Prints common XML element - tag with name and text value (<tag>value</tag>) If value is empty, nothing will be printed.- Since:
- 4.1
-
projectVersion
Inserts an optional project version attribute in the output. If the project version is not initialized for encoder, will do nothing.- Since:
- 4.1
-