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

public final Class RepairingNsStreamWriter

extends BaseNsStreamWriter
Class Inheritance
Imports
java.io.IOException, java.util.HashMap, .Iterator, .Map, javax.xml.namespace.QName, javax.xml.stream.XMLStreamWriter, .XMLStreamException, javax.xml.stream.events.Attribute, .StartElement, org.codehaus.stax2.ri.typed.AsciiValueEncoder, com.ctc.wstx.api.WriterConfig, com.ctc.wstx.cfg.ErrorConsts, com.ctc.wstx.sr.AttributeCollector, .InputElementStack

Namespace-aware implementation of XMLStreamWriter, that does namespace repairing, ie resolves possible conflicts between prefixes (add new bindings as necessary), as well as automatically creates namespace declarations as necessary.

Field Summary

Modifier and TypeField and Description
protected final String
protected int[]
mAutoNsSeq

Sequence number used for generating dynamic namespace prefixes.

protected String
protected HashMap<String, String>
mSuggestedPrefixes

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

Inherited from com.ctc.wstx.sw.BaseNsStreamWriter:
ERR_NSDECL_WRONG_STATEmAutomaticNSMAX_POOL_SIZEmCurrElemmEmptyElementHandlermOutputElemPoolmPoolSizemRootNsContextsPrefixXmlsPrefixXmlns

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public final void
copyStartElement(InputElementStack elemStack, AttributeCollector ac)

Implements abstract com.ctc.wstx.sw.BaseStreamWriter.copyStartElement.

Element copier method implementation suitable for use with namespace-aware writers in repairing mode.

public void
protected final String
findElemPrefix(String
URI of namespace for which we need a prefix
nsURI
,
SimpleOutputElement elem)

Method called to find an existing prefix for the given namespace, if any exists in the scope.

protected final String
findOrCreateAttrPrefix(String
Suggested prefix to bind, if any; may be null to indicate "no preference"
suggPrefix
,
String
URI of namespace for which we need a prefix
nsURI
,
SimpleOutputElement
Currently open start element, on which the attribute will be added.
elem
)

Method called to somehow find a prefix for given namespace, to be used for a new start element; either use an existing one, or generate a new one.

protected final String
generateElemPrefix(String suggPrefix, String nsURI, SimpleOutputElement elem)

Method called after findElemPrefix has returned null, to create and bind a namespace mapping for specified namespace.

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

Implements abstract com.ctc.wstx.sw.BaseNsStreamWriter.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.

private final String
public String
validateQNamePrefix(QName name)

Implements abstract com.ctc.wstx.sw.BaseStreamWriter.validateQNamePrefix.

Method called before writing a QName via Typed Access API.

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.ctc.wstx.sw.BaseNsStreamWriter.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.ctc.wstx.sw.BaseNsStreamWriter.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.ctc.wstx.sw.BaseNsStreamWriter.writeDefaultNamespace.

Implements javax.xml.stream.XMLStreamWriter.writeDefaultNamespace.

Writes the default namespace to the stream

public void
writeNamespace(String
the prefix to bind this namespace to
prefix
,
String
the uri to bind the prefix to
nsURI
)

Implements abstract com.ctc.wstx.sw.BaseNsStreamWriter.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(StartElement elem)

Implements abstract com.ctc.wstx.sw.BaseNsStreamWriter.writeStartElement.

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

protected void
protected void
protected void
writeTypedAttribute(String prefix, String nsURI, String localName, AsciiValueEncoder enc)

Overrides com.ctc.wstx.sw.BaseNsStreamWriter.writeTypedAttribute.

Method that will write attribute with value that is known not to require additional escaping.

Inherited from com.ctc.wstx.sw.BaseNsStreamWriter:
checkStartElementcloseStartElementdoWriteAttrdoWriteAttrdoWriteDefaultNsdoWriteEndTagdoWriteNamespacedoWriteStartTagdoWriteStartTaggetCurrentElementNamegetNamespaceContextgetNamespaceURIgetPrefixgetTopElementDescsetNamespaceContextsetPrefixwriteAttributewriteEmptyElementwriteEmptyElementwriteEmptyElementwriteEndElementwriteEndElementwriteFullEndElementwriteStartElementwriteStartElementwriteStartElement

Field Detail

mAutomaticNsPrefixback to summary
protected final String mAutomaticNsPrefix
mAutoNsSeqback to summary
protected int[] mAutoNsSeq

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

mSuggestedDefNsback to summary
protected String mSuggestedDefNs
mSuggestedPrefixesback to summary
protected HashMap<String, String> mSuggestedPrefixes

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

