public class EnhancedXMLStreamWriter extends Object implements XMLStreamWriter
A version of XMLStreamWriter
that adds convenience methods
for adding simple elements and typed attributes, as well as offering
pretty-printing. Can be used on its own with a Writer,
or as a wrapper to an existing XMLStreamWriter
instance.
Since 2.0.0 checked exceptions are wrapped in an XMLException
.
Constructor and Description |
---|
EnhancedXMLStreamWriter(Writer writer) |
EnhancedXMLStreamWriter(Writer writer,
boolean writeBlanks)
Creates a new xml stream writer.
|
EnhancedXMLStreamWriter(Writer writer,
boolean writeBlanks,
int indent)
Creates a new xml stream writer.
|
Modifier and Type | Method and Description |
---|---|
void |
close() |
void |
flush() |
NamespaceContext |
getNamespaceContext() |
String |
getPrefix(String uri) |
Object |
getProperty(String name) |
Writer |
getWriter()
Gets the underlying writer, after flushing this XML stream writer.
|
void |
setDefaultNamespace(String uri) |
void |
setNamespaceContext(NamespaceContext context) |
void |
setPrefix(String prefix,
String uri) |
void |
writeAttribute(String localName,
String value) |
void |
writeAttribute(String namespaceURI,
String localName,
String value) |
void |
writeAttribute(String prefix,
String namespaceURI,
String localName,
String value) |
void |
writeAttributeBoolean(String localName,
Boolean value) |
void |
writeAttributeBoolean(String localName,
Boolean value,
boolean writeBlanks)
Writes a Boolean attribute.
|
void |
writeAttributeClass(Class<?> value)
Write a "class" attribute with the value obtained from
getting it by invoking
Class.getCanonicalName() . |
void |
writeAttributeClass(Class<?> value,
boolean writeBlanks)
Write a "class" attribute with the value obtained from
getting it by invoking
Class.getCanonicalName() . |
void |
writeAttributeClass(String localName,
Class<?> value) |
void |
writeAttributeClass(String localName,
Class<?> value,
boolean writeBlanks)
Writes an attribute containing a class name, getting it by invoking
Class.getCanonicalName() . |
void |
writeAttributeDelimited(String localName,
List<?> values)
Writes an attribute by converting a list into a comma-separated
string.
|
void |
writeAttributeDelimited(String localName,
List<?> values,
String delimiter)
Writes an attribute by converting a list into a comma-separated
string.
|
void |
writeAttributeDisabled()
Write a "disabled" attribute set to
true . |
void |
writeAttributeDisabled(boolean value)
Write a "disabled" attribute.
|
void |
writeAttributeDisabled(Boolean value,
boolean writeBlanks)
Write a "disabled" attribute.
|
void |
writeAttributeDouble(String localName,
Double value) |
void |
writeAttributeDouble(String localName,
Double value,
boolean writeBlanks)
Writes a Double attribute.
|
void |
writeAttributeFloat(String localName,
Float value) |
void |
writeAttributeFloat(String localName,
Float value,
boolean writeBlanks)
Writes a Float attribute.
|
void |
writeAttributeInteger(String localName,
Integer value) |
void |
writeAttributeInteger(String localName,
Integer value,
boolean writeBlanks)
Writes a Integer attribute.
|
void |
writeAttributeLong(String localName,
Long value) |
void |
writeAttributeLong(String localName,
Long value,
boolean writeBlanks)
Writes a Long attribute.
|
void |
writeAttributeObject(String localName,
Object value)
Writes an attribute object by first converting it to string
using its "toString()" method.
|
void |
writeAttributeObject(String localName,
Object value,
boolean writeBlanks)
Writes an attribute object by first converting it to string
using its "toString()" method.
|
void |
writeAttributeString(String localName,
String value) |
void |
writeAttributeString(String localName,
String value,
boolean writeBlanks)
Writes a String attribute.
|
void |
writeCData(String data) |
void |
writeCharacters(char[] text,
int start,
int len) |
void |
writeCharacters(String text) |
void |
writeComment(String data) |
void |
writeDefaultNamespace(String namespaceURI) |
void |
writeDTD(String dtd) |
void |
writeElementBoolean(String localName,
Boolean value) |
void |
writeElementBoolean(String localName,
Boolean value,
boolean writeBlanks)
Writes a simple Boolean element.
|
void |
writeElementClass(String localName,
Class<?> value) |
void |
writeElementClass(String localName,
Class<?> value,
boolean writeBlanks)
Writes a simple element containing a class name, getting it by invoking
Class.getCanonicalName() . |
void |
writeElementDelimited(String localName,
List<?> values)
Writes an element by converting a list into a comma-separated
string.
|
void |
writeElementDelimited(String localName,
List<?> values,
String delimiter)
Writes an element by converting a list into a comma-separated
string.
|
void |
writeElementDimension(String localName,
Dimension value)
Writes a simple element containing a Dimension.
|
void |
writeElementDimension(String localName,
Dimension value,
boolean writeBlanks)
Writes a simple element containing a Dimension.
|
void |
writeElementDisabled(String localName)
Writes an empty element with a "disabled" attribute set to
true . |
void |
writeElementDisabled(String localName,
Class<?> clazz)
Writes an empty element with a "disabled" attribute set to
true and a "class" attribute matching the class name. |
void |
writeElementDouble(String localName,
Double value) |
void |
writeElementDouble(String localName,
Double value,
boolean writeBlanks)
Writes a simple Double element.
|
void |
writeElementFile(String localName,
File value)
Writes a
File element. |
void |
writeElementFile(String localName,
File value,
boolean writeBlanks)
Writes a
File element. |
void |
writeElementFloat(String localName,
Float value) |
void |
writeElementFloat(String localName,
Float value,
boolean writeBlanks)
Writes a simple Float element.
|
void |
writeElementInteger(String localName,
Integer value) |
void |
writeElementInteger(String localName,
Integer value,
boolean writeBlanks)
Writes a simple Integer element.
|
void |
writeElementLong(String localName,
Long value) |
void |
writeElementLong(String localName,
Long value,
boolean writeBlanks)
Writes a simple Long element.
|
void |
writeElementObject(String localName,
Object value)
Writes an element object as string.
|
void |
writeElementObject(String localName,
Object value,
boolean writeBlanks)
Writes an element object as string.
|
void |
writeElementObjectList(String parentLocalName,
String localName,
List<?> values)
Writes a list of objects.
|
void |
writeElementObjectList(String parentLocalName,
String localName,
List<?> values,
boolean writeBlanks)
Writes a list of objects.
|
void |
writeElementString(String localName,
String value) |
void |
writeElementString(String localName,
String value,
boolean writeBlanks)
Writes a simple string element.
|
void |
writeEmptyElement(String localName) |
void |
writeEmptyElement(String namespaceURI,
String localName) |
void |
writeEmptyElement(String prefix,
String localName,
String namespaceURI) |
void |
writeEndDocument() |
void |
writeEndElement() |
void |
writeEntityRef(String name) |
void |
writeNamespace(String prefix,
String namespaceURI) |
void |
writeObject(String localName,
Object value)
Writes an object.
|
void |
writeObject(String localName,
Object value,
boolean disabled)
Writes an object.
|
void |
writeObjectList(String parentLocalName,
String localName,
List<? extends Object> values)
Writes a list of objects.
|
void |
writeProcessingInstruction(String target) |
void |
writeProcessingInstruction(String target,
String data) |
void |
writeStartDocument() |
void |
writeStartDocument(String version) |
void |
writeStartDocument(String encoding,
String version) |
void |
writeStartElement(String localName) |
void |
writeStartElement(String localName,
Class<?> clazz)
Writes a start element of the supplied name, with a "class" attribute
for the given class.
|
void |
writeStartElement(String localName,
Class<?> clazz,
boolean disabled)
Writes a start element of the supplied name, with a "class" attribute
for the given class, and a "disabled" attribute if
true . |
void |
writeStartElement(String namespaceURI,
String localName) |
void |
writeStartElement(String prefix,
String localName,
String namespaceURI) |
public EnhancedXMLStreamWriter(Writer writer)
public EnhancedXMLStreamWriter(Writer writer, boolean writeBlanks)
writer
- writer used to write XMLwriteBlanks
- true
to write attributes/elements
with no values when invoking methods without the
"writeBlanks" argument. This sets the default behavior which
can be overwritten using methods with "writeBlanks" argument.public EnhancedXMLStreamWriter(Writer writer, boolean writeBlanks, int indent)
writer
- writer used to write XMLwriteBlanks
- true
to write attributes/elements
with no values when invoking methods without the
"writeBlanks" argument. This sets the default behavior which
can be overwritten using methods with "writeBlanks" argument.indent
- how many spaces to use for indentation (-1=no indent;
0=newline only; 1+=number of spaces after newline)public Writer getWriter()
public void writeAttributeInteger(String localName, Integer value, boolean writeBlanks)
localName
- attribute namevalue
- Integer attribute valuewriteBlanks
- whether a blank value should be written as
an empty attribute.public void writeAttributeLong(String localName, Long value, boolean writeBlanks)
localName
- attribute namevalue
- Long attribute valuewriteBlanks
- whether a blank value should be written as
an empty attribute.public void writeAttributeFloat(String localName, Float value, boolean writeBlanks)
localName
- attribute namevalue
- Float attribute valuewriteBlanks
- whether a blank value should be written as
an empty attribute.public void writeAttributeDouble(String localName, Double value, boolean writeBlanks)
localName
- attribute namevalue
- Double attribute valuewriteBlanks
- whether a blank value should be written as
an empty attribute.public void writeAttributeBoolean(String localName, Boolean value, boolean writeBlanks)
localName
- attribute namevalue
- Boolean attribute valuewriteBlanks
- whether a blank value should be written as
an empty attribute.public void writeAttributeString(String localName, String value, boolean writeBlanks)
localName
- attribute namevalue
- String attribute valuewriteBlanks
- whether a blank value should be written as
an empty attribute.public void writeAttributeClass(Class<?> value, boolean writeBlanks)
Class.getCanonicalName()
.value
- the class to writewriteBlanks
- whether a blank value should be written as
an empty attribute.public void writeAttributeClass(Class<?> value)
Class.getCanonicalName()
.value
- the class to writepublic void writeAttributeClass(String localName, Class<?> value, boolean writeBlanks)
Class.getCanonicalName()
.localName
- attribute namevalue
- Class attribute valuewriteBlanks
- whether a blank value should be written as
an empty attribute.public void writeAttributeDisabled(Boolean value, boolean writeBlanks)
value
- true
or false
writeBlanks
- whether a blank value should be written as
an empty attribute.public void writeAttributeDisabled(boolean value)
value
- true
or false
public void writeAttributeDisabled()
true
.public void writeAttributeObject(String localName, Object value)
localName
- attribute namevalue
- attribute valuepublic void writeAttributeObject(String localName, Object value, boolean writeBlanks)
localName
- attribute namevalue
- attribute valuewriteBlanks
- whether a blank value should be written as
an empty attribute.public void writeAttributeDelimited(String localName, List<?> values)
localName
- attribute namevalues
- the values to writepublic void writeAttributeDelimited(String localName, List<?> values, String delimiter)
localName
- attribute namevalues
- the values to writedelimiter
- the string separating each valuespublic void writeElementDisabled(String localName)
true
.localName
- element (tag) namepublic void writeElementDisabled(String localName, Class<?> clazz)
true
and a "class" attribute matching the class name.localName
- element (tag) nameclazz
- the classpublic void writeElementInteger(String localName, Integer value, boolean writeBlanks)
localName
- element (tag) namevalue
- the Integer valuewriteBlanks
- whether a blank value should be written as an empty element.public void writeElementLong(String localName, Long value, boolean writeBlanks)
localName
- element (tag) namevalue
- the Long valuewriteBlanks
- whether a blank value should be written as an empty element.public void writeElementFloat(String localName, Float value, boolean writeBlanks)
localName
- element (tag) namevalue
- the Float valuewriteBlanks
- whether a blank value should be written as an empty element.public void writeElementDouble(String localName, Double value, boolean writeBlanks)
localName
- element (tag) namevalue
- the Double valuewriteBlanks
- whether a blank value should be written as an empty element.public void writeElementBoolean(String localName, Boolean value, boolean writeBlanks)
localName
- element (tag) namevalue
- the Boolean valuewriteBlanks
- whether a blank value should be written as an empty element.public void writeElementString(String localName, String value, boolean writeBlanks)
localName
- element (tag) namevalue
- the string valuewriteBlanks
- whether a blank value should be written as an empty element.public void writeElementClass(String localName, Class<?> value, boolean writeBlanks)
Class.getCanonicalName()
.localName
- element (tag) namevalue
- the classwriteBlanks
- whether a blank value should be written as an empty element.public void writeElementFile(String localName, File value, boolean writeBlanks)
File
element.localName
- element (tag) namevalue
- the FilewriteBlanks
- whether a blank value should be written as an empty element.public void writeElementFile(String localName, File value)
File
element.localName
- element (tag) namevalue
- the Filepublic void writeElementDimension(String localName, Dimension value)
localName
- element (tag) namevalue
- the dimensionpublic void writeElementDimension(String localName, Dimension value, boolean writeBlanks)
localName
- element (tag) namevalue
- the dimensionwriteBlanks
- whether a blank value should be written as an empty element.public void writeElementObjectList(String parentLocalName, String localName, List<?> values, boolean writeBlanks)
parentLocalName
- parent tag wrapping child elements
(set to null
for no parent)localName
- element (tag) namevalues
- the listwriteBlanks
- whether a blank value should be written as an empty element.public void writeElementObjectList(String parentLocalName, String localName, List<?> values)
parentLocalName
- parent tag wrapping child elements
(set to null
for no parent)localName
- element (tag) namevalues
- the listpublic void writeElementObject(String localName, Object value)
localName
- element (tag) namevalue
- element (tag) valuewriteObject(String, Object)
public void writeElementObject(String localName, Object value, boolean writeBlanks)
localName
- element (tag) namevalue
- element (tag) valuewriteBlanks
- whether a blank value should be written as an empty element.writeObject(String, Object)
public void writeElementDelimited(String localName, List<?> values)
localName
- element namevalues
- the values to writepublic void writeElementDelimited(String localName, List<?> values, String delimiter)
localName
- element namevalues
- the values to writedelimiter
- the string separating each valuespublic void writeObject(String localName, Object value)
IXMLConfigurable
,
its is responsible for creating its own XML through its
IXMLConfigurable.saveToXML(XML)
method.
Otherwise, an empty element is created with the "class" attribute
matching the object class canonical name.localName
- element (tag) namevalue
- the object to writewriteElementObject(String, Object)
public void writeObject(String localName, Object value, boolean disabled)
IXMLConfigurable
,
its is responsible for creating its own XML through its
IXMLConfigurable.saveToXML(XML)
method.
Otherwise, an empty element is created with the "class" attribute
matching the object class canonical name.localName
- element (tag) namevalue
- the object to writedisabled
- whether the object should have the "diabled" attributewriteElementObject(String, Object)
public void writeObjectList(String parentLocalName, String localName, List<? extends Object> values)
IXMLConfigurable
,
its is responsible for creating its own XML through its
IXMLConfigurable.saveToXML(XML)
method.
Otherwise, an empty element is created with the "class" attribute
matching the object class canonical name.parentLocalName
- parent tag wrapping child elements
(set to null
for no parent)localName
- element (tag) namevalues
- the objects to writewriteElementObjectList(String, String, List)
public void writeStartElement(String localName)
writeStartElement
in interface XMLStreamWriter
public void writeStartElement(String localName, Class<?> clazz)
localName
- tag nameclazz
- name of class, or null
public void writeStartElement(String localName, Class<?> clazz, boolean disabled)
true
.localName
- tag nameclazz
- name of class, or null
disabled
- true
to disable this classpublic void writeStartElement(String namespaceURI, String localName)
writeStartElement
in interface XMLStreamWriter
public void writeStartElement(String prefix, String localName, String namespaceURI)
writeStartElement
in interface XMLStreamWriter
public void writeEmptyElement(String namespaceURI, String localName)
writeEmptyElement
in interface XMLStreamWriter
public void writeEmptyElement(String prefix, String localName, String namespaceURI)
writeEmptyElement
in interface XMLStreamWriter
public void writeEmptyElement(String localName)
writeEmptyElement
in interface XMLStreamWriter
public void writeEndElement()
writeEndElement
in interface XMLStreamWriter
public void writeEndDocument()
writeEndDocument
in interface XMLStreamWriter
public void close()
close
in interface XMLStreamWriter
public void flush()
flush
in interface XMLStreamWriter
public void writeAttribute(String localName, String value)
writeAttribute
in interface XMLStreamWriter
public void writeAttribute(String prefix, String namespaceURI, String localName, String value)
writeAttribute
in interface XMLStreamWriter
public void writeAttribute(String namespaceURI, String localName, String value)
writeAttribute
in interface XMLStreamWriter
public void writeNamespace(String prefix, String namespaceURI)
writeNamespace
in interface XMLStreamWriter
public void writeDefaultNamespace(String namespaceURI)
writeDefaultNamespace
in interface XMLStreamWriter
public void writeComment(String data)
writeComment
in interface XMLStreamWriter
public void writeProcessingInstruction(String target)
writeProcessingInstruction
in interface XMLStreamWriter
public void writeProcessingInstruction(String target, String data)
writeProcessingInstruction
in interface XMLStreamWriter
public void writeCData(String data)
writeCData
in interface XMLStreamWriter
public void writeDTD(String dtd)
writeDTD
in interface XMLStreamWriter
public void writeEntityRef(String name)
writeEntityRef
in interface XMLStreamWriter
public void writeStartDocument()
writeStartDocument
in interface XMLStreamWriter
public void writeStartDocument(String version)
writeStartDocument
in interface XMLStreamWriter
public void writeStartDocument(String encoding, String version)
writeStartDocument
in interface XMLStreamWriter
public void writeCharacters(String text)
writeCharacters
in interface XMLStreamWriter
public void writeCharacters(char[] text, int start, int len)
writeCharacters
in interface XMLStreamWriter
public String getPrefix(String uri)
getPrefix
in interface XMLStreamWriter
public void setPrefix(String prefix, String uri)
setPrefix
in interface XMLStreamWriter
public void setDefaultNamespace(String uri)
setDefaultNamespace
in interface XMLStreamWriter
public void setNamespaceContext(NamespaceContext context)
setNamespaceContext
in interface XMLStreamWriter
public NamespaceContext getNamespaceContext()
getNamespaceContext
in interface XMLStreamWriter
public Object getProperty(String name)
getProperty
in interface XMLStreamWriter
Copyright © 2008–2023 Norconex Inc.. All rights reserved.