Top Description Fields Constructors Methods
com.ctc.wstx.sw

public abstract Class BaseStreamWriter

extends Stax2WriterImpl
implements ValidationContext, OutputConfigFlags
Class Inheritance
All Implemented Interfaces
com.ctc.wstx.cfg.OutputConfigFlags, org.codehaus.stax2.validation.ValidationContext
Known Direct Subclasses
com.ctc.wstx.sw.TypedStreamWriter
Imports
java.io.IOException, .Writer, java.text.MessageFormat, javax.xml.namespace.NamespaceContext, .QName, javax.xml.stream.Location, .XMLReporter, .XMLStreamException, .XMLStreamWriter, javax.xml.stream.events.Characters, .StartElement, org.codehaus.stax2.DTDInfo, .XMLStreamLocation2, .XMLStreamReader2, org.codehaus.stax2.ri.Stax2WriterImpl, org.codehaus.stax2.validation.*, com.ctc.wstx.api.*, com.ctc.wstx.cfg.ErrorConsts, .OutputConfigFlags, .XmlConsts, com.ctc.wstx.exc.*, com.ctc.wstx.io.WstxInputLocation, com.ctc.wstx.sr.StreamReaderImpl, .AttributeCollector, .InputElementStack, com.ctc.wstx.util.DataUtil, .StringUtil

Base class for XMLStreamWriter implementations Woodstox has. Contains partial stream writer implementation, plus utility methods shared by concrete implementation classes. Main reason for such abstract base class is to allow other parts of Woodstox core to refer to any of stream writer implementations in general way.

Field Summary

Modifier and TypeField and Description
protected static final int
protected static final char
protected static final int
protected boolean
mAnyOutput

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

protected final boolean
protected final boolean
protected final boolean
protected boolean
protected boolean
protected final WriterConfig
protected char[]
mCopyBuffer

Intermediate buffer into which characters of a String can be copied, in cases where such a copy followed by array access is faster than calling String.charAt() (which perhaps surprisingly is often case, and especially significant for longer buffers).

protected String
mDtdRootElem

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

protected boolean
mEmptyElement

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 String
mEncoding

Encoding to use; may be passed from the factory (when a method that defines encoding is used), updated by a call to writeStartDocument, or null if neither.

protected static final int
MIN_ARRAYCOPY

This constant defines minimum length of a String, for which it is beneficial to do an intermediate copy (using String.getChars()), and iterate over intermediate array, instead of iterating using String.charAt().

protected boolean
protected boolean
mStartElementOpen

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

protected int
protected XMLValidator
mValidator

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

protected int
mVldContent

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

protected ValidationProblemHandler
mVldProbHandler

Custom validation problem handler, if any.

protected final XmlWriter
mWriter

Actual physical writer to output serialized XML content to

protected boolean
mXml11

Since XML 1.1 has some differences to 1.0, we need to keep a flag to indicate if we were to output XML 1.1 document.

protected static final int
protected static final int
protected static final int

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
private final void
_finishDocument(boolean
If true, will force calling of close() on the underlying physical result (stream, writer). If false, will let XmlWriter decide whether to call close(); will be done if auto-closing enabled, but not otherwise.
forceRealClose
)

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.

protected abstract 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.

public void
copyEventFromReader(XMLStreamReader2
Stream reader to use for accessing event to copy
sr
,
boolean
If true, writer is not allowed to change the state of the reader (so that all the data associated with the current event has to be preserved); if false, writer is allowed to use methods that may cause some data to be discarded. Setting this to false may improve the performance, since it may allow full no-copy streaming of data, especially textual contents.
preserveEventData
)

Overrides org.codehaus.stax2.ri.Stax2WriterImpl.copyEventFromReader.

Implements org.codehaus.stax2.XMLStreamWriter2.copyEventFromReader.

Method that essentially copies event that the specified reader has just read.

public abstract void
copyStartElement(InputElementStack elemStack, AttributeCollector attrCollector)

