public class StreamWriterToReceiver extends Object implements XMLStreamWriter
This class does not itself perform "namespace repairing" as defined in the interface Javadoc
(also referred to as "prefix defaulting" in the StaX JSR specification). In normal use, however,
the events emitted by this class are piped into a NamespaceReducer which performs a function
very similar to namespace repairing; specifically, it ensures that when elements and attribute are
generated with a given namespace URI and local name, then namespace declarations are generated
automatically without any explicit need to call the writeNamespace(String, String) method.
The class will check all names, URIs, and character content for conformance against XML well-formedness
rules unless the checkValues option is set to false.
The implementation of this class is influenced not only by the Javadoc documentation of the
XMLStreamWriter interface (which is woefully inadequate), but also by the helpful
but unofficial interpretation of the spec to be found at
http://veithen.github.io/2009/11/01/understanding-stax.html
| Constructor and Description |
|---|
StreamWriterToReceiver(Receiver receiver)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
void |
flush() |
void |
flushStartTag() |
NamespaceContext |
getNamespaceContext()
Return the current namespace context.
|
String |
getPrefix(String uri) |
Object |
getProperty(String name) |
Receiver |
getReceiver()
Get the Receiver to which this StreamWriterToReceiver is writing events
|
boolean |
isCheckValues()
Ask whether names and values are to be checked for conformance with XML rules
|
boolean |
isInventPrefixes()
Deprecated.
since 9.7.0.2
|
void |
setCheckValues(boolean check)
Say whether names and values are to be checked for conformance with XML rules
|
void |
setDefaultNamespace(String uri) |
void |
setInventPrefixes(boolean invent)
Deprecated.
since 9.7.0.2. In normal use this class feeds its output into a
NamespaceReducer
which performs the equivalent of "namespace repairing" or "prefix invention": that is, it ensures
that when elements or attributes are written in a specific namespace, there is no need for an
explicit writeNamespace(String, String) call to create the namespace declaration. |
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 |
writeCData(String data) |
void |
writeCharacters(char[] text,
int start,
int len) |
void |
writeCharacters(String text) |
void |
writeComment(String data) |
void |
writeDefaultNamespace(String namespaceURI)
Emits a default namespace declaration
|
void |
writeDTD(String dtd) |
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)
Emits a namespace declaration event.
|
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)
Generate a start element event for an element in no namespace.
|
void |
writeStartElement(String namespaceURI,
String localName)
Generate a start element event.
|
void |
writeStartElement(String prefix,
String localName,
String namespaceURI)
Generate a start element event.
|
public StreamWriterToReceiver(Receiver receiver)
receiver - the Receiver that is to receive the events generated
by this StreamWriter.public Receiver getReceiver()
public void setInventPrefixes(boolean invent)
NamespaceReducer
which performs the equivalent of "namespace repairing" or "prefix invention": that is, it ensures
that when elements or attributes are written in a specific namespace, there is no need for an
explicit writeNamespace(String, String) call to create the namespace declaration.invent - true if prefixes are to be invented.public boolean isInventPrefixes()
NamespaceReducer; this is an approximation
of the result in earlier releases.public void setCheckValues(boolean check)
check - true if names and values are to be checked. Default is false;public boolean isCheckValues()
public void flushStartTag()
throws XMLStreamException
XMLStreamExceptionpublic void writeStartElement(String localName) throws XMLStreamException
setDefaultNamespace(String) has been called;
this is Saxon's interpretation of the intended effect of the StAX specification.writeStartElement in interface XMLStreamWriterlocalName - local name of the tag, may not be nullXMLStreamException - if names are being checked and the name is invalid, or if an error occurs downstreamNullPointerException - if the supplied local name is nullpublic void writeStartElement(String namespaceURI, String localName) throws XMLStreamException
setPrefix(String, String) and/or setDefaultNamespace(String)
if these include the specified namespace URI; otherwise the namespace will become the default namespace
and there will therefore be no prefix.writeStartElement in interface XMLStreamWriternamespaceURI - the namespace URI of the element name. Must not be null. A zero-length
string means the element is in no namespace.localName - local part of the element name. Must not be nullXMLStreamException - if names are being checked and are found to be invalid, or if an
error occurs downstream in the pipeline.NullPointerException - if either argument is nullpublic void writeStartElement(String prefix, String localName, String namespaceURI) throws XMLStreamException
writeStartElement in interface XMLStreamWriterprefix - the prefix of the element, must not be null. If the prefix is supplied as a zero-length
string, the element will nave no prefix (that is, the namespace URI will become the default
namespace).localName - local name of the element, must not be nullnamespaceURI - the uri to bind the prefix to, must not be null. If the value is a zero-length string,
the element will be in no namespace; in this case any prefix is ignored.NullPointerException - if any of the arguments is null.XMLStreamException - if names are being checked and are found to be invalid, or if an
error occurs downstream in the pipeline.public void writeEmptyElement(String namespaceURI, String localName) throws XMLStreamException
writeEmptyElement in interface XMLStreamWriterXMLStreamExceptionpublic void writeEmptyElement(String prefix, String localName, String namespaceURI) throws XMLStreamException
writeEmptyElement in interface XMLStreamWriterXMLStreamExceptionpublic void writeEmptyElement(String localName) throws XMLStreamException
writeEmptyElement in interface XMLStreamWriterXMLStreamExceptionpublic void writeEndElement()
throws XMLStreamException
writeEndElement in interface XMLStreamWriterXMLStreamExceptionpublic void writeEndDocument()
throws XMLStreamException
writeEndDocument in interface XMLStreamWriterXMLStreamExceptionpublic void close()
throws XMLStreamException
close in interface XMLStreamWriterXMLStreamExceptionpublic void flush()
throws XMLStreamException
flush in interface XMLStreamWriterXMLStreamExceptionpublic void writeAttribute(String localName, String value) throws XMLStreamException
writeAttribute in interface XMLStreamWriterXMLStreamExceptionpublic void writeAttribute(String prefix, String namespaceURI, String localName, String value) throws XMLStreamException
writeAttribute in interface XMLStreamWriterXMLStreamExceptionpublic void writeAttribute(String namespaceURI, String localName, String value) throws XMLStreamException
writeAttribute in interface XMLStreamWriterXMLStreamExceptionpublic void writeNamespace(String prefix, String namespaceURI) throws XMLStreamException
If the prefix argument to this method is the empty string, "xmlns", or null this method will delegate to writeDefaultNamespace.
This method does not change the name of any element or attribute; its only use is to write additional or redundant namespace declarations. With this implementation of XMLStreamWriter, this method is needed only to generate namespace declarations for prefixes that do not appear in element or attribute names. If an attempt is made to generate a namespace declaration that conflicts with the prefix-uri bindings in scope for element and attribute names, an exception occurs.
writeNamespace in interface XMLStreamWriterprefix - the prefix to bind this namespace tonamespaceURI - the uri to bind the prefix toIllegalStateException - if the current state does not allow Namespace writingXMLStreamExceptionpublic void writeDefaultNamespace(String namespaceURI) throws XMLStreamException
This method does not change the name of any element or attribute; its only use is to write additional or redundant namespace declarations. With this implementation of XMLStreamWriter, this method is needed only to generate namespace declarations for prefixes that do not appear in element or attribute names. If an attempt is made to generate a namespace declaration that conflicts with the prefix-uri bindings in scope for element and attribute names, an exception occurs.
writeDefaultNamespace in interface XMLStreamWriternamespaceURI - the uri to bind the default namespace toIllegalStateException - if the current state does not allow Namespace writingXMLStreamExceptionpublic void writeComment(String data) throws XMLStreamException
writeComment in interface XMLStreamWriterXMLStreamExceptionpublic void writeProcessingInstruction(String target) throws XMLStreamException
writeProcessingInstruction in interface XMLStreamWriterXMLStreamExceptionpublic void writeProcessingInstruction(String target, String data) throws XMLStreamException
writeProcessingInstruction in interface XMLStreamWriterXMLStreamExceptionpublic void writeCData(String data) throws XMLStreamException
writeCData in interface XMLStreamWriterXMLStreamExceptionpublic void writeDTD(String dtd) throws XMLStreamException
writeDTD in interface XMLStreamWriterXMLStreamExceptionpublic void writeEntityRef(String name) throws XMLStreamException
writeEntityRef in interface XMLStreamWriterXMLStreamExceptionpublic void writeStartDocument()
throws XMLStreamException
writeStartDocument in interface XMLStreamWriterXMLStreamExceptionpublic void writeStartDocument(String version) throws XMLStreamException
writeStartDocument in interface XMLStreamWriterXMLStreamExceptionpublic void writeStartDocument(String encoding, String version) throws XMLStreamException
writeStartDocument in interface XMLStreamWriterXMLStreamExceptionpublic void writeCharacters(String text) throws XMLStreamException
writeCharacters in interface XMLStreamWriterXMLStreamExceptionpublic void writeCharacters(char[] text,
int start,
int len)
throws XMLStreamException
writeCharacters in interface XMLStreamWriterXMLStreamExceptionpublic String getPrefix(String uri)
getPrefix in interface XMLStreamWriterpublic void setPrefix(String prefix, String uri)
setPrefix in interface XMLStreamWriterpublic void setDefaultNamespace(String uri) throws XMLStreamException
setDefaultNamespace in interface XMLStreamWriterXMLStreamExceptionpublic void setNamespaceContext(NamespaceContext context) throws XMLStreamException
setNamespaceContext in interface XMLStreamWriterXMLStreamExceptionpublic NamespaceContext getNamespaceContext()
The specification of this method is hopelessly vague. This method returns a namespace context
that contains the namespaces declared using setPrefix(String, String) calls that are
in-scope at the time, overlaid on the root namespace context that was defined using
setNamespaceContext(NamespaceContext). The namespaces bound using setPrefix(String, String)
are copied, and are therefore unaffected by subsequent changes, but the root namespace context
is not copied, because the NamespaceContext interface provides no way of doing so.
getNamespaceContext in interface XMLStreamWriterpublic Object getProperty(String name) throws IllegalArgumentException
getProperty in interface XMLStreamWriterIllegalArgumentExceptionCopyright (c) 2004-2015 Saxonica Limited. All rights reserved.