Class RepairingNsStreamWriter
java.lang.Object
org.codehaus.stax2.ri.Stax2WriterImpl
com.ctc.wstx.sw.BaseStreamWriter
com.ctc.wstx.sw.TypedStreamWriter
com.ctc.wstx.sw.BaseNsStreamWriter
com.ctc.wstx.sw.RepairingNsStreamWriter
- All Implemented Interfaces:
OutputConfigFlags, XMLStreamConstants, XMLStreamWriter, org.codehaus.stax2.typed.TypedXMLStreamWriter, org.codehaus.stax2.validation.Validatable, org.codehaus.stax2.validation.ValidationContext, org.codehaus.stax2.XMLStreamWriter2
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
FieldsModifier and TypeFieldDescriptionprotected final Stringprotected int[]Sequence number used for generating dynamic namespace prefixes.protected StringMap that contains URI-to-prefix entries that point out suggested prefixes for URIs.Fields inherited from class BaseNsStreamWriter
ERR_NSDECL_WRONG_STATE, mAutomaticNS, MAX_POOL_SIZE, mCurrElem, mEmptyElementHandler, mOutputElemPool, mPoolSize, mRootNsContext, sPrefixXml, sPrefixXmlnsFields inherited from class TypedStreamWriter
mValueEncoderFactoryFields inherited from class BaseStreamWriter
ATTR_MIN_ARRAYCOPY, CHAR_SPACE, DEFAULT_COPYBUFFER_LEN, mAnyOutput, mCfgAutomaticEmptyElems, mCfgCDataAsText, mCfgCopyDefaultAttrs, mCheckAttrs, mCheckStructure, mConfig, mCopyBuffer, mDtdRootElem, mEmptyElement, mEncoding, MIN_ARRAYCOPY, mReturnNullForDefaultNamespace, mStartElementOpen, mState, mValidator, mVldContent, mVldProbHandler, mWriter, mXml11, STATE_EPILOG, STATE_PROLOG, STATE_TREEFields inherited from interface OutputConfigFlags
CFG_ADD_SPACE_AFTER_EMPTY_ELEM, CFG_AUTO_CLOSE_OUTPUT, CFG_AUTOMATIC_EMPTY_ELEMENTS, CFG_AUTOMATIC_END_ELEMENTS, CFG_AUTOMATIC_NS, CFG_COPY_DEFAULT_ATTRS, CFG_ENABLE_NS, CFG_ESCAPE_CR, CFG_FIX_CONTENT, CFG_OUTPUT_CDATA_AS_TEXT, CFG_USE_DOUBLE_QUOTES_IN_XML_DECL, CFG_VALIDATE_ATTR, CFG_VALIDATE_CONTENT, CFG_VALIDATE_NAMES, CFG_VALIDATE_STRUCTUREFields inherited from interface XMLStreamConstants
ATTRIBUTE, CDATA, CHARACTERS, COMMENT, DTD, END_DOCUMENT, END_ELEMENT, ENTITY_DECLARATION, ENTITY_REFERENCE, NAMESPACE, NOTATION_DECLARATION, PROCESSING_INSTRUCTION, SPACE, START_DOCUMENT, START_ELEMENT -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal voidcopyStartElement(InputElementStack elemStack, AttributeCollector ac) Element copier method implementation suitable for use with namespace-aware writers in repairing mode.voiddoSetPrefix(String prefix, String uri) protected final StringfindElemPrefix(String nsURI, SimpleOutputElement elem) Method called to find an existing prefix for the given namespace, if any exists in the scope.protected final StringfindOrCreateAttrPrefix(String suggPrefix, String nsURI, SimpleOutputElement 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 StringgenerateElemPrefix(String suggPrefix, String nsURI, SimpleOutputElement elem) Method called afterfindElemPrefix(String, SimpleOutputElement)has returned null, to create and bind a namespace mapping for specified namespace.voidWith repairing writer, this is only taken as a suggestion as to how the caller would prefer prefixes to be mapped.private final StringvalidateElemPrefix(String prefix, String nsURI, SimpleOutputElement elem) validateQNamePrefix(QName name) Method called before writing a QName via Typed Access API.voidwriteAttribute(String nsURI, String localName, String value) voidwriteAttribute(String prefix, String nsURI, String localName, String value) voidwriteDefaultNamespace(String nsURI) voidwriteNamespace(String prefix, String nsURI) voidConvenience method needed byXMLEventWriterimplementation, to use when writing a start element, and possibly its attributes and namespace declarations.protected voidwriteStartOrEmpty(String localName, String nsURI) protected voidwriteStartOrEmpty(String suggPrefix, String localName, String nsURI) protected voidwriteTypedAttribute(String prefix, String nsURI, String localName, org.codehaus.stax2.ri.typed.AsciiValueEncoder enc) Method that will write attribute with value that is known not to require additional escaping.Methods inherited from class BaseNsStreamWriter
checkStartElement, closeStartElement, doWriteAttr, doWriteAttr, doWriteDefaultNs, doWriteEndTag, doWriteNamespace, doWriteStartTag, doWriteStartTag, getCurrentElementName, getNamespaceContext, getNamespaceURI, getPrefix, getTopElementDesc, setNamespaceContext, setPrefix, writeAttribute, writeEmptyElement, writeEmptyElement, writeEmptyElement, writeEndElement, writeEndElement, writeFullEndElement, writeStartElement, writeStartElement, writeStartElementMethods inherited from class TypedStreamWriter
valueEncoderFactory, writeBinary, writeBinary, writeBinaryAttribute, writeBinaryAttribute, writeBoolean, writeBooleanAttribute, writeDecimal, writeDecimalAttribute, writeDouble, writeDoubleArray, writeDoubleArrayAttribute, writeDoubleAttribute, writeFloat, writeFloatArray, writeFloatArrayAttribute, writeFloatAttribute, writeInt, writeIntArray, writeIntArrayAttribute, writeIntAttribute, writeInteger, writeIntegerAttribute, writeLong, writeLongArray, writeLongArrayAttribute, writeLongAttribute, writeQName, writeQNameAttribute, writeTypedElementMethods inherited from class BaseStreamWriter
addDefaultAttribute, close, closeCompletely, copyEventFromReader, doReportProblem, doReportProblem, doWriteStartDocument, findAttributeIndex, flush, getAttributeCount, getAttributeLocalName, getAttributeNamespace, getAttributePrefix, getAttributeType, getAttributeValue, getAttributeValue, getBaseUri, getCopyBuffer, getCopyBuffer, getEncoding, getLocation, getProperty, getValidationLocation, getXmlVersion, inPrologOrEpilog, isNotationDeclared, isPropertySupported, isUnparsedEntityDeclared, isValidating, reportIllegalArg, reportIllegalMethod, reportInvalidContent, reportNwfAttr, reportNwfAttr, reportNwfContent, reportNwfContent, reportNwfStructure, reportNwfStructure, reportProblem, reportValidationProblem, reportValidationProblem, reportValidationProblem, reportValidationProblem, reportValidationProblem, reportValidationProblem, setProperty, setValidationProblemHandler, stopValidatingAgainst, stopValidatingAgainst, throwFromIOE, throwOutputError, throwOutputError, toString, validateAgainst, verifyRootElement, verifyWriteCData, verifyWriteDTD, wrapAsRawWriter, wrapAsTextWriter, writeCData, writeCData, writeCharacters, writeCharacters, writeCharacters, writeComment, writeDTD, writeDTD, writeDTD, writeEndDocument, writeEntityRef, writeProcessingInstruction, writeProcessingInstruction, writeRaw, writeRaw, writeRaw, writeSpace, writeSpace, writeStartDocument, writeStartDocument, writeStartDocument, writeStartDocumentMethods inherited from class org.codehaus.stax2.ri.Stax2WriterImpl
copyStartElement
-
Field Details
-
mAutomaticNsPrefix
-
mAutoNsSeq
protected int[] mAutoNsSeqSequence number used for generating dynamic namespace prefixes. Array used as a wrapper to allow for easy sharing of the sequence number. -
mSuggestedDefNs
-
mSuggestedPrefixes
Map that contains URI-to-prefix entries that point out suggested prefixes for URIs. These are populated by calls toBaseNsStreamWriter.setPrefix(String, String), and they are only used as hints for binding; if there are conflicts, repairing writer can just use some other prefix.
-
-
Constructor Details
-
RepairingNsStreamWriter
-
-
Method Details
-
writeAttribute
- Specified by:
writeAttributein interfaceXMLStreamWriter- Specified by:
writeAttributein classBaseNsStreamWriter- Throws:
XMLStreamException
-
writeAttribute
public void writeAttribute(String prefix, String nsURI, String localName, String value) throws XMLStreamException - Specified by:
writeAttributein interfaceXMLStreamWriter- Specified by:
writeAttributein classBaseNsStreamWriter- Throws:
XMLStreamException
-
writeDefaultNamespace
- Specified by:
writeDefaultNamespacein interfaceXMLStreamWriter- Specified by:
writeDefaultNamespacein classBaseNsStreamWriter- Throws:
XMLStreamException
-
writeNamespace
- Specified by:
writeNamespacein interfaceXMLStreamWriter- Specified by:
writeNamespacein classBaseNsStreamWriter- Throws:
XMLStreamException
-
setDefaultNamespace
With repairing writer, this is only taken as a suggestion as to how the caller would prefer prefixes to be mapped.- Specified by:
setDefaultNamespacein interfaceXMLStreamWriter- Specified by:
setDefaultNamespacein classBaseNsStreamWriter- Throws:
XMLStreamException
-
doSetPrefix
- Specified by:
doSetPrefixin classBaseNsStreamWriter- Throws:
XMLStreamException
-
writeStartElement
Description copied from class:BaseStreamWriterConvenience method needed byXMLEventWriterimplementation, to use when writing a start element, and possibly its attributes and namespace declarations.- Specified by:
writeStartElementin classBaseNsStreamWriter- Throws:
XMLStreamException
-
writeTypedAttribute
protected void writeTypedAttribute(String prefix, String nsURI, String localName, org.codehaus.stax2.ri.typed.AsciiValueEncoder enc) throws XMLStreamException Description copied from class:TypedStreamWriterMethod that will write attribute with value that is known not to require additional escaping.- Overrides:
writeTypedAttributein classBaseNsStreamWriter- Throws:
XMLStreamException
-
writeStartOrEmpty
- Specified by:
writeStartOrEmptyin classBaseNsStreamWriter- Throws:
XMLStreamException
-
writeStartOrEmpty
protected void writeStartOrEmpty(String suggPrefix, String localName, String nsURI) throws XMLStreamException - Specified by:
writeStartOrEmptyin classBaseNsStreamWriter- Throws:
XMLStreamException
-
copyStartElement
public final void copyStartElement(InputElementStack elemStack, AttributeCollector ac) throws IOException, XMLStreamException Element copier method implementation suitable for use with namespace-aware writers in repairing mode. The trickiest thing is having to properly order calls tosetPrefix,writeNamespaceandwriteStartElement; the order writers expect is bit different from the order in which element information is passed in.- Specified by:
copyStartElementin classBaseStreamWriter- Throws:
IOExceptionXMLStreamException
-
validateQNamePrefix
Description copied from class:BaseStreamWriterMethod 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- Specified by:
validateQNamePrefixin classBaseStreamWriter- Returns:
- Prefix to use when writing out given QName as an element or attribute value
- Throws:
XMLStreamException
-
findElemPrefix
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- URI of namespace for which we need a prefix- Throws:
XMLStreamException
-
generateElemPrefix
protected final String generateElemPrefix(String suggPrefix, String nsURI, SimpleOutputElement elem) throws XMLStreamException Method called afterfindElemPrefix(String, SimpleOutputElement)has returned null, to create and bind a namespace mapping for specified namespace.- Throws:
XMLStreamException
-
findOrCreateAttrPrefix
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- Suggested prefix to bind, if any; may be null to indicate "no preference"nsURI- URI of namespace for which we need a prefixelem- Currently open start element, on which the attribute will be added.- Throws:
XMLStreamException
-
validateElemPrefix
private final String validateElemPrefix(String prefix, String nsURI, SimpleOutputElement elem) throws XMLStreamException - Throws:
XMLStreamException
-