public abstract class XMLOutputFactory
extends java.lang.Object
The class represents the factory for getting XMLStreamWriter
intances.
The default implementation
automatically
recycles
any writer which has been
closed
.
Usage example:
// Lets format to an appendable.
TextBuilder xml = new TextBuilder();
AppendableWriter out = new AppendableWriter(xml);
// Creates a factory producing writers using tab indentation.
XMLOutpuFactory factory = XMLOutputFactory.newInstance();
factory.setProperty(XMLOutputFactory.INDENTATION, "/t");
// Creates a new writer (potentially recycled).
XMLStreamWriter writer = factory.createXMLStreamReader(out);
// Formats to XML.
writer.writeStartDocument();
writer.writeStartElement(...);
...
writer.close(); // Automatically recycles this writer.
out.close(); // Underlying output should be closed explicitly.
// Displays the formatted output.
System.out.println(xml);
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
AUTOMATIC_EMPTY_ELEMENTS
Property indicating if the stream writers are allowed to automatically
output empty elements when a start element is immediately followed by
matching end element
(type:
Boolean , default: FALSE ). |
static Configurable<java.lang.Class<? extends XMLOutputFactory>> |
CLASS
Holds the XMLOutputFactory implementation (configurable).
|
static java.lang.String |
INDENTATION
Property used to specify an indentation string; non-null indentation
forces the writer to write elements into separate lines
(type:
String , default: null ). |
static java.lang.String |
IS_REPAIRING_NAMESPACES
Property used to set prefix defaulting on the output side
(type:
Boolean , default: FALSE ). |
static java.lang.String |
LINE_SEPARATOR
Property used to specify the new line characters
(type:
String , default: "\n" ). |
static java.lang.String |
NO_EMPTY_ELEMENT_TAG
Property indicating if the stream writers are not allowed to use
empty element tags
(type:
Boolean , default: FALSE ). |
static java.lang.String |
REPAIRING_PREFIX
Property used to specify the prefix to be appended by a trailing
part (a sequence number) in order to make it unique to be usable as
a temporary non-colliding prefix when repairing namespaces
(type:
String , default: "ns" ). |
Modifier | Constructor and Description |
---|---|
protected |
XMLOutputFactory()
Default constructor.
|
Modifier and Type | Method and Description |
---|---|
abstract XMLStreamWriter |
createXMLStreamWriter(java.io.OutputStream stream)
Returns a XML stream writer to the specified output stream (UTF-8
encoding).
|
abstract XMLStreamWriter |
createXMLStreamWriter(java.io.OutputStream stream,
java.lang.String encoding)
Returns a XML stream writer to the specified output stream using the
specified encoding.
|
abstract XMLStreamWriter |
createXMLStreamWriter(java.io.Writer writer)
Returns a XML stream writer to the specified i/o writer.
|
abstract java.lang.Object |
getProperty(java.lang.String name)
Gets a feature/property on the underlying implementation.
|
abstract boolean |
isPropertySupported(java.lang.String name)
Queries the set of properties that this factory supports.
|
static XMLOutputFactory |
newInstance()
Returns a new instance of the
CLASS output factory
implementation which may be configurated by the user
(see setProperty(String, Object) ). |
abstract void |
setProperty(java.lang.String name,
java.lang.Object value)
Allows the user to set specific features/properties on the underlying
implementation.
|
public static final Configurable<java.lang.Class<? extends XMLOutputFactory>> CLASS
public static final java.lang.String IS_REPAIRING_NAMESPACES
Boolean
, default: FALSE
).public static final java.lang.String REPAIRING_PREFIX
String
, default: "ns"
).public static final java.lang.String INDENTATION
String
, default: null
).public static final java.lang.String LINE_SEPARATOR
String
, default: "\n"
).public static final java.lang.String AUTOMATIC_EMPTY_ELEMENTS
Boolean
, default: FALSE
).public static final java.lang.String NO_EMPTY_ELEMENT_TAG
Boolean
, default: FALSE
).
When set, this property forces the use of start/end element tag
(e.g. i.e. "<empty />" replaced by "<empty></empty>"),
This property takes precedence over AUTOMATIC_EMPTY_ELEMENTS
.public static XMLOutputFactory newInstance()
CLASS
output factory
implementation which may be configurated by the user
(see setProperty(String, Object)
). The output factory
instance is allocated through ObjectFactory.getInstance(Class)
.public abstract XMLStreamWriter createXMLStreamWriter(java.io.Writer writer) throws XMLStreamException
writer
- the writer to write to.XMLStreamException
public abstract XMLStreamWriter createXMLStreamWriter(java.io.OutputStream stream) throws XMLStreamException
stream
- the stream to write to.XMLStreamException
public abstract XMLStreamWriter createXMLStreamWriter(java.io.OutputStream stream, java.lang.String encoding) throws XMLStreamException
stream
- the stream to write to.encoding
- the encoding to use.XMLStreamException
public abstract void setProperty(java.lang.String name, java.lang.Object value) throws java.lang.IllegalArgumentException
name
- the name of the property.value
- the value of the property.java.lang.IllegalArgumentException
- if the property is not supported.public abstract java.lang.Object getProperty(java.lang.String name) throws java.lang.IllegalArgumentException
name
- the name of the propertyjava.lang.IllegalArgumentException
- if the property is not supported.public abstract boolean isPropertySupported(java.lang.String name)
name
- the name of the property (may not be null).true
if the property is supported;
false
otherwise.Copyright © 2005 - 2007 Javolution.