@Parallelizable(comment="Factory configuration should be performed sequentially.") public interface XMLOutputFactory extends Cloneable
The OSGi factory service to create XMLStreamWriter
instances.
For each bundle, a distinct factory instance is returned and can be
individually configured (if not enough the factory can be
cloned
).
import javolution.xml.stream.*; public class Activator implements BundleActivator { public void start(BundleContext bc) throws Exception { // Configures factory. ServiceTracker<XMLOutputFactory, XMLOutputFactory> tracker = new ServiceTracker<>(bc, XMLOutputFactory.class, null); tracker.open(); tracker.getService().setProperty(XMLOutputFactory.INDENTATION, "/t"); // Use tab for indentations. // Instantiates a new writer. TextBuilder xml = new TextBuilder(); AppendableWriter out = new AppendableWriter(xml); XMLStreamWriter writer = tracker.getService().createXMLStreamWriter(out); // Formats to XML. writer.writeStartDocument("1.0"); writer.writeCharacters("\n"); writer.writeStartElement("ns1", "sample", "http://www.e.com/ns1"); writer.writeNamespace("ns1", "http://www.e.com/ns1"); writer.writeEndElement(); writer.writeEndDocument(); // Closes the writer which may be recycled back to the factory. writer.close(); // Displays the formatted output. System.out.println(xml); }
Modifier and Type | Field and Description |
---|---|
static 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 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 String |
IS_REPAIRING_NAMESPACES
Property used to set prefix defaulting on the output side
(type:
Boolean , default: FALSE ). |
static String |
LINE_SEPARATOR
Property used to specify the new line characters
(type:
String , default: "\n" ). |
static String |
NO_EMPTY_ELEMENT_TAG
Property indicating if the stream writers are not allowed to use
empty element tags
(type:
Boolean , default: FALSE ). |
static 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 and Type | Method and Description |
---|---|
XMLOutputFactory |
clone()
Returns a clone of this factory which can be independently configured.
|
XMLStreamWriter |
createXMLStreamWriter(OutputStream stream)
Returns a XML stream writer to the specified output stream (UTF-8
encoding).
|
XMLStreamWriter |
createXMLStreamWriter(OutputStream stream,
String encoding)
Returns a XML stream writer to the specified output stream using the
specified encoding.
|
XMLStreamWriter |
createXMLStreamWriter(Writer writer)
Returns a XML stream writer to the specified i/o writer.
|
Object |
getProperty(String name)
Gets a feature/property on the underlying implementation.
|
boolean |
isPropertySupported(String name)
Queries the set of properties that this factory supports.
|
void |
setProperty(String name,
Object value)
Allows the user to set specific features/properties on the underlying
implementation.
|
static final String IS_REPAIRING_NAMESPACES
Boolean
, default: FALSE
).static final String REPAIRING_PREFIX
String
, default: "ns"
).static final String INDENTATION
String
, default: null
).static final String LINE_SEPARATOR
String
, default: "\n"
).static final String AUTOMATIC_EMPTY_ELEMENTS
Boolean
, default: FALSE
).static final 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
.XMLStreamWriter createXMLStreamWriter(Writer writer) throws XMLStreamException
writer
- the writer to write to.XMLStreamException
XMLStreamWriter createXMLStreamWriter(OutputStream stream) throws XMLStreamException
stream
- the stream to write to.XMLStreamException
XMLStreamWriter createXMLStreamWriter(OutputStream stream, String encoding) throws XMLStreamException
stream
- the stream to write to.encoding
- the encoding to use.XMLStreamException
void setProperty(String name, Object value) throws IllegalArgumentException
name
- the name of the property.value
- the value of the property.IllegalArgumentException
- if the property is not supported.Object getProperty(String name) throws IllegalArgumentException
name
- the name of the propertyIllegalArgumentException
- if the property is not supported.boolean isPropertySupported(String name)
name
- the name of the property (may not be null).true
if the property is supported;
false
otherwise.XMLOutputFactory clone()
Copyright © 2005-2013 Javolution. All Rights Reserved.