Top Description Inners Fields Constructors Methods
com.fasterxml.aalto.out

public abstract Class StreamWriterBase

extends Stax2WriterImpl
implements NamespaceContext, ValidationContext
Class Inheritance
All Implemented Interfaces
org.codehaus.stax2.validation.ValidationContext, javax.xml.namespace.NamespaceContext
Known Direct Subclasses
com.fasterxml.aalto.out.NonRepairingStreamWriter, com.fasterxml.aalto.out.RepairingStreamWriter
Imports
java.io.IOException, java.math.BigDecimal, .BigInteger, java.text.MessageFormat, java.util.*, javax.xml.XMLConstants, javax.xml.namespace.NamespaceContext, .QName, javax.xml.stream.*, org.codehaus.stax2.*, org.codehaus.stax2.validation.*, org.codehaus.stax2.ri.Stax2WriterImpl, org.codehaus.stax2.ri.typed.AsciiValueEncoder, .ValueEncoderFactory, org.codehaus.stax2.typed.Base64Variant, .Base64Variants, com.fasterxml.aalto.ValidationException, com.fasterxml.aalto.impl.ErrorConsts, .IoStreamException, .LocationImpl, .StreamExceptionBase, com.fasterxml.aalto.util.TextUtil, .XmlConsts

Base class for XMLStreamReader implementations.

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected static enum

Field Summary

Modifier and TypeField and Description
protected final boolean
protected boolean
protected boolean
protected boolean
protected final WriterConfig
protected OutputElement
_currElem

We'll use a virtual root element (like a document node of sort), to simplify other processing, basically such that there is always a current output element instance, even when in prolog or epilog.

protected String
_dtdRootElemName

Value passed as the expected root element, when using the multiple argument writeDTD method.

protected OutputElement
protected int
protected NamespaceContext
_rootNsContext

Root namespace context defined for this writer, if any.

protected StreamWriterBase.State
protected boolean
_stateAnyOutput

Flag that is set to true first time something has been output.

protected boolean
_stateEmptyElement

Flag that indicates that current element is an empty element (one that is explicitly defined as one, by calling a method -- NOT one that just happens to be empty).

protected boolean
_stateStartElementOpen

Flag that is set during time that a start element is "open", ie.

protected WNameTable
protected XMLValidator
_validator

Optional validator to use for validating output against one or more schemas, and/or for safe pretty-printing (indentation).

protected ValueEncoderFactory
_valueEncoderFactory

When outputting using Typed Access API, we will need encoders.

protected int
_vldContent

State value used with validation, to track types of content that is allowed at this point in output stream.

protected ValidationProblemHandler
_vldProblemHandler

Custom validation problem handler, if any.

protected final XmlWriter
_xmlWriter

Actual physical writer to output serialized XML content to

pack-priv static final int
MAX_POOL_SIZE

Although pooled objects are small, let's limit the pool size nonetheless, to minimize extra memory usage for deeply nested documents.

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
protected void
_closeStartElement(boolean emptyElem)

Method called to close an open start element, when another main-level element (not namespace declaration or attribute) is being output; except for end element which is handled differently.

private final void
_finishDocument(boolean forceRealClose)

protected void
_reportInvalidContent(int evtType)

protected static void
_reportNwfAttr(String msg)

This is the method called when an output method call violates attribute well-formedness checks (trying to output dup attrs) and name validaty checking is enabled.

protected static void
protected static void
_reportNwfContent(String msg)

This is the method called when an output method call violates content well-formedness checks and content validation is enabled.

protected static void
protected static void
protected static void
_reportNwfStructure(String msg)

This is the method called when an output method call violates structural well-formedness checks and structural checking is enabled.

protected static void
public void
protected abstract String
protected abstract void
_setPrefix(String prefix, String uri)

protected void
_verifyRootElement(String prefix, String localName)

protected void
_verifyStartElement(String prefix, String localName)

Method that is called to ensure that we can start writing an element, both from structural point of view, and from syntactic (close previously open start element, if any).

protected final void
protected final void
protected final void
protected final void
protected final void
protected final void
protected final void
protected void
_writeStartDocument(String version, String encoding, String standAlone)

protected void
_writeStartTag(WName name, boolean isEmpty)

protected void
_writeStartTag(WName name, boolean isEmpty, String uri)

public int
addDefaultAttribute(String localName, String uri, String prefix, String value)

Implements org.codehaus.stax2.validation.ValidationContext.addDefaultAttribute.

Adding default attribute values does not usually make sense on output side, so the implementation is a NOP for now.
public void
close()

Implements javax.xml.stream.XMLStreamWriter.close.

Close this writer and free any resources associated with the writer.
public void
closeCompletely()

Implements org.codehaus.stax2.XMLStreamWriter2.closeCompletely.

Method similar to javax.xml.stream.XMLStreamWriter#close(), except that this method also does close the underlying output destination (stream) if it has not yet been closed.
public int
public void
flush()

Implements javax.xml.stream.XMLStreamWriter.flush.

Write any cached data to the underlying output mechanism.
public int
getAttributeCount()

Implements org.codehaus.stax2.validation.ValidationContext.getAttributeCount.

This method returns number of attributes accessible from within currently active start element.
public String
public String
public String
public String
public String
public String
public String
getBaseUri()

Implements org.codehaus.stax2.validation.ValidationContext.getBaseUri.

As of now, there is no way to specify the base URI.
public QName
getCurrentElementName()

Implements org.codehaus.stax2.validation.ValidationContext.getCurrentElementName.

Method that can be used to access name information of the innermost (top) element in the element stack.
public String
getEncoding()

Implements abstract org.codehaus.stax2.ri.Stax2WriterImpl.getEncoding.

Implements org.codehaus.stax2.XMLStreamWriter2.getEncoding.

Method that can be called to get information about encoding that this writer is using (or at least claims is using).
public XMLStreamLocation2
getLocation()

Implements abstract org.codehaus.stax2.ri.Stax2WriterImpl.getLocation.

Implements org.codehaus.stax2.XMLStreamWriter2.getLocation.

Method that should return current output location, if the writer keeps track of it; null if it does not.
public final NamespaceContext
getNamespaceContext()

Implements javax.xml.stream.XMLStreamWriter.getNamespaceContext.

Returns the current namespace context.
public String
getNamespaceURI(String
prefix to look up
prefix
)

Implements javax.xml.namespace.NamespaceContext.getNamespaceURI, org.codehaus.stax2.validation.ValidationContext.getNamespaceURI.

Get Namespace URI bound to a prefix in the current scope.
public String
getPrefix(String
URI of Namespace to lookup
uri
)

Implements javax.xml.namespace.NamespaceContext.getPrefix, javax.xml.stream.XMLStreamWriter.getPrefix.

Get prefix bound to Namespace URI in the current scope.
public Iterator<String>
getPrefixes(String
URI of Namespace to lookup
uri
)

Implements javax.xml.namespace.NamespaceContext.getPrefixes.

Get all prefixes bound to a Namespace URI in the current scope.
public Object
getProperty(String
The name of the property, may not be null
name
)

Implements javax.xml.stream.XMLStreamWriter.getProperty.

Get the value of a feature/property from the underlying implementation
public Location
getValidationLocation()

Implements org.codehaus.stax2.validation.ValidationContext.getValidationLocation.

Method that will return the location that best represents current location within document to be validated, if such information is available.
public String
getXmlVersion()

Implements org.codehaus.stax2.validation.ValidationContext.getXmlVersion.

Method that validator can call to figure out which xml version document being validated declared (if none, "1.0" is assumed as per xml specifications 1.0 and 1.1).
protected final boolean
public boolean
public boolean
public boolean
protected static void
protected static void
reportIllegalMethod(String msg)

Method called when an illegal method (namespace-specific method on non-ns writer) is called by the application.

public void
reportProblem(XMLValidationProblem prob)

Implements org.codehaus.stax2.validation.ValidationContext.reportProblem.

Method called by the validator, upon encountering a validation problem.
private void
public abstract void
setDefaultNamespace(String
the uri to bind to the default namespace, may be null
uri
)

Redeclares javax.xml.stream.XMLStreamWriter.setDefaultNamespace.

Binds a URI to the default namespace This URI is bound in the scope of the current START_ELEMENT / END_ELEMENT pair.
public void
setNamespaceContext(NamespaceContext
the namespace context to use for this writer, may not be null
ctxt
)

Implements javax.xml.stream.XMLStreamWriter.setNamespaceContext.

Sets the current namespace context for prefix and uri bindings.
public final void
setPrefix(String
the prefix to bind to the uri, may not be null
prefix
,
String
the uri to bind to the prefix, may be null
uri
)

Implements javax.xml.stream.XMLStreamWriter.setPrefix.

Sets the prefix the uri is bound to.
public boolean

Returns:

True, if the specified property was succesfully set to specified value; false if its value was not changed
setProperty
(String
Name of the property to set
name
,
Object
Value to set property to.
value
)

Overrides org.codehaus.stax2.ri.Stax2WriterImpl.setProperty.

Implements org.codehaus.stax2.XMLStreamWriter2.setProperty.

Method that can be used to set per-writer properties; a subset of properties one can set via matching org.codehaus.stax2.XMLOutputFactory2 instance.
public ValidationProblemHandler
setValidationProblemHandler(ValidationProblemHandler
Handler to install, if non null; if null, indicates that the default (implementation-specific) handling should be used
h
)

Overrides org.codehaus.stax2.ri.Stax2WriterImpl.setValidationProblemHandler.

Implements org.codehaus.stax2.validation.Validatable.setValidationProblemHandler.

Method that application can call to define a custom handler for validation problems encountered during validation process.
public XMLValidator
stopValidatingAgainst(XMLValidationSchema schema)

Overrides org.codehaus.stax2.ri.Stax2WriterImpl.stopValidatingAgainst.

Implements org.codehaus.stax2.validation.Validatable.stopValidatingAgainst.

Method that can be called by application to stop validating output against a schema, for which validateAgainst was called earlier.
public XMLValidator
stopValidatingAgainst(XMLValidator validator)

Overrides org.codehaus.stax2.ri.Stax2WriterImpl.stopValidatingAgainst.

Implements org.codehaus.stax2.validation.Validatable.stopValidatingAgainst.

Method that can be called by application to stop validating output using specified validator.
protected static void
protected static void
protected static void
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
public XMLValidator
validateAgainst(XMLValidationSchema schema)

Overrides org.codehaus.stax2.ri.Stax2WriterImpl.validateAgainst.

Implements org.codehaus.stax2.validation.Validatable.validateAgainst.

Method that will construct a XMLValidator instance from the given schema (unless a validator for that schema has already been added), initialize it if necessary, and make validatable object (reader, writer) call appropriate validation methods from this point on until the end of the document (that is, it's not scoped with sub-trees), or until validator is removed by an explicit call to stopValidatingAgainst.
protected final ValueEncoderFactory
public final void
writeAttribute(String
the local name of the attribute
localName
,
String
the value of the attribute
value
)

Implements javax.xml.stream.XMLStreamWriter.writeAttribute.

Writes an attribute to the output stream without a prefix.
public abstract void
writeAttribute(String
the uri of the prefix for this attribute
nsURI
,
String
the local name of the attribute
localName
,
String
the value of the attribute
value
)

Redeclares javax.xml.stream.XMLStreamWriter.writeAttribute.

Writes an attribute to the output stream
public abstract void
writeAttribute(String
the prefix for this attribute
prefix
,
String
the uri of the prefix for this attribute
nsURI
,
String
the local name of the attribute
localName
,
String
the value of the attribute
value
)

Redeclares javax.xml.stream.XMLStreamWriter.writeAttribute.

Writes an attribute to the output stream
public void
writeBinary(byte[]
The array from which to write the bytes.
value
,
int
The index in the array from which writing starts.
from
,
int
The number of bytes to write.
length
)

Implements org.codehaus.stax2.typed.TypedXMLStreamWriter.writeBinary.

Write binary content as base64 encoded characters to the output.

public void
public void
writeBinaryAttribute(String
The attribute's prefix.
prefix
,
String
The attribute's URI.
nsURI
,
String
The attribute's local name.
localName
,
byte[]
The array from which to write the bytes.
value
)

Implements org.codehaus.stax2.typed.TypedXMLStreamWriter.writeBinaryAttribute.

Write a byte array attribute.

public void
public void
writeBoolean(boolean
The boolean value to write.
b
)

Implements org.codehaus.stax2.typed.TypedXMLStreamWriter.writeBoolean.

Write a boolean value to the output as textual element content.
public final void
writeBooleanAttribute(String
The attribute's prefix. Null or "" if no prefix is to be used
prefix
,
String
The attribute's URI (can be either null or empty String for "no namespace")
nsURI
,
String
The attribute's local name
localName
,
boolean
The boolean value to write.
value
)

Implements org.codehaus.stax2.typed.TypedXMLStreamWriter.writeBooleanAttribute.

Write a boolean value to the output as attribute value.
public void
writeCData(String
the data contained in the CData Section, may not be null
data
)

Implements javax.xml.stream.XMLStreamWriter.writeCData.

Writes a CData section
public void
public void
writeCharacters(char[]
the value to write
text
,
int
the starting position in the array
start
,
int
the number of characters to write
len
)

Implements javax.xml.stream.XMLStreamWriter.writeCharacters.

Write text to the output
public void
writeCharacters(String
the value to write
text
)

Implements javax.xml.stream.XMLStreamWriter.writeCharacters.

Write text to the output
public void
writeComment(String
the data contained in the comment, may be null
data
)

Implements javax.xml.stream.XMLStreamWriter.writeComment.

Writes an xml comment with the data enclosed
public void
writeDecimal(BigDecimal value)

Implements org.codehaus.stax2.typed.TypedXMLStreamWriter.writeDecimal.

Write a decimal value to the output as textual element content.
public final void
public abstract void
writeDefaultNamespace(String
the uri to bind the default namespace to
nsURI
)

Redeclares javax.xml.stream.XMLStreamWriter.writeDefaultNamespace.

Writes the default namespace to the stream
public void
writeDouble(double value)

Implements org.codehaus.stax2.typed.TypedXMLStreamWriter.writeDouble.

Write a double value to the output as textual element content.
public void
public void
public final void
public final void
writeDTD(String
the DTD to be written
dtd
)

Implements javax.xml.stream.XMLStreamWriter.writeDTD.

Write a DTD section.
public void
public void
public void
writeEmptyElement(String
local name of the tag, may not be null
localName
)

Implements javax.xml.stream.XMLStreamWriter.writeEmptyElement.

It is assumed here that caller actually wants whatever is the default namespace (or it is used in "non-namespace" mode, where no namespaces are bound ever).
public abstract void
writeEmptyElement(String
the uri to bind the tag to, may not be null
nsURI
,
String
local name of the tag, may not be null
localName
)

Redeclares javax.xml.stream.XMLStreamWriter.writeEmptyElement.

Writes an empty element tag to the output
public abstract void
writeEmptyElement(String
the prefix of the tag, may not be null
prefix
,
String
local name of the tag, may not be null
localName
,
String
the uri to bind the tag to, may not be null
nsURI
)

Redeclares javax.xml.stream.XMLStreamWriter.writeEmptyElement.

Writes an empty element tag to the output
public void
writeEndDocument()

Implements javax.xml.stream.XMLStreamWriter.writeEndDocument.

Closes any start tags and writes corresponding end tags.
public void
writeEndElement()

Implements javax.xml.stream.XMLStreamWriter.writeEndElement.

Writes an end tag to the output relying on the internal state of the writer to determine the prefix and local name of the event.
public void
writeEntityRef(String
the name of the entity
name
)

Implements javax.xml.stream.XMLStreamWriter.writeEntityRef.

Writes an entity reference
public void
writeFloat(float value)

Implements org.codehaus.stax2.typed.TypedXMLStreamWriter.writeFloat.

Write a float value to the output as textual element content.
public void
public void
public final void
public void
public void
writeInt(int value)

Implements org.codehaus.stax2.typed.TypedXMLStreamWriter.writeInt.

Write an int value to the output as textual element content.
public final void
writeIntArray(int[]
The array from which to write the ints.
value
,
int
The index in the array from which writing starts.
from
,
int
The number of ints to write.
length
)

Implements org.codehaus.stax2.typed.TypedXMLStreamWriter.writeIntArray.

Write int array to the output.

public void
writeIntArrayAttribute(String
The attribute's prefix.
prefix
,
String
The attribute's URI.
nsURI
,
String
The attribute's local name.
localName
,
int[]
The array from which to write the ints.
value
)

Implements org.codehaus.stax2.typed.TypedXMLStreamWriter.writeIntArrayAttribute.

Write int array attribute.

public final void
writeIntAttribute(String
The attribute's prefix. Null or "" if no prefix is to be used
prefix
,
String
The attribute's URI (can be either null or empty String for "no namespace")
nsURI
,
String
The attribute's local name
localName
,
int
The integer value to write.
value
)

Implements org.codehaus.stax2.typed.TypedXMLStreamWriter.writeIntAttribute.

Write an integer value to the output as attribute value.
public void
public final void
public void
writeLong(long value)

Implements org.codehaus.stax2.typed.TypedXMLStreamWriter.writeLong.

Write a long value to the output as textual element content.
public void
public void
public final void
writeLongAttribute(String
The attribute's prefix. Null or "" if no prefix is to be used
prefix
,
String
The attribute's URI (can be either null or empty String for "no namespace")
nsURI
,
String
The attribute's local name
localName
,
long
The long value to write.
value
)

Implements org.codehaus.stax2.typed.TypedXMLStreamWriter.writeLongAttribute.

Write an long value to the output as attribute value.
public abstract void
writeNamespace(String
the prefix to bind this namespace to
prefix
,
String
the uri to bind the prefix to
nsURI
)

Redeclares javax.xml.stream.XMLStreamWriter.writeNamespace.

Writes a namespace to the output stream If the prefix argument to this method is the empty string, "xmlns", or null this method will delegate to writeDefaultNamespace
public void
writeProcessingInstruction(String
the target of the processing instruction, may not be null
target
)

Implements javax.xml.stream.XMLStreamWriter.writeProcessingInstruction.

Writes a processing instruction
public void
writeProcessingInstruction(String
the target of the processing instruction, may not be null
target
,
String
the data contained in the processing instruction, may not be null
data
)

Implements javax.xml.stream.XMLStreamWriter.writeProcessingInstruction.

Writes a processing instruction
public void
public final void
public void
writeRaw(String text)

Overrides org.codehaus.stax2.ri.Stax2WriterImpl.writeRaw.

Implements org.codehaus.stax2.XMLStreamWriter2.writeRaw.

Method that writes specified content as is, without encoding or deciphering it in any way.
public void
writeRaw(String text, int start, int offset)

Implements abstract org.codehaus.stax2.ri.Stax2WriterImpl.writeRaw.

Implements org.codehaus.stax2.XMLStreamWriter2.writeRaw.

Method that writes specified content as is, without encoding or deciphering it in any way.
public void
writeRaw(char[] text, int offset, int length)

Implements abstract org.codehaus.stax2.ri.Stax2WriterImpl.writeRaw.

Implements org.codehaus.stax2.XMLStreamWriter2.writeRaw.

Method that writes specified content as is, without encoding or deciphering it in any way.
public void
writeSpace(String text)

Overrides org.codehaus.stax2.ri.Stax2WriterImpl.writeSpace.

Implements org.codehaus.stax2.XMLStreamWriter2.writeSpace.

Method that can be called to write whitespace-only content.
public void
writeSpace(char[] cbuf, int offset, int len)

Overrides org.codehaus.stax2.ri.Stax2WriterImpl.writeSpace.

Implements org.codehaus.stax2.XMLStreamWriter2.writeSpace.

Method that can be called to write whitespace-only content.
public void
public void
writeStartDocument(String
version of the xml document
version
)

Implements javax.xml.stream.XMLStreamWriter.writeStartDocument.

Write the XML Declaration.
public void
writeStartDocument(String
encoding of the xml declaration
encoding
,
String
version of the xml document
version
)

Implements javax.xml.stream.XMLStreamWriter.writeStartDocument.

Write the XML Declaration.
public void
public void
writeStartElement(String
local name of the tag, may not be null
localName
)

Implements javax.xml.stream.XMLStreamWriter.writeStartElement.

It is assumed here that caller actually wants whatever is the default namespace (or it is used in "non-namespace" mode, where no namespaces are bound ever).
public abstract void
writeStartElement(String
the namespaceURI of the prefix to use, may not be null
nsURI
,
String
local name of the tag, may not be null
localName
)

Redeclares javax.xml.stream.XMLStreamWriter.writeStartElement.

Writes a start tag to the output
public abstract void
writeStartElement(String
the prefix of the tag, may not be null
prefix
,
String
local name of the tag, may not be null
localName
,
String
the uri to bind the prefix to, may not be null
nsURI
)

Redeclares javax.xml.stream.XMLStreamWriter.writeStartElement.

Writes a start tag to the output
public abstract void
writeTypedAttribute(String prefix, String nsURI, String localName, AsciiValueEncoder enc)

Need to leave implementation of this method abstract, because repairing and non-repairing modes differ in how names are handled.

private final void
Inherited from org.codehaus.stax2.ri.Stax2WriterImpl:
copyEventFromReadercopyStartElement