RepairingNsStreamWriterback to summary
public RepairingNsStreamWriter(XmlWriter xw, String enc, WriterConfig cfg)

Method Detail

copyStartElementback to summary
public final void copyStartElement(InputElementStack elemStack, AttributeCollector ac) throws IOException, XMLStreamException

Implements abstract com.ctc.wstx.sw.BaseStreamWriter.copyStartElement.

Element copier method implementation suitable for use with namespace-aware writers in repairing mode. The trickiest thing is having to properly order calls to setPrefix, writeNamespace and writeStartElement; the order writers expect is bit different from the order in which element information is passed in.

Annotations
@Override
doSetPrefixback to summary
public void doSetPrefix(String prefix, String uri) throws XMLStreamException

Implements abstract com.ctc.wstx.sw.BaseNsStreamWriter.doSetPrefix.

Annotations
@Override
findElemPrefixback to summary
protected final String findElemPrefix(String nsURI, SimpleOutputElement elem) throws XMLStreamException

Method called to find an existing prefix for the given namespace, if any exists in the scope. If one is found, it's returned (including "" for the current default namespace); if not, null is returned.

Parameters
nsURI:String

URI of namespace for which we need a prefix

findOrCreateAttrPrefixback to summary
protected final String findOrCreateAttrPrefix(String suggPrefix, String nsURI, SimpleOutputElement elem) throws XMLStreamException

Method called to somehow find a prefix for given namespace, to be used for a new start element; either use an existing one, or generate a new one. If a new mapping needs to be generated, it will also be automatically bound, and necessary namespace declaration output.

Parameters
suggPrefix:String

Suggested prefix to bind, if any; may be null to indicate "no preference"

nsURI:String

URI of namespace for which we need a prefix

elem:SimpleOutputElement

Currently open start element, on which the attribute will be added.

generateElemPrefixback to summary
protected final String generateElemPrefix(String suggPrefix, String nsURI, SimpleOutputElement elem) throws XMLStreamException

Method called after findElemPrefix has returned null, to create and bind a namespace mapping for specified namespace.

setDefaultNamespaceback to summary
public void setDefaultNamespace(String uri) throws XMLStreamException

Implements abstract com.ctc.wstx.sw.BaseNsStreamWriter.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

validateElemPrefixback to summary
private final String validateElemPrefix(String prefix, String nsURI, SimpleOutputElement elem) throws XMLStreamException
validateQNamePrefixback to summary
public String validateQNamePrefix(QName name) throws XMLStreamException

Implements abstract com.ctc.wstx.sw.BaseStreamWriter.validateQNamePrefix.

Doc from com.ctc.wstx.sw.BaseStreamWriter.validateQNamePrefix.

Method called before writing a QName via Typed Access API. In namespace-repairing mode it should take appropriate actions to ensure that the given namespace URI is bound to a namespace and return whatever it maps to. In non-repairing work no additional work is to be done and methods

Returns:String

Prefix to use when writing out given QName as an element or attribute value

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

Implements abstract com.ctc.wstx.sw.BaseNsStreamWriter.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.ctc.wstx.sw.BaseNsStreamWriter.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.ctc.wstx.sw.BaseNsStreamWriter.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
writeNamespaceback to summary
public void writeNamespace(String prefix, String nsURI) throws XMLStreamException

Implements abstract com.ctc.wstx.sw.BaseNsStreamWriter.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(StartElement elem) throws XMLStreamException

Implements abstract com.ctc.wstx.sw.BaseNsStreamWriter.writeStartElement.

Doc from com.ctc.wstx.sw.BaseStreamWriter.writeStartElement.

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

Annotations
@Override
writeStartOrEmptyback to summary
protected void writeStartOrEmpty(String localName, String nsURI) throws XMLStreamException

Implements abstract com.ctc.wstx.sw.BaseNsStreamWriter.writeStartOrEmpty.

Annotations
@Override
writeStartOrEmptyback to summary
protected void writeStartOrEmpty(String suggPrefix, String localName, String nsURI) throws XMLStreamException

Implements abstract com.ctc.wstx.sw.BaseNsStreamWriter.writeStartOrEmpty.

Annotations
@Override
writeTypedAttributeback to summary
protected void writeTypedAttribute(String prefix, String nsURI, String localName, AsciiValueEncoder enc) throws XMLStreamException

Overrides com.ctc.wstx.sw.BaseNsStreamWriter.writeTypedAttribute.

Doc from com.ctc.wstx.sw.TypedStreamWriter.writeTypedAttribute.

Method that will write attribute with value that is known not to require additional escaping.

Annotations
@Override