java.lang.Object
org.panteleyev.commons.xml.XMLStreamWriterWrapper
- All Implemented Interfaces:
AutoCloseable
Implements convenience wrapper for
XMLStreamWriter instances.
Attribute values are converted to string accoring to the following rules:
| Class | String Value |
|---|---|
String | as is |
LocalDateTime | ISO date time |
Enum | Enum.name() |
LocalDate | LocalDate.toEpochDay() or ISO date depending on options. |
Object | Object.toString() |
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumSerialization options. -
Method Summary
Modifier and TypeMethodDescriptionWrites a single attribute.attributes(Map<String, ?> attributes) Writes several attributes.voidclose()Closes the writer.voidWrites XML document.Writes XML element.Writes XML element with text.Writes element with attributes.Writes element with attributes and text.voidflush()Flushes the writer.static XMLStreamWriterWrappernewInstance(OutputStream out) Creates an instance ofXMLStreamWriterWrapperwith default options.static XMLStreamWriterWrappernewInstance(OutputStream out, Set<XMLStreamWriterWrapper.Option> options) Creates an instance ofXMLStreamWriterWrapperwith specified options.Writes element text.
-
Method Details
-
newInstance
Creates an instance ofXMLStreamWriterWrapperwith default options.- Parameters:
out- output stream- Returns:
- instance of
XMLStreamWriterWrapper
-
newInstance
public static XMLStreamWriterWrapper newInstance(OutputStream out, Set<XMLStreamWriterWrapper.Option> options) Creates an instance ofXMLStreamWriterWrapperwith specified options.- Parameters:
out- output streamoptions- set of options- Returns:
- instance of
XMLStreamWriterWrapper
-
close
public void close()Closes the writer. SeeXMLStreamWriter.close().- Specified by:
closein interfaceAutoCloseable
-
flush
public void flush()Flushes the writer. SeeXMLStreamWriter.flush(). -
document
Writes XML document.- Parameters:
body- block that generates document XML
-
element
Writes XML element.- Parameters:
localName- element local namebody- block that generates element XML: attributes, nodes, etc.- Returns:
- this instance
-
element
Writes XML element with text.
<localName>text</localName>- Parameters:
localName- element local nametext- element text- Returns:
- this instance
-
element
Writes element with attributes.- Parameters:
localName- element local nameattributes- attributes- Returns:
- this instance
-
element
Writes element with attributes and text.- Parameters:
localName- element local nameattributes- attributestext- element text- Returns:
- this instance
-
attribute
Writes a single attribute.- Parameters:
name- attribute namevalue- attribute value- Returns:
- this instance
-
attributes
Writes several attributes.- Parameters:
attributes- attributes- Returns:
- this instance
-
text
Writes element text.- Parameters:
text- element text- Returns:
- this instance
-