public class XMLStructuredOutput extends AbstractStructuredOutput
StructuredOutput
emitting XML data.
Can be used to construct XML using the StructuredOutput interface.
AbstractStructuredOutput.Element, AbstractStructuredOutput.ElementType, AbstractStructuredOutput.TagBuilder
Modifier and Type | Field and Description |
---|---|
protected OutputStream |
out |
nesting
Constructor and Description |
---|
XMLStructuredOutput(OutputStream out)
Creates a new output writing to the given output stream.
|
XMLStructuredOutput(OutputStream output,
Charset encoding,
String doctype)
Creates a new output writing to the given output stream.
|
XMLStructuredOutput(OutputStream output,
String doctype)
Creates a new output writing to the given output stream.
|
Modifier and Type | Method and Description |
---|---|
StructuredOutput |
beginOutput(String rootElement)
Starts the output with the given root element.
|
StructuredOutput |
beginOutput(String rootElement,
Attribute... attr)
Starts the output with the given root element and attributes
|
StructuredOutput |
beginResult()
Starts the result with a default root element ("result").
|
StructuredOutput |
beginResult(String name)
Starts the result by specifying the name of the root element.
|
AbstractStructuredOutput.TagBuilder |
buildBegin(String rootElement)
Creates a
AbstractStructuredOutput.TagBuilder used to fluently create the root element. |
void |
close()
Closes the underlying stream
|
protected void |
endArray(String name)
Must be implemented by subclasses to end an array.
|
protected void |
endObject(String name)
Must be implemented by subclasses to end an object.
|
void |
endOutput()
Closes the output and this XML document.
|
void |
endResult()
Finishes (closes) the result
|
StructuredOutput |
propertyIfFilled(String name,
Object data)
Adds a property to the current object.
|
protected void |
startArray(String name)
Must be implemented by subclasses to start a new array.
|
protected void |
startObject(String name,
Attribute... attributes)
Must be implemented by subclasses to start a new object.
|
StructuredOutput |
text(Object text)
Creates a text node for the current node.
|
protected void |
writeProperty(String name,
Object value)
Must be implemented by subclasses to generate a property.
|
array, array, beginArray, beginObject, beginObject, buildObject, endArray, endObject, getCurrentType, isCurrentObjectEmpty, nullsafeProperty, property
protected OutputStream out
public XMLStructuredOutput(@Nonnull OutputStream out)
out
- the stream used as destination for the generated xmlpublic XMLStructuredOutput(@Nonnull OutputStream output, @Nullable String doctype)
output
- the stream used as destination for the generated xmldoctype
- the doc type used in the XML headerpublic XMLStructuredOutput(@Nonnull OutputStream output, @Nonnull Charset encoding, @Nullable String doctype)
output
- the stream used as destination for the generated xmlencoding
- the charset used to encode the outputdoctype
- the doc type used in the XML headerprotected void endArray(String name)
AbstractStructuredOutput
endArray
in class AbstractStructuredOutput
name
- the name of the array property to closeprotected void endObject(String name)
AbstractStructuredOutput
endObject
in class AbstractStructuredOutput
name
- the name of the object to closepublic StructuredOutput beginResult()
StructuredOutput
public StructuredOutput beginResult(String name)
StructuredOutput
name
- the name of the root elementpublic StructuredOutput beginOutput(@Nonnull String rootElement)
rootElement
- the name of the root element of the generated document.public StructuredOutput beginOutput(@Nonnull String rootElement, Attribute... attr)
rootElement
- the name of the root element of the generated document.attr
- the attributes for the root element@CheckReturnValue public AbstractStructuredOutput.TagBuilder buildBegin(@Nonnull String rootElement)
AbstractStructuredOutput.TagBuilder
used to fluently create the root element.rootElement
- name of the root elementpublic void endOutput()
public void endResult()
StructuredOutput
endResult
in interface StructuredOutput
endResult
in class AbstractStructuredOutput
protected void startArray(String name)
AbstractStructuredOutput
startArray
in class AbstractStructuredOutput
name
- the name of the array property.protected void startObject(String name, Attribute... attributes)
AbstractStructuredOutput
startObject
in class AbstractStructuredOutput
name
- the name of the objectattributes
- the attributes of the objectprotected void writeProperty(String name, Object value)
AbstractStructuredOutput
writeProperty
in class AbstractStructuredOutput
name
- the name of the propertyvalue
- the value of the propertypublic StructuredOutput propertyIfFilled(@Nonnull String name, @Nullable Object data)
This will create a property only if the specified data object is not null. Else no property is created.
name
- the name of the propertydata
- the value of the propertypublic StructuredOutput text(Object text)
text
- the text to be added to the current nodepublic void close() throws IOException
IOException
- if an IO error occurs while closing the streamCopyright © 2018. All rights reserved.