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

public final Class RepairingStreamWriter

extends StreamWriterBase
Class Inheritance
Imports
java.util.*, javax.xml.namespace.QName, javax.xml.stream.*, org.codehaus.stax2.ri.typed.AsciiValueEncoder, com.fasterxml.aalto.impl.ErrorConsts

Concrete implementation of StreamWriterBase, which implements the "namespace repairing" mode of operation. This means that the writer ensures correctness and validity of namespace bindings, as based on namespace URIs caller passes, by adding necessary namespace declarations and using prefixes as required to obtain expected results.

Field Summary

Modifier and TypeField and Description
pack-priv int[]
_autoNsSeq

Sequence number used for generating dynamic namespace prefixes.

pack-priv final String
pack-priv String
pack-priv HashMap<String, String>
_suggestedPrefixes

Map that contains URI-to-prefix entries that point out suggested prefixes for URIs.

Inherited from com.fasterxml.aalto.out.StreamWriterBase:
_cfgCDataAsText_cfgCheckAttrs_cfgCheckContent_cfgCheckStructure_config_currElem_dtdRootElemName_outputElemPool_poolSize_rootNsContext_state_stateAnyOutput_stateEmptyElement_stateStartElementOpen_symbols_validator_valueEncoderFactory_vldContent_vldProblemHandler_xmlWriterMAX_POOL_SIZE

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected WName
_generateAttrName(String suggPrefix, String localName, String
Non-empty namespace URI that will be used for the attribute
uri
)

protected final String
_generateElemPrefix(String uri)

Method called if given URI is not yet bound, and no suggested prefix is given (or one given can't be used).

protected String
public void
private final boolean

Returns:

True, if prefix indicates default namespace (is null or empty); false otherwise
_writeStartAndVerify
(String prefix, String localName, String nsURI, boolean isEmpty)

public void
_writeStartOrEmpty(String prefix, String localName, String nsURI, boolean isEmpty)

public void
setDefaultNamespace(String
the uri to bind to the default namespace, may be null
uri
)

Implements abstract com.fasterxml.aalto.out.StreamWriterBase.setDefaultNamespace.

Implements javax.xml.stream.XMLStreamWriter.setDefaultNamespace.

With repairing writer, this is only taken as a suggestion as to how the caller would prefer prefixes to be mapped.
public 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
)

Implements abstract com.fasterxml.aalto.out.StreamWriterBase.writeAttribute.

Implements javax.xml.stream.XMLStreamWriter.writeAttribute.

Writes an attribute to the output stream
public 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
)

Implements abstract com.fasterxml.aalto.out.StreamWriterBase.writeAttribute.

Implements javax.xml.stream.XMLStreamWriter.writeAttribute.

Writes an attribute to the output stream
public void
writeDefaultNamespace(String
the uri to bind the default namespace to
nsURI
)

Implements abstract com.fasterxml.aalto.out.StreamWriterBase.writeDefaultNamespace.

Implements javax.xml.stream.XMLStreamWriter.writeDefaultNamespace.

Writes the default namespace to the stream
public 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
)

Implements abstract com.fasterxml.aalto.out.StreamWriterBase.writeEmptyElement.

Implements javax.xml.stream.XMLStreamWriter.writeEmptyElement.

Writes an empty element tag to the output
public 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
)

Implements abstract com.fasterxml.aalto.out.StreamWriterBase.writeEmptyElement.

Implements javax.xml.stream.XMLStreamWriter.writeEmptyElement.

Writes an empty element tag to the output
public void
writeNamespace(String
the prefix to bind this namespace to
prefix
,
String
the uri to bind the prefix to
nsURI
)

Implements abstract com.fasterxml.aalto.out.StreamWriterBase.writeNamespace.

Implements 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
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
)

Implements abstract com.fasterxml.aalto.out.StreamWriterBase.writeStartElement.

Implements javax.xml.stream.XMLStreamWriter.writeStartElement.

Writes a start tag to the output
public 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
)

Implements abstract com.fasterxml.aalto.out.StreamWriterBase.writeStartElement.

Implements javax.xml.stream.XMLStreamWriter.writeStartElement.

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

Implements abstract com.fasterxml.aalto.out.StreamWriterBase.writeTypedAttribute.