Implementation-dependant method called to fully copy START_ELEMENT event that the passed-in stream reader points to

protected void
protected void
protected void
doWriteStartDocument(String version, String encoding, String standAlone)

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.

protected final char[]
protected final char[]
getCopyBuffer(int minLen)

public abstract QName
getCurrentElementName()

Redeclares 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 abstract NamespaceContext
getNamespaceContext()

Redeclares javax.xml.stream.XMLStreamWriter.getNamespaceContext.

Returns the current namespace context.

public abstract String
getNamespaceURI(String prefix)

Redeclares org.codehaus.stax2.validation.ValidationContext.getNamespaceURI.

Method that can be called by the validator to resolve a namespace prefix of the currently active top-level element.

public abstract String
getPrefix(String
the uri the prefix is bound to
uri
)

Redeclares javax.xml.stream.XMLStreamWriter.getPrefix.

Gets the prefix the uri is bound to.

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

protected abstract String
getTopElementDesc()

Method needed for error message generation

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 boolean
isValidating()

Method that is used by output classes to determine whether we are in validating mode.

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.

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 WstxOutputProperties#P_OUTPUT_VALIDATE_NAMES is 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 WstxOutputProperties#P_OUTPUT_VALIDATE_CONTENT is is enabled.

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 WstxOutputProperties#P_OUTPUT_VALIDATE_STRUCTURE is is enabled.

protected static void
public void
reportProblem(XMLValidationProblem prob)

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

Method called by the validator, upon encountering a validation problem.

public void
reportValidationProblem(String msg, Location loc, int severity)

public void
reportValidationProblem(String msg, int severity)

public void
public void
public void
public void
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 abstract void
setNamespaceContext(NamespaceContext
the namespace context to use for this writer, may not be null
context
)

Redeclares javax.xml.stream.XMLStreamWriter.setNamespaceContext.

Sets the current namespace context for prefix and uri bindings.

public abstract 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
)

Redeclares 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.

public abstract String

Returns:

Prefix to use when writing out given QName as an element or attribute value
validateQNamePrefix
(QName name)

Method called before writing a QName via Typed Access API.

protected void
verifyRootElement(String localName, String prefix)

protected final void
protected final void
public final Writer
wrapAsRawWriter()

Method that can be called to get a wrapper instance that can be used to essentially call the writeRaw method via regular Writer interface.

public final Writer
wrapAsTextWriter()

Method that can be called to get a wrapper instance that can be used to essentially call the writeCharacters method via regular Writer interface.

public abstract void
writeAttribute(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 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
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
writeCharacters(Characters ch)

Method called by javax.xml.stream.XMLEventWriter (instead of more generic text output methods), so that we can verify (if necessary) that this character output type is legal in this context.

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 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
writeDTD(String
the DTD to be written
dtd
)

Implements javax.xml.stream.XMLStreamWriter.writeDTD.

Write a DTD section.

public void
public void
public abstract void
writeEmptyElement(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 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 abstract void
writeEndElement()

Redeclares 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 abstract void
writeEndElement(QName name)

Method called by javax.xml.stream.XMLEventWriter (instead of the version that takes no argument), so that we can verify it does match the start element if necessary.

public void
writeEntityRef(String
the name of the entity
name
)

Implements javax.xml.stream.XMLStreamWriter.writeEntityRef.

Writes an entity reference

public abstract void
writeFullEndElement()

Redeclares org.codehaus.stax2.XMLStreamWriter2.writeFullEndElement.

Overrides org.codehaus.stax2.ri.Stax2WriterImpl.writeFullEndElement.

Method similar to writeEndElement, but that will always write the full end element, instead of empty element.

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
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 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
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[] text, int offset, int length)

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 abstract void
writeStartElement(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 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
writeStartElement(StartElement elem)

Convenience method needed by javax.xml.stream.XMLEventWriter implementation, to use when writing a start element, and possibly its attributes and namespace declarations.

Inherited from org.codehaus.stax2.ri.Stax2WriterImpl:
copyStartElement