Need to leave implementation of this method abstract, because repairing and non-repairing modes differ in how names are handled.
Inherited from com.fasterxml.aalto.out.StreamWriterBase:
_closeStartElement_reportInvalidContent_reportNwfAttr_reportNwfAttr_reportNwfContent_reportNwfContent_reportNwfName_reportNwfStructure_reportNwfStructure_reportValidationProblem_verifyRootElement_verifyStartElement_verifyWriteAttr_verifyWriteCData_verifyWriteDTD_writeAttribute_writeAttribute_writeDefaultNamespace_writeNamespace_writeStartDocument_writeStartTag_writeStartTagaddDefaultAttributeclosecloseCompletelyfindAttributeIndexflushgetAttributeCountgetAttributeLocalNamegetAttributeNamespacegetAttributePrefixgetAttributeTypegetAttributeValuegetAttributeValuegetBaseUrigetCurrentElementNamegetEncodinggetLocationgetNamespaceContextgetNamespaceURIgetPrefixgetPrefixesgetPropertygetValidationLocationgetXmlVersioninPrologOrEpilogisNotationDeclaredisPropertySupportedisUnparsedEntityDeclaredreportIllegalArgreportIllegalMethodreportProblemsetNamespaceContextsetPrefixsetPropertysetValidationProblemHandlerstopValidatingAgainststopValidatingAgainstthrowFromIOEthrowOutputErrorthrowOutputErrortoStringvalidateAgainstvalueEncoderFactorywriteAttributewriteBinarywriteBinarywriteBinaryAttributewriteBinaryAttributewriteBooleanwriteBooleanAttributewriteCDatawriteCDatawriteCharacterswriteCharacterswriteCommentwriteDecimalwriteDecimalAttributewriteDoublewriteDoubleArraywriteDoubleArrayAttributewriteDoubleAttributewriteDTDwriteDTDwriteDTDwriteEmptyElementwriteEndDocumentwriteEndElementwriteEntityRefwriteFloatwriteFloatArraywriteFloatArrayAttributewriteFloatAttributewriteFullEndElementwriteIntwriteIntArraywriteIntArrayAttributewriteIntAttributewriteIntegerwriteIntegerAttributewriteLongwriteLongArraywriteLongArrayAttributewriteLongAttributewriteProcessingInstructionwriteProcessingInstructionwriteQNamewriteQNameAttributewriteRawwriteRawwriteRawwriteSpacewriteSpacewriteStartDocumentwriteStartDocumentwriteStartDocumentwriteStartDocumentwriteStartElement

Field Detail

_autoNsSeqback to summary
pack-priv int[] _autoNsSeq

Sequence number used for generating dynamic namespace prefixes. Array used as a wrapper to allow for easy sharing of the sequence number.

_cfgAutomaticNsPrefixback to summary
pack-priv final String _cfgAutomaticNsPrefix
_suggestedDefNsback to summary
pack-priv String _suggestedDefNs
_suggestedPrefixesback to summary
pack-priv HashMap<String, String> _suggestedPrefixes

Map that contains URI-to-prefix entries that point out suggested prefixes for URIs. These are populated by calls to setPrefix, and they are only used as hints for binding; if there are conflicts, repairing writer can just use some other prefix.

Constructor Detail

RepairingStreamWriterback to summary
public RepairingStreamWriter(WriterConfig cfg, XmlWriter writer, WNameTable symbols)

Method Detail

_generateAttrNameback to summary
protected WName _generateAttrName(String suggPrefix, String localName, String uri) throws XMLStreamException
Parameters
uri:String

Non-empty namespace URI that will be used for the attribute

_generateElemPrefixback to summary
protected final String _generateElemPrefix(String uri) throws XMLStreamException

Method called if given URI is not yet bound, and no suggested prefix is given (or one given can't be used). If so, methods is to create a not-yet-bound-prefix for the namespace.

_serializeQNameback to summary
protected String _serializeQName(QName name) throws XMLStreamException

Implements abstract com.fasterxml.aalto.out.StreamWriterBase._serializeQName.

Annotations
@Override
_setPrefixback to summary
public void _setPrefix(String prefix, String uri)

Implements abstract com.fasterxml.aalto.out.StreamWriterBase._setPrefix.

Annotations
@Override
_writeStartAndVerifyback to summary
private final boolean _writeStartAndVerify(String prefix, String localName, String nsURI, boolean isEmpty) throws XMLStreamException
Returns:boolean

True, if prefix indicates default namespace (is null or empty); false otherwise

_writeStartOrEmptyback to summary
public void _writeStartOrEmpty(String prefix, String localName, String nsURI, boolean isEmpty) throws XMLStreamException
setDefaultNamespaceback to summary
public void setDefaultNamespace(String uri) throws XMLStreamException

Implements abstract com.fasterxml.aalto.out.StreamWriterBase.setDefaultNamespace.

Implements javax.xml.stream.XMLStreamWriter.setDefaultNamespace.

With repairing writer, this is only taken as a suggestion as to how the caller would prefer prefixes to be mapped.

Parameters
uri:String

Doc from javax.xml.stream.XMLStreamWriter.setDefaultNamespace.

the uri to bind to the default namespace, may be null

Annotations
@Override
Exceptions
XMLStreamException:

Doc from javax.xml.stream.XMLStreamWriter.setDefaultNamespace.

if an error occurs

writeAttributeback to summary
public void writeAttribute(String nsURI, String localName, String value) throws XMLStreamException

Implements abstract com.fasterxml.aalto.out.StreamWriterBase.writeAttribute.

Implements javax.xml.stream.XMLStreamWriter.writeAttribute.

Doc from javax.xml.stream.XMLStreamWriter.writeAttribute.

Writes an attribute to the output stream

Parameters
nsURI:String

the uri of the prefix for this attribute

localName:String

the local name of the attribute

value:String

the value of the attribute

Annotations
@Override
Exceptions
XMLStreamException:
if the namespace URI has not been bound to a prefix and javax.xml.stream.isRepairingNamespaces has not been set to true
writeAttributeback to summary
public void writeAttribute(String prefix, String nsURI, String localName, String value) throws XMLStreamException

Implements abstract com.fasterxml.aalto.out.StreamWriterBase.writeAttribute.

Implements javax.xml.stream.XMLStreamWriter.writeAttribute.

Doc from javax.xml.stream.XMLStreamWriter.writeAttribute.

Writes an attribute to the output stream

Parameters
prefix:String

the prefix for this attribute

nsURI:String

the uri of the prefix for this attribute

localName:String

the local name of the attribute

value:String

the value of the attribute

Annotations
@Override
Exceptions
XMLStreamException:
if the namespace URI has not been bound to a prefix and javax.xml.stream.isRepairingNamespaces has not been set to true
writeDefaultNamespaceback to summary
public void writeDefaultNamespace(String nsURI) throws XMLStreamException

Implements abstract com.fasterxml.aalto.out.StreamWriterBase.writeDefaultNamespace.

Implements javax.xml.stream.XMLStreamWriter.writeDefaultNamespace.

Doc from javax.xml.stream.XMLStreamWriter.writeDefaultNamespace.

Writes the default namespace to the stream

Parameters
nsURI:String

the uri to bind the default namespace to

Annotations
@Override
Exceptions
XMLStreamException:
if an error occurs
writeEmptyElementback to summary
public void writeEmptyElement(String nsURI, String localName) throws XMLStreamException

Implements abstract com.fasterxml.aalto.out.StreamWriterBase.writeEmptyElement.

Implements javax.xml.stream.XMLStreamWriter.writeEmptyElement.

Doc from javax.xml.stream.XMLStreamWriter.writeEmptyElement.

Writes an empty element tag to the output

Parameters
nsURI:String

the uri to bind the tag to, may not be null

localName:String

local name of the tag, may not be null

Annotations
@Override
Exceptions
XMLStreamException:
if the namespace URI has not been bound to a prefix and javax.xml.stream.isRepairingNamespaces has not been set to true
writeEmptyElementback to summary
public void writeEmptyElement(String prefix, String localName, String nsURI) throws XMLStreamException

Implements abstract com.fasterxml.aalto.out.StreamWriterBase.writeEmptyElement.

Implements javax.xml.stream.XMLStreamWriter.writeEmptyElement.

Doc from javax.xml.stream.XMLStreamWriter.writeEmptyElement.

Writes an empty element tag to the output

Parameters
prefix:String

the prefix of the tag, may not be null

localName:String

local name of the tag, may not be null

nsURI:String

the uri to bind the tag to, may not be null

Annotations
@Override
Exceptions
XMLStreamException:
if an error occurs
writeNamespaceback to summary
public void writeNamespace(String prefix, String nsURI) throws XMLStreamException

Implements abstract com.fasterxml.aalto.out.StreamWriterBase.writeNamespace.

Implements javax.xml.stream.XMLStreamWriter.writeNamespace.

Doc from 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

Parameters
prefix:String

the prefix to bind this namespace to

nsURI:String

the uri to bind the prefix to

Annotations
@Override
Exceptions
XMLStreamException:
if an error occurs
writeStartElementback to summary
public void writeStartElement(String nsURI, String localName) throws XMLStreamException

Implements abstract com.fasterxml.aalto.out.StreamWriterBase.writeStartElement.

Implements javax.xml.stream.XMLStreamWriter.writeStartElement.

Doc from javax.xml.stream.XMLStreamWriter.writeStartElement.

Writes a start tag to the output

Parameters
nsURI:String

the namespaceURI of the prefix to use, may not be null

localName:String

local name of the tag, may not be null

Annotations
@Override
Exceptions
XMLStreamException:
if the namespace URI has not been bound to a prefix and javax.xml.stream.isRepairingNamespaces has not been set to true
writeStartElementback to summary
public void writeStartElement(String prefix, String localName, String nsURI) throws XMLStreamException

Implements abstract com.fasterxml.aalto.out.StreamWriterBase.writeStartElement.

Implements javax.xml.stream.XMLStreamWriter.writeStartElement.

Doc from javax.xml.stream.XMLStreamWriter.writeStartElement.

Writes a start tag to the output

Parameters
prefix:String

the prefix of the tag, may not be null

localName:String

local name of the tag, may not be null

nsURI:String

the uri to bind the prefix to, may not be null

Annotations
@Override
Exceptions
XMLStreamException:
if an error occurs
writeTypedAttributeback to summary
public void writeTypedAttribute(String prefix, String nsURI, String localName, AsciiValueEncoder enc) throws XMLStreamException

Implements abstract com.fasterxml.aalto.out.StreamWriterBase.writeTypedAttribute.

Doc from com.fasterxml.aalto.out.StreamWriterBase.writeTypedAttribute.

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

Annotations
@